Adding a 'showAllQuestions'-flag'

This commit is contained in:
pietervdvn 2021-05-17 00:18:21 +02:00
parent fa5ed7c690
commit e555a19d30
7 changed files with 75 additions and 25 deletions

View file

@ -22,6 +22,18 @@ export default class AllKnownLayers {
}
}
}
for(const layout of known_layers.themes){
for (const layer of layout.layers) {
if(typeof layer === "string"){
continue;
}
const parsed = new LayerConfig(layer, "shared_layer_in_theme")
sharedLayers.set(layer.id, parsed);
sharedLayers[layer.id] = parsed;
}
}
return sharedLayers;
}

View file

@ -25,7 +25,7 @@ export default class LayoutConfig {
public readonly widenFactor: number;
public readonly roamingRenderings: TagRenderingConfig[];
public readonly defaultBackgroundId?: string;
public readonly layers: LayerConfig[];
public layers: LayerConfig[];
public readonly clustering?: {
maxZoom: number,
minNeededElements: number
@ -41,6 +41,8 @@ export default class LayoutConfig {
public readonly enableSearch: boolean;
public readonly enableGeolocation: boolean;
public readonly enableBackgroundLayerSelection: boolean;
public readonly enableShowAllQuestions: boolean;
public readonly customCss?: string;
/*
How long is the cache valid, in seconds?
@ -181,6 +183,7 @@ export default class LayoutConfig {
this.enableGeolocation = json.enableGeolocation ?? true;
this.enableAddNewPoints = json.enableAddNewPoints ?? true;
this.enableBackgroundLayerSelection = json.enableBackgroundLayerSelection ?? true;
this.enableShowAllQuestions = json.enableShowAllQuestions ?? false;
this.customCss = json.customCss;
this.cacheTimeout = json.cacheTimout ?? (60 * 24 * 60 * 60)
}

View file

@ -205,4 +205,5 @@ export interface LayoutConfigJson {
enableAddNewPoints?: boolean;
enableGeolocation?: boolean;
enableBackgroundLayerSelection?: boolean;
enableShowAllQuestions?: boolean;
}

View file

@ -39,6 +39,9 @@ import {LayoutConfigJson} from "./Customizations/JSON/LayoutConfigJson";
import AttributionPanel from "./UI/BigComponents/AttributionPanel";
import ContributorCount from "./Logic/ContributorCount";
import FeatureSource from "./Logic/FeatureSource/FeatureSource";
import {AllKnownLayouts} from "./Customizations/AllKnownLayouts";
import AllKnownLayers from "./Customizations/AllKnownLayers";
import LayerConfig from "./Customizations/JSON/LayerConfig";
export class InitUiElements {
@ -83,24 +86,45 @@ export class InitUiElements {
// This is purely for the personal theme to load the layers there
const favs = State.state.favouriteLayers.data ?? [];
const neededLayers = new Set<LayerConfig>();
console.log("Favourites are: ", favs)
layoutToUse.layers.splice(0, layoutToUse.layers.length);
let somethingChanged = false;
for (const fav of favs) {
if(AllKnownLayers.sharedLayers.has(fav)){
const layer = AllKnownLayers.sharedLayers.get(fav)
if(!neededLayers.has(layer)){
neededLayers.add(layer)
somethingChanged = true;
}
}
for (const layouts of State.state.installedThemes.data) {
for (const layer of layouts.layout.layers) {
if (typeof layer === "string") {
continue;
}
if (layer.id === fav) {
layoutToUse.layers.push(layer);
if(!neededLayers.has(layer)){
neededLayers.add(layer)
somethingChanged = true;
}
}
}
}
}
if(somethingChanged){
console.log("layoutToUse.layers:", layoutToUse.layers)
State.state.layoutToUse.data.layers = Array.from(neededLayers);
State.state.layoutToUse.ping();
State.state.layerUpdater?.ForceRefresh();
}
}
if (layoutToUse.customCss !== undefined) {
Utils.LoadCustomCss(layoutToUse.customCss);

View file

@ -2,7 +2,7 @@ import { Utils } from "../Utils";
export default class Constants {
public static vNumber = "0.7.2d";
public static vNumber = "0.7.2e";
// The user journey states thresholds when a new feature gets unlocked
public static userJourney = {

View file

@ -97,6 +97,7 @@ export default class State {
public readonly featureSwitchGeolocation: UIEventSource<boolean>;
public readonly featureSwitchIsTesting: UIEventSource<boolean>;
public readonly featureSwitchIsDebugging: UIEventSource<boolean>;
public readonly featureSwitchShowAllQuestions: UIEventSource<boolean>;
/**
@ -197,6 +198,8 @@ export default class State {
"Disables/Enables the 'Share-screen'-tab in the welcome message");
this.featureSwitchGeolocation = featSw("fs-geolocation", (layoutToUse) => layoutToUse?.enableGeolocation ?? true,
"Disables/Enables the geolocation button");
this.featureSwitchShowAllQuestions = featSw("fs-all-questions", (layoutToUse) => layoutToUse?.enableShowAllQuestions ?? false,
"Always show all questions");
this.featureSwitchIsTesting = QueryParameters.GetQueryParameter("test", "false",

View file

@ -3,6 +3,8 @@ import {UIEventSource} from "../../Logic/UIEventSource";
import TagRenderingConfig from "../../Customizations/JSON/TagRenderingConfig";
import TagRenderingQuestion from "./TagRenderingQuestion";
import Translations from "../i18n/Translations";
import State from "../../State";
import Combine from "../Base/Combine";
/**
@ -47,6 +49,7 @@ export default class QuestionBox extends UIElement {
}
InnerRender(): string {
const allQuestions : UIElement[] = []
for (let i = 0; i < this._tagRenderingQuestions.length; i++) {
let tagRendering = this._tagRenderings[i];
@ -57,15 +60,19 @@ export default class QuestionBox extends UIElement {
if (this._skippedQuestions.data.indexOf(i) >= 0) {
continue;
}
// this value is NOT known
return this._tagRenderingQuestions[i].Render();
// 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(this._skippedQuestions.data.length > 0){
return this._skippedQuestionsButton.Render();
allQuestions.push(this._skippedQuestionsButton)
}
return "";
return new Combine(allQuestions).Render();
}
}