Themes: allow to disable auto filters

This commit is contained in:
Pieter Vander Vennet 2024-09-11 17:30:17 +02:00
parent c591770eab
commit b3492930b8
5 changed files with 37 additions and 32 deletions

View file

@ -201,6 +201,7 @@
] ]
} }
}, },
"filter": null,
"=presets": [] "=presets": []
} }
}, },

View file

@ -7,7 +7,7 @@ export class AllSharedLayers {
public static sharedLayers: Map<string, LayerConfig> = AllSharedLayers.getSharedLayers() public static sharedLayers: Map<string, LayerConfig> = AllSharedLayers.getSharedLayers()
public static getSharedLayersConfigs(): Map<string, LayerConfigJson> { public static getSharedLayersConfigs(): Map<string, LayerConfigJson> {
const sharedLayers = new Map<string, LayerConfigJson>() const sharedLayers = new Map<string, LayerConfigJson>()
for (const layer of known_layers.layers) { for (const layer of known_layers["layers"]) {
// @ts-ignore // @ts-ignore
sharedLayers.set(layer.id, layer) sharedLayers.set(layer.id, layer)
} }
@ -16,7 +16,7 @@ export class AllSharedLayers {
} }
private static getSharedLayers(): Map<string, LayerConfig> { private static getSharedLayers(): Map<string, LayerConfig> {
const sharedLayers = new Map<string, LayerConfig>() const sharedLayers = new Map<string, LayerConfig>()
for (const layer of known_layers.layers) { for (const layer of known_layers["layers"]) {
try { try {
// @ts-ignore // @ts-ignore
const parsed = new LayerConfig(layer, "shared_layers") const parsed = new LayerConfig(layer, "shared_layers")

View file

@ -39,7 +39,8 @@ class ExpandFilter extends DesugaringStep<LayerConfigJson> {
constructor(state: DesugaringContext) { constructor(state: DesugaringContext) {
super( super(
["Expands filters: replaces a shorthand by the value found in 'filters.json'.", ["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(" "), ""].join(" "),
["filter"], ["filter"],
"ExpandFilter", "ExpandFilter",
@ -96,6 +97,8 @@ class ExpandFilter extends DesugaringStep<LayerConfigJson> {
return json // Nothing to change here return json // Nothing to change here
} }
const noAutoFilters = json["#filter"] === "no-auto"
const newFilters: FilterConfigJson[] = [] const newFilters: FilterConfigJson[] = []
const filters = <(FilterConfigJson | string)[]>json.filter const filters = <(FilterConfigJson | string)[]>json.filter
@ -109,34 +112,36 @@ class ExpandFilter extends DesugaringStep<LayerConfigJson> {
}) })
} }
/** if (!noAutoFilters){
* Checks all tagRendering. If a tagrendering has 'filter' set, add this filter to the layer config /**
*/ * 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 = <TagRenderingConfigJson>json.tagRenderings[i] for (let i = 0; i < json.tagRenderings?.length; i++) {
if (!tagRendering?.filter) { const tagRendering = <TagRenderingConfigJson>json.tagRenderings[i]
continue if (!tagRendering?.filter) {
}
if (tagRendering.filter === true) {
if (filterExists(tagRendering["id"])) {
continue continue
} }
filters.push(ExpandFilter.buildFilterFromTagRendering(tagRendering, context.enters("tagRenderings", i, "filter"))) if (tagRendering.filter === true) {
continue if (filterExists(tagRendering["id"])) {
} continue
for (const filterName of tagRendering.filter ?? []) { }
if (typeof filterName !== "string") { filters.push(ExpandFilter.buildFilterFromTagRendering(tagRendering, context.enters("tagRenderings", i, "filter")))
context.enters("tagRenderings", i, "filter").err("Not a string: " + filterName)
}
if (filterExists(filterName)) {
// This filter has already been added
continue continue
} }
if (!filterName) { for (const filterName of tagRendering.filter ?? []) {
context.err("Got undefined as filter expansion in " + tagRendering["id"]) if (typeof filterName !== "string") {
continue 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)
} }
} }

View file

@ -442,6 +442,7 @@ export interface LayerConfigJson {
* 2. search 'filters.json' for the appropriate filter or * 2. search 'filters.json' for the appropriate filter or
* 3. will try to parse it as `layername.filterid` and us that one. * 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 * group: filters
*/ */

View file

@ -8,12 +8,13 @@
import FilterToggle from "./FilterToggle.svelte" import FilterToggle from "./FilterToggle.svelte"
import ToSvelte from "../Base/ToSvelte.svelte" import ToSvelte from "../Base/ToSvelte.svelte"
import Tr from "../Base/Tr.svelte" import Tr from "../Base/Tr.svelte"
import Constants from "../../Models/Constants"
import { Store } from "../../Logic/UIEventSource" import { Store } from "../../Logic/UIEventSource"
import Translations from "../i18n/Translations"
export let activeFilters: ActiveFilter[] export let activeFilters: ActiveFilter[]
export let state: SpecialVisualizationState export let state: SpecialVisualizationState
let loading = false let loading = false
const t =Translations.t.general.search
let activeLayers: Store<FilteredLayer[]> = state.layerState.activeLayers.mapD(l => l.filter(l => l.layerDef.isNormal())) let activeLayers: Store<FilteredLayer[]> = 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} {#if activeFilters.length > 0 || $activeLayers.length === 1 || $nonactiveLayers.length > 0}
<SidebarUnit> <SidebarUnit>
<div class="flex justify-between"> <div class="flex justify-between">
<h3>Active filters</h3> <h3><Tr t={t.activeFilters}/></h3>
<button class="as-link subtle self-end" on:click={() => clear()} style="margin-right: 0.75rem"> <button class="as-link subtle self-end" on:click={() => clear()} style="margin-right: 0.75rem">
Clear filters <Tr t={t.clearFilters}/>
</button> </button>
</div> </div>
{#if loading} {#if loading}
@ -82,9 +83,6 @@
</div> </div>
{/each} {/each}
</div> </div>
{/if} {/if}
</SidebarUnit> </SidebarUnit>
{/if} {/if}