Refactoring: introduce 'isPrivileged'

This commit is contained in:
Pieter Vander Vennet 2025-02-07 01:37:36 +01:00
parent 6ca055cf28
commit f405116bb1
11 changed files with 29 additions and 28 deletions

View file

@ -9,16 +9,12 @@ import {
DoesImageExist, DoesImageExist,
PrevalidateTheme, PrevalidateTheme,
ValidateLayer, ValidateLayer,
ValidateThemeEnsemble, ValidateThemeEnsemble
} from "../src/Models/ThemeConfig/Conversion/Validation" } from "../src/Models/ThemeConfig/Conversion/Validation"
import { Translation } from "../src/UI/i18n/Translation" import { Translation } from "../src/UI/i18n/Translation"
import { PrepareLayer } from "../src/Models/ThemeConfig/Conversion/PrepareLayer" import { PrepareLayer } from "../src/Models/ThemeConfig/Conversion/PrepareLayer"
import { PrepareTheme } from "../src/Models/ThemeConfig/Conversion/PrepareTheme" import { PrepareTheme } from "../src/Models/ThemeConfig/Conversion/PrepareTheme"
import { import { Conversion, DesugaringContext, DesugaringStep } from "../src/Models/ThemeConfig/Conversion/Conversion"
Conversion,
DesugaringContext,
DesugaringStep,
} from "../src/Models/ThemeConfig/Conversion/Conversion"
import { Utils } from "../src/Utils" import { Utils } from "../src/Utils"
import Script from "./Script" import Script from "./Script"
import { AllSharedLayers } from "../src/Customizations/AllSharedLayers" import { AllSharedLayers } from "../src/Customizations/AllSharedLayers"
@ -625,7 +621,7 @@ class LayerOverviewUtils extends Script {
if (whitelist.size > 0) { if (whitelist.size > 0) {
const idByPath = sharedLayerPath.split("/").at(-1).split(".")[0] const idByPath = sharedLayerPath.split("/").at(-1).split(".")[0]
if ( if (
Constants.priviliged_layers.indexOf(<any>idByPath) < 0 && !Constants.isPriviliged(idByPath) &&
!whitelist.has(idByPath) !whitelist.has(idByPath)
) { ) {
continue continue

View file

@ -15,7 +15,7 @@ export default class NoElementsInViewDetector {
const state = themeViewState const state = themeViewState
const minZoom = Math.min( const minZoom = Math.min(
...themeViewState.theme.layers ...themeViewState.theme.layers
.filter((l) => Constants.priviliged_layers.indexOf(<any>l.id) < 0) .filter((l) => !Constants.isPriviliged(l))
.map((l) => l.minzoom) .map((l) => l.minzoom)
) )
const mapProperties = themeViewState.mapProperties const mapProperties = themeViewState.mapProperties

View file

@ -23,7 +23,7 @@ export class SummaryTileSourceRewriter implements FeatureSource {
filteredLayers: ReadonlyMap<string, FilteredLayer> filteredLayers: ReadonlyMap<string, FilteredLayer>
) { ) {
this.filteredLayers = Array.from(filteredLayers.values()).filter( 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 this._summarySource = summarySource
filteredLayers.forEach((v) => { filteredLayers.forEach((v) => {

View file

@ -99,7 +99,7 @@ export default class FilterSearch {
if (!Array.isArray(filteredLayer.layerDef.filters)) { if (!Array.isArray(filteredLayer.layerDef.filters)) {
continue continue
} }
if (Constants.priviliged_layers.indexOf(<any>id) >= 0) { if (Constants.isPriviliged(id)) {
continue continue
} }
for (const filter of filteredLayer.layerDef.filters) { for (const filter of filteredLayer.layerDef.filters) {

View file

@ -242,4 +242,16 @@ export default class Constants {
(window.devicePixelRatio && window.devicePixelRatio >= 2) (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)
}
} }

View file

@ -136,7 +136,7 @@ export class PrevalidateLayer extends DesugaringStep<LayerConfigJson> {
} }
if (json.source === "special") { if (json.source === "special") {
if (!Constants.priviliged_layers.find((x) => x == json.id)) { if (!Constants.isPriviliged(json)) {
context.err( context.err(
"Layer " + "Layer " +
json.id + json.id +
@ -150,7 +150,7 @@ export class PrevalidateLayer extends DesugaringStep<LayerConfigJson> {
json.allowMove === undefined && json.allowMove === undefined &&
json.source["geoJson"] === 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'") context.err("Layer " + json.id + " does not have an explicit 'allowMove'")
} }
} }

View file

@ -1128,7 +1128,7 @@ export class ValidateThemeEnsemble extends Conversion<
if (typeof layer.source === "string") { if (typeof layer.source === "string") {
continue continue
} }
if (Constants.priviliged_layers.indexOf(<any>layer.id) >= 0) { if (Constants.isPriviliged(layer)) {
continue continue
} }
if (!layer.source) { if (!layer.source) {

View file

@ -13,7 +13,6 @@ import PointRenderingConfig from "./PointRenderingConfig"
import WithContextLoader from "./WithContextLoader" import WithContextLoader from "./WithContextLoader"
import LineRenderingConfig from "./LineRenderingConfig" import LineRenderingConfig from "./LineRenderingConfig"
import { TagRenderingConfigJson } from "./Json/TagRenderingConfigJson" import { TagRenderingConfigJson } from "./Json/TagRenderingConfigJson"
import BaseUIElement from "../../UI/BaseUIElement"
import Link from "../../UI/Base/Link" import Link from "../../UI/Base/Link"
import { Utils } from "../../Utils" import { Utils } from "../../Utils"
import { TagsFilter } from "../../Logic/Tags/TagsFilter" import { TagsFilter } from "../../Logic/Tags/TagsFilter"
@ -23,10 +22,6 @@ import Constants from "../Constants"
import { QuestionableTagRenderingConfigJson } from "./Json/QuestionableTagRenderingConfigJson" import { QuestionableTagRenderingConfigJson } from "./Json/QuestionableTagRenderingConfigJson"
import MarkdownUtils from "../../Utils/MarkdownUtils" import MarkdownUtils from "../../Utils/MarkdownUtils"
import { And } from "../../Logic/Tags/And" 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 { export default class LayerConfig extends WithContextLoader {
public static readonly syncSelectionAllowed = ["no", "local", "theme-only", "global"] as const public static readonly syncSelectionAllowed = ["no", "local", "theme-only", "global"] as const
@ -257,7 +252,7 @@ export default class LayerConfig extends WithContextLoader {
} else if ( } else if (
!hasCenterRendering && !hasCenterRendering &&
this.lineRendering.length === 0 && this.lineRendering.length === 0 &&
Constants.priviliged_layers.indexOf(<any>this.id) < 0 && !Constants.isPriviliged(this) &&
this.source !== null /*library layer*/ && this.source !== null /*library layer*/ &&
!this.source?.geojsonSource?.startsWith( !this.source?.geojsonSource?.startsWith(
"https://api.openstreetmap.org/api/0.6/notes.json" "https://api.openstreetmap.org/api/0.6/notes.json"

View file

@ -18,7 +18,7 @@ import { Store, UIEventSource } from "../../Logic/UIEventSource"
import NearbyFeatureSource from "../../Logic/FeatureSource/Sources/NearbyFeatureSource" import NearbyFeatureSource from "../../Logic/FeatureSource/Sources/NearbyFeatureSource"
import { import {
SummaryTileSource, SummaryTileSource,
SummaryTileSourceRewriter, SummaryTileSourceRewriter
} from "../../Logic/FeatureSource/TiledFeatureSource/SummaryTileSource" } from "../../Logic/FeatureSource/TiledFeatureSource/SummaryTileSource"
import { ShowDataLayerOptions } from "../../UI/Map/ShowDataLayerOptions" import { ShowDataLayerOptions } from "../../UI/Map/ShowDataLayerOptions"
@ -95,7 +95,7 @@ export class WithSpecialLayers extends WithChangesState {
const layers = this.theme.layers.filter( const layers = this.theme.layers.filter(
(l) => (l) =>
(<string[]>(<unknown>Constants.priviliged_layers)).indexOf(l.id) < 0 && !Constants.isPriviliged(l) &&
l.source.geojsonSource === undefined && l.source.geojsonSource === undefined &&
l.doCount l.doCount
) )

View file

@ -3,29 +3,27 @@
import ActiveFilters from "./ActiveFilters.svelte" import ActiveFilters from "./ActiveFilters.svelte"
import Constants from "../../Models/Constants" import Constants from "../../Models/Constants"
import type { ActiveFilter } from "../../Logic/State/LayerState" import type { ActiveFilter } from "../../Logic/State/LayerState"
import ThemeViewState from "../../Models/ThemeViewState"
import ThemeResults from "./ThemeResults.svelte" import ThemeResults from "./ThemeResults.svelte"
import GeocodeResults from "./GeocodeResults.svelte" import GeocodeResults from "./GeocodeResults.svelte"
import FilterResults from "./FilterResults.svelte" import FilterResults from "./FilterResults.svelte"
import Tr from "../Base/Tr.svelte" import Tr from "../Base/Tr.svelte"
import Translations from "../i18n/Translations" import Translations from "../i18n/Translations"
import type { FilterSearchResult } from "../../Logic/Search/FilterSearch" 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)[]> = let activeFilters: Store<(ActiveFilter & FilterSearchResult)[]> =
state.layerState.activeFilters.map((fs) => state.layerState.activeFilters.map((fs) =>
fs fs
.filter( .filter(
(f) => (f) => f.filter.options[0].fields.length === 0 && !Constants.isPriviliged(f.layer)
f.filter.options[0].fields.length === 0 &&
Constants.priviliged_layers.indexOf(<any>f.layer.id) < 0
) )
.map((af) => { .map((af) => {
const index = <number>af.control.data const index = <number>af.control.data
const r: FilterSearchResult & ActiveFilter = { const r: FilterSearchResult & ActiveFilter = {
...af, ...af,
index, index,
option: af.filter.options[index], option: af.filter.options[index]
} }
return r return r
}) })

View file

@ -62,7 +62,7 @@ export default class StudioServer {
} }
const category = <"layers" | "themes">parts[0] const category = <"layers" | "themes">parts[0]
const id = file.substring(file.lastIndexOf("/") + 1, file.length - ".json".length) const id = file.substring(file.lastIndexOf("/") + 1, file.length - ".json".length)
if (Constants.priviliged_layers.indexOf(<any>id) > 0) { if (Constants.isPriviliged(id)) {
continue continue
} }
layerOverview.push({ id, owner, category }) layerOverview.push({ id, owner, category })