forked from MapComplete/MapComplete
Fix: filtering for dates now works again
This commit is contained in:
parent
75a8ef5cb8
commit
bea9f66b9a
3 changed files with 25 additions and 13 deletions
|
|
@ -36,7 +36,7 @@ export default class FilteredLayer {
|
||||||
constructor(
|
constructor(
|
||||||
layer: LayerConfig,
|
layer: LayerConfig,
|
||||||
appliedFilters?: ReadonlyMap<string, UIEventSource<undefined | number | string>>,
|
appliedFilters?: ReadonlyMap<string, UIEventSource<undefined | number | string>>,
|
||||||
isDisplayed?: UIEventSource<boolean>
|
isDisplayed?: UIEventSource<boolean>,
|
||||||
) {
|
) {
|
||||||
this.layerDef = layer
|
this.layerDef = layer
|
||||||
this.isDisplayed = isDisplayed ?? new UIEventSource(true)
|
this.isDisplayed = isDisplayed ?? new UIEventSource(true)
|
||||||
|
|
@ -82,25 +82,25 @@ export default class FilteredLayer {
|
||||||
layer: LayerConfig,
|
layer: LayerConfig,
|
||||||
context: string,
|
context: string,
|
||||||
osmConnection: OsmConnection,
|
osmConnection: OsmConnection,
|
||||||
enabledByDefault?: Store<boolean>
|
enabledByDefault?: Store<boolean>,
|
||||||
) {
|
) {
|
||||||
let isDisplayed: UIEventSource<boolean>
|
let isDisplayed: UIEventSource<boolean>
|
||||||
if (layer.syncSelection === "local") {
|
if (layer.syncSelection === "local") {
|
||||||
isDisplayed = LocalStorageSource.GetParsed(
|
isDisplayed = LocalStorageSource.GetParsed(
|
||||||
context + "-layer-" + layer.id + "-enabled",
|
context + "-layer-" + layer.id + "-enabled",
|
||||||
layer.shownByDefault
|
layer.shownByDefault,
|
||||||
)
|
)
|
||||||
} else if (layer.syncSelection === "theme-only") {
|
} else if (layer.syncSelection === "theme-only") {
|
||||||
isDisplayed = FilteredLayer.getPref(
|
isDisplayed = FilteredLayer.getPref(
|
||||||
osmConnection,
|
osmConnection,
|
||||||
context + "-layer-" + layer.id + "-enabled",
|
context + "-layer-" + layer.id + "-enabled",
|
||||||
layer
|
layer,
|
||||||
)
|
)
|
||||||
} else if (layer.syncSelection === "global") {
|
} else if (layer.syncSelection === "global") {
|
||||||
isDisplayed = FilteredLayer.getPref(
|
isDisplayed = FilteredLayer.getPref(
|
||||||
osmConnection,
|
osmConnection,
|
||||||
"layer-" + layer.id + "-enabled",
|
"layer-" + layer.id + "-enabled",
|
||||||
layer
|
layer,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
let isShown = layer.shownByDefault
|
let isShown = layer.shownByDefault
|
||||||
|
|
@ -110,7 +110,7 @@ export default class FilteredLayer {
|
||||||
isDisplayed = QueryParameters.GetBooleanQueryParameter(
|
isDisplayed = QueryParameters.GetBooleanQueryParameter(
|
||||||
FilteredLayer.queryParameterKey(layer),
|
FilteredLayer.queryParameterKey(layer),
|
||||||
isShown,
|
isShown,
|
||||||
"Whether or not layer " + layer.id + " is shown"
|
"Whether or not layer " + layer.id + " is shown",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -134,13 +134,18 @@ export default class FilteredLayer {
|
||||||
/**
|
/**
|
||||||
* import Translations from "../UI/i18n/Translations"
|
* import Translations from "../UI/i18n/Translations"
|
||||||
* import { RegexTag } from "../Logic/Tags/RegexTag"
|
* import { RegexTag } from "../Logic/Tags/RegexTag"
|
||||||
|
* import { ComparingTag } from "../Logic/Tags/ComparingTag"
|
||||||
*
|
*
|
||||||
* const option: FilterConfigOption = {question: Translations.T("question"), osmTags: undefined, originalTagsSpec: "key~.*{search}.*", fields: [{name: "search", type: "string"}] }
|
* const option: FilterConfigOption = {question: Translations.T("question"), osmTags: undefined, originalTagsSpec: "key~.*{search}.*", fields: [{name: "search", type: "string"}] }
|
||||||
* FilteredLayer.fieldsToTags(option, {search: "value_regex"}) // => new RegexTag("key", /^(.*(value_regex).*)$/s)
|
* FilteredLayer.fieldsToTags(option, {search: "value_regex"}) // => new RegexTag("key", /^(.*(value_regex).*)$/s)
|
||||||
|
*
|
||||||
|
* const option: FilterConfigOption = {question: Translations.T("question"), searchTerms: undefined, osmTags: undefined, originalTagsSpec: "edit_time>{search}", fields: [{name: "search", type: "date"}] }
|
||||||
|
* const comparingTag = FilteredLayer.fieldsToTags(option, {search: "2024-09-20"})
|
||||||
|
* comparingTag.asJson() // => "edit_time>1726790400000"
|
||||||
*/
|
*/
|
||||||
private static fieldsToTags(
|
private static fieldsToTags(
|
||||||
option: FilterConfigOption,
|
option: FilterConfigOption,
|
||||||
fieldstate: string | Record<string, string>
|
fieldstate: string | Record<string, string>,
|
||||||
): TagsFilter | undefined {
|
): TagsFilter | undefined {
|
||||||
let properties: Record<string, string>
|
let properties: Record<string, string>
|
||||||
if (typeof fieldstate === "string") {
|
if (typeof fieldstate === "string") {
|
||||||
|
|
@ -160,7 +165,12 @@ export default class FilteredLayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const key in properties) {
|
for (const key in properties) {
|
||||||
v = (<string>v).replace("{" + key + "}", "(" + properties[key] + ")")
|
const needsParentheses = v.match(/[a-zA-Z0-9_:]+~/)
|
||||||
|
if (needsParentheses) {
|
||||||
|
v = (<string>v).replace("{" + key + "}", "(" + properties[key] + ")")
|
||||||
|
} else {
|
||||||
|
v = (<string>v).replace("{" + key + "}", properties[key])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return v
|
return v
|
||||||
|
|
@ -171,7 +181,7 @@ export default class FilteredLayer {
|
||||||
private static getPref(
|
private static getPref(
|
||||||
osmConnection: OsmConnection,
|
osmConnection: OsmConnection,
|
||||||
key: string,
|
key: string,
|
||||||
layer: LayerConfig
|
layer: LayerConfig,
|
||||||
): UIEventSource<boolean> {
|
): UIEventSource<boolean> {
|
||||||
return osmConnection.GetPreference(key, layer.shownByDefault + "").sync(
|
return osmConnection.GetPreference(key, layer.shownByDefault + "").sync(
|
||||||
(v) => {
|
(v) => {
|
||||||
|
|
@ -186,7 +196,7 @@ export default class FilteredLayer {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
return "" + b
|
return "" + b
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ export abstract class Validator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public getPlaceholder() {
|
public getPlaceholder() {
|
||||||
return Translations.t.validation[this.name].description
|
return Translations.t.validation[this.name]?.description
|
||||||
}
|
}
|
||||||
|
|
||||||
public isValid(_: string, getCountry?: () => string): boolean {
|
public isValid(_: string, getCountry?: () => string): boolean {
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ import Filterview from "./BigComponents/Filterview.svelte"
|
||||||
import FilteredLayer from "../Models/FilteredLayer"
|
import FilteredLayer from "../Models/FilteredLayer"
|
||||||
import { SubtleButton } from "./Base/SubtleButton"
|
import { SubtleButton } from "./Base/SubtleButton"
|
||||||
import { GeoOperations } from "../Logic/GeoOperations"
|
import { GeoOperations } from "../Logic/GeoOperations"
|
||||||
import { Polygon } from "geojson"
|
import { FeatureCollection, Polygon } from "geojson"
|
||||||
import { Feature } from "geojson"
|
import { Feature } from "geojson"
|
||||||
|
|
||||||
class StatsticsForOverviewFile extends Combine {
|
class StatsticsForOverviewFile extends Combine {
|
||||||
|
|
@ -30,7 +30,9 @@ class StatsticsForOverviewFile extends Combine {
|
||||||
new Title("Filters"),
|
new Title("Filters"),
|
||||||
new SvelteUIElement(Filterview, { filteredLayer }),
|
new SvelteUIElement(Filterview, { filteredLayer }),
|
||||||
])
|
])
|
||||||
|
filteredLayer.currentFilter.addCallbackAndRun(tf => {
|
||||||
|
console.log("Filters are", tf)
|
||||||
|
})
|
||||||
const downloaded = new UIEventSource<{ features: ChangeSetData[] }[]>([])
|
const downloaded = new UIEventSource<{ features: ChangeSetData[] }[]>([])
|
||||||
|
|
||||||
for (const filepath of paths) {
|
for (const filepath of paths) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue