From baab3d784ffa1998fe33b1d39916f8a664990fc4 Mon Sep 17 00:00:00 2001 From: Osmwithspace <> Date: Sun, 2 Mar 2025 09:33:28 +0100 Subject: [PATCH 01/17] add brand search --- .../layers/scouting_group/scouting_group.json | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/assets/layers/scouting_group/scouting_group.json b/assets/layers/scouting_group/scouting_group.json index 231e9ec94b..996e098097 100644 --- a/assets/layers/scouting_group/scouting_group.json +++ b/assets/layers/scouting_group/scouting_group.json @@ -99,7 +99,23 @@ "mastodon" ], "filter": [ - "nsi_brand.brand" + "nsi_brand.brand", + { + "id": "brand_search", + "options": [ + { + "osmTags": "brand~i~.*{search}.*", + "fields": [ + { + "name": "search" + } + ], + "question": { + "en": "Search for brand: {search}" + } + } + ] + } ], "allowMove": true, "credits": "Osmwithspace", From c68bce2421977e5fcb76181e38fbeb8f4f65c7f7 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Sun, 9 Mar 2025 13:11:57 +0100 Subject: [PATCH 02/17] Fix: fix partially #2343 --- src/Models/ThemeConfig/TagRenderingConfig.ts | 74 +++++++++++++------ .../TagRendering/TagRenderingQuestion.svelte | 6 +- 2 files changed, 56 insertions(+), 24 deletions(-) diff --git a/src/Models/ThemeConfig/TagRenderingConfig.ts b/src/Models/ThemeConfig/TagRenderingConfig.ts index 07e559401a..c8ab20a99e 100644 --- a/src/Models/ThemeConfig/TagRenderingConfig.ts +++ b/src/Models/ThemeConfig/TagRenderingConfig.ts @@ -223,7 +223,7 @@ export default class TagRenderingConfig { inline: json.freeform.inline ?? false, default: json.freeform.default, postfixDistinguished: json.freeform.postfixDistinguished?.trim(), - args: json.freeform.helperArgs, + args: json.freeform.helperArgs } if (json.freeform["extraTags"] !== undefined) { throw `Freeform.extraTags is defined. This should probably be 'freeform.addExtraTag' (at ${context})` @@ -447,7 +447,7 @@ export default class TagRenderingConfig { iconClass, addExtraTags, searchTerms: mapping.searchTerms, - priorityIf: prioritySearch, + priorityIf: prioritySearch } if (isQuestionable) { if (hideInAnswer !== true && mp.if !== undefined && !mp.if.isUsableAsAnswer()) { @@ -554,7 +554,7 @@ export default class TagRenderingConfig { then: new TypedTranslation( this.render.replace("{" + this.freeform.key + "}", leftover).translations, this.render.context - ), + ) }) } } @@ -607,7 +607,7 @@ export default class TagRenderingConfig { return { then: this.render.PartialSubs({ [this.freeform.key]: v.trim() }), icon: this.renderIcon, - iconClass: this.renderIconClass, + iconClass: this.renderIconClass } } } @@ -662,7 +662,7 @@ export default class TagRenderingConfig { key: commonKey, values: Utils.NoNull( values.map((arr) => arr.filter((item) => item.k === commonKey)[0]?.v) - ), + ) } } @@ -677,7 +677,7 @@ export default class TagRenderingConfig { return { key, type: this.freeform.type, - values, + values } } catch (e) { console.error("Could not create FreeformValues for tagrendering", this.id) @@ -746,14 +746,18 @@ export default class TagRenderingConfig { if (freeformValue === "") { freeformValue = undefined } - if (this.freeform?.postfixDistinguished && freeformValue !== undefined) { + if (this.freeform?.postfixDistinguished) { const allValues = currentProperties[this.freeform.key].split(";").map((s) => s.trim()) const perPostfix: Record = {} for (const value of allValues) { const [v, postfix] = value.split("/") perPostfix[postfix.trim()] = v.trim() } - perPostfix[this.freeform.postfixDistinguished] = freeformValue + if (freeformValue === "" || freeformValue === undefined) { + delete perPostfix[this.freeform.postfixDistinguished] + } else { + perPostfix[this.freeform.postfixDistinguished] = freeformValue + } const keys = Object.keys(perPostfix) keys.sort() freeformValue = keys.map((k) => perPostfix[k] + "/" + k).join("; ") @@ -783,7 +787,7 @@ export default class TagRenderingConfig { // Either no mappings, or this is a radio-button selected freeform value const tag = new And([ new Tag(this.freeform.key, freeformValue), - ...(this.freeform.addExtraTags ?? []), + ...(this.freeform.addExtraTags ?? []) ]) const newProperties = tag.applyOn(currentProperties) if (this.invalidValues?.matchesProperties(newProperties)) { @@ -807,7 +811,7 @@ export default class TagRenderingConfig { selectedMappings.push( new And([ new Tag(this.freeform.key, freeformValue), - ...(this.freeform.addExtraTags ?? []), + ...(this.freeform.addExtraTags ?? []) ]) ) } @@ -845,12 +849,12 @@ export default class TagRenderingConfig { if (useFreeform) { return new And([ new Tag(this.freeform.key, freeformValue), - ...(this.freeform.addExtraTags ?? []), + ...(this.freeform.addExtraTags ?? []) ]) } else if (singleSelectedMapping !== undefined) { return new And([ this.mappings[singleSelectedMapping].if, - ...(this.mappings[singleSelectedMapping].addExtraTags ?? []), + ...(this.mappings[singleSelectedMapping].addExtraTags ?? []) ]) } else { console.error("TagRenderingConfig.ConstructSpecification has a weird fallback for", { @@ -858,7 +862,7 @@ export default class TagRenderingConfig { singleSelectedMapping, multiSelectedMapping, currentProperties, - useFreeform, + useFreeform }) return undefined @@ -888,11 +892,11 @@ export default class TagRenderingConfig { } const msgs: string[] = [ icon + - " " + - "*" + - m.then.textFor(lang) + - "* is shown if with " + - m.if.asHumanString(true, false, {}), + " " + + "*" + + m.then.textFor(lang) + + "* is shown if with " + + m.if.asHumanString(true, false, {}) ] if (m.hideInAnswer === true) { @@ -901,7 +905,7 @@ export default class TagRenderingConfig { if (m.ifnot !== undefined) { msgs.push( "Unselecting this answer will add " + - m.ifnot.asHumanString(true, false, {}) + m.ifnot.asHumanString(true, false, {}) ) } return msgs.join(". ") @@ -925,7 +929,7 @@ export default class TagRenderingConfig { if (this.labels?.length > 0) { labels = [ "This tagrendering has labels ", - ...this.labels.map((label) => "`" + label + "`"), + ...this.labels.map((label) => "`" + label + "`") ].join("\n") } @@ -938,7 +942,7 @@ export default class TagRenderingConfig { freeform, mappings, condition, - labels, + labels ].join("\n") } @@ -964,6 +968,32 @@ export default class TagRenderingConfig { return Utils.NoNull(tags) } + /** + * Returns the freeform value that should be initially shown in the question + * @param properties + */ + public initialFreeformValue(properties: Record): string { + const value = properties[this.freeform.key] + if (!value) { + return "" + } + const distinguish = this.freeform.postfixDistinguished + if (!distinguish) { + return value + } + const parts = value.split(";") + for (const part of parts) { + if (part.indexOf("/") < 0) { + continue + } + const [v, denom] = part.split("/").map(s => s.trim()) + if (denom === distinguish) { + return v + } + } + return "" + } + /** * The keys that should be erased if one has to revert to 'unknown'. * Might give undefined if setting to unknown is not possible @@ -1050,7 +1080,7 @@ export class TagRenderingConfigUtils { clone.mappings?.map((m) => { const mapping = { ...m, - priorityIf: m.priorityIf ?? TagUtils.Tag("id~*"), + priorityIf: m.priorityIf ?? TagUtils.Tag("id~*") } if (m.if.usedKeys().indexOf("nobrand") < 0) { // Erase 'nobrand=yes', unless this option explicitly sets it diff --git a/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte b/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte index 4cebecb6f8..3b354959e7 100644 --- a/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte +++ b/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte @@ -143,7 +143,7 @@ if (confg.freeform?.key) { if (!confg.multiAnswer) { // Somehow, setting multi-answer freeform values is broken if this is not set - freeformInput.set(tgs[confg.freeform.key]) + freeformInput.set(confg.initialFreeformValue(tgs)) } } else { freeformInput.set(undefined) @@ -208,6 +208,7 @@ !$freeformInput && !$freeformInputUnvalidated && !checkedMappings?.some((m) => m) && + !config.freeform.postfixDistinguished && $tags[config.freeform.key] // We need to have a current value in order to delete it ) { selectedTags = new Tag(config.freeform.key, "") @@ -613,7 +614,8 @@ - {#if config.freeform?.key && !checkedMappings?.some((m) => m) && !$freeformInput && !$freeformInputUnvalidated && $tags[config.freeform.key]} + {#if config.freeform?.key && !checkedMappings?.some((m) => m) && !$freeformInput && !$freeformInputUnvalidated && $tags[config.freeform.key] + && (!config.freeform.postfixDistinguished)}