chore: refactor FeatureMixin.matchFacets

This commit is contained in:
Yohan Boniface 2024-04-17 18:26:35 +02:00
parent 9c326d09e1
commit 91f0f29d5e

View file

@ -493,30 +493,25 @@ U.FeatureMixin = {
}, },
matchFacets: function () { matchFacets: function () {
const facets = this.map.facets.selected const selected = this.map.facets.selected
for (const [property, criteria] of Object.entries(facets)) { for (let [name, { type, min, max, choices }] of Object.entries(selected)) {
let value = this.properties[property] let value = this.properties[name]
const type = criteria["type"] switch (type) {
if (["date", "datetime", "number"].includes(type)) { case 'date':
let min = criteria["min"] case 'datetime':
let max = criteria["max"] case 'number':
value = (value != null ? value : undefined) const caster = type === 'number' ? parseFloat : (v) => new Date(v)
if (["date", "datetime"].includes(type)) { value = value != null ? value : undefined
min = new Date(min) min = caster(min)
max = new Date(max) max = caster(max)
value = new Date(value) value = caster(value)
} if (!isNaN(min) && !isNaN(value) && min > value) return false
if (["number"].includes(type)) { if (!isNaN(max) && !isNaN(value) && max < value) return false
min = parseFloat(min) break
max = parseFloat(max) default:
value = parseFloat(value) value = String(value || '') || L._('<empty value>')
} if (choices?.length && (!value || !choices.includes(value))) return false
if (!isNaN(min) && !isNaN(value) && min > value) return false break
if (!isNaN(max) && !isNaN(value) && max < value) return false
} else {
const choices = criteria["choices"]
value = String(value || '') || L._("<empty value>")
if (choices?.length && (!value || !choices.includes(value))) return false
} }
} }
return true return true