forked from MapComplete/MapComplete
		
	Add a personal, configurable quest
This commit is contained in:
		
							parent
							
								
									7ec00a3301
								
							
						
					
					
						commit
						b36b103ed3
					
				
					 7 changed files with 55 additions and 54 deletions
				
			
		|  | @ -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 {All} from "./Layouts/All"; | ||||||
| import {Layout} from "./Layout"; |  | ||||||
| import {MetaMap} from "./Layouts/MetaMap"; |  | ||||||
| import {StreetWidth} from "./Layouts/StreetWidth"; | import {StreetWidth} from "./Layouts/StreetWidth"; | ||||||
| import {Natuurpunt} from "./Layouts/Natuurpunt"; | import {LayerDefinition} from "./LayerDefinition"; | ||||||
| import {ClimbingTrees} from "./Layouts/ClimbingTrees"; | import {ClimbingTrees} from "./Layouts/ClimbingTrees"; | ||||||
| import {Smoothness} from "./Layouts/Smoothness"; | 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 {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 { | export class AllKnownLayouts { | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,24 +1,22 @@ | ||||||
| import {UIEventSource} from "../UI/UIEventSource"; | import {UIEventSource} from "../UI/UIEventSource"; | ||||||
| import {UIElement} from "../UI/UIElement"; |  | ||||||
| 
 | 
 | ||||||
| export class LocalStorageSource { | export class LocalStorageSource { | ||||||
| 
 | 
 | ||||||
|     static Get(key: string, defaultValue: string = undefined): UIEventSource<string> { |     static Get(key: string, defaultValue: string = undefined): UIEventSource<string> { | ||||||
| 
 | 
 | ||||||
|         if (UIElement.runningFromConsole) { |         try { | ||||||
| 
 | 
 | ||||||
|             // ignore when running from the console
 | 
 | ||||||
|  |             const saved = localStorage.getItem(key); | ||||||
|  |             const source = new UIEventSource<string>(saved ?? defaultValue); | ||||||
|  | 
 | ||||||
|  |             source.addCallback((data) => { | ||||||
|  |                 localStorage.setItem(key, data); | ||||||
|  |                 console.log("Wriging ", key, data) | ||||||
|  |             }); | ||||||
|  |             return source; | ||||||
|  |         } catch (e) { | ||||||
|             return new UIEventSource<string>(defaultValue); |             return new UIEventSource<string>(defaultValue); | ||||||
|         } |         } | ||||||
|          |  | ||||||
| 
 |  | ||||||
|         const saved = localStorage.getItem(key); |  | ||||||
|         const source = new UIEventSource<string>(saved ?? defaultValue); |  | ||||||
| 
 |  | ||||||
|         source.addCallback((data) => { |  | ||||||
|             localStorage.setItem(key, data); |  | ||||||
|             console.log("Wriging ", key, data) |  | ||||||
|         }); |  | ||||||
|         return source; |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | @ -2,11 +2,13 @@ | ||||||
|  * Wraps the query parameters into UIEventSources |  * Wraps the query parameters into UIEventSources | ||||||
|  */ |  */ | ||||||
| import {UIEventSource} from "../UI/UIEventSource"; | import {UIEventSource} from "../UI/UIEventSource"; | ||||||
|  | import {UIElement} from "../UI/UIElement"; | ||||||
| 
 | 
 | ||||||
| export class QueryParameters { | export class QueryParameters { | ||||||
| 
 | 
 | ||||||
|     private static order: string [] = ["layout","test","z","lat","lon"]; |     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 defaults = {} | ||||||
|      |      | ||||||
|     private static addOrder(key){ |     private static addOrder(key){ | ||||||
|  | @ -16,11 +18,13 @@ export class QueryParameters { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private static init() { |     private static init() { | ||||||
|         const knownSources = {} |          | ||||||
|         if(window === undefined){ |         if(this.initialized){ | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|         if (window.location.search) { |         this.initialized = true; | ||||||
|  |         | ||||||
|  |         if (window?.location?.search) { | ||||||
|             const params = window.location.search.substr(1).split("&"); |             const params = window.location.search.substr(1).split("&"); | ||||||
|             for (const param of params) { |             for (const param of params) { | ||||||
|                 const kv = param.split("="); |                 const kv = param.split("="); | ||||||
|  | @ -29,10 +33,9 @@ export class QueryParameters { | ||||||
|                 const v = kv[1]; |                 const v = kv[1]; | ||||||
|                 const source = new UIEventSource<string>(v); |                 const source = new UIEventSource<string>(v); | ||||||
|                 source.addCallback(() => QueryParameters.Serialize()) |                 source.addCallback(() => QueryParameters.Serialize()) | ||||||
|                 knownSources[key] = source; |                 QueryParameters.knownSources[key] = source; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         return knownSources; |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private static Serialize() { |     private static Serialize() { | ||||||
|  | @ -51,6 +54,9 @@ export class QueryParameters { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public static GetQueryParameter(key: string, deflt: string): UIEventSource<string> { |     public static GetQueryParameter(key: string, deflt: string): UIEventSource<string> { | ||||||
|  |         if(!this.initialized){ | ||||||
|  |             this.init(); | ||||||
|  |         } | ||||||
|         if (deflt !== undefined) { |         if (deflt !== undefined) { | ||||||
|             QueryParameters.defaults[key] = deflt; |             QueryParameters.defaults[key] = deflt; | ||||||
|         } |         } | ||||||
|  |  | ||||||
							
								
								
									
										5
									
								
								State.ts
									
										
									
									
									
								
							
							
						
						
									
										5
									
								
								State.ts
									
										
									
									
									
								
							|  | @ -25,6 +25,7 @@ export class State { | ||||||
|     // The singleton of the global state
 |     // The singleton of the global state
 | ||||||
|     public static state: State; |     public static state: State; | ||||||
| 
 | 
 | ||||||
|  |     public static runningFromConsole: boolean = false;  | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      THe layout to use |      THe layout to use | ||||||
|  | @ -176,6 +177,10 @@ export class State { | ||||||
|             "Beantwoorden van vragen met #MapComplete voor vragenset #" + this.layoutToUse.data.name, |             "Beantwoorden van vragen met #MapComplete voor vragenset #" + this.layoutToUse.data.name, | ||||||
|            this); |            this); | ||||||
| 
 | 
 | ||||||
|  |         if(State.runningFromConsole){ | ||||||
|  |             console.warn("running from console - not initializing map. Assuming test.html"); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|         if (document.getElementById("leafletDiv") === null) { |         if (document.getElementById("leafletDiv") === null) { | ||||||
|  |  | ||||||
|  | @ -1,19 +1,18 @@ | ||||||
| import {UIEventSource} from "../UIEventSource"; | import {UIEventSource} from "../UIEventSource"; | ||||||
| import {LocalStorageSource} from "../../Logic/LocalStorageSource"; | import {LocalStorageSource} from "../../Logic/LocalStorageSource"; | ||||||
| import {DropDown} from "../Input/DropDown"; |  | ||||||
| import {Layout} from "../../Customizations/Layout"; |  | ||||||
| import {UIElement} from "../UIElement"; | import {UIElement} from "../UIElement"; | ||||||
| import {State} from "../../State"; |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| export default class Locale { | export default class Locale { | ||||||
| 
 | 
 | ||||||
|     public static language: UIEventSource<string> = Locale.setup(); |     public static language: UIEventSource<string> = Locale.setup(); | ||||||
|     private static setup() { |     private static setup() { | ||||||
|        const source = LocalStorageSource.Get('language', "en"); |         const source = LocalStorageSource.Get('language', "en"); | ||||||
|         // @ts-ignore
 |         if (!UIElement.runningFromConsole) { | ||||||
|         window.setLanguage = function (language: string) { |             // @ts-ignore
 | ||||||
|            source.setData(language) |             window.setLanguage = function (language: string) { | ||||||
|  |                 source.setData(language) | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|         return source; |         return source; | ||||||
|     } |     } | ||||||
|  |  | ||||||
							
								
								
									
										3
									
								
								Utils.ts
									
										
									
									
									
								
							
							
						
						
									
										3
									
								
								Utils.ts
									
										
									
									
									
								
							|  | @ -25,6 +25,9 @@ export class Utils { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     static DoEvery(millis: number, f: (() => void)) { |     static DoEvery(millis: number, f: (() => void)) { | ||||||
|  |         if(State.runningFromConsole){ | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|         window.setTimeout( |         window.setTimeout( | ||||||
|             function () { |             function () { | ||||||
|                 f(); |                 f(); | ||||||
|  |  | ||||||
|  | @ -1,25 +1,15 @@ | ||||||
| import {Groen} from "./Customizations/Layouts/Groen"; | import {UIElement} from "./UI/UIElement"; | ||||||
| import {Bookcases} from "./Customizations/Layouts/Bookcases"; | UIElement.runningFromConsole = true; | ||||||
| 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 {AllKnownLayouts} from "./Customizations/AllKnownLayouts"; | import {AllKnownLayouts} from "./Customizations/AllKnownLayouts"; | ||||||
| import {Layout} from "./Customizations/Layout"; | import {Layout} from "./Customizations/Layout"; | ||||||
| import {readFileSync, writeFile, writeFileSync} from "fs"; | import {readFileSync, writeFile, writeFileSync} from "fs"; | ||||||
| import {Utils} from "./Utils"; |  | ||||||
| import svg2img from 'promise-svg2img'; | import svg2img from 'promise-svg2img'; | ||||||
| import Translation from "./UI/i18n/Translation"; | import Translation from "./UI/i18n/Translation"; | ||||||
| import Locale from "./UI/i18n/Locale"; | import Locale from "./UI/i18n/Locale"; | ||||||
| import Translations from "./UI/i18n/Translations"; | import Translations from "./UI/i18n/Translations"; | ||||||
| import {UIElement} from "./UI/UIElement"; |  | ||||||
| import {LayerDefinition} from "./Customizations/LayerDefinition"; | import {LayerDefinition} from "./Customizations/LayerDefinition"; | ||||||
| 
 |  | ||||||
| console.log("Building the layouts") | console.log("Building the layouts") | ||||||
| 
 | 
 | ||||||
| UIElement.runningFromConsole = true; |  | ||||||
| 
 | 
 | ||||||
| function enc(str: string): string { | function enc(str: string): string { | ||||||
|     return encodeURIComponent(str.toLowerCase()); |     return encodeURIComponent(str.toLowerCase()); | ||||||
|  | @ -73,7 +63,6 @@ function validate(layout: Layout) { | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| const alreadyWritten = [] | const alreadyWritten = [] | ||||||
| 
 | 
 | ||||||
| function createIcon(iconPath: string, size: number) { | function createIcon(iconPath: string, size: number) { | ||||||
|  | @ -110,7 +99,7 @@ function createIcon(iconPath: string, size: number) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function createManifest(layout: Layout, relativePath: string) { | function createManifest(layout: Layout, relativePath: string) { | ||||||
|     const name = Utils.Upper(layout.name); |     const name = layout.name;  | ||||||
| 
 | 
 | ||||||
|     const icons = []; |     const icons = []; | ||||||
| 
 | 
 | ||||||
|  | @ -151,7 +140,6 @@ function createManifest(layout: Layout, relativePath: string) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const template = readFileSync("index.html", "utf8"); | const template = readFileSync("index.html", "utf8"); | ||||||
| 
 |  | ||||||
| function createLandingPage(layout: Layout) { | function createLandingPage(layout: Layout) { | ||||||
| 
 | 
 | ||||||
|     Locale.language.setData(layout.supportedLanguages[0]); |     Locale.language.setData(layout.supportedLanguages[0]); | ||||||
|  | @ -172,9 +160,9 @@ function createLandingPage(layout: Layout) { | ||||||
|             `<link rel="icon" href="${layout.icon}" sizes="any" type="image/svg+xml">`) |             `<link rel="icon" href="${layout.icon}" sizes="any" type="image/svg+xml">`) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| const blacklist = ["", "test", ".", "..", "manifest", "index", "land", "preferences", "account", "openstreetmap"] | const blacklist = ["", "test", ".", "..", "manifest", "index", "land", "preferences", "account", "openstreetmap"] | ||||||
| const all = AllKnownLayouts.allSets; | const all = AllKnownLayouts.allSets; | ||||||
|  | /* | ||||||
| for (const layoutName in all) { | for (const layoutName in all) { | ||||||
|     if (blacklist.indexOf(layoutName.toLowerCase()) >= 0) { |     if (blacklist.indexOf(layoutName.toLowerCase()) >= 0) { | ||||||
|         console.log(`Skipping a layout with name${layoutName}, it is on the blacklist`); |         console.log(`Skipping a layout with name${layoutName}, it is on the blacklist`); | ||||||
|  | @ -197,3 +185,5 @@ for (const layoutName in all) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| Translations.CountTranslations(); | Translations.CountTranslations(); | ||||||
|  | 
 | ||||||
|  |  */ | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue