Adding a 'showAllQuestions'-flag'
This commit is contained in:
parent
fa5ed7c690
commit
e555a19d30
7 changed files with 75 additions and 25 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<string, LayerConfig>{
|
||||
|
||||
public LayerIndex(): Map<string, LayerConfig> {
|
||||
const index = new Map<string, LayerConfig>();
|
||||
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")
|
||||
|
|
|
@ -205,4 +205,5 @@ export interface LayoutConfigJson {
|
|||
enableAddNewPoints?: boolean;
|
||||
enableGeolocation?: boolean;
|
||||
enableBackgroundLayerSelection?: boolean;
|
||||
enableShowAllQuestions?: boolean;
|
||||
}
|
||||
|
|
|
@ -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<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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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 = {
|
||||
|
|
3
State.ts
3
State.ts
|
@ -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",
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue