From 382f96596ed474bef086d64cabb748257416f2de Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Tue, 19 Sep 2023 22:49:20 +0200 Subject: [PATCH] Fix: fix #1503, fix #1571 --- src/Logic/Tags/TagUtils.ts | 3 + src/Models/ThemeConfig/TagRenderingConfig.ts | 15 +- .../TagRendering/TagRenderingQuestion.svelte | 192 +++++++++++------- 3 files changed, 132 insertions(+), 78 deletions(-) diff --git a/src/Logic/Tags/TagUtils.ts b/src/Logic/Tags/TagUtils.ts index 94c60522b..91ce6c5e1 100644 --- a/src/Logic/Tags/TagUtils.ts +++ b/src/Logic/Tags/TagUtils.ts @@ -132,6 +132,9 @@ export class TagUtils { /** * Given multiple tagsfilters which can be used as answer, will take the tags with the same keys together as set. + * + * @see MatchesMultiAnswer to do the reverse + * * E.g: * * const tag = TagUtils.ParseUploadableTag({"and": [ diff --git a/src/Models/ThemeConfig/TagRenderingConfig.ts b/src/Models/ThemeConfig/TagRenderingConfig.ts index 2039022e8..dafdd4e59 100644 --- a/src/Models/ThemeConfig/TagRenderingConfig.ts +++ b/src/Models/ThemeConfig/TagRenderingConfig.ts @@ -243,7 +243,10 @@ export default class TagRenderingConfig { if (txt === "") { throw context + " Rendering for language " + ln + " is empty" } - if (txt.indexOf("{" + this.freeform.key + "}") >= 0 || txt.indexOf("&LBRACE" + this.freeform.key + "&RBRACE") ) { + if ( + txt.indexOf("{" + this.freeform.key + "}") >= 0 || + txt.indexOf("&LBRACE" + this.freeform.key + "&RBRACE") + ) { continue } if (txt.indexOf("{" + this.freeform.key + ":") >= 0) { @@ -645,6 +648,16 @@ export default class TagRenderingConfig { /** * Given a value for the freeform key and an overview of the selected mappings, construct the correct tagsFilter to apply * + * const config = new TagRenderingConfig({"id":"bookcase-booktypes","render":{"en":"This place mostly serves {books}" }, + * "question":{"en":"What kind of books can be found in this public bookcase?"}, + * "freeform":{"key":"books","addExtraTags":["fixme=Freeform tag `books` used, to be doublechecked"], + * "inline":true}, + * "multiAnswer":true, + * "mappings":[{"if":"books=children","then":"Mostly children books"}, + * {"if":"books=adults","then": "Mostly books for adults"}]} + * , "testcase") + * config.constructChangeSpecification(undefined, undefined, [false, true, false], {amenity: "public_bookcase"}) // => new And([new Tag("books","adult")]) + * * @param freeformValue The freeform value which will be applied as 'freeform.key'. Ignored if 'freeform.key' is not set * * @param singleSelectedMapping (Only used if multiAnswer == false): the single mapping to apply. Use (mappings.length) for the freeform diff --git a/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte b/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte index 8f0979dad..0522baf0e 100644 --- a/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte +++ b/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte @@ -1,76 +1,114 @@ {#if config.question !== undefined}