diff --git a/Customizations/AllKnownLayers.ts b/Customizations/AllKnownLayers.ts index 68bd2f1de..2c97f7513 100644 --- a/Customizations/AllKnownLayers.ts +++ b/Customizations/AllKnownLayers.ts @@ -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; } diff --git a/Customizations/JSON/LayoutConfig.ts b/Customizations/JSON/LayoutConfig.ts index ad7876224..ba1032cf5 100644 --- a/Customizations/JSON/LayoutConfig.ts +++ b/Customizations/JSON/LayoutConfig.ts @@ -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? @@ -94,10 +96,10 @@ export default class LayoutConfig { this.layers = json.layers.map((layer, i) => { if (typeof layer === "string") { if (AllKnownLayers.sharedLayersJson[layer] !== undefined) { - if(json.overrideAll !== undefined){ - let lyr = JSON.parse(JSON.stringify( AllKnownLayers.sharedLayersJson[layer])); - return new LayerConfig(Utils.Merge(json.overrideAll, lyr),`${this.id}+overrideAll.layers[${i}]`, official); - }else{ + if (json.overrideAll !== undefined) { + let lyr = JSON.parse(JSON.stringify(AllKnownLayers.sharedLayersJson[layer])); + return new LayerConfig(Utils.Merge(json.overrideAll, lyr), `${this.id}+overrideAll.layers[${i}]`, official); + } else { return AllKnownLayers.sharedLayers[layer] } } else { @@ -114,17 +116,17 @@ export default class LayoutConfig { } // @ts-ignore layer = Utils.Merge(layer.override, JSON.parse(JSON.stringify(shared))); // We make a deep copy of the shared layer, in order to protect it from changes - - + + } - if(json.overrideAll !== undefined){ + if (json.overrideAll !== undefined) { layer = Utils.Merge(json.overrideAll, layer); } - + // @ts-ignore return new LayerConfig(layer, `${this.id}.layers[${i}]`, official) }); - + // ALl the layers are constructed, let them share tags in now! const roaming: { r, source: LayerConfig }[] = [] for (const layer of this.layers) { @@ -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) } @@ -210,8 +213,8 @@ export default class LayoutConfig { icons.add(this.socialImage) return icons } - - public LayerIndex() : Map{ + + public LayerIndex(): Map { const index = new Map(); for (const layer of this.layers) { index.set(layer.id, layer) @@ -236,7 +239,7 @@ export default class LayoutConfig { let path = new URL(originalURL).href path = path.substring(0, path.lastIndexOf("/")) for (const image of allImages) { - if(image == "" || image == undefined){ + if (image == "" || image == undefined) { continue } if (image.startsWith("http://") || image.startsWith("https://")) { @@ -260,8 +263,8 @@ export default class LayoutConfig { return this; } rewriting.forEach((value, key) => { - console.log("Rewriting",key, "==>", value) - + console.log("Rewriting", key, "==>", value) + originalJson = originalJson.replace(new RegExp(key, "g"), value) }) return new LayoutConfig(JSON.parse(originalJson), false, "Layout rewriting") diff --git a/Customizations/JSON/LayoutConfigJson.ts b/Customizations/JSON/LayoutConfigJson.ts index 3543effc8..f17041b79 100644 --- a/Customizations/JSON/LayoutConfigJson.ts +++ b/Customizations/JSON/LayoutConfigJson.ts @@ -205,4 +205,5 @@ export interface LayoutConfigJson { enableAddNewPoints?: boolean; enableGeolocation?: boolean; enableBackgroundLayerSelection?: boolean; + enableShowAllQuestions?: boolean; } diff --git a/InitUiElements.ts b/InitUiElements.ts index 76f5e7838..9bd3f7302 100644 --- a/InitUiElements.ts +++ b/InitUiElements.ts @@ -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 { @@ -82,23 +85,44 @@ export class InitUiElements { function updateFavs() { // This is purely for the personal theme to load the layers there const favs = State.state.favouriteLayers.data ?? []; + + const neededLayers = new Set(); - + 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; + } } } } } - State.state.layoutToUse.ping(); - State.state.layerUpdater?.ForceRefresh(); + if(somethingChanged){ + console.log("layoutToUse.layers:", layoutToUse.layers) + State.state.layoutToUse.data.layers = Array.from(neededLayers); + State.state.layoutToUse.ping(); + State.state.layerUpdater?.ForceRefresh(); + } + } diff --git a/Models/Constants.ts b/Models/Constants.ts index 9191a0e95..c2fbebd0d 100644 --- a/Models/Constants.ts +++ b/Models/Constants.ts @@ -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 = { diff --git a/State.ts b/State.ts index 5f682f74d..25053f497 100644 --- a/State.ts +++ b/State.ts @@ -97,6 +97,7 @@ export default class State { public readonly featureSwitchGeolocation: UIEventSource; public readonly featureSwitchIsTesting: UIEventSource; public readonly featureSwitchIsDebugging: UIEventSource; + public readonly featureSwitchShowAllQuestions: UIEventSource; /** @@ -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", diff --git a/UI/Popup/QuestionBox.ts b/UI/Popup/QuestionBox.ts index dca20fcf9..26b7906b1 100644 --- a/UI/Popup/QuestionBox.ts +++ b/UI/Popup/QuestionBox.ts @@ -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(); + if(this._skippedQuestions.data.length > 0){ + allQuestions.push(this._skippedQuestionsButton) } + - return ""; + return new Combine(allQuestions).Render(); } } \ No newline at end of file