diff --git a/Customizations/AllKnownLayouts.ts b/Customizations/AllKnownLayouts.ts index 134dec0..4da0610 100644 --- a/Customizations/AllKnownLayouts.ts +++ b/Customizations/AllKnownLayouts.ts @@ -1,18 +1,18 @@ -import {Groen} from "./Layouts/Groen"; -import {GRB} from "./Layouts/GRB"; -import {Artworks} from "./Layouts/Artworks"; -import {Bookcases} from "./Layouts/Bookcases"; -import Cyclofix from "./Layouts/Cyclofix"; -import {WalkByBrussels} from "./Layouts/WalkByBrussels"; import {All} from "./Layouts/All"; -import {Layout} from "./Layout"; -import {MetaMap} from "./Layouts/MetaMap"; import {StreetWidth} from "./Layouts/StreetWidth"; -import {Natuurpunt} from "./Layouts/Natuurpunt"; +import {LayerDefinition} from "./LayerDefinition"; import {ClimbingTrees} from "./Layouts/ClimbingTrees"; import {Smoothness} from "./Layouts/Smoothness"; -import {LayerDefinition} from "./LayerDefinition"; +import {Natuurpunt} from "./Layouts/Natuurpunt"; +import {Groen} from "./Layouts/Groen"; +import Cyclofix from "./Layouts/Cyclofix"; +import {Layout} from "./Layout"; import {CustomLayout} from "../Logic/CustomLayers"; +import {GRB} from "./Layouts/GRB"; +import {Artworks} from "./Layouts/Artworks"; +import {WalkByBrussels} from "./Layouts/WalkByBrussels"; +import {MetaMap} from "./Layouts/MetaMap"; +import {Bookcases} from "./Layouts/Bookcases"; export class AllKnownLayouts { diff --git a/Logic/LocalStorageSource.ts b/Logic/LocalStorageSource.ts index 6000725..ce6a82a 100644 --- a/Logic/LocalStorageSource.ts +++ b/Logic/LocalStorageSource.ts @@ -1,24 +1,22 @@ import {UIEventSource} from "../UI/UIEventSource"; -import {UIElement} from "../UI/UIElement"; export class LocalStorageSource { static Get(key: string, defaultValue: string = undefined): UIEventSource { - if (UIElement.runningFromConsole) { + try { - // ignore when running from the console + + const saved = localStorage.getItem(key); + const source = new UIEventSource(saved ?? defaultValue); + + source.addCallback((data) => { + localStorage.setItem(key, data); + console.log("Wriging ", key, data) + }); + return source; + } catch (e) { return new UIEventSource(defaultValue); } - - - const saved = localStorage.getItem(key); - const source = new UIEventSource(saved ?? defaultValue); - - source.addCallback((data) => { - localStorage.setItem(key, data); - console.log("Wriging ", key, data) - }); - return source; } -} \ No newline at end of file +} diff --git a/Logic/QueryParameters.ts b/Logic/QueryParameters.ts index 9d5a004..b769258 100644 --- a/Logic/QueryParameters.ts +++ b/Logic/QueryParameters.ts @@ -2,11 +2,13 @@ * Wraps the query parameters into UIEventSources */ import {UIEventSource} from "../UI/UIEventSource"; +import {UIElement} from "../UI/UIElement"; export class QueryParameters { private static order: string [] = ["layout","test","z","lat","lon"]; - private static knownSources = QueryParameters.init(); + private static knownSources = {}; + private static initialized = false; private static defaults = {} private static addOrder(key){ @@ -16,11 +18,13 @@ export class QueryParameters { } private static init() { - const knownSources = {} - if(window === undefined){ + + if(this.initialized){ return; } - if (window.location.search) { + this.initialized = true; + + if (window?.location?.search) { const params = window.location.search.substr(1).split("&"); for (const param of params) { const kv = param.split("="); @@ -29,10 +33,9 @@ export class QueryParameters { const v = kv[1]; const source = new UIEventSource(v); source.addCallback(() => QueryParameters.Serialize()) - knownSources[key] = source; + QueryParameters.knownSources[key] = source; } } - return knownSources; } private static Serialize() { @@ -51,6 +54,9 @@ export class QueryParameters { } public static GetQueryParameter(key: string, deflt: string): UIEventSource { + if(!this.initialized){ + this.init(); + } if (deflt !== undefined) { QueryParameters.defaults[key] = deflt; } diff --git a/State.ts b/State.ts index 1a3ce5e..b2171fd 100644 --- a/State.ts +++ b/State.ts @@ -25,6 +25,7 @@ export class State { // The singleton of the global state public static state: State; + public static runningFromConsole: boolean = false; /** THe layout to use @@ -176,6 +177,10 @@ export class State { "Beantwoorden van vragen met #MapComplete voor vragenset #" + this.layoutToUse.data.name, this); + if(State.runningFromConsole){ + console.warn("running from console - not initializing map. Assuming test.html"); + return; + } if (document.getElementById("leafletDiv") === null) { diff --git a/UI/i18n/Locale.ts b/UI/i18n/Locale.ts index 821cfbf..9a40fb3 100644 --- a/UI/i18n/Locale.ts +++ b/UI/i18n/Locale.ts @@ -1,19 +1,18 @@ import {UIEventSource} from "../UIEventSource"; import {LocalStorageSource} from "../../Logic/LocalStorageSource"; -import {DropDown} from "../Input/DropDown"; -import {Layout} from "../../Customizations/Layout"; import {UIElement} from "../UIElement"; -import {State} from "../../State"; export default class Locale { public static language: UIEventSource = Locale.setup(); private static setup() { - const source = LocalStorageSource.Get('language', "en"); - // @ts-ignore - window.setLanguage = function (language: string) { - source.setData(language) + const source = LocalStorageSource.Get('language', "en"); + if (!UIElement.runningFromConsole) { + // @ts-ignore + window.setLanguage = function (language: string) { + source.setData(language) + } } return source; } diff --git a/Utils.ts b/Utils.ts index 6391016..0b29860 100644 --- a/Utils.ts +++ b/Utils.ts @@ -25,6 +25,9 @@ export class Utils { } static DoEvery(millis: number, f: (() => void)) { + if(State.runningFromConsole){ + return; + } window.setTimeout( function () { f(); diff --git a/createLayouts.ts b/createLayouts.ts index dbab8db..261f57d 100644 --- a/createLayouts.ts +++ b/createLayouts.ts @@ -1,25 +1,15 @@ -import {Groen} from "./Customizations/Layouts/Groen"; -import {Bookcases} from "./Customizations/Layouts/Bookcases"; -import {GRB} from "./Customizations/Layouts/GRB"; -import Cyclofix from "./Customizations/Layouts/Cyclofix"; -import {WalkByBrussels} from "./Customizations/Layouts/WalkByBrussels"; -import {MetaMap} from "./Customizations/Layouts/MetaMap"; -import {StreetWidth} from "./Customizations/Layouts/StreetWidth"; -import {Natuurpunt} from "./Customizations/Layouts/Natuurpunt"; +import {UIElement} from "./UI/UIElement"; +UIElement.runningFromConsole = true; import {AllKnownLayouts} from "./Customizations/AllKnownLayouts"; import {Layout} from "./Customizations/Layout"; import {readFileSync, writeFile, writeFileSync} from "fs"; -import {Utils} from "./Utils"; import svg2img from 'promise-svg2img'; import Translation from "./UI/i18n/Translation"; import Locale from "./UI/i18n/Locale"; import Translations from "./UI/i18n/Translations"; -import {UIElement} from "./UI/UIElement"; import {LayerDefinition} from "./Customizations/LayerDefinition"; - console.log("Building the layouts") -UIElement.runningFromConsole = true; function enc(str: string): string { return encodeURIComponent(str.toLowerCase()); @@ -73,7 +63,6 @@ function validate(layout: Layout) { } - const alreadyWritten = [] function createIcon(iconPath: string, size: number) { @@ -110,7 +99,7 @@ function createIcon(iconPath: string, size: number) { } function createManifest(layout: Layout, relativePath: string) { - const name = Utils.Upper(layout.name); + const name = layout.name; const icons = []; @@ -151,7 +140,6 @@ function createManifest(layout: Layout, relativePath: string) { } const template = readFileSync("index.html", "utf8"); - function createLandingPage(layout: Layout) { Locale.language.setData(layout.supportedLanguages[0]); @@ -172,9 +160,9 @@ function createLandingPage(layout: Layout) { ``) } - const blacklist = ["", "test", ".", "..", "manifest", "index", "land", "preferences", "account", "openstreetmap"] const all = AllKnownLayouts.allSets; +/* for (const layoutName in all) { if (blacklist.indexOf(layoutName.toLowerCase()) >= 0) { console.log(`Skipping a layout with name${layoutName}, it is on the blacklist`); @@ -196,4 +184,6 @@ for (const layoutName in all) { writeFile(enc(layout.name) + ".html", landing, err) } -Translations.CountTranslations(); \ No newline at end of file +Translations.CountTranslations(); + + */ \ No newline at end of file