From e1d7b256f934d989d5d5e037f233c9df8b4997f6 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Tue, 6 Apr 2021 20:02:41 +0200 Subject: [PATCH] Small improvement to custom theme generator --- UI/CustomGenerator/TagRenderingPanel.ts | 53 ++++++++++++++----------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/UI/CustomGenerator/TagRenderingPanel.ts b/UI/CustomGenerator/TagRenderingPanel.ts index 0633411..302a1a3 100644 --- a/UI/CustomGenerator/TagRenderingPanel.ts +++ b/UI/CustomGenerator/TagRenderingPanel.ts @@ -21,15 +21,14 @@ import Constants from "../../Models/Constants"; export default class TagRenderingPanel extends InputElement { + public IsImage = false; + public options: { title?: string; description?: string; disableQuestions?: boolean; isImage?: boolean; }; + public readonly validText: UIElement; + IsSelected: UIEventSource = new UIEventSource(false); private intro: UIElement; private settingsTable: UIElement; - - public IsImage = false; private readonly _value: UIEventSource; - public options: { title?: string; description?: string; disableQuestions?: boolean; isImage?: boolean; }; - public readonly validText : UIElement; - constructor(languages: UIEventSource, currentlySelected: UIEventSource>, userDetails: UserDetails, @@ -47,11 +46,11 @@ export default class TagRenderingPanel extends InputElement", options?.title ?? "TagRendering", "", + this.intro = new Combine(["

", options?.title ?? "TagRendering", "

", options?.description ?? "A tagrendering converts OSM-tags into a value on screen. Fill out the field 'render' with the text that should appear. Note that `{key}` will be replaced with the corresponding `value`, if present.
For specific known tags (e.g. if `foo=bar`, make a mapping). "]) this.IsImage = options?.isImage ?? false; @@ -61,10 +60,20 @@ export default class TagRenderingPanel extends InputElement, id: string | string[], name: string, description: string | UIElement): SingleSetting { return new SingleSetting(value, input, id, name, description); } - + this._value.addCallback(value => { - if(value?.freeform?.key == ""){ + let doPing = false; + if (value?.freeform?.key == "") { value.freeform = undefined; + doPing = true; + } + + if (value?.render == "") { + value.render = undefined; + doPing = true; + } + + if (doPing) { this._value.ping(); } }) @@ -72,7 +81,7 @@ export default class TagRenderingPanel extends InputElementFreeform key", @@ -90,11 +99,11 @@ export default class TagRenderingPanel extends InputElement)[] = [ setting( - options?.noLanguage ? new TextField({placeholder:"Rendering"}) : - new MultiLingualTextFields(languages), "render", "Value to show", + options?.noLanguage ? new TextField({placeholder: "Rendering"}) : + new MultiLingualTextFields(languages), "render", "Value to show", "Renders this value. Note that {key}-parts are substituted by the corresponding values of the element. If neither 'textFieldQuestion' nor 'mappings' are defined, this text is simply shown as default value." + "

" + - "Furhtermore, some special functions are supported:"+SpecialVisualizations.HelpMessage.Render()), + "Furhtermore, some special functions are supported:" + SpecialVisualizations.HelpMessage.Render()), questionsNotUnlocked ? `You need at least ${Constants.userJourney.themeGeneratorFullUnlock} changesets to unlock the 'question'-field and to use your theme to edit OSM data` : "", ...(options?.disableQuestions ? [] : questionSettings), @@ -114,17 +123,17 @@ export default class TagRenderingPanel extends InputElement { - try{ - new TagRenderingConfig(json,undefined, options?.title ?? ""); + try { + new TagRenderingConfig(json, undefined, options?.title ?? ""); return ""; - }catch(e){ - return ""+e+"" + } catch (e) { + return "" + e + "" } })); - + } InnerRender(): string { @@ -138,8 +147,6 @@ export default class TagRenderingPanel extends InputElement = new UIEventSource(false); - IsValid(t: TagRenderingConfigJson): boolean { return false; }