forked from MapComplete/MapComplete
Detect an element that is deleted upstream; show 'this element is deleted in infopanel'
This commit is contained in:
parent
c9f6b93add
commit
5e1b4d95ab
3 changed files with 41 additions and 11 deletions
|
@ -1,11 +1,11 @@
|
||||||
/**
|
/**
|
||||||
* This actor will download the latest version of the selected element from OSM and update the tags if necessary.
|
* This actor will download the latest version of the selected element from OSM and update the tags if necessary.
|
||||||
*/
|
*/
|
||||||
import { UIEventSource } from "../UIEventSource"
|
import {UIEventSource} from "../UIEventSource"
|
||||||
import { ElementStorage } from "../ElementStorage"
|
import {ElementStorage} from "../ElementStorage"
|
||||||
import { Changes } from "../Osm/Changes"
|
import {Changes} from "../Osm/Changes"
|
||||||
import { OsmObject } from "../Osm/OsmObject"
|
import {OsmObject} from "../Osm/OsmObject"
|
||||||
import { OsmConnection } from "../Osm/OsmConnection"
|
import {OsmConnection} from "../Osm/OsmConnection"
|
||||||
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig"
|
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig"
|
||||||
import SimpleMetaTagger from "../SimpleMetaTagger"
|
import SimpleMetaTagger from "../SimpleMetaTagger"
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ export default class SelectedElementTagsUpdater {
|
||||||
osmConnection: OsmConnection
|
osmConnection: OsmConnection
|
||||||
layoutToUse: LayoutConfig
|
layoutToUse: LayoutConfig
|
||||||
}) {
|
}) {
|
||||||
state.selectedElement.addCallbackAndRunD((s) => {
|
state.selectedElement.addCallbackAndRunD(async (s) => {
|
||||||
let id = s.properties?.id
|
let id = s.properties?.id
|
||||||
|
|
||||||
const backendUrl = state.osmConnection._oauth_config.url
|
const backendUrl = state.osmConnection._oauth_config.url
|
||||||
|
@ -58,9 +58,24 @@ export default class SelectedElementTagsUpdater {
|
||||||
// This is a new object
|
// This is a new object
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
OsmObject.DownloadPropertiesOf(id).then((latestTags) => {
|
try {
|
||||||
|
|
||||||
|
const latestTags = await OsmObject.DownloadPropertiesOf(id)
|
||||||
|
if (latestTags === "deleted") {
|
||||||
|
console.warn("The current selected element has been deleted upstream!")
|
||||||
|
const currentTagsSource = state.allElements.getEventSourceById(id)
|
||||||
|
if(currentTagsSource.data["_deleted"] === "yes"){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
currentTagsSource.data["_deleted"] = "yes"
|
||||||
|
currentTagsSource.ping()
|
||||||
|
return;
|
||||||
|
}
|
||||||
SelectedElementTagsUpdater.applyUpdate(state, latestTags, id)
|
SelectedElementTagsUpdater.applyUpdate(state, latestTags, id)
|
||||||
})
|
console.log("Updated", id)
|
||||||
|
} catch (e) {
|
||||||
|
console.warn("Could not update", id, " due to", e)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ export abstract class OsmObject {
|
||||||
return src
|
return src
|
||||||
}
|
}
|
||||||
|
|
||||||
static async DownloadPropertiesOf(id: string): Promise<any> {
|
static async DownloadPropertiesOf(id: string): Promise<OsmTags | "deleted"> {
|
||||||
const splitted = id.split("/")
|
const splitted = id.split("/")
|
||||||
const idN = Number(splitted[1])
|
const idN = Number(splitted[1])
|
||||||
if (idN < 0) {
|
if (idN < 0) {
|
||||||
|
@ -69,8 +69,12 @@ export abstract class OsmObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = `${OsmObject.backendURL}api/0.6/${id}`
|
const url = `${OsmObject.backendURL}api/0.6/${id}`
|
||||||
const rawData = await Utils.downloadJsonCached(url, 1000)
|
const rawData = await Utils.downloadJsonCachedAdvanced(url, 1000)
|
||||||
return rawData.elements[0].tags
|
console.log(rawData)
|
||||||
|
if(rawData["error"] !== undefined && rawData["statuscode"] === 410){
|
||||||
|
return "deleted"
|
||||||
|
}
|
||||||
|
return rawData["contents"].elements[0].tags
|
||||||
}
|
}
|
||||||
|
|
||||||
static async DownloadObjectAsync(
|
static async DownloadObjectAsync(
|
||||||
|
|
|
@ -77,10 +77,21 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GenerateContent(
|
public static GenerateContent(
|
||||||
|
tags: UIEventSource<any>,
|
||||||
|
layerConfig: LayerConfig,
|
||||||
|
state: FeaturePipelineState): BaseUIElement{
|
||||||
|
return new Toggle(
|
||||||
|
"This object is deleted",
|
||||||
|
FeatureInfoBox.GenerateMainContent(tags, layerConfig, state),
|
||||||
|
tags.map(t => t["_deleted"] == "yes")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
private static GenerateMainContent(
|
||||||
tags: UIEventSource<any>,
|
tags: UIEventSource<any>,
|
||||||
layerConfig: LayerConfig,
|
layerConfig: LayerConfig,
|
||||||
state: FeaturePipelineState
|
state: FeaturePipelineState
|
||||||
): BaseUIElement {
|
): BaseUIElement {
|
||||||
|
|
||||||
let questionBoxes: Map<string, QuestionBox> = new Map<string, QuestionBox>()
|
let questionBoxes: Map<string, QuestionBox> = new Map<string, QuestionBox>()
|
||||||
const t = Translations.t.general
|
const t = Translations.t.general
|
||||||
const allGroupNames = Utils.Dedup(layerConfig.tagRenderings.map((tr) => tr.group))
|
const allGroupNames = Utils.Dedup(layerConfig.tagRenderings.map((tr) => tr.group))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue