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; return sharedLayers;
} }

View file

@ -25,7 +25,7 @@ export default class LayoutConfig {
public readonly widenFactor: number; public readonly widenFactor: number;
public readonly roamingRenderings: TagRenderingConfig[]; public readonly roamingRenderings: TagRenderingConfig[];
public readonly defaultBackgroundId?: string; public readonly defaultBackgroundId?: string;
public readonly layers: LayerConfig[]; public layers: LayerConfig[];
public readonly clustering?: { public readonly clustering?: {
maxZoom: number, maxZoom: number,
minNeededElements: number minNeededElements: number
@ -41,6 +41,8 @@ export default class LayoutConfig {
public readonly enableSearch: boolean; public readonly enableSearch: boolean;
public readonly enableGeolocation: boolean; public readonly enableGeolocation: boolean;
public readonly enableBackgroundLayerSelection: boolean; public readonly enableBackgroundLayerSelection: boolean;
public readonly enableShowAllQuestions: boolean;
public readonly customCss?: string; public readonly customCss?: string;
/* /*
How long is the cache valid, in seconds? How long is the cache valid, in seconds?
@ -94,10 +96,10 @@ export default class LayoutConfig {
this.layers = json.layers.map((layer, i) => { this.layers = json.layers.map((layer, i) => {
if (typeof layer === "string") { if (typeof layer === "string") {
if (AllKnownLayers.sharedLayersJson[layer] !== undefined) { if (AllKnownLayers.sharedLayersJson[layer] !== undefined) {
if(json.overrideAll !== undefined){ if (json.overrideAll !== undefined) {
let lyr = JSON.parse(JSON.stringify( AllKnownLayers.sharedLayersJson[layer])); let lyr = JSON.parse(JSON.stringify(AllKnownLayers.sharedLayersJson[layer]));
return new LayerConfig(Utils.Merge(json.overrideAll, lyr),`${this.id}+overrideAll.layers[${i}]`, official); return new LayerConfig(Utils.Merge(json.overrideAll, lyr), `${this.id}+overrideAll.layers[${i}]`, official);
}else{ } else {
return AllKnownLayers.sharedLayers[layer] return AllKnownLayers.sharedLayers[layer]
} }
} else { } else {
@ -117,7 +119,7 @@ export default class LayoutConfig {
} }
if(json.overrideAll !== undefined){ if (json.overrideAll !== undefined) {
layer = Utils.Merge(json.overrideAll, layer); layer = Utils.Merge(json.overrideAll, layer);
} }
@ -181,6 +183,7 @@ export default class LayoutConfig {
this.enableGeolocation = json.enableGeolocation ?? true; this.enableGeolocation = json.enableGeolocation ?? true;
this.enableAddNewPoints = json.enableAddNewPoints ?? true; this.enableAddNewPoints = json.enableAddNewPoints ?? true;
this.enableBackgroundLayerSelection = json.enableBackgroundLayerSelection ?? true; this.enableBackgroundLayerSelection = json.enableBackgroundLayerSelection ?? true;
this.enableShowAllQuestions = json.enableShowAllQuestions ?? false;
this.customCss = json.customCss; this.customCss = json.customCss;
this.cacheTimeout = json.cacheTimout ?? (60 * 24 * 60 * 60) this.cacheTimeout = json.cacheTimout ?? (60 * 24 * 60 * 60)
} }
@ -211,7 +214,7 @@ export default class LayoutConfig {
return icons return icons
} }
public LayerIndex() : Map<string, LayerConfig>{ public LayerIndex(): Map<string, LayerConfig> {
const index = new Map<string, LayerConfig>(); const index = new Map<string, LayerConfig>();
for (const layer of this.layers) { for (const layer of this.layers) {
index.set(layer.id, layer) index.set(layer.id, layer)
@ -236,7 +239,7 @@ export default class LayoutConfig {
let path = new URL(originalURL).href let path = new URL(originalURL).href
path = path.substring(0, path.lastIndexOf("/")) path = path.substring(0, path.lastIndexOf("/"))
for (const image of allImages) { for (const image of allImages) {
if(image == "" || image == undefined){ if (image == "" || image == undefined) {
continue continue
} }
if (image.startsWith("http://") || image.startsWith("https://")) { if (image.startsWith("http://") || image.startsWith("https://")) {
@ -260,7 +263,7 @@ export default class LayoutConfig {
return this; return this;
} }
rewriting.forEach((value, key) => { rewriting.forEach((value, key) => {
console.log("Rewriting",key, "==>", value) console.log("Rewriting", key, "==>", value)
originalJson = originalJson.replace(new RegExp(key, "g"), value) originalJson = originalJson.replace(new RegExp(key, "g"), value)
}) })

View file

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

View file

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

View file

@ -2,7 +2,7 @@ import { Utils } from "../Utils";
export default class Constants { 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 // The user journey states thresholds when a new feature gets unlocked
public static userJourney = { public static userJourney = {

View file

@ -97,6 +97,7 @@ export default class State {
public readonly featureSwitchGeolocation: UIEventSource<boolean>; public readonly featureSwitchGeolocation: UIEventSource<boolean>;
public readonly featureSwitchIsTesting: UIEventSource<boolean>; public readonly featureSwitchIsTesting: UIEventSource<boolean>;
public readonly featureSwitchIsDebugging: 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"); "Disables/Enables the 'Share-screen'-tab in the welcome message");
this.featureSwitchGeolocation = featSw("fs-geolocation", (layoutToUse) => layoutToUse?.enableGeolocation ?? true, this.featureSwitchGeolocation = featSw("fs-geolocation", (layoutToUse) => layoutToUse?.enableGeolocation ?? true,
"Disables/Enables the geolocation button"); "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", this.featureSwitchIsTesting = QueryParameters.GetQueryParameter("test", "false",

View file

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