forked from MapComplete/MapComplete
		
	Refactoring: introduce 'isPrivileged'
This commit is contained in:
		
							parent
							
								
									6ca055cf28
								
							
						
					
					
						commit
						f405116bb1
					
				
					 11 changed files with 29 additions and 28 deletions
				
			
		|  | @ -9,16 +9,12 @@ import { | |||
|     DoesImageExist, | ||||
|     PrevalidateTheme, | ||||
|     ValidateLayer, | ||||
|     ValidateThemeEnsemble, | ||||
|     ValidateThemeEnsemble | ||||
| } from "../src/Models/ThemeConfig/Conversion/Validation" | ||||
| import { Translation } from "../src/UI/i18n/Translation" | ||||
| import { PrepareLayer } from "../src/Models/ThemeConfig/Conversion/PrepareLayer" | ||||
| import { PrepareTheme } from "../src/Models/ThemeConfig/Conversion/PrepareTheme" | ||||
| import { | ||||
|     Conversion, | ||||
|     DesugaringContext, | ||||
|     DesugaringStep, | ||||
| } from "../src/Models/ThemeConfig/Conversion/Conversion" | ||||
| import { Conversion, DesugaringContext, DesugaringStep } from "../src/Models/ThemeConfig/Conversion/Conversion" | ||||
| import { Utils } from "../src/Utils" | ||||
| import Script from "./Script" | ||||
| import { AllSharedLayers } from "../src/Customizations/AllSharedLayers" | ||||
|  | @ -625,7 +621,7 @@ class LayerOverviewUtils extends Script { | |||
|             if (whitelist.size > 0) { | ||||
|                 const idByPath = sharedLayerPath.split("/").at(-1).split(".")[0] | ||||
|                 if ( | ||||
|                     Constants.priviliged_layers.indexOf(<any>idByPath) < 0 && | ||||
|                     !Constants.isPriviliged(idByPath) && | ||||
|                     !whitelist.has(idByPath) | ||||
|                 ) { | ||||
|                     continue | ||||
|  |  | |||
|  | @ -15,7 +15,7 @@ export default class NoElementsInViewDetector { | |||
|         const state = themeViewState | ||||
|         const minZoom = Math.min( | ||||
|             ...themeViewState.theme.layers | ||||
|                 .filter((l) => Constants.priviliged_layers.indexOf(<any>l.id) < 0) | ||||
|                 .filter((l) => !Constants.isPriviliged(l)) | ||||
|                 .map((l) => l.minzoom) | ||||
|         ) | ||||
|         const mapProperties = themeViewState.mapProperties | ||||
|  |  | |||
|  | @ -23,7 +23,7 @@ export class SummaryTileSourceRewriter implements FeatureSource { | |||
|         filteredLayers: ReadonlyMap<string, FilteredLayer> | ||||
|     ) { | ||||
|         this.filteredLayers = Array.from(filteredLayers.values()).filter( | ||||
|             (l) => Constants.priviliged_layers.indexOf(<any>l.layerDef.id) < 0 | ||||
|             (l) => !Constants.isPriviliged(l.layerDef) | ||||
|         ) | ||||
|         this._summarySource = summarySource | ||||
|         filteredLayers.forEach((v) => { | ||||
|  |  | |||
|  | @ -99,7 +99,7 @@ export default class FilterSearch { | |||
|             if (!Array.isArray(filteredLayer.layerDef.filters)) { | ||||
|                 continue | ||||
|             } | ||||
|             if (Constants.priviliged_layers.indexOf(<any>id) >= 0) { | ||||
|             if (Constants.isPriviliged(id)) { | ||||
|                 continue | ||||
|             } | ||||
|             for (const filter of filteredLayer.layerDef.filters) { | ||||
|  |  | |||
|  | @ -242,4 +242,16 @@ export default class Constants { | |||
|             (window.devicePixelRatio && window.devicePixelRatio >= 2) | ||||
|         ) | ||||
|     } | ||||
| 
 | ||||
|     private static priviligedLayerSet = new Set<string>(Constants.priviliged_layers) | ||||
| 
 | ||||
|     public static isPriviliged(layer: string | { id: string }) { | ||||
|         let id: string | ||||
|         if (typeof layer === "string") { | ||||
|             id = layer | ||||
|         } else { | ||||
|             id = layer.id | ||||
|         } | ||||
|         return this.priviligedLayerSet.has(id) | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -136,7 +136,7 @@ export class PrevalidateLayer extends DesugaringStep<LayerConfigJson> { | |||
|         } | ||||
| 
 | ||||
|         if (json.source === "special") { | ||||
|             if (!Constants.priviliged_layers.find((x) => x == json.id)) { | ||||
|             if (!Constants.isPriviliged(json)) { | ||||
|                 context.err( | ||||
|                     "Layer " + | ||||
|                         json.id + | ||||
|  | @ -150,7 +150,7 @@ export class PrevalidateLayer extends DesugaringStep<LayerConfigJson> { | |||
|             json.allowMove === undefined && | ||||
|             json.source["geoJson"] === undefined | ||||
|         ) { | ||||
|             if (!Constants.priviliged_layers.find((x) => x == json.id)) { | ||||
|             if (!Constants.isPriviliged(json)) { | ||||
|                 context.err("Layer " + json.id + " does not have an explicit 'allowMove'") | ||||
|             } | ||||
|         } | ||||
|  |  | |||
|  | @ -1128,7 +1128,7 @@ export class ValidateThemeEnsemble extends Conversion< | |||
|                 if (typeof layer.source === "string") { | ||||
|                     continue | ||||
|                 } | ||||
|                 if (Constants.priviliged_layers.indexOf(<any>layer.id) >= 0) { | ||||
|                 if (Constants.isPriviliged(layer)) { | ||||
|                     continue | ||||
|                 } | ||||
|                 if (!layer.source) { | ||||
|  |  | |||
|  | @ -13,7 +13,6 @@ import PointRenderingConfig from "./PointRenderingConfig" | |||
| import WithContextLoader from "./WithContextLoader" | ||||
| import LineRenderingConfig from "./LineRenderingConfig" | ||||
| import { TagRenderingConfigJson } from "./Json/TagRenderingConfigJson" | ||||
| import BaseUIElement from "../../UI/BaseUIElement" | ||||
| import Link from "../../UI/Base/Link" | ||||
| import { Utils } from "../../Utils" | ||||
| import { TagsFilter } from "../../Logic/Tags/TagsFilter" | ||||
|  | @ -23,10 +22,6 @@ import Constants from "../Constants" | |||
| import { QuestionableTagRenderingConfigJson } from "./Json/QuestionableTagRenderingConfigJson" | ||||
| import MarkdownUtils from "../../Utils/MarkdownUtils" | ||||
| import { And } from "../../Logic/Tags/And" | ||||
| import Combine from "../../UI/Base/Combine" | ||||
| import SvelteUIElement from "../../UI/Base/SvelteUIElement" | ||||
| import DynamicMarker from "../../UI/Map/DynamicMarker.svelte" | ||||
| import { ImmutableStore } from "../../Logic/UIEventSource" | ||||
| 
 | ||||
| export default class LayerConfig extends WithContextLoader { | ||||
|     public static readonly syncSelectionAllowed = ["no", "local", "theme-only", "global"] as const | ||||
|  | @ -257,7 +252,7 @@ export default class LayerConfig extends WithContextLoader { | |||
|             } else if ( | ||||
|                 !hasCenterRendering && | ||||
|                 this.lineRendering.length === 0 && | ||||
|                 Constants.priviliged_layers.indexOf(<any>this.id) < 0 && | ||||
|                 !Constants.isPriviliged(this) && | ||||
|                 this.source !== null /*library layer*/ && | ||||
|                 !this.source?.geojsonSource?.startsWith( | ||||
|                     "https://api.openstreetmap.org/api/0.6/notes.json" | ||||
|  |  | |||
|  | @ -18,7 +18,7 @@ import { Store, UIEventSource } from "../../Logic/UIEventSource" | |||
| import NearbyFeatureSource from "../../Logic/FeatureSource/Sources/NearbyFeatureSource" | ||||
| import { | ||||
|     SummaryTileSource, | ||||
|     SummaryTileSourceRewriter, | ||||
|     SummaryTileSourceRewriter | ||||
| } from "../../Logic/FeatureSource/TiledFeatureSource/SummaryTileSource" | ||||
| import { ShowDataLayerOptions } from "../../UI/Map/ShowDataLayerOptions" | ||||
| 
 | ||||
|  | @ -95,7 +95,7 @@ export class WithSpecialLayers extends WithChangesState { | |||
| 
 | ||||
|         const layers = this.theme.layers.filter( | ||||
|             (l) => | ||||
|                 (<string[]>(<unknown>Constants.priviliged_layers)).indexOf(l.id) < 0 && | ||||
|                 !Constants.isPriviliged(l) && | ||||
|                 l.source.geojsonSource === undefined && | ||||
|                 l.doCount | ||||
|         ) | ||||
|  |  | |||
|  | @ -3,29 +3,27 @@ | |||
|   import ActiveFilters from "./ActiveFilters.svelte" | ||||
|   import Constants from "../../Models/Constants" | ||||
|   import type { ActiveFilter } from "../../Logic/State/LayerState" | ||||
|   import ThemeViewState from "../../Models/ThemeViewState" | ||||
|   import ThemeResults from "./ThemeResults.svelte" | ||||
|   import GeocodeResults from "./GeocodeResults.svelte" | ||||
|   import FilterResults from "./FilterResults.svelte" | ||||
|   import Tr from "../Base/Tr.svelte" | ||||
|   import Translations from "../i18n/Translations" | ||||
|   import type { FilterSearchResult } from "../../Logic/Search/FilterSearch" | ||||
|   import { WithSearchState } from "../../Models/ThemeViewState/WithSearchState" | ||||
| 
 | ||||
|   export let state: ThemeViewState | ||||
|   export let state: WithSearchState | ||||
|   let activeFilters: Store<(ActiveFilter & FilterSearchResult)[]> = | ||||
|     state.layerState.activeFilters.map((fs) => | ||||
|       fs | ||||
|         .filter( | ||||
|           (f) => | ||||
|             f.filter.options[0].fields.length === 0 && | ||||
|             Constants.priviliged_layers.indexOf(<any>f.layer.id) < 0 | ||||
|           (f) => f.filter.options[0].fields.length === 0 && !Constants.isPriviliged(f.layer) | ||||
|         ) | ||||
|         .map((af) => { | ||||
|           const index = <number>af.control.data | ||||
|           const r: FilterSearchResult & ActiveFilter = { | ||||
|             ...af, | ||||
|             index, | ||||
|             option: af.filter.options[index], | ||||
|             option: af.filter.options[index] | ||||
|           } | ||||
|           return r | ||||
|         }) | ||||
|  |  | |||
|  | @ -62,7 +62,7 @@ export default class StudioServer { | |||
|             } | ||||
|             const category = <"layers" | "themes">parts[0] | ||||
|             const id = file.substring(file.lastIndexOf("/") + 1, file.length - ".json".length) | ||||
|             if (Constants.priviliged_layers.indexOf(<any>id) > 0) { | ||||
|             if (Constants.isPriviliged(id)) { | ||||
|                 continue | ||||
|             } | ||||
|             layerOverview.push({ id, owner, category }) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue