From 95f1bdd797ed2cd7b59fbffe2e228a1470d58979 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Wed, 21 Apr 2021 01:26:36 +0200 Subject: [PATCH] Small refactoring, add 'last edit by'-rendering --- Customizations/JSON/LayerConfig.ts | 26 ++++++++++++-------- Customizations/JSON/LayoutConfig.ts | 4 +-- Customizations/SharedTagRenderings.ts | 10 ++++---- Models/Constants.ts | 4 ++- UI/BigComponents/LayerSelection.ts | 7 ++++-- UI/Popup/FeatureInfoBox.ts | 10 +++++++- UI/i18n/Translation.ts | 14 ++++++++--- assets/tagRenderings/questions.json | 5 ++++ assets/themes/speelplekken/speelplekken.json | 19 ++++++++++---- index.css | 6 +++++ 10 files changed, 76 insertions(+), 29 deletions(-) diff --git a/Customizations/JSON/LayerConfig.ts b/Customizations/JSON/LayerConfig.ts index 6e87f2b..1816b8f 100644 --- a/Customizations/JSON/LayerConfig.ts +++ b/Customizations/JSON/LayerConfig.ts @@ -136,7 +136,7 @@ export default class LayerConfig { return new TagRenderingConfig(deflt, self.source.osmTags, `${context}.${key}.default value`); } if (typeof v === "string") { - const shared = SharedTagRenderings.SharedTagRendering[v]; + const shared = SharedTagRenderings.SharedTagRendering.get(v); if (shared) { return shared; } @@ -166,7 +166,7 @@ export default class LayerConfig { } - const shared = SharedTagRenderings.SharedTagRendering[renderingJson]; + const shared = SharedTagRenderings.SharedTagRendering.get(renderingJson); if (shared !== undefined) { return shared; } @@ -196,8 +196,8 @@ export default class LayerConfig { this.icon = tr("icon", ""); this.iconOverlays = (json.iconOverlays ?? []).map((overlay, i) => { let tr = new TagRenderingConfig(overlay.then, self.source.osmTags, `iconoverlays.${i}`); - if (typeof overlay.then === "string" && SharedTagRenderings.SharedIcons[overlay.then] !== undefined) { - tr = SharedTagRenderings.SharedIcons[overlay.then]; + if (typeof overlay.then === "string" && SharedTagRenderings.SharedIcons.get(overlay.then) !== undefined) { + tr = SharedTagRenderings.SharedIcons.get(overlay.then); } return { if: FromJSON.Tag(overlay.if), @@ -410,13 +410,19 @@ export default class LayerConfig { htmlParts.push(badgesComponent) } - if(sourceParts.length ==0){iconH = 0} + if (sourceParts.length == 0) { + iconH = 0 + } + try { - const label = self.label.GetRenderValue(tgs)?.Subs(tgs) - .SetClass("block w-min text-center") - .SetStyle("margin-top: "+(iconH + 2) +"px") - if (label !== undefined) { - htmlParts.push(new Combine([label]).SetClass("flex flex-col items-center")) + const label = self.label?.GetRenderValue(tgs)?.Subs(tgs) + ?.SetClass("block w-min text-center") + ?.SetStyle("margin-top: " + (iconH + 2) + "px") + if (label !== undefined) { + htmlParts.push(new Combine([label]).SetClass("flex flex-col items-center")) + } + } catch (e) { + console.error(e, tgs) } return new Combine(htmlParts).Render(); }) diff --git a/Customizations/JSON/LayoutConfig.ts b/Customizations/JSON/LayoutConfig.ts index 0da4f1e..6966101 100644 --- a/Customizations/JSON/LayoutConfig.ts +++ b/Customizations/JSON/LayoutConfig.ts @@ -83,8 +83,8 @@ export default class LayoutConfig { this.widenFactor = json.widenFactor ?? 0.05; this.roamingRenderings = (json.roamingRenderings ?? []).map((tr, i) => { if (typeof tr === "string") { - if (SharedTagRenderings.SharedTagRendering[tr] !== undefined) { - return SharedTagRenderings.SharedTagRendering[tr]; + if (SharedTagRenderings.SharedTagRendering.get(tr) !== undefined) { + return SharedTagRenderings.SharedTagRendering.get(tr); } } return new TagRenderingConfig(tr, undefined, `${this.id}.roaming_renderings[${i}]`); diff --git a/Customizations/SharedTagRenderings.ts b/Customizations/SharedTagRenderings.ts index 772bd97..3d3a052 100644 --- a/Customizations/SharedTagRenderings.ts +++ b/Customizations/SharedTagRenderings.ts @@ -4,15 +4,15 @@ import * as icons from "../assets/tagRenderings/icons.json"; export default class SharedTagRenderings { - public static SharedTagRendering = SharedTagRenderings.generatedSharedFields(); - public static SharedIcons = SharedTagRenderings.generatedSharedFields(true); + public static SharedTagRendering : Map = SharedTagRenderings.generatedSharedFields(); + public static SharedIcons : Map = SharedTagRenderings.generatedSharedFields(true); - private static generatedSharedFields(iconsOnly = false) { - const dict = {} + private static generatedSharedFields(iconsOnly = false) : Map{ + const dict = new Map(); function add(key, store) { try { - dict[key] = new TagRenderingConfig(store[key], key) + dict.set(key, new TagRenderingConfig(store[key], key)) } catch (e) { console.error("BUG: could not parse", key, " from questions.json or icons.json - this error happened during the build step of the SharedTagRenderings", e) } diff --git a/Models/Constants.ts b/Models/Constants.ts index 2dfe67a..599384c 100644 --- a/Models/Constants.ts +++ b/Models/Constants.ts @@ -9,13 +9,15 @@ export default class Constants { addNewPointsUnlock: 0, moreScreenUnlock: 1, personalLayoutUnlock: 15, + historyLinkVisible: 20, tagsVisibleAt: 25, mapCompleteHelpUnlock: 50, tagsVisibleAndWikiLinked: 30, themeGeneratorReadOnlyUnlock: 50, themeGeneratorFullUnlock: 500, addNewPointWithUnreadMessagesUnlock: 500, - minZoomLevelToAddNewPoints: (Constants.isRetina() ? 18 : 19) + minZoomLevelToAddNewPoints: (Constants.isRetina() ? 18 : 19), + }; /** * Used by 'PendingChangesUploader', which waits this amount of seconds to upload changes. diff --git a/UI/BigComponents/LayerSelection.ts b/UI/BigComponents/LayerSelection.ts index d564559..fe55f1c 100644 --- a/UI/BigComponents/LayerSelection.ts +++ b/UI/BigComponents/LayerSelection.ts @@ -47,9 +47,12 @@ export default class LayerSelection extends UIElement { .SetClass("single-layer-selection-toggle") .SetStyle("opacity:0.2;"); - const name = Translations.WT(layer.layerDef.name).Clone() - .SetStyle("font-size:large;margin-left: 0.5em;"); + const name = Translations.WT(layer.layerDef.name)?.Clone() + ?.SetStyle("font-size:large;margin-left: 0.5em;"); + if(name === undefined){ + continue + } const zoomStatus = new VariableUiElement(State.state.locationControl.map(location => { if (location.zoom < layer.layerDef.minzoom) { diff --git a/UI/Popup/FeatureInfoBox.ts b/UI/Popup/FeatureInfoBox.ts index b81e1af..c3f249c 100644 --- a/UI/Popup/FeatureInfoBox.ts +++ b/UI/Popup/FeatureInfoBox.ts @@ -9,6 +9,8 @@ import State from "../../State"; import TagRenderingConfig from "../../Customizations/JSON/TagRenderingConfig"; import ScrollableFullScreen from "../Base/ScrollableFullScreen"; import {Tag} from "../../Logic/Tags/Tag"; +import Constants from "../../Models/Constants"; +import SharedTagRenderings from "../../Customizations/SharedTagRenderings"; export default class FeatureInfoBox extends ScrollableFullScreen { @@ -49,7 +51,7 @@ export default class FeatureInfoBox extends ScrollableFullScreen { private static GenerateContent(tags: UIEventSource, layerConfig: LayerConfig): UIElement { let questionBox: UIElement = undefined; - + if (State.state.featureSwitchUserbadge.data) { questionBox = new QuestionBox(tags, layerConfig.tagRenderings); } @@ -67,6 +69,12 @@ export default class FeatureInfoBox extends ScrollableFullScreen { renderings.push(questionBox); } + if (State.state.osmConnection.userDetails.data.csCount >= Constants.userJourney.historyLinkVisible || + State.state.featureSwitchIsDebugging.data == true || + State.state.featureSwitchIsTesting.data == true) { + renderings.push(new TagRenderingAnswer( tags, SharedTagRenderings.SharedTagRendering.get("last_edit"))) + } + if (State.state.featureSwitchIsDebugging.data) { const config: TagRenderingConfig = new TagRenderingConfig({render: "{all_tags()}"}, new Tag("id", ""), ""); renderings.push(new TagRenderingAnswer(tags, config)) diff --git a/UI/i18n/Translation.ts b/UI/i18n/Translation.ts index 0730f28..6372245 100644 --- a/UI/i18n/Translation.ts +++ b/UI/i18n/Translation.ts @@ -73,10 +73,18 @@ export class Translation extends UIElement { let rtext: string = ""; if (typeof (el) === "string") { rtext = el; - } else if(typeof(el) === "number") { - // HUH? Where did that number come from? + } else if (typeof (el) === "number") { + // HUH? Where did that number come from? It might be a version number or something calculated rtext = "" + el; - }else { + } else if (el["toISOString"] != undefined) { + // This is a date, probably the timestamp of the object + // @ts-ignore + const date: Date = el; + rtext = date.toLocaleString(); + } else if (el.InnerRender === undefined) { + console.error("InnerREnder is not defined", el); + throw "Hmmm, el.InnerRender is not defined?" + } else { Translation.forcedLanguage = lang; // This is a very dirty hack - it'll bite me one day rtext = el.InnerRender(); diff --git a/assets/tagRenderings/questions.json b/assets/tagRenderings/questions.json index 32334a5..667ef7d 100644 --- a/assets/tagRenderings/questions.json +++ b/assets/tagRenderings/questions.json @@ -77,5 +77,10 @@ "key": "opening_hours", "type": "opening_hours" } + }, + "last_edit": { + "#": "Gives some metainfo about the last edit and who did edit it - rendering only", + "#condition": "_last_edit:contributor~*", + "render": "" } } \ No newline at end of file diff --git a/assets/themes/speelplekken/speelplekken.json b/assets/themes/speelplekken/speelplekken.json index ebbb23c..3b8f652 100644 --- a/assets/themes/speelplekken/speelplekken.json +++ b/assets/themes/speelplekken/speelplekken.json @@ -15,7 +15,7 @@ "maintainer": "MapComplete", "icon": "./assets/layers/play_forest/icon.svg", "hideFromOverview": true, - "lockLocation": false, + "lockLocation": true, "version": "0", "startLat": 51.17174, "startLon": 4.449462, @@ -27,7 +27,8 @@ "play_forest", "playground", "sport_pitch", - { "builtin": "slow_roads", + { + "builtin": "slow_roads", "override": { "calculatedTags": [ "_part_of_walking_routes=feat.memberships().map(r => \"\" + r.relation.tags.name + \"\").join(', ')" @@ -109,7 +110,7 @@ "nl": "Wie beheert deze wandeling en plaatst dus de signalisatiebordjes?" }, "render": "Signalisatie geplaatst door {operator}", - "freeform":{ + "freeform": { "key": "operator" } }, @@ -130,7 +131,7 @@ ], "color": { "render": "#6d6", - "mappings":[ + "mappings": [ { "if": "color~*", "then": "{color}" @@ -140,8 +141,16 @@ "width": { "render": "3" } + }, + { + "source": { + "osmTags": { + "or": [] + }, + "geoJson": "https://pietervdvn.github.io/speelplekken-cache.geojson" + }, + "passAllFeatures": true } - ], "roamingRenderings": [ { diff --git a/index.css b/index.css index 0ebf81a..7760163 100644 --- a/index.css +++ b/index.css @@ -283,6 +283,12 @@ li::marker { color: #999; } +.link-underline .subtle a { + color: var(--foreground-color); + text-decoration: underline 1px #7193bb88; + color: #7193bb; +} + .bold { font-weight: bold; }