Tweaks to question box

This commit is contained in:
Pieter Vander Vennet 2023-03-31 04:04:11 +02:00
parent cce14564dc
commit 64532d1faf
7 changed files with 97 additions and 18 deletions

View file

@ -620,6 +620,10 @@ export default class TagRenderingConfig {
singleSelectedMapping: number,
multiSelectedMapping: boolean[] | undefined
): UploadableTag {
freeformValue = freeformValue?.trim()
if (freeformValue === "") {
freeformValue = undefined
}
if (
freeformValue === undefined &&
singleSelectedMapping === undefined &&
@ -627,6 +631,7 @@ export default class TagRenderingConfig {
) {
return undefined
}
if (this.mappings === undefined && freeformValue === undefined) {
return undefined
}
@ -663,7 +668,13 @@ export default class TagRenderingConfig {
}
return TagUtils.FlattenMultiAnswer([...selectedMappings, ...unselectedMappings])
} else {
if (singleSelectedMapping === undefined) {
return undefined
}
if (singleSelectedMapping === this.mappings.length) {
if (freeformValue === undefined) {
return undefined
}
return new And([
new Tag(this.freeform.key, freeformValue),
...(this.freeform.addExtraTags ?? []),

View file

@ -6,7 +6,7 @@
export let src: string;
let htmlElem: HTMLElement;
$: {
if(htmlElem !== undefined){
if(htmlElem){
htmlElem.innerHTML = src
}
}

View file

@ -46,7 +46,7 @@
const baseQuestions = (layer.tagRenderings ?? [])?.filter(tr => allowed(tr.labels) && tr.question !== undefined);
console.log("BaseQuestions are", baseQuestions);
let skippedQuestions = new UIEventSource<Set<string>>(new Set<string>());
let answered : number = 0
let questionsToAsk = tags.map(tags => {
const questionsToAsk: TagRenderingConfig[] = [];
for (const baseQuestion of baseQuestions) {
@ -56,32 +56,75 @@
if (baseQuestion.condition !== undefined && !baseQuestion.condition.matchesProperties(tags)) {
continue;
}
if (baseQuestion.IsKnown(tags)) {
continue;
}
questionsToAsk.push(baseQuestion);
}
return questionsToAsk;
}, [skippedQuestions]);
let _questionsToAsk: TagRenderingConfig[];
let _firstQuestion: TagRenderingConfig
let _firstQuestion: TagRenderingConfig;
onDestroy(questionsToAsk.subscribe(qta => {
_questionsToAsk = qta;
_firstQuestion = qta[0]
_firstQuestion = qta[0];
}));
let answered: number = 0;
let skipped: number = 0;
function skip(question: TagRenderingConfig, didAnswer: boolean = false) {
skippedQuestions.data.add(question.id);
skippedQuestions.ping();
if(didAnswer ){
answered ++
if (didAnswer) {
answered++;
} else {
skipped++;
}
}
</script>
{#if _questionsToAsk.length === 0}
All done! You answered {answered} questions and skipped {$skippedQuestions.size} questions.
{#if $skippedQuestions.size > 0 }
<button on:click={() => skippedQuestions.setData(new Set())}>Re-activate skipped questions</button>
{#if skipped + answered > 0 }
<div class="thanks">
<Tr t={Translations.t.general.questionBox.done} />
</div>
{#if answered === 0}
{#if skipped === 1}
<Tr t={Translations.t.general.questionBox.skippedOne} />
{:else}
<Tr t={Translations.t.general.questionBox.skippedMultiple.Subs({skipped})} />
{/if}
{:else if answered === 1}
{#if skipped === 0}
<Tr t={Translations.t.general.questionBox.answeredOne} />
{:else if skipped === 1}
<Tr t={Translations.t.general.questionBox.answeredOneSkippedOne} />
{:else}
<Tr t={Translations.t.general.questionBox.answeredOneSkippedMultiple.Subs({skipped})} />
{/if}
{:else}
{#if skipped === 0}
<Tr t={Translations.t.general.questionBox.answeredMultiple.Subs({answered})} />
{:else if skipped === 1}
<Tr t={Translations.t.general.questionBox.answeredMultipleSkippedOne.Subs({answered})} />
{:else}
<Tr
t={Translations.t.general.questionBox.answeredMultipleSkippedMultiple.Subs({answered, skipped})} />
{/if}
{/if}
{#if skipped > 0 }
<button on:click={() => {skippedQuestions.setData(new Set()); skipped=0}}>
Re-activate skipped questions
</button>
{/if}
{/if}
{:else }
<div>
<If condition={state.userRelatedState.showAllQuestionsAtOnce}>

View file

@ -14,6 +14,7 @@
import ChangeTagAction from "../../../Logic/Osm/Actions/ChangeTagAction";
import { createEventDispatcher } from "svelte";
import LayerConfig from "../../../Models/ThemeConfig/LayerConfig";
import { ExclamationIcon } from "@rgossiaux/svelte-heroicons/solid";
export let config: TagRenderingConfig;
export let tags: UIEventSource<Record<string, string>>;
@ -23,13 +24,24 @@
// Will be bound if a freeform is available
let freeformInput = new UIEventSource<string>(undefined);
let selectedMapping: number = 0;
let selectedMapping: number = undefined;
let checkedMappings: boolean[];
if (config.mappings?.length > 0) {
checkedMappings = [...config.mappings.map(_ => false), false /*One element extra in case a freeform value is added*/];
$: {
if (config.mappings?.length > 0) {
checkedMappings = [...config.mappings.map(_ => false), false /*One element extra in case a freeform value is added*/];
}
}
let selectedTags: TagsFilter = undefined;
$:selectedTags = config?.constructChangeSpecification($freeformInput, selectedMapping, checkedMappings);
$: {
try {
selectedTags = config?.constructChangeSpecification($freeformInput, selectedMapping, checkedMappings);
} catch (e) {
console.debug("Could not calculate changeSpecification:", e);
selectedTags = undefined;
}
}
function mappingIsHidden(mapping: Mapping): boolean {
if (mapping.hideInAnswer === undefined || mapping.hideInAnswer === false) {
@ -59,6 +71,9 @@
changeType: "answer"
}
);
freeformInput.setData(undefined);
selectedMapping = 0;
selectedTags = undefined;
change.CreateChangeDescriptions().then(changes =>
state.changes.applyChanges(changes)
).catch(console.error);
@ -138,9 +153,16 @@
<div>
<!-- TagRenderingQuestion-buttons -->
<slot name="cancel"></slot>
<button on:click={onSave}>
<Tr t={Translations.t.general.save}></Tr>
</button>
{#if selectedTags !== undefined}
<button on:click={onSave}>
<Tr t={Translations.t.general.save}></Tr>
</button>
{:else }
<div class="w-6 h-6">
<!-- Invalid value; show an inactive button or something like that-->
<ExclamationIcon></ExclamationIcon>
</div>
{/if}
</div>
</div>

View file

@ -1984,4 +1984,4 @@
"pl": "Nazwa sieci to <b>{internet_access:ssid}</b>"
}
}
}
}

View file

@ -495,4 +495,4 @@
]
},
"enableDownload": true
}
}

View file

@ -253,12 +253,15 @@
"pickLanguage": "Choose a language: ",
"poweredByOsm": "Powered by OpenStreetMap",
"questionBox": {
"answeredMultiple": "You answered {answered} questions",
"answeredMultipleSkippedMultiple": "You answered {answered} questions and skipped {skipped} questions",
"answeredMultipleSkippedOne": "You answered {answered} questions and skipped one question",
"answeredOne": "You answered one question",
"answeredOneSkippedMultiple": "You answered one question and skipped {skipped} questions",
"answeredOneSkippedOne": "You answered one and skipped one question",
"done": "No more questions! Thank you!",
"reactivate": "Reactive skipped questions",
"skippedMultiple": "You skipped {skipped} questions",
"skippedOne": "You skipped one question"
},
"questions": {