forked from MapComplete/MapComplete
Tweaks to question box
This commit is contained in:
parent
cce14564dc
commit
64532d1faf
7 changed files with 97 additions and 18 deletions
|
@ -620,6 +620,10 @@ export default class TagRenderingConfig {
|
||||||
singleSelectedMapping: number,
|
singleSelectedMapping: number,
|
||||||
multiSelectedMapping: boolean[] | undefined
|
multiSelectedMapping: boolean[] | undefined
|
||||||
): UploadableTag {
|
): UploadableTag {
|
||||||
|
freeformValue = freeformValue?.trim()
|
||||||
|
if (freeformValue === "") {
|
||||||
|
freeformValue = undefined
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
freeformValue === undefined &&
|
freeformValue === undefined &&
|
||||||
singleSelectedMapping === undefined &&
|
singleSelectedMapping === undefined &&
|
||||||
|
@ -627,6 +631,7 @@ export default class TagRenderingConfig {
|
||||||
) {
|
) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.mappings === undefined && freeformValue === undefined) {
|
if (this.mappings === undefined && freeformValue === undefined) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
@ -663,7 +668,13 @@ export default class TagRenderingConfig {
|
||||||
}
|
}
|
||||||
return TagUtils.FlattenMultiAnswer([...selectedMappings, ...unselectedMappings])
|
return TagUtils.FlattenMultiAnswer([...selectedMappings, ...unselectedMappings])
|
||||||
} else {
|
} else {
|
||||||
|
if (singleSelectedMapping === undefined) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
if (singleSelectedMapping === this.mappings.length) {
|
if (singleSelectedMapping === this.mappings.length) {
|
||||||
|
if (freeformValue === undefined) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
return new And([
|
return new And([
|
||||||
new Tag(this.freeform.key, freeformValue),
|
new Tag(this.freeform.key, freeformValue),
|
||||||
...(this.freeform.addExtraTags ?? []),
|
...(this.freeform.addExtraTags ?? []),
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
export let src: string;
|
export let src: string;
|
||||||
let htmlElem: HTMLElement;
|
let htmlElem: HTMLElement;
|
||||||
$: {
|
$: {
|
||||||
if(htmlElem !== undefined){
|
if(htmlElem){
|
||||||
htmlElem.innerHTML = src
|
htmlElem.innerHTML = src
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
const baseQuestions = (layer.tagRenderings ?? [])?.filter(tr => allowed(tr.labels) && tr.question !== undefined);
|
const baseQuestions = (layer.tagRenderings ?? [])?.filter(tr => allowed(tr.labels) && tr.question !== undefined);
|
||||||
console.log("BaseQuestions are", baseQuestions);
|
console.log("BaseQuestions are", baseQuestions);
|
||||||
let skippedQuestions = new UIEventSource<Set<string>>(new Set<string>());
|
let skippedQuestions = new UIEventSource<Set<string>>(new Set<string>());
|
||||||
let answered : number = 0
|
|
||||||
let questionsToAsk = tags.map(tags => {
|
let questionsToAsk = tags.map(tags => {
|
||||||
const questionsToAsk: TagRenderingConfig[] = [];
|
const questionsToAsk: TagRenderingConfig[] = [];
|
||||||
for (const baseQuestion of baseQuestions) {
|
for (const baseQuestion of baseQuestions) {
|
||||||
|
@ -56,31 +56,74 @@
|
||||||
if (baseQuestion.condition !== undefined && !baseQuestion.condition.matchesProperties(tags)) {
|
if (baseQuestion.condition !== undefined && !baseQuestion.condition.matchesProperties(tags)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (baseQuestion.IsKnown(tags)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
questionsToAsk.push(baseQuestion);
|
questionsToAsk.push(baseQuestion);
|
||||||
}
|
}
|
||||||
return questionsToAsk;
|
return questionsToAsk;
|
||||||
|
|
||||||
}, [skippedQuestions]);
|
}, [skippedQuestions]);
|
||||||
let _questionsToAsk: TagRenderingConfig[];
|
let _questionsToAsk: TagRenderingConfig[];
|
||||||
let _firstQuestion: TagRenderingConfig
|
let _firstQuestion: TagRenderingConfig;
|
||||||
onDestroy(questionsToAsk.subscribe(qta => {
|
onDestroy(questionsToAsk.subscribe(qta => {
|
||||||
_questionsToAsk = qta;
|
_questionsToAsk = qta;
|
||||||
_firstQuestion = qta[0]
|
_firstQuestion = qta[0];
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
let answered: number = 0;
|
||||||
|
let skipped: number = 0;
|
||||||
|
|
||||||
function skip(question: TagRenderingConfig, didAnswer: boolean = false) {
|
function skip(question: TagRenderingConfig, didAnswer: boolean = false) {
|
||||||
skippedQuestions.data.add(question.id);
|
skippedQuestions.data.add(question.id);
|
||||||
skippedQuestions.ping();
|
skippedQuestions.ping();
|
||||||
if(didAnswer ){
|
if (didAnswer) {
|
||||||
answered ++
|
answered++;
|
||||||
|
} else {
|
||||||
|
skipped++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if _questionsToAsk.length === 0}
|
{#if _questionsToAsk.length === 0}
|
||||||
All done! You answered {answered} questions and skipped {$skippedQuestions.size} questions.
|
|
||||||
{#if $skippedQuestions.size > 0 }
|
{#if skipped + answered > 0 }
|
||||||
<button on:click={() => skippedQuestions.setData(new Set())}>Re-activate skipped questions</button>
|
<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}
|
{/if}
|
||||||
{:else }
|
{:else }
|
||||||
<div>
|
<div>
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
import ChangeTagAction from "../../../Logic/Osm/Actions/ChangeTagAction";
|
import ChangeTagAction from "../../../Logic/Osm/Actions/ChangeTagAction";
|
||||||
import { createEventDispatcher } from "svelte";
|
import { createEventDispatcher } from "svelte";
|
||||||
import LayerConfig from "../../../Models/ThemeConfig/LayerConfig";
|
import LayerConfig from "../../../Models/ThemeConfig/LayerConfig";
|
||||||
|
import { ExclamationIcon } from "@rgossiaux/svelte-heroicons/solid";
|
||||||
|
|
||||||
export let config: TagRenderingConfig;
|
export let config: TagRenderingConfig;
|
||||||
export let tags: UIEventSource<Record<string, string>>;
|
export let tags: UIEventSource<Record<string, string>>;
|
||||||
|
@ -23,13 +24,24 @@
|
||||||
|
|
||||||
// Will be bound if a freeform is available
|
// Will be bound if a freeform is available
|
||||||
let freeformInput = new UIEventSource<string>(undefined);
|
let freeformInput = new UIEventSource<string>(undefined);
|
||||||
let selectedMapping: number = 0;
|
let selectedMapping: number = undefined;
|
||||||
let checkedMappings: boolean[];
|
let checkedMappings: boolean[];
|
||||||
|
$: {
|
||||||
|
|
||||||
if (config.mappings?.length > 0) {
|
if (config.mappings?.length > 0) {
|
||||||
checkedMappings = [...config.mappings.map(_ => false), false /*One element extra in case a freeform value is added*/];
|
checkedMappings = [...config.mappings.map(_ => false), false /*One element extra in case a freeform value is added*/];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
let selectedTags: TagsFilter = undefined;
|
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 {
|
function mappingIsHidden(mapping: Mapping): boolean {
|
||||||
if (mapping.hideInAnswer === undefined || mapping.hideInAnswer === false) {
|
if (mapping.hideInAnswer === undefined || mapping.hideInAnswer === false) {
|
||||||
|
@ -59,6 +71,9 @@
|
||||||
changeType: "answer"
|
changeType: "answer"
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
freeformInput.setData(undefined);
|
||||||
|
selectedMapping = 0;
|
||||||
|
selectedTags = undefined;
|
||||||
change.CreateChangeDescriptions().then(changes =>
|
change.CreateChangeDescriptions().then(changes =>
|
||||||
state.changes.applyChanges(changes)
|
state.changes.applyChanges(changes)
|
||||||
).catch(console.error);
|
).catch(console.error);
|
||||||
|
@ -138,9 +153,16 @@
|
||||||
<div>
|
<div>
|
||||||
<!-- TagRenderingQuestion-buttons -->
|
<!-- TagRenderingQuestion-buttons -->
|
||||||
<slot name="cancel"></slot>
|
<slot name="cancel"></slot>
|
||||||
|
{#if selectedTags !== undefined}
|
||||||
<button on:click={onSave}>
|
<button on:click={onSave}>
|
||||||
<Tr t={Translations.t.general.save}></Tr>
|
<Tr t={Translations.t.general.save}></Tr>
|
||||||
</button>
|
</button>
|
||||||
|
{:else }
|
||||||
|
<div class="w-6 h-6">
|
||||||
|
<!-- Invalid value; show an inactive button or something like that-->
|
||||||
|
<ExclamationIcon></ExclamationIcon>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -253,12 +253,15 @@
|
||||||
"pickLanguage": "Choose a language: ",
|
"pickLanguage": "Choose a language: ",
|
||||||
"poweredByOsm": "Powered by OpenStreetMap",
|
"poweredByOsm": "Powered by OpenStreetMap",
|
||||||
"questionBox": {
|
"questionBox": {
|
||||||
|
"answeredMultiple": "You answered {answered} questions",
|
||||||
"answeredMultipleSkippedMultiple": "You answered {answered} questions and skipped {skipped} questions",
|
"answeredMultipleSkippedMultiple": "You answered {answered} questions and skipped {skipped} questions",
|
||||||
"answeredMultipleSkippedOne": "You answered {answered} questions and skipped one question",
|
"answeredMultipleSkippedOne": "You answered {answered} questions and skipped one question",
|
||||||
"answeredOne": "You answered one question",
|
"answeredOne": "You answered one question",
|
||||||
"answeredOneSkippedMultiple": "You answered one question and skipped {skipped} questions",
|
"answeredOneSkippedMultiple": "You answered one question and skipped {skipped} questions",
|
||||||
"answeredOneSkippedOne": "You answered one and skipped one question",
|
"answeredOneSkippedOne": "You answered one and skipped one question",
|
||||||
|
"done": "No more questions! Thank you!",
|
||||||
"reactivate": "Reactive skipped questions",
|
"reactivate": "Reactive skipped questions",
|
||||||
|
"skippedMultiple": "You skipped {skipped} questions",
|
||||||
"skippedOne": "You skipped one question"
|
"skippedOne": "You skipped one question"
|
||||||
},
|
},
|
||||||
"questions": {
|
"questions": {
|
||||||
|
|
Loading…
Add table
Reference in a new issue