Small refactoring, add 'last edit by'-rendering

This commit is contained in:
pietervdvn 2021-04-21 01:26:36 +02:00
parent c6b4ba43fb
commit 95f1bdd797
10 changed files with 76 additions and 29 deletions

View file

@ -136,7 +136,7 @@ export default class LayerConfig {
return new TagRenderingConfig(deflt, self.source.osmTags, `${context}.${key}.default value`); return new TagRenderingConfig(deflt, self.source.osmTags, `${context}.${key}.default value`);
} }
if (typeof v === "string") { if (typeof v === "string") {
const shared = SharedTagRenderings.SharedTagRendering[v]; const shared = SharedTagRenderings.SharedTagRendering.get(v);
if (shared) { if (shared) {
return 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) { if (shared !== undefined) {
return shared; return shared;
} }
@ -196,8 +196,8 @@ export default class LayerConfig {
this.icon = tr("icon", ""); this.icon = tr("icon", "");
this.iconOverlays = (json.iconOverlays ?? []).map((overlay, i) => { this.iconOverlays = (json.iconOverlays ?? []).map((overlay, i) => {
let tr = new TagRenderingConfig(overlay.then, self.source.osmTags, `iconoverlays.${i}`); let tr = new TagRenderingConfig(overlay.then, self.source.osmTags, `iconoverlays.${i}`);
if (typeof overlay.then === "string" && SharedTagRenderings.SharedIcons[overlay.then] !== undefined) { if (typeof overlay.then === "string" && SharedTagRenderings.SharedIcons.get(overlay.then) !== undefined) {
tr = SharedTagRenderings.SharedIcons[overlay.then]; tr = SharedTagRenderings.SharedIcons.get(overlay.then);
} }
return { return {
if: FromJSON.Tag(overlay.if), if: FromJSON.Tag(overlay.if),
@ -410,13 +410,19 @@ export default class LayerConfig {
htmlParts.push(badgesComponent) htmlParts.push(badgesComponent)
} }
if(sourceParts.length ==0){iconH = 0} if (sourceParts.length == 0) {
iconH = 0
}
try {
const label = self.label.GetRenderValue(tgs)?.Subs(tgs) const label = self.label?.GetRenderValue(tgs)?.Subs(tgs)
.SetClass("block w-min text-center") ?.SetClass("block w-min text-center")
.SetStyle("margin-top: "+(iconH + 2) +"px") ?.SetStyle("margin-top: " + (iconH + 2) + "px")
if (label !== undefined) { if (label !== undefined) {
htmlParts.push(new Combine([label]).SetClass("flex flex-col items-center")) htmlParts.push(new Combine([label]).SetClass("flex flex-col items-center"))
}
} catch (e) {
console.error(e, tgs)
} }
return new Combine(htmlParts).Render(); return new Combine(htmlParts).Render();
}) })

View file

@ -83,8 +83,8 @@ export default class LayoutConfig {
this.widenFactor = json.widenFactor ?? 0.05; this.widenFactor = json.widenFactor ?? 0.05;
this.roamingRenderings = (json.roamingRenderings ?? []).map((tr, i) => { this.roamingRenderings = (json.roamingRenderings ?? []).map((tr, i) => {
if (typeof tr === "string") { if (typeof tr === "string") {
if (SharedTagRenderings.SharedTagRendering[tr] !== undefined) { if (SharedTagRenderings.SharedTagRendering.get(tr) !== undefined) {
return SharedTagRenderings.SharedTagRendering[tr]; return SharedTagRenderings.SharedTagRendering.get(tr);
} }
} }
return new TagRenderingConfig(tr, undefined, `${this.id}.roaming_renderings[${i}]`); return new TagRenderingConfig(tr, undefined, `${this.id}.roaming_renderings[${i}]`);

View file

@ -4,15 +4,15 @@ import * as icons from "../assets/tagRenderings/icons.json";
export default class SharedTagRenderings { export default class SharedTagRenderings {
public static SharedTagRendering = SharedTagRenderings.generatedSharedFields(); public static SharedTagRendering : Map<string, TagRenderingConfig> = SharedTagRenderings.generatedSharedFields();
public static SharedIcons = SharedTagRenderings.generatedSharedFields(true); public static SharedIcons : Map<string, TagRenderingConfig> = SharedTagRenderings.generatedSharedFields(true);
private static generatedSharedFields(iconsOnly = false) { private static generatedSharedFields(iconsOnly = false) : Map<string, TagRenderingConfig>{
const dict = {} const dict = new Map<string, TagRenderingConfig>();
function add(key, store) { function add(key, store) {
try { try {
dict[key] = new TagRenderingConfig(store[key], key) dict.set(key, new TagRenderingConfig(store[key], key))
} catch (e) { } 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) console.error("BUG: could not parse", key, " from questions.json or icons.json - this error happened during the build step of the SharedTagRenderings", e)
} }

View file

@ -9,13 +9,15 @@ export default class Constants {
addNewPointsUnlock: 0, addNewPointsUnlock: 0,
moreScreenUnlock: 1, moreScreenUnlock: 1,
personalLayoutUnlock: 15, personalLayoutUnlock: 15,
historyLinkVisible: 20,
tagsVisibleAt: 25, tagsVisibleAt: 25,
mapCompleteHelpUnlock: 50, mapCompleteHelpUnlock: 50,
tagsVisibleAndWikiLinked: 30, tagsVisibleAndWikiLinked: 30,
themeGeneratorReadOnlyUnlock: 50, themeGeneratorReadOnlyUnlock: 50,
themeGeneratorFullUnlock: 500, themeGeneratorFullUnlock: 500,
addNewPointWithUnreadMessagesUnlock: 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. * Used by 'PendingChangesUploader', which waits this amount of seconds to upload changes.

View file

@ -47,9 +47,12 @@ export default class LayerSelection extends UIElement {
.SetClass("single-layer-selection-toggle") .SetClass("single-layer-selection-toggle")
.SetStyle("opacity:0.2;"); .SetStyle("opacity:0.2;");
const name = Translations.WT(layer.layerDef.name).Clone() const name = Translations.WT(layer.layerDef.name)?.Clone()
.SetStyle("font-size:large;margin-left: 0.5em;"); ?.SetStyle("font-size:large;margin-left: 0.5em;");
if(name === undefined){
continue
}
const zoomStatus = new VariableUiElement(State.state.locationControl.map(location => { const zoomStatus = new VariableUiElement(State.state.locationControl.map(location => {
if (location.zoom < layer.layerDef.minzoom) { if (location.zoom < layer.layerDef.minzoom) {

View file

@ -9,6 +9,8 @@ import State from "../../State";
import TagRenderingConfig from "../../Customizations/JSON/TagRenderingConfig"; import TagRenderingConfig from "../../Customizations/JSON/TagRenderingConfig";
import ScrollableFullScreen from "../Base/ScrollableFullScreen"; import ScrollableFullScreen from "../Base/ScrollableFullScreen";
import {Tag} from "../../Logic/Tags/Tag"; import {Tag} from "../../Logic/Tags/Tag";
import Constants from "../../Models/Constants";
import SharedTagRenderings from "../../Customizations/SharedTagRenderings";
export default class FeatureInfoBox extends ScrollableFullScreen { export default class FeatureInfoBox extends ScrollableFullScreen {
@ -67,6 +69,12 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
renderings.push(questionBox); 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) { if (State.state.featureSwitchIsDebugging.data) {
const config: TagRenderingConfig = new TagRenderingConfig({render: "{all_tags()}"}, new Tag("id", ""), ""); const config: TagRenderingConfig = new TagRenderingConfig({render: "{all_tags()}"}, new Tag("id", ""), "");
renderings.push(new TagRenderingAnswer(tags, config)) renderings.push(new TagRenderingAnswer(tags, config))

View file

@ -73,10 +73,18 @@ export class Translation extends UIElement {
let rtext: string = ""; let rtext: string = "";
if (typeof (el) === "string") { if (typeof (el) === "string") {
rtext = el; rtext = el;
} else if(typeof(el) === "number") { } else if (typeof (el) === "number") {
// HUH? Where did that number come from? // HUH? Where did that number come from? It might be a version number or something calculated
rtext = "" + el; 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 Translation.forcedLanguage = lang; // This is a very dirty hack - it'll bite me one day
rtext = el.InnerRender(); rtext = el.InnerRender();

View file

@ -77,5 +77,10 @@
"key": "opening_hours", "key": "opening_hours",
"type": "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": "<div class='subtle' style='font-size: small'><a href='https://www.openStreetMap.org/changeset/{_last_edit:changeset}' target='_blank'>Last edited on {_last_edit:timestamp}</a> by <a href='https://www.openStreetMap.org/user/{_last_edit:contributor}' target='_blank'>{_last_edit:contributor}</a></div>"
} }
} }

View file

@ -15,7 +15,7 @@
"maintainer": "MapComplete", "maintainer": "MapComplete",
"icon": "./assets/layers/play_forest/icon.svg", "icon": "./assets/layers/play_forest/icon.svg",
"hideFromOverview": true, "hideFromOverview": true,
"lockLocation": false, "lockLocation": true,
"version": "0", "version": "0",
"startLat": 51.17174, "startLat": 51.17174,
"startLon": 4.449462, "startLon": 4.449462,
@ -27,7 +27,8 @@
"play_forest", "play_forest",
"playground", "playground",
"sport_pitch", "sport_pitch",
{ "builtin": "slow_roads", {
"builtin": "slow_roads",
"override": { "override": {
"calculatedTags": [ "calculatedTags": [
"_part_of_walking_routes=feat.memberships().map(r => \"<a href='#relation/\"+r.relation.id+\"'>\" + r.relation.tags.name + \"</a>\").join(', ')" "_part_of_walking_routes=feat.memberships().map(r => \"<a href='#relation/\"+r.relation.id+\"'>\" + r.relation.tags.name + \"</a>\").join(', ')"
@ -109,7 +110,7 @@
"nl": "Wie beheert deze wandeling en plaatst dus de signalisatiebordjes?" "nl": "Wie beheert deze wandeling en plaatst dus de signalisatiebordjes?"
}, },
"render": "Signalisatie geplaatst door {operator}", "render": "Signalisatie geplaatst door {operator}",
"freeform":{ "freeform": {
"key": "operator" "key": "operator"
} }
}, },
@ -130,7 +131,7 @@
], ],
"color": { "color": {
"render": "#6d6", "render": "#6d6",
"mappings":[ "mappings": [
{ {
"if": "color~*", "if": "color~*",
"then": "{color}" "then": "{color}"
@ -140,8 +141,16 @@
"width": { "width": {
"render": "3" "render": "3"
} }
},
{
"source": {
"osmTags": {
"or": []
},
"geoJson": "https://pietervdvn.github.io/speelplekken-cache.geojson"
},
"passAllFeatures": true
} }
], ],
"roamingRenderings": [ "roamingRenderings": [
{ {

View file

@ -283,6 +283,12 @@ li::marker {
color: #999; color: #999;
} }
.link-underline .subtle a {
color: var(--foreground-color);
text-decoration: underline 1px #7193bb88;
color: #7193bb;
}
.bold { .bold {
font-weight: bold; font-weight: bold;
} }