From 5e1b4d95ab7662c6b86e716a9a34007c54b14055 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Fri, 16 Dec 2022 01:09:18 +0100 Subject: [PATCH] Detect an element that is deleted upstream; show 'this element is deleted in infopanel' --- Logic/Actors/SelectedElementTagsUpdater.ts | 31 ++++++++++++++++------ Logic/Osm/OsmObject.ts | 10 ++++--- UI/Popup/FeatureInfoBox.ts | 11 ++++++++ 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/Logic/Actors/SelectedElementTagsUpdater.ts b/Logic/Actors/SelectedElementTagsUpdater.ts index 071efd3a82..2aa6566810 100644 --- a/Logic/Actors/SelectedElementTagsUpdater.ts +++ b/Logic/Actors/SelectedElementTagsUpdater.ts @@ -1,11 +1,11 @@ /** * This actor will download the latest version of the selected element from OSM and update the tags if necessary. */ -import { UIEventSource } from "../UIEventSource" -import { ElementStorage } from "../ElementStorage" -import { Changes } from "../Osm/Changes" -import { OsmObject } from "../Osm/OsmObject" -import { OsmConnection } from "../Osm/OsmConnection" +import {UIEventSource} from "../UIEventSource" +import {ElementStorage} from "../ElementStorage" +import {Changes} from "../Osm/Changes" +import {OsmObject} from "../Osm/OsmObject" +import {OsmConnection} from "../Osm/OsmConnection" import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig" import SimpleMetaTagger from "../SimpleMetaTagger" @@ -41,7 +41,7 @@ export default class SelectedElementTagsUpdater { osmConnection: OsmConnection layoutToUse: LayoutConfig }) { - state.selectedElement.addCallbackAndRunD((s) => { + state.selectedElement.addCallbackAndRunD(async (s) => { let id = s.properties?.id const backendUrl = state.osmConnection._oauth_config.url @@ -58,9 +58,24 @@ export default class SelectedElementTagsUpdater { // This is a new object 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) - }) + console.log("Updated", id) + } catch (e) { + console.warn("Could not update", id, " due to", e) + } }) } diff --git a/Logic/Osm/OsmObject.ts b/Logic/Osm/OsmObject.ts index e12df9419f..973c0503e9 100644 --- a/Logic/Osm/OsmObject.ts +++ b/Logic/Osm/OsmObject.ts @@ -61,7 +61,7 @@ export abstract class OsmObject { return src } - static async DownloadPropertiesOf(id: string): Promise { + static async DownloadPropertiesOf(id: string): Promise { const splitted = id.split("/") const idN = Number(splitted[1]) if (idN < 0) { @@ -69,8 +69,12 @@ export abstract class OsmObject { } const url = `${OsmObject.backendURL}api/0.6/${id}` - const rawData = await Utils.downloadJsonCached(url, 1000) - return rawData.elements[0].tags + const rawData = await Utils.downloadJsonCachedAdvanced(url, 1000) + console.log(rawData) + if(rawData["error"] !== undefined && rawData["statuscode"] === 410){ + return "deleted" + } + return rawData["contents"].elements[0].tags } static async DownloadObjectAsync( diff --git a/UI/Popup/FeatureInfoBox.ts b/UI/Popup/FeatureInfoBox.ts index 9d2840e388..f75d9128d9 100644 --- a/UI/Popup/FeatureInfoBox.ts +++ b/UI/Popup/FeatureInfoBox.ts @@ -77,10 +77,21 @@ export default class FeatureInfoBox extends ScrollableFullScreen { } public static GenerateContent( + tags: UIEventSource, + 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, layerConfig: LayerConfig, state: FeaturePipelineState ): BaseUIElement { + let questionBoxes: Map = new Map() const t = Translations.t.general const allGroupNames = Utils.Dedup(layerConfig.tagRenderings.map((tr) => tr.group))