From ab28fbe35c97de56e765bc3b35277489aebb1872 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Tue, 9 May 2023 00:05:38 +0200 Subject: [PATCH] Fix: fix icons in mappings which use a builtin svg --- Models/ThemeConfig/PointRenderingConfig.ts | 19 +++++---- Models/ThemeConfig/TagRenderingConfig.ts | 45 ++++++++++++---------- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/Models/ThemeConfig/PointRenderingConfig.ts b/Models/ThemeConfig/PointRenderingConfig.ts index d32926be2d..c3cc1059ac 100644 --- a/Models/ThemeConfig/PointRenderingConfig.ts +++ b/Models/ThemeConfig/PointRenderingConfig.ts @@ -1,17 +1,16 @@ import PointRenderingConfigJson from "./Json/PointRenderingConfigJson" import TagRenderingConfig from "./TagRenderingConfig" -import { TagsFilter } from "../../Logic/Tags/TagsFilter" -import { TagUtils } from "../../Logic/Tags/TagUtils" -import { Utils } from "../../Utils" +import {TagsFilter} from "../../Logic/Tags/TagsFilter" +import {TagUtils} from "../../Logic/Tags/TagUtils" +import {Utils} from "../../Utils" import Svg from "../../Svg" import WithContextLoader from "./WithContextLoader" -import { Store } from "../../Logic/UIEventSource" +import {Store} from "../../Logic/UIEventSource" import BaseUIElement from "../../UI/BaseUIElement" -import { FixedUiElement } from "../../UI/Base/FixedUiElement" +import {FixedUiElement} from "../../UI/Base/FixedUiElement" import Img from "../../UI/Base/Img" import Combine from "../../UI/Base/Combine" -import { VariableUiElement } from "../../UI/Base/VariableUIElement" -import Constants from "../Constants"; +import {VariableUiElement} from "../../UI/Base/VariableUIElement" export default class PointRenderingConfig extends WithContextLoader { static readonly allowed_location_codes: ReadonlySet = new Set([ @@ -84,7 +83,7 @@ export default class PointRenderingConfig extends WithContextLoader { } }) - const iconPath = this.icon?.GetRenderValue({ id: "node/-1" })?.txt + const iconPath = this.icon?.GetRenderValue({id: "node/-1"})?.txt if (iconPath !== undefined && iconPath.startsWith(Utils.assets_path)) { const iconKey = iconPath.substr(Utils.assets_path.length) if (Svg.All[iconKey] === undefined) { @@ -110,7 +109,7 @@ export default class PointRenderingConfig extends WithContextLoader { return undefined } const match = htmlSpec.match(/([a-zA-Z0-9_]*):([^;]*)/) - if (match !== null && Constants.defaultPinIcons.indexOf(match[1] ) >= 0) { + if (match !== null && Svg.All[match[1] + ".svg"] !== undefined) { const svg = Svg.All[match[1] + ".svg"] as string const targetColor = match[2] const img = new Img( @@ -169,7 +168,7 @@ export default class PointRenderingConfig extends WithContextLoader { noFullWidth?: boolean } ): BaseUIElement { - tags = tags ?? { id: "node/-1" } + tags = tags ?? {id: "node/-1"} let defaultPin: BaseUIElement = undefined if (this.label === undefined) { defaultPin = Svg.teardrop_with_hole_green_svg() diff --git a/Models/ThemeConfig/TagRenderingConfig.ts b/Models/ThemeConfig/TagRenderingConfig.ts index 6dc60840e8..b0890ab5a3 100644 --- a/Models/ThemeConfig/TagRenderingConfig.ts +++ b/Models/ThemeConfig/TagRenderingConfig.ts @@ -15,7 +15,6 @@ import {FixedUiElement} from "../../UI/Base/FixedUiElement" import {Paragraph} from "../../UI/Base/Paragraph" import Svg from "../../Svg" import Validators, {ValidatorType} from "../../UI/InputElement/Validators"; -import Constants from "../Constants"; export interface Mapping { readonly if: UploadableTag @@ -69,6 +68,7 @@ export default class TagRenderingConfig { public readonly mappings?: Mapping[] public readonly labels: string[] public readonly classes: string[] + constructor(json: string | QuestionableTagRenderingConfigJson, context?: string) { if (json === undefined) { throw "Initing a TagRenderingConfig with undefined in " + context @@ -118,9 +118,9 @@ export default class TagRenderingConfig { this.question = Translations.T(json.question, translationKey + ".question") this.questionhint = Translations.T(json.questionHint, translationKey + ".questionHint") this.description = Translations.T(json.description, translationKey + ".description") - this.condition = TagUtils.Tag(json.condition ?? { and: [] }, `${context}.condition`) + this.condition = TagUtils.Tag(json.condition ?? {and: []}, `${context}.condition`) this.metacondition = TagUtils.Tag( - json.metacondition ?? { and: [] }, + json.metacondition ?? {and: []}, `${context}.metacondition` ) if (json.freeform) { @@ -379,9 +379,7 @@ export default class TagRenderingConfig { if (stripped.endsWith(".svg")) { stripped = stripped.substring(0, stripped.length - 4) } - if ( - Constants.defaultPinIcons.indexOf(stripped) - ) { + if (Svg.All[stripped + ".svg"] !== undefined) { icon = "./assets/svg/" + mapping.icon if (!icon.endsWith(".svg")) { icon += ".svg" @@ -544,7 +542,7 @@ export default class TagRenderingConfig { this.freeform?.key === undefined || tags[this.freeform.key] !== undefined ) { - return { then: this.render } + return {then: this.render} } return undefined @@ -634,9 +632,9 @@ export default class TagRenderingConfig { currentProperties: Record ): UploadableTag { freeformValue = freeformValue?.trim() - const validator = Validators.get( this.freeform?.type) - if(validator && freeformValue){ - freeformValue = validator.reformat(freeformValue,() => currentProperties["_country"]) + const validator = Validators.get(this.freeform?.type) + if (validator && freeformValue) { + freeformValue = validator.reformat(freeformValue, () => currentProperties["_country"]) } if (freeformValue === "") { freeformValue = undefined @@ -687,12 +685,12 @@ export default class TagRenderingConfig { } else { // Is at least one mapping shown in the answer? const someMappingIsShown = this.mappings.some(m => { - if(typeof m.hideInAnswer === "boolean"){ + if (typeof m.hideInAnswer === "boolean") { return !m.hideInAnswer } const isHidden = m.hideInAnswer.matchesProperties(currentProperties) return !isHidden - } ) + }) // If all mappings are hidden for the current tags, we can safely assume that we should use the freeform key const useFreeform = freeformValue !== undefined && (singleSelectedMapping === this.mappings.length || !someMappingIsShown) if (useFreeform) { @@ -700,13 +698,18 @@ export default class TagRenderingConfig { new Tag(this.freeform.key, freeformValue), ...(this.freeform.addExtraTags ?? []), ]) - } else if(singleSelectedMapping !== undefined) { + } else if (singleSelectedMapping !== undefined) { return new And([ this.mappings[singleSelectedMapping].if, ...(this.mappings[singleSelectedMapping].addExtraTags ?? []), ]) - }else{ - console.warn("TagRenderingConfig.ConstructSpecification has a weird fallback for", {freeformValue, singleSelectedMapping, multiSelectedMapping, currentProperties}) + } else { + console.warn("TagRenderingConfig.ConstructSpecification has a weird fallback for", { + freeformValue, + singleSelectedMapping, + multiSelectedMapping, + currentProperties + }) return undefined } } @@ -751,7 +754,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 @@ -781,12 +784,12 @@ export default class TagRenderingConfig { this.description, this.question !== undefined ? new Combine([ - "The question is ", - new FixedUiElement(this.question.txt).SetClass("font-bold bold"), - ]) + "The question is ", + new FixedUiElement(this.question.txt).SetClass("font-bold bold"), + ]) : new FixedUiElement( - "This tagrendering has no question and is thus read-only" - ).SetClass("italic"), + "This tagrendering has no question and is thus read-only" + ).SetClass("italic"), new Combine(withRender), mappings, condition,