Add the possibility to show all questions of a group as one + documentation update
This commit is contained in:
parent
3570cfbaa8
commit
519feaa54b
10 changed files with 140 additions and 34 deletions
|
@ -187,10 +187,10 @@ class OpeningHoursTextField implements TextFieldDef {
|
|||
return new OpeningHoursInput(value, prefix, postfix)
|
||||
}
|
||||
}
|
||||
|
||||
export default class ValidatedTextField {
|
||||
|
||||
public static tpList: TextFieldDef[] = [
|
||||
|
||||
ValidatedTextField.tp(
|
||||
"string",
|
||||
"A basic string"),
|
||||
|
|
|
@ -18,6 +18,7 @@ import {Utils} from "../../Utils";
|
|||
import {SubstitutedTranslation} from "../SubstitutedTranslation";
|
||||
import MoveWizard from "./MoveWizard";
|
||||
import Toggle from "../Input/Toggle";
|
||||
import {FixedUiElement} from "../Base/FixedUiElement";
|
||||
|
||||
export default class FeatureInfoBox extends ScrollableFullScreen {
|
||||
|
||||
|
@ -56,9 +57,16 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
|
|||
|
||||
const allGroupNames = Utils.Dedup(layerConfig.tagRenderings.map(tr => tr.group))
|
||||
if (State.state.featureSwitchUserbadge.data) {
|
||||
const questionSpecs = layerConfig.tagRenderings.filter(tr => tr.id === "questions")
|
||||
for (const groupName of allGroupNames) {
|
||||
const questions = layerConfig.tagRenderings.filter(tr => tr.group === groupName)
|
||||
const questionBox = new QuestionBox({tagsSource: tags, tagRenderings: questions, units:layerConfig.units});
|
||||
const questionSpec = questionSpecs.filter(tr => tr.group === groupName)[0]
|
||||
const questionBox = new QuestionBox({
|
||||
tagsSource: tags,
|
||||
tagRenderings: questions,
|
||||
units: layerConfig.units,
|
||||
showAllQuestionsAtOnce: questionSpec?.freeform?.helperArgs["showAllQuestions"] ?? State.state.featureSwitchShowAllQuestions
|
||||
});
|
||||
questionBoxes.set(groupName, questionBox)
|
||||
}
|
||||
}
|
||||
|
@ -75,21 +83,22 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
|
|||
// This is a question box!
|
||||
const questionBox = questionBoxes.get(tr.group)
|
||||
questionBoxes.delete(tr.group)
|
||||
|
||||
if(tr.render !== undefined){
|
||||
|
||||
if (tr.render !== undefined) {
|
||||
questionBox.SetClass("text-sm")
|
||||
const renderedQuestion = new TagRenderingAnswer(tags, tr, tr.group + " questions", "", {
|
||||
specialViz: new Map<string, BaseUIElement>([["questions", questionBox]])
|
||||
})
|
||||
const possiblyHidden = new Toggle(
|
||||
renderedQuestion,
|
||||
undefined,
|
||||
questionBox.currentQuestion.map(i => i !== undefined)
|
||||
questionBox.restingQuestions.map(ls => ls?.length > 0)
|
||||
)
|
||||
renderingsForGroup.push(possiblyHidden)
|
||||
}else{
|
||||
} else {
|
||||
renderingsForGroup.push(questionBox)
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
let classes = innerClasses
|
||||
let isHeader = renderingsForGroup.length === 0 && i > 0
|
||||
|
|
|
@ -14,14 +14,19 @@ import Lazy from "../Base/Lazy";
|
|||
*/
|
||||
export default class QuestionBox extends VariableUiElement {
|
||||
public readonly skippedQuestions: UIEventSource<number[]>;
|
||||
public readonly currentQuestion: UIEventSource<number | undefined>;
|
||||
public readonly restingQuestions: UIEventSource<BaseUIElement[]>;
|
||||
|
||||
constructor(options: { tagsSource: UIEventSource<any>, tagRenderings: TagRenderingConfig[], units: Unit[] }) {
|
||||
constructor(options: {
|
||||
tagsSource: UIEventSource<any>,
|
||||
tagRenderings: TagRenderingConfig[], units: Unit[],
|
||||
showAllQuestionsAtOnce?: boolean | UIEventSource<boolean>
|
||||
}) {
|
||||
|
||||
const skippedQuestions: UIEventSource<number[]> = new UIEventSource<number[]>([])
|
||||
|
||||
const tagsSource = options.tagsSource
|
||||
const units = options.units
|
||||
options.showAllQuestionsAtOnce = options.showAllQuestionsAtOnce ?? false
|
||||
const tagRenderings = options.tagRenderings
|
||||
.filter(tr => tr.question !== undefined)
|
||||
.filter(tr => tr.question !== null)
|
||||
|
@ -50,8 +55,7 @@ export default class QuestionBox extends VariableUiElement {
|
|||
.onClick(() => {
|
||||
skippedQuestions.setData([]);
|
||||
})
|
||||
|
||||
const currentQuestion: UIEventSource<number | undefined> = tagsSource.map(tags => {
|
||||
tagsSource.map(tags => {
|
||||
if (tags === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
|
@ -74,13 +78,40 @@ export default class QuestionBox extends VariableUiElement {
|
|||
return i
|
||||
}
|
||||
return undefined; // The questions are depleted
|
||||
}, [skippedQuestions]);
|
||||
|
||||
const questionsToAsk: UIEventSource<BaseUIElement[]> = tagsSource.map(tags => {
|
||||
if (tags === undefined) {
|
||||
return [];
|
||||
}
|
||||
const qs = []
|
||||
for (let i = 0; i < tagRenderingQuestions.length; i++) {
|
||||
let tagRendering = tagRenderings[i];
|
||||
|
||||
if (skippedQuestions.data.indexOf(i) >= 0) {
|
||||
continue;
|
||||
}
|
||||
if (tagRendering.IsKnown(tags)) {
|
||||
continue;
|
||||
}
|
||||
if (tagRendering.condition &&
|
||||
!tagRendering.condition.matchesProperties(tags)) {
|
||||
// Filtered away by the condition, so it is kindof known
|
||||
continue;
|
||||
}
|
||||
|
||||
// this value is NOT known - this is the question we have to show!
|
||||
qs.push(tagRenderingQuestions[i])
|
||||
}
|
||||
return qs
|
||||
}, [skippedQuestions])
|
||||
|
||||
|
||||
super(currentQuestion.map(i => {
|
||||
super(questionsToAsk.map(allQuestions => {
|
||||
const els: BaseUIElement[] = []
|
||||
if (i !== undefined) {
|
||||
els.push(tagRenderingQuestions[i])
|
||||
if (options.showAllQuestionsAtOnce === true || options.showAllQuestionsAtOnce["data"]) {
|
||||
els.push(...questionsToAsk.data)
|
||||
} else {
|
||||
els.push(allQuestions[0])
|
||||
}
|
||||
|
||||
if (skippedQuestions.data.length > 0) {
|
||||
|
@ -92,7 +123,7 @@ export default class QuestionBox extends VariableUiElement {
|
|||
)
|
||||
|
||||
this.skippedQuestions = skippedQuestions;
|
||||
this.currentQuestion = currentQuestion
|
||||
this.restingQuestions = questionsToAsk
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue