Another sanity check, another bunch of fixed layers; add tagrendering-steal possibility, add some styling to TV-theme

This commit is contained in:
Pieter Vander Vennet 2021-11-10 18:42:31 +01:00
parent 10ac6a72e2
commit 746273f594
57 changed files with 602 additions and 940 deletions

View file

@ -44,6 +44,11 @@ export default class DefaultGUI {
this.SetupUIElements();
this.SetupMap()
if(state.layoutToUse.customCss !== undefined && window.location.pathname.indexOf("index") >= 0){
Utils.LoadCustomCss(state.layoutToUse.customCss)
}
}
public setupClickDialogOnMap(filterViewIsOpened: UIEventSource<boolean>, state: FeaturePipelineState) {

View file

@ -17,6 +17,7 @@ import {Translation} from "../i18n/Translation";
import {Utils} from "../../Utils";
import {SubstitutedTranslation} from "../SubstitutedTranslation";
import MoveWizard from "./MoveWizard";
import Toggle from "../Input/Toggle";
export default class FeatureInfoBox extends ScrollableFullScreen {
@ -51,13 +52,13 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
private static GenerateContent(tags: UIEventSource<any>,
layerConfig: LayerConfig): BaseUIElement {
let questionBoxes: Map<string, BaseUIElement> = new Map<string, BaseUIElement>();
let questionBoxes: Map<string, QuestionBox> = new Map<string, QuestionBox>();
const allGroupNames = Utils.Dedup(layerConfig.tagRenderings.map(tr => tr.group))
if (State.state.featureSwitchUserbadge.data) {
for (const groupName of allGroupNames) {
const questions = layerConfig.tagRenderings.filter(tr => tr.group === groupName)
const questionBox = new QuestionBox(tags, questions, layerConfig.units);
const questionBox = new QuestionBox({tagsSource: tags, tagRenderings: questions, units:layerConfig.units});
questionBoxes.set(groupName, questionBox)
}
}
@ -75,7 +76,20 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
const questionBox = questionBoxes.get(tr.group)
questionBoxes.delete(tr.group)
renderingsForGroup.push(questionBox)
if(tr.render !== undefined){
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)
)
renderingsForGroup.push(possiblyHidden)
}else{
renderingsForGroup.push(questionBox)
}
} else {
let classes = innerClasses
let isHeader = renderingsForGroup.length === 0 && i > 0

View file

@ -1,7 +1,6 @@
import {UIEventSource} from "../../Logic/UIEventSource";
import TagRenderingQuestion from "./TagRenderingQuestion";
import Translations from "../i18n/Translations";
import State from "../../State";
import Combine from "../Base/Combine";
import BaseUIElement from "../BaseUIElement";
import {VariableUiElement} from "../Base/VariableUIElement";
@ -14,71 +13,88 @@ import Lazy from "../Base/Lazy";
* Generates all the questions, one by one
*/
export default class QuestionBox extends VariableUiElement {
public readonly skippedQuestions: UIEventSource<number[]>;
public readonly currentQuestion: UIEventSource<number | undefined>;
constructor(tagsSource: UIEventSource<any>, tagRenderings: TagRenderingConfig[], units: Unit[]) {
constructor(options: { tagsSource: UIEventSource<any>, tagRenderings: TagRenderingConfig[], units: Unit[] }) {
const skippedQuestions: UIEventSource<number[]> = new UIEventSource<number[]>([])
tagRenderings = tagRenderings
const tagsSource = options.tagsSource
const units = options.units
const tagRenderings = options.tagRenderings
.filter(tr => tr.question !== undefined)
.filter(tr => tr.question !== null);
.filter(tr => tr.question !== null)
super(tagsSource.map(tags => {
if (tags === undefined) {
return undefined;
const tagRenderingQuestions = tagRenderings
.map((tagRendering, i) =>
new Lazy(() => new TagRenderingQuestion(tagsSource, tagRendering,
{
units: units,
afterSave: () => {
// We save and indicate progress by pinging and recalculating
skippedQuestions.ping();
},
cancelButton: Translations.t.general.skip.Clone()
.SetClass("btn btn-secondary mr-3")
.onClick(() => {
skippedQuestions.data.push(i);
skippedQuestions.ping();
})
}
)));
const skippedQuestionsButton = Translations.t.general.skippedQuestions
.onClick(() => {
skippedQuestions.setData([]);
})
const currentQuestion: UIEventSource<number | undefined> = tagsSource.map(tags => {
if (tags === undefined) {
return undefined;
}
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;
}
const tagRenderingQuestions = tagRenderings
.map((tagRendering, i) =>
new Lazy(() => new TagRenderingQuestion(tagsSource, tagRendering,
{
units: units,
afterSave: () => {
// We save and indicate progress by pinging and recalculating
skippedQuestions.ping();
},
cancelButton: Translations.t.general.skip.Clone()
.SetClass("btn btn-secondary mr-3")
.onClick(() => {
skippedQuestions.data.push(i);
skippedQuestions.ping();
})
}
)));
const skippedQuestionsButton = Translations.t.general.skippedQuestions
.onClick(() => {
skippedQuestions.setData([]);
})
// this value is NOT known - this is the question we have to show!
return i
}
return undefined; // The questions are depleted
}, [skippedQuestions])
const allQuestions: BaseUIElement[] = []
for (let i = 0; i < tagRenderingQuestions.length; i++) {
let tagRendering = tagRenderings[i];
if (tagRendering.IsKnown(tags)) {
continue;
}
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])
}
super(currentQuestion.map(i => {
const els: BaseUIElement[] = []
if (i !== undefined) {
els.push(tagRenderingQuestions[i])
}
if (skippedQuestions.data.length > 0) {
allQuestions.push(skippedQuestionsButton)
els.push(skippedQuestionsButton)
}
return new Combine(allQuestions).SetClass("block mb-8")
}, [skippedQuestions])
return new Combine(els).SetClass("block mb-8")
})
)
this.skippedQuestions = skippedQuestions;
this.currentQuestion = currentQuestion
}
}

View file

@ -12,7 +12,9 @@ import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig";
export default class TagRenderingAnswer extends VariableUiElement {
constructor(tagsSource: UIEventSource<any>, configuration: TagRenderingConfig,
contentClasses: string = "", contentStyle: string = "") {
contentClasses: string = "", contentStyle: string = "", options?:{
specialViz: Map<string, BaseUIElement>
}) {
if (configuration === undefined) {
throw "Trying to generate a tagRenderingAnswer without configuration..."
}
@ -35,7 +37,7 @@ export default class TagRenderingAnswer extends VariableUiElement {
return undefined;
}
const valuesToRender: BaseUIElement[] = trs.map(tr => new SubstitutedTranslation(tr, tagsSource))
const valuesToRender: BaseUIElement[] = trs.map(tr => new SubstitutedTranslation(tr, tagsSource, options?.specialViz))
if (valuesToRender.length === 1) {
return valuesToRender[0];
} else if (valuesToRender.length > 1) {