From 4fd30d1a62d63623a77d1c5fe1c036f6b79f00c2 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Wed, 5 Jan 2022 17:08:35 +0100 Subject: [PATCH 1/2] Add support for 'contact:email','contact:phone' and 'contact:website' (write to 'email', 'phone' and 'website' if changed) - fix #601; remove 'tel:' from phone addresses - fix #602; small fixes to tag preview in case of deletion --- Logic/Tags/And.ts | 2 +- Logic/Tags/Tag.ts | 2 +- UI/Input/ValidatedTextField.ts | 10 ++++++++- assets/tagRenderings/questions.json | 32 +++++++++++++++++++++++++---- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/Logic/Tags/And.ts b/Logic/Tags/And.ts index a5161b90fd..78b6d47106 100644 --- a/Logic/Tags/And.ts +++ b/Logic/Tags/And.ts @@ -59,7 +59,7 @@ export class And extends TagsFilter { } asHumanString(linkToWiki: boolean, shorten: boolean, properties) { - return this.and.map(t => t.asHumanString(linkToWiki, shorten, properties)).join("&"); + return this.and.map(t => t.asHumanString(linkToWiki, shorten, properties)).filter(x => x !== "").join("&"); } isUsableAsAnswer(): boolean { diff --git a/Logic/Tags/Tag.ts b/Logic/Tags/Tag.ts index 2d3c8a4a32..90b2c8841a 100644 --- a/Logic/Tags/Tag.ts +++ b/Logic/Tags/Tag.ts @@ -48,7 +48,7 @@ export class Tag extends TagsFilter { } if(v === "" || v === undefined){ // This tag will be removed if in the properties, so we indicate this with special rendering - if(currentProperties !== undefined && (currentProperties[this.key] ?? "") !== ""){ + if(currentProperties !== undefined && (currentProperties[this.key] ?? "") === ""){ // This tag is not present in the current properties, so this tag doesn't change anything return "" } diff --git a/UI/Input/ValidatedTextField.ts b/UI/Input/ValidatedTextField.ts index 12e043b390..8002186069 100644 --- a/UI/Input/ValidatedTextField.ts +++ b/UI/Input/ValidatedTextField.ts @@ -406,9 +406,17 @@ export default class ValidatedTextField { if (str === undefined) { return false; } + if(str.startsWith("tel:")){ + str = str.substring("tel:".length) + } return parsePhoneNumberFromString(str, (country())?.toUpperCase() as any)?.isValid() ?? false }, - (str, country: () => string) => parsePhoneNumberFromString(str, (country())?.toUpperCase() as any).formatInternational(), + (str, country: () => string) => { + if(str.startsWith("tel:")){ + str = str.substring("tel:".length) + } + return parsePhoneNumberFromString(str, (country())?.toUpperCase() as any).formatInternational(); + }, undefined, "tel" ), diff --git a/assets/tagRenderings/questions.json b/assets/tagRenderings/questions.json index 25a9549efa..f43b36ad09 100644 --- a/assets/tagRenderings/questions.json +++ b/assets/tagRenderings/questions.json @@ -71,9 +71,17 @@ "ca": "Quin és el telèfon de {name}?" }, "render": "{phone}", + "mappings": [ + { + "if": "contact:phone~*", + "then": "{contact:phone}", + "hideInAnswer": true + } + ], "freeform": { "key": "phone", - "type": "phone" + "type": "phone", + "addExtraTags": ["contact:phone="] } }, "osmlink": { @@ -140,9 +148,17 @@ "hu": "Mi a(z) {name} e-mail címe?", "ca": "Quina és l'adreça de correu electrònic de {name}?" }, + "mappings": [ + { + "if": "contact:email~*", + "then": "{contact:email}", + "hideInAnswer": true + } + ], "freeform": { "key": "email", - "type": "email" + "type": "email", + "addExtraTags": ["contact:email="] } }, "website": { @@ -168,8 +184,16 @@ "render": "{website}", "freeform": { "key": "website", - "type": "url" - } + "type": "url", + "addExtraTags": ["contact:website="] + }, + "mappings": [ + { + "if": "contact:website~*", + "then": "{contact:website}", + "hideInAnswer": true + } + ] }, "wheelchair-access": { "question": { From ee962f4ba3a19c98b0ec756bfb485769e3a00d47 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Wed, 5 Jan 2022 18:08:42 +0100 Subject: [PATCH 2/2] Small performance issues, improvement of #579 --- Logic/UIEventSource.ts | 5 ++++- UI/ShowDataLayer/ShowDataLayer.ts | 21 +++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Logic/UIEventSource.ts b/Logic/UIEventSource.ts index 3aebda8532..28f2152575 100644 --- a/Logic/UIEventSource.ts +++ b/Logic/UIEventSource.ts @@ -281,10 +281,12 @@ export class UIEventSource { * @param f: The transforming function * @param extraSources: also trigger the update if one of these sources change * @param g: a 'backfunction to let the sync run in two directions. (data of the new UIEVEntSource, currentData) => newData + * @param allowUnregister: if set, the update will be halted if no listeners are registered */ public map(f: ((t: T) => J), extraSources: UIEventSource[] = [], - g: ((j: J, t: T) => T) = undefined): UIEventSource { + g: ((j: J, t: T) => T) = undefined, + allowUnregister = false): UIEventSource { const self = this; const stack = new Error().stack.split("\n"); @@ -297,6 +299,7 @@ export class UIEventSource { const update = function () { newSource.setData(f(self.data)); + return allowUnregister && newSource._callbacks.length === 0 } this.addCallback(update); diff --git a/UI/ShowDataLayer/ShowDataLayer.ts b/UI/ShowDataLayer/ShowDataLayer.ts index f306cadf23..d1af720010 100644 --- a/UI/ShowDataLayer/ShowDataLayer.ts +++ b/UI/ShowDataLayer/ShowDataLayer.ts @@ -145,7 +145,8 @@ export default class ShowDataLayer { pointToLayer: (feature, latLng) => self.pointToLayer(feature, latLng), onEachFeature: (feature, leafletLayer) => self.postProcessFeature(feature, leafletLayer) }); - + + const selfLayer = this.geoLayer; const allFeats = this._features.features.data; for (const feat of allFeats) { if (feat === undefined) { @@ -153,12 +154,11 @@ export default class ShowDataLayer { } try { if (feat.geometry.type === "LineString") { - const self = this; const coords = L.GeoJSON.coordsToLatLngs(feat.geometry.coordinates) const tagsSource = this.allElements?.addOrGetElement(feat) ?? new UIEventSource(feat.properties); let offsettedLine; tagsSource - .map(tags => this._layerToShow.lineRendering[feat.lineRenderingIndex].GenerateLeafletStyle(tags)) + .map(tags => this._layerToShow.lineRendering[feat.lineRenderingIndex].GenerateLeafletStyle(tags), [], undefined, true) .withEqualityStabilized((a, b) => { if (a === b) { return true @@ -176,6 +176,9 @@ export default class ShowDataLayer { offsettedLine = L.polyline(coords, lineStyle); this.postProcessFeature(feat, offsettedLine) offsettedLine.addTo(this.geoLayer) + + // If 'self.geoLayer' is not the same as the layer the feature is added to, we can safely remove this callback + return self.geoLayer !== selfLayer }) } else { this.geoLayer.addData(feat); @@ -186,11 +189,13 @@ export default class ShowDataLayer { } if (options.zoomToFeatures ?? false) { - try { - const bounds = this.geoLayer.getBounds() - mp.fitBounds(bounds, {animate: false}) - } catch (e) { - console.debug("Invalid bounds", e) + if(this.geoLayer.getLayers().length > 0){ + try { + const bounds = this.geoLayer.getBounds() + mp.fitBounds(bounds, {animate: false}) + } catch (e) { + console.debug("Invalid bounds", e) + } } }