From b3492930b8e5090e9a9d3449d6e9abc365fc1780 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Wed, 11 Sep 2024 17:30:17 +0200 Subject: [PATCH] Themes: allow to disable auto filters --- assets/themes/cyclofix/cyclofix.json | 1 + src/Customizations/AllSharedLayers.ts | 4 +- .../ThemeConfig/Conversion/PrepareLayer.ts | 53 ++++++++++--------- .../ThemeConfig/Json/LayerConfigJson.ts | 1 + src/UI/Search/ActiveFilters.svelte | 10 ++-- 5 files changed, 37 insertions(+), 32 deletions(-) diff --git a/assets/themes/cyclofix/cyclofix.json b/assets/themes/cyclofix/cyclofix.json index 5eb503733..c82fc18b0 100644 --- a/assets/themes/cyclofix/cyclofix.json +++ b/assets/themes/cyclofix/cyclofix.json @@ -201,6 +201,7 @@ ] } }, + "filter": null, "=presets": [] } }, diff --git a/src/Customizations/AllSharedLayers.ts b/src/Customizations/AllSharedLayers.ts index e7f229a49..2dd0cd8b8 100644 --- a/src/Customizations/AllSharedLayers.ts +++ b/src/Customizations/AllSharedLayers.ts @@ -7,7 +7,7 @@ export class AllSharedLayers { public static sharedLayers: Map = AllSharedLayers.getSharedLayers() public static getSharedLayersConfigs(): Map { const sharedLayers = new Map() - for (const layer of known_layers.layers) { + for (const layer of known_layers["layers"]) { // @ts-ignore sharedLayers.set(layer.id, layer) } @@ -16,7 +16,7 @@ export class AllSharedLayers { } private static getSharedLayers(): Map { const sharedLayers = new Map() - for (const layer of known_layers.layers) { + for (const layer of known_layers["layers"]) { try { // @ts-ignore const parsed = new LayerConfig(layer, "shared_layers") diff --git a/src/Models/ThemeConfig/Conversion/PrepareLayer.ts b/src/Models/ThemeConfig/Conversion/PrepareLayer.ts index 5565815ce..a5b060e05 100644 --- a/src/Models/ThemeConfig/Conversion/PrepareLayer.ts +++ b/src/Models/ThemeConfig/Conversion/PrepareLayer.ts @@ -39,7 +39,8 @@ class ExpandFilter extends DesugaringStep { constructor(state: DesugaringContext) { super( ["Expands filters: replaces a shorthand by the value found in 'filters.json'.", - "If the string is formatted 'layername.filtername, it will be looked up into that layer instead. If a tagRendering sets 'filter', this filter will also be included", + "If the string is formatted 'layername.filtername, it will be looked up into that layer instead.", + "If a tagRendering sets 'filter', this filter will also be included - unless \"#filter\":\"no-auto\" is set", ""].join(" "), ["filter"], "ExpandFilter", @@ -96,6 +97,8 @@ class ExpandFilter extends DesugaringStep { return json // Nothing to change here } + const noAutoFilters = json["#filter"] === "no-auto" + const newFilters: FilterConfigJson[] = [] const filters = <(FilterConfigJson | string)[]>json.filter @@ -109,34 +112,36 @@ class ExpandFilter extends DesugaringStep { }) } - /** - * Checks all tagRendering. If a tagrendering has 'filter' set, add this filter to the layer config - */ - for (let i = 0; i < json.tagRenderings?.length; i++) { - const tagRendering = json.tagRenderings[i] - if (!tagRendering?.filter) { - continue - } - if (tagRendering.filter === true) { - if (filterExists(tagRendering["id"])) { + if (!noAutoFilters){ + /** + * Checks all tagRendering. If a tagrendering has 'filter' set, add this filter to the layer config + */ + for (let i = 0; i < json.tagRenderings?.length; i++) { + const tagRendering = json.tagRenderings[i] + if (!tagRendering?.filter) { continue } - filters.push(ExpandFilter.buildFilterFromTagRendering(tagRendering, context.enters("tagRenderings", i, "filter"))) - continue - } - for (const filterName of tagRendering.filter ?? []) { - if (typeof filterName !== "string") { - context.enters("tagRenderings", i, "filter").err("Not a string: " + filterName) - } - if (filterExists(filterName)) { - // This filter has already been added + if (tagRendering.filter === true) { + if (filterExists(tagRendering["id"])) { + continue + } + filters.push(ExpandFilter.buildFilterFromTagRendering(tagRendering, context.enters("tagRenderings", i, "filter"))) continue } - if (!filterName) { - context.err("Got undefined as filter expansion in " + tagRendering["id"]) - continue + for (const filterName of tagRendering.filter ?? []) { + if (typeof filterName !== "string") { + context.enters("tagRenderings", i, "filter").err("Not a string: " + filterName) + } + if (filterExists(filterName)) { + // This filter has already been added + continue + } + if (!filterName) { + context.err("Got undefined as filter expansion in " + tagRendering["id"]) + continue + } + filters.push(filterName) } - filters.push(filterName) } } diff --git a/src/Models/ThemeConfig/Json/LayerConfigJson.ts b/src/Models/ThemeConfig/Json/LayerConfigJson.ts index 1805158e2..500dac4c8 100644 --- a/src/Models/ThemeConfig/Json/LayerConfigJson.ts +++ b/src/Models/ThemeConfig/Json/LayerConfigJson.ts @@ -442,6 +442,7 @@ export interface LayerConfigJson { * 2. search 'filters.json' for the appropriate filter or * 3. will try to parse it as `layername.filterid` and us that one. * + * Note: adding "#filter":"no-auto" will disable the filters added by tagRenderings * * group: filters */ diff --git a/src/UI/Search/ActiveFilters.svelte b/src/UI/Search/ActiveFilters.svelte index 04b199c07..bdbb20f7c 100644 --- a/src/UI/Search/ActiveFilters.svelte +++ b/src/UI/Search/ActiveFilters.svelte @@ -8,12 +8,13 @@ import FilterToggle from "./FilterToggle.svelte" import ToSvelte from "../Base/ToSvelte.svelte" import Tr from "../Base/Tr.svelte" - import Constants from "../../Models/Constants" import { Store } from "../../Logic/UIEventSource" + import Translations from "../i18n/Translations" export let activeFilters: ActiveFilter[] export let state: SpecialVisualizationState let loading = false + const t =Translations.t.general.search let activeLayers: Store = state.layerState.activeLayers.mapD(l => l.filter(l => l.layerDef.isNormal())) @@ -42,10 +43,10 @@ {#if activeFilters.length > 0 || $activeLayers.length === 1 || $nonactiveLayers.length > 0}
-

Active filters

+

{#if loading} @@ -82,9 +83,6 @@ {/each} - - {/if}
- {/if}