translation capability and small cleanups
This commit is contained in:
parent
10b1bc6265
commit
f4413a8a74
4 changed files with 28 additions and 21 deletions
|
@ -710,7 +710,7 @@ const ControlsMixin = {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
value = String(value)
|
value = String(value)
|
||||||
value = (value.length ? value : "empty string")
|
value = (value.length ? value : L._("empty string"))
|
||||||
if (!!value && !facetCriteria[key]["choices"].includes(value)) {
|
if (!!value && !facetCriteria[key]["choices"].includes(value)) {
|
||||||
facetCriteria[key]["choices"].push(value)
|
facetCriteria[key]["choices"].push(value)
|
||||||
}
|
}
|
||||||
|
@ -729,15 +729,20 @@ const ControlsMixin = {
|
||||||
if (!found)
|
if (!found)
|
||||||
this.ui.alert({ content: L._('No results for these facets'), level: 'info' })
|
this.ui.alert({ content: L._('No results for these facets'), level: 'info' })
|
||||||
}
|
}
|
||||||
const fields = keys.map((key) => [
|
const fields = keys.map((key) => {
|
||||||
|
let criteria = facetCriteria[key]
|
||||||
|
let handler = ["date", "datetime-local", "number"].includes(criteria["inputType"]) ? 'FacetSearchMinMax' : 'FacetSearchChoices'
|
||||||
|
let label = facetKeys[key]["label"]
|
||||||
|
return [
|
||||||
`facets.${key}`,
|
`facets.${key}`,
|
||||||
{
|
{
|
||||||
handler: ["date", "datetime-local", "number"].includes(facetCriteria[key]["inputType"]) ? 'FacetSearchMinMax' : 'FacetSearchChoices',
|
criteria: criteria,
|
||||||
criteria: facetCriteria[key],
|
handler: handler,
|
||||||
label: facetKeys[key]["label"]
|
label: label
|
||||||
},
|
},
|
||||||
])
|
]
|
||||||
const builder = new U.FormBuilder(this, fields, {
|
})
|
||||||
|
const builder = new L.U.FormBuilder(this, fields, {
|
||||||
makeDirty: false,
|
makeDirty: false,
|
||||||
callback: filterFeatures,
|
callback: filterFeatures,
|
||||||
callbackContext: this,
|
callbackContext: this,
|
||||||
|
|
|
@ -67,6 +67,13 @@ L.Util.setNullableBooleanFromQueryString = function (options, name) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
L.Util.calculateStepFromNumber = function (n) {
|
||||||
|
// calculate step for number input field from significant digits of number
|
||||||
|
let step = String(n).replace(/^\d+?(0*)((\.)(\d*?)0*|)$/, "1$1$3$4").split('.')
|
||||||
|
step = parseFloat((step[1] || "").replace(/\d/g, "0").replace(/^0/, "0.0").replace(/0$/, "1") || (step[0] || "").replace(/0$/, "") || "1")
|
||||||
|
return step
|
||||||
|
}
|
||||||
|
|
||||||
L.DomUtil.add = (tagName, className, container, content) => {
|
L.DomUtil.add = (tagName, className, container, content) => {
|
||||||
const el = L.DomUtil.create(tagName, className, container)
|
const el = L.DomUtil.create(tagName, className, container)
|
||||||
if (content) {
|
if (content) {
|
||||||
|
|
|
@ -516,7 +516,7 @@ U.FeatureMixin = {
|
||||||
} else {
|
} else {
|
||||||
const choices = criteria["choices"]
|
const choices = criteria["choices"]
|
||||||
value = String(value)
|
value = String(value)
|
||||||
value = (value.length ? value : "empty string")
|
value = (value.length ? value : L._("empty string"))
|
||||||
if (choices.length && (!value || !choices.includes(value))) return false
|
if (choices.length && (!value || !choices.includes(value))) return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -796,7 +796,7 @@ L.FormBuilder.FacetSearchMinMax = L.FormBuilder.Element.extend({
|
||||||
|
|
||||||
this.minTdLabel = L.DomUtil.create('td', '', this.minTr)
|
this.minTdLabel = L.DomUtil.create('td', '', this.minTr)
|
||||||
this.minLabel = L.DomUtil.create('label', '', this.minTdLabel)
|
this.minLabel = L.DomUtil.create('label', '', this.minTdLabel)
|
||||||
this.minLabel.innerHTML = 'Min'
|
this.minLabel.innerHTML = L._('Min')
|
||||||
this.minLabel.htmlFor = `${this.inputType}_${this.name}_min`
|
this.minLabel.htmlFor = `${this.inputType}_${this.name}_min`
|
||||||
|
|
||||||
this.minTdInput = L.DomUtil.create('td', '', this.minTr)
|
this.minTdInput = L.DomUtil.create('td', '', this.minTr)
|
||||||
|
@ -813,7 +813,7 @@ L.FormBuilder.FacetSearchMinMax = L.FormBuilder.Element.extend({
|
||||||
|
|
||||||
this.maxTdLabel = L.DomUtil.create('td', '', this.maxTr)
|
this.maxTdLabel = L.DomUtil.create('td', '', this.maxTr)
|
||||||
this.maxLabel = L.DomUtil.create('label', '', this.maxTdLabel)
|
this.maxLabel = L.DomUtil.create('label', '', this.maxTdLabel)
|
||||||
this.maxLabel.innerHTML = 'Max'
|
this.maxLabel.innerHTML = L._('Max')
|
||||||
this.maxLabel.htmlFor = `${this.inputType}_${this.name}_max`
|
this.maxLabel.htmlFor = `${this.inputType}_${this.name}_max`
|
||||||
|
|
||||||
this.maxTdInput = L.DomUtil.create('td', '', this.maxTr)
|
this.maxTdInput = L.DomUtil.create('td', '', this.maxTr)
|
||||||
|
@ -827,8 +827,8 @@ L.FormBuilder.FacetSearchMinMax = L.FormBuilder.Element.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
if (["date", "datetime-local"].includes(this.inputType)) {
|
if (["date", "datetime-local"].includes(this.inputType)) {
|
||||||
this.minLabel.innerHTML = 'From'
|
this.minLabel.innerHTML = L._('From')
|
||||||
this.maxLabel.innerHTML = 'Until'
|
this.maxLabel.innerHTML = L._('Until')
|
||||||
if (min != null) {
|
if (min != null) {
|
||||||
this.minInput.valueAsNumber = (min.valueOf() - min.getTimezoneOffset() * 60000)
|
this.minInput.valueAsNumber = (min.valueOf() - min.getTimezoneOffset() * 60000)
|
||||||
}
|
}
|
||||||
|
@ -845,12 +845,7 @@ L.FormBuilder.FacetSearchMinMax = L.FormBuilder.Element.extend({
|
||||||
if (["number"].includes(this.inputType)) {
|
if (["number"].includes(this.inputType)) {
|
||||||
if (min != null && max != null) {
|
if (min != null && max != null) {
|
||||||
// calculate step from significant digits of min and max values
|
// calculate step from significant digits of min and max values
|
||||||
let minStep = String(min).replace(/^\d+?(0*)((\.)(\d*?)0*|)$/, "1$1$3$4").split('.')
|
const step = Math.min(L.Util.calculateStepFromNumber(min), L.Util.calculateStepFromNumber(max))
|
||||||
let maxStep = String(max).replace(/^\d+?(0*)((\.)(\d*?)0*|)$/, "1$1$3$4").split('.')
|
|
||||||
minStep = parseFloat((minStep[1] || "").replace(/\d/g, "0").replace(/^0/, "0.0").replace(/0$/, "1") || (minStep[0] || "").replace(/0$/, "") || "1")
|
|
||||||
maxStep = parseFloat((maxStep[1] || "").replace(/\d/g, "0").replace(/^0/, "0.0").replace(/0$/, "1") || (maxStep[0] || "").replace(/0$/, "") || "1")
|
|
||||||
|
|
||||||
const step = Math.min(minStep, maxStep)
|
|
||||||
this.minInput.step = String(step)
|
this.minInput.step = String(step)
|
||||||
this.maxInput.step = String(step)
|
this.maxInput.step = String(step)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue