From 2813c31a93919c038b70fe79bc03f4b6c8f7fa92 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Sun, 3 Oct 2021 02:50:11 +0200 Subject: [PATCH] Temporary fix to questions --- UI/Popup/EditableTagRendering.ts | 2 +- UI/Popup/TagRenderingQuestion.ts | 74 ++++++++++++++------------------ package.json | 1 + 3 files changed, 34 insertions(+), 43 deletions(-) diff --git a/UI/Popup/EditableTagRendering.ts b/UI/Popup/EditableTagRendering.ts index 5d7657fa5..585a75fee 100644 --- a/UI/Popup/EditableTagRendering.ts +++ b/UI/Popup/EditableTagRendering.ts @@ -50,7 +50,7 @@ export default class EditableTagRendering extends Toggle { const question = new Lazy(() => { - return new TagRenderingQuestion(tags, configuration, + return new TagRenderingQuestion(tags, configuration, { units: units, cancelButton: Translations.t.general.cancel.Clone() diff --git a/UI/Popup/TagRenderingQuestion.ts b/UI/Popup/TagRenderingQuestion.ts index 9f99b2bb2..576189175 100644 --- a/UI/Popup/TagRenderingQuestion.ts +++ b/UI/Popup/TagRenderingQuestion.ts @@ -31,7 +31,7 @@ import {Unit} from "../../Models/Unit"; * Shows the question element. * Note that the value _migh_ already be known, e.g. when selected or when changing the value */ -export default class TagRenderingQuestion extends VariableUiElement { +export default class TagRenderingQuestion extends Combine { constructor(tags: UIEventSource, configuration: TagRenderingConfig, @@ -45,7 +45,7 @@ export default class TagRenderingQuestion extends VariableUiElement { ) { - const applicableMappings = + /* const applicableMappings = UIEventSource.ListStabilized(tags.map(tags => { const applicableMappings : {if: TagsFilter, then: any, ifnot?: TagsFilter}[] = [] for (const mapping of configuration.mappings ?? []) { @@ -69,7 +69,8 @@ export default class TagRenderingQuestion extends VariableUiElement { applicableMappings.map(applicableMappings => { return TagRenderingQuestion.GenerateFullQuestion(tags, applicableMappings, configuration, options) }) - ) + )*/ + super([TagRenderingQuestion.GenerateFullQuestion(tags, (configuration.mappings??[]).filter(mapping => mapping.hideInAnswer !== undefined), configuration, options)]) } private static GenerateFullQuestion(tags: UIEventSource, @@ -98,17 +99,21 @@ export default class TagRenderingQuestion extends VariableUiElement { console.error("MultiAnswer failed - probably not a single option was possible", configuration) throw "MultiAnswer failed - probably not a single option was possible" } - const save = async () => { + inputElement.GetValue().addCallbackAndRun(s => console.trace("Current selection is ", s)) + const save = () => { + console.log("OnSaveTriggered", inputElement) const selection = inputElement.GetValue().data; + console.log("Saving changes", selection) if (selection) { - await (State.state?.changes ?? new Changes()) + (State.state?.changes ?? new Changes()) .applyAction(new ChangeTagAction( tags.data.id, selection, tags.data - )) - } - - if (options.afterSave) { - options.afterSave(); + )).then(_ => { + console.log("Tagchanges applied") + }) + if (options.afterSave) { + options.afterSave(); + } } } @@ -155,13 +160,15 @@ export default class TagRenderingQuestion extends VariableUiElement { private static GenerateInputElement(configuration: TagRenderingConfig, applicableMappings: {if: TagsFilter, then: any, ifnot?: TagsFilter}[], - applicableUnit: Unit, tagsSource: UIEventSource): InputElement { + applicableUnit: Unit, + tagsSource: UIEventSource) + : InputElement { let inputEls: InputElement[]; const ifNotsPresent = applicableMappings.some(mapping => mapping.ifnot !== undefined) - function allIfNotsExcept(excludeIndex: number): UIEventSource { + function allIfNotsExcept(excludeIndex: number): TagsFilter[] { if (configuration.mappings === undefined || configuration.mappings.length === 0) { return undefined } @@ -172,34 +179,17 @@ export default class TagRenderingQuestion extends VariableUiElement { // The multianswer will do the ifnot configuration themself return undefined } - return tagsSource.map(currentTags => { - const negativeMappings = [] - - for (let i = 0; i < configuration.mappings.length; i++) { - const mapping = configuration.mappings[i]; - if (i === excludeIndex || mapping.ifnot === undefined) { - continue - } - - const hidden = mapping.hideInAnswer - if (hidden === undefined) { - negativeMappings.push(mapping.ifnot) - continue - } - if (hidden === true) { - continue - } - - if ((hidden).matchesProperties(currentTags)) { - // This option is currently hidden - continue - } - negativeMappings.push(mapping.ifnot) + + const negativeMappings = [] + for (let i = 0; i < applicableMappings.length; i++) { + const mapping = applicableMappings[i]; + if (i === excludeIndex || mapping.ifnot === undefined) { + continue } - - return Utils.NoNull(negativeMappings) - }) + negativeMappings.push(mapping.ifnot) + } + return Utils.NoNull(negativeMappings) } @@ -213,7 +203,7 @@ export default class TagRenderingQuestion extends VariableUiElement { const dropdown: InputElement = new DropDown("", applicableMappings.map((mapping, i) => { return { - value: new And([mapping.if, ...allIfNotsExcept(i).data]), + value: new And([mapping.if, ...allIfNotsExcept(i)]), shown: Translations.WT(mapping.then).Clone() } }) @@ -356,11 +346,11 @@ export default class TagRenderingQuestion extends VariableUiElement { mapping: { if: TagsFilter, then: Translation, - }, ifNot?: UIEventSource): InputElement { + }, ifNot?: TagsFilter[]): InputElement { - let tagging: TagsFilter | UIEventSource = mapping.if; + let tagging: TagsFilter = mapping.if; if (ifNot !== undefined) { - tagging = ifNot.map(ifNots => new And([mapping.if, ...ifNots])) + tagging = new And([mapping.if, ...ifNot]) } return new FixedInputElement( diff --git a/package.json b/package.json index d7485c874..4f8cc5a9d 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "start:prepare": "ts-node scripts/generateLayerOverview.ts --no-fail && npm run increase-memory", "start:parallel:parcel": "parcel *.html UI/** Logic/** assets/*.json assets/svg/* assets/generated/* assets/layers/*/*.svg assets/layers/*/*.jpg assets/layers/*/*.png assets/tagRenderings/*.json assets/themes/*/*.svg assets/themes/*/*.jpg assets/themes/*/*.png vendor/* vendor/*/*", "start:parallel:tailwindcli": "tailwindcss -i index.css -o css/index-tailwind-output.css --watch", + "generate:css": "tailwindcss -i index.css -o css/index-tailwind-output.css", "test": "ts-node test/TestAll.ts", "init": "npm ci && npm run generate && npm run generate:editor-layer-index && npm run generate:layouts && npm run clean", "add-weblate-upstream": "git remote add weblate-layers https://hosted.weblate.org/git/mapcomplete/layer-translations/ ; git remote update weblate-layers",