Further cleanup: further removal of the UIElement

This commit is contained in:
Pieter Vander Vennet 2021-06-28 00:45:49 +02:00
parent 09ba1b37c6
commit 785f57262e
15 changed files with 169 additions and 294 deletions

View file

@ -1,4 +1,3 @@
import {UIElement} from "../UIElement";
import {UIEventSource} from "../../Logic/UIEventSource";
import TagRenderingConfig from "../../Customizations/JSON/TagRenderingConfig";
import TagRenderingQuestion from "./TagRenderingQuestion";
@ -7,74 +6,73 @@ import State from "../../State";
import Combine from "../Base/Combine";
import BaseUIElement from "../BaseUIElement";
import {Unit} from "../../Customizations/JSON/Denomination";
import {VariableUiElement} from "../Base/VariableUIElement";
/**
* Generates all the questions, one by one
*/
export default class QuestionBox extends UIElement {
private readonly _tags: UIEventSource<any>;
export default class QuestionBox extends VariableUiElement {
private readonly _tagRenderings: TagRenderingConfig[];
private _tagRenderingQuestions: BaseUIElement[];
constructor(tagsSource: UIEventSource<any>, tagRenderings: TagRenderingConfig[], units: Unit[]) {
const skippedQuestions: UIEventSource<number[]> = new UIEventSource<number[]>([])
private _skippedQuestions: UIEventSource<number[]> = new UIEventSource<number[]>([])
private _skippedQuestionsButton: BaseUIElement;
constructor(tags: UIEventSource<any>, tagRenderings: TagRenderingConfig[], units: Unit[]) {
super(tags);
this.ListenTo(this._skippedQuestions);
this._tags = tags;
const self = this;
this._tagRenderings = tagRenderings
tagRenderings = tagRenderings
.filter(tr => tr.question !== undefined)
.filter(tr => tr.question !== null);
this._tagRenderingQuestions = this._tagRenderings
.map((tagRendering, i) => new TagRenderingQuestion(this._tags, tagRendering,units,
() => {
// We save
self._skippedQuestions.ping();
},
Translations.t.general.skip.Clone()
.SetClass("btn btn-secondary mr-3")
super(tagsSource.map(tags => {
if (tags === undefined) {
return undefined;
}
const tagRenderingQuestions = tagRenderings
.map((tagRendering, i) => new TagRenderingQuestion(tagsSource, tagRendering, units,
() => {
// We save
skippedQuestions.ping();
},
Translations.t.general.skip.Clone()
.SetClass("btn btn-secondary mr-3")
.onClick(() => {
skippedQuestions.data.push(i);
skippedQuestions.ping();
})
));
const skippedQuestionsButton = Translations.t.general.skippedQuestions.Clone()
.onClick(() => {
self._skippedQuestions.data.push(i);
self._skippedQuestions.ping();
skippedQuestions.setData([]);
})
));
this._skippedQuestionsButton = Translations.t.general.skippedQuestions.Clone()
.onClick(() => {
self._skippedQuestions.setData([]);
})
this.SetClass("block mb-8")
}
InnerRender() {
const allQuestions : BaseUIElement[] = []
for (let i = 0; i < this._tagRenderingQuestions.length; i++) {
let tagRendering = this._tagRenderings[i];
const allQuestions: BaseUIElement[] = []
for (let i = 0; i < tagRenderingQuestions.length; i++) {
let tagRendering = tagRenderings[i];
if(tagRendering.IsKnown(this._tags.data)){
continue;
}
if (tagRendering.IsKnown(tags)) {
continue;
}
if (this._skippedQuestions.data.indexOf(i) >= 0) {
continue;
}
// this value is NOT known - we show the questions for it
if(State.state.featureSwitchShowAllQuestions.data || allQuestions.length == 0){
allQuestions.push(this._tagRenderingQuestions[i])
}
}
if (skippedQuestions.data.indexOf(i) >= 0) {
continue;
}
// this value is NOT known - we show the questions for it
if (State.state.featureSwitchShowAllQuestions.data || allQuestions.length == 0) {
allQuestions.push(tagRenderingQuestions[i])
}
if(this._skippedQuestions.data.length > 0){
allQuestions.push(this._skippedQuestionsButton)
}
}
if (skippedQuestions.data.length > 0) {
allQuestions.push(skippedQuestionsButton)
}
return new Combine(allQuestions).SetClass("block mb-8")
}, [skippedQuestions])
)
return new Combine(allQuestions);
}
}