Tweaks to question box
This commit is contained in:
parent
cce14564dc
commit
64532d1faf
7 changed files with 97 additions and 18 deletions
|
@ -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}>
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue