Support date properties in facet search - fix indents

This commit is contained in:
flammermann 2023-12-28 00:26:09 +00:00 committed by Yohan Boniface
parent a2e3d6f327
commit 4de6bc6c91
3 changed files with 25 additions and 25 deletions

View file

@ -671,18 +671,18 @@ const ControlsMixin = {
keys.forEach((key) => { keys.forEach((key) => {
if (facetKeys[key]["type"] === "date") { if (facetKeys[key]["type"] === "date") {
if (!facetCriteria[key]) facetCriteria[key] = { if (!facetCriteria[key]) facetCriteria[key] = {
"min": undefined, "min": undefined,
"max": undefined "max": undefined
} }
if (!this.facets[key]) this.facets[key] = { if (!this.facets[key]) this.facets[key] = {
"type": facetKeys[key]["type"], "type": facetKeys[key]["type"],
"min": undefined, "min": undefined,
"max": undefined "max": undefined
} }
} else { } else {
if (!facetCriteria[key]) facetCriteria[key] = { if (!facetCriteria[key]) facetCriteria[key] = {
"choices": [] "choices": []
} }
if (!this.facets[key]) this.facets[key] = { if (!this.facets[key]) this.facets[key] = {
"type": facetKeys[key]["type"], "type": facetKeys[key]["type"],
"choices": [] "choices": []
@ -695,18 +695,18 @@ const ControlsMixin = {
keys.forEach((key) => { keys.forEach((key) => {
let value = feature.properties[key] let value = feature.properties[key]
if (facetKeys[key]["type"] === "date") { if (facetKeys[key]["type"] === "date") {
value = feature.parseDateField(value) value = feature.parseDateField(value)
if (!!value && (!facetCriteria[key]["min"] || facetCriteria[key]["min"] > value)) { if (!!value && (!facetCriteria[key]["min"] || facetCriteria[key]["min"] > value)) {
facetCriteria[key]["min"] = value facetCriteria[key]["min"] = value
} }
if (!!value && (!facetCriteria[key]["max"] || facetCriteria[key]["max"] < value)) { if (!!value && (!facetCriteria[key]["max"] || facetCriteria[key]["max"] < value)) {
facetCriteria[key]["max"] = value facetCriteria[key]["max"] = value
} }
} else { } else {
if (!!value && !facetCriteria[key]["choices"].includes(value)) { if (!!value && !facetCriteria[key]["choices"].includes(value)) {
facetCriteria[key]["choices"].push(value) facetCriteria[key]["choices"].push(value)
} }
} }
}) })
}) })
}) })
@ -725,7 +725,7 @@ const ControlsMixin = {
const fields = keys.map((key) => [ const fields = keys.map((key) => [
`facets.${key}`, `facets.${key}`,
{ {
handler: facetKeys[key]["type"] === "date" ? 'FacetSearchDate' : 'FacetSearchCheckbox', handler: facetKeys[key]["type"] === "date" ? 'FacetSearchDate' : 'FacetSearchCheckbox',
criteria: facetCriteria[key], criteria: facetCriteria[key],
label: facetKeys[key]["label"] label: facetKeys[key]["label"]
}, },

View file

@ -508,13 +508,13 @@ U.FeatureMixin = {
let value = this.properties[property] let value = this.properties[property]
const type = criteria["type"] const type = criteria["type"]
if (type === "date") { if (type === "date") {
const min = new Date(criteria["min"]) const min = new Date(criteria["min"])
const max = new Date(criteria["max"]) const max = new Date(criteria["max"])
value = this.parseDateField(value) value = this.parseDateField(value)
if (!!min && (!value || min > value)) return false if (!!min && (!value || min > value)) return false
if (!!max && (!value || max < value)) return false if (!!max && (!value || max < value)) return false
} else { } else {
const choices = criteria["choices"] const choices = criteria["choices"]
if (choices.length && (!value || !choices.includes(value))) return false if (choices.length && (!value || !choices.includes(value))) return false
} }
} }

View file

@ -1849,8 +1849,8 @@ U.Map = L.Map.extend({
return (this.options.facetKey || '').split(',').reduce((acc, curr) => { return (this.options.facetKey || '').split(',').reduce((acc, curr) => {
const els = curr.split('|') const els = curr.split('|')
acc[els[0]] = { acc[els[0]] = {
"label": els[1] || els[0], "label": els[1] || els[0],
"type": els[2] || "checkbox" "type": els[2] || "checkbox"
} }
return acc return acc
}, {}) }, {})