Allow to control facet labels
This commit is contained in:
parent
b013692527
commit
d2c3b8694b
6 changed files with 22 additions and 13 deletions
|
@ -794,7 +794,7 @@ L.U.Map.include({
|
||||||
_openFacet: function () {
|
_openFacet: function () {
|
||||||
const container = L.DomUtil.create('div', 'umap-facet-search'),
|
const container = L.DomUtil.create('div', 'umap-facet-search'),
|
||||||
title = L.DomUtil.add('h3', 'umap-filter-title', container, L._('Facet search')),
|
title = L.DomUtil.add('h3', 'umap-filter-title', container, L._('Facet search')),
|
||||||
keys = this.getFacetKeys()
|
keys = Object.keys(this.getFacetKeys())
|
||||||
|
|
||||||
const knownValues = {}
|
const knownValues = {}
|
||||||
|
|
||||||
|
@ -830,6 +830,7 @@ L.U.Map.include({
|
||||||
{
|
{
|
||||||
handler: 'FacetSearch',
|
handler: 'FacetSearch',
|
||||||
choices: knownValues[current],
|
choices: knownValues[current],
|
||||||
|
label: this.getFacetKeys()[current],
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
const builder = new L.U.FormBuilder(this, fields, {
|
const builder = new L.U.FormBuilder(this, fields, {
|
||||||
|
|
|
@ -569,7 +569,7 @@ L.U.Help = L.Class.extend({
|
||||||
slugKey: L._('The name of the property to use as feature unique identifier.'),
|
slugKey: L._('The name of the property to use as feature unique identifier.'),
|
||||||
filterKey: L._('Comma separated list of properties to use when filtering features'),
|
filterKey: L._('Comma separated list of properties to use when filtering features'),
|
||||||
facetKey: L._(
|
facetKey: L._(
|
||||||
'Comma separated list of properties to use for facet search'
|
'Comma separated list of properties to use for facet search (eg.: mykey,otherkey). To control label, add it after a | (eg.: mykey|My Key,otherkeyOther Key)'
|
||||||
),
|
),
|
||||||
interactive: L._('If false, the polygon will act as a part of the underlying map.'),
|
interactive: L._('If false, the polygon will act as a part of the underlying map.'),
|
||||||
outlink: L._('Define link to open in a new window on polygon click.'),
|
outlink: L._('Define link to open in a new window on polygon click.'),
|
||||||
|
|
|
@ -686,14 +686,17 @@ L.FormBuilder.Switch = L.FormBuilder.CheckBox.extend({
|
||||||
|
|
||||||
L.FormBuilder.FacetSearch = L.FormBuilder.Element.extend({
|
L.FormBuilder.FacetSearch = L.FormBuilder.Element.extend({
|
||||||
build: function () {
|
build: function () {
|
||||||
this.container = L.DomUtil.create('div', 'property-container', this.parentNode)
|
this.container = L.DomUtil.create('div', 'umap-facet', this.parentNode)
|
||||||
this.headline = L.DomUtil.add('h5', '', this.container, this.name)
|
|
||||||
this.ul = L.DomUtil.create('ul', '', this.container)
|
this.ul = L.DomUtil.create('ul', '', this.container)
|
||||||
const choices = this.options.choices
|
const choices = this.options.choices
|
||||||
choices.sort()
|
choices.sort()
|
||||||
choices.forEach((value) => this.buildLi(value))
|
choices.forEach((value) => this.buildLi(value))
|
||||||
},
|
},
|
||||||
|
|
||||||
|
buildLabel: function () {
|
||||||
|
this.label = L.DomUtil.add('h5', '', this.parentNode, this.options.label);
|
||||||
|
},
|
||||||
|
|
||||||
buildLi: function (value) {
|
buildLi: function (value) {
|
||||||
const property_li = L.DomUtil.create('li', '', this.ul),
|
const property_li = L.DomUtil.create('li', '', this.ul),
|
||||||
input = L.DomUtil.create('input', '', property_li),
|
input = L.DomUtil.create('input', '', property_li),
|
||||||
|
|
|
@ -2104,7 +2104,11 @@ L.U.Map.include({
|
||||||
},
|
},
|
||||||
|
|
||||||
getFacetKeys: function () {
|
getFacetKeys: function () {
|
||||||
return (this.options.facetKey || '').split(',')
|
return (this.options.facetKey || '').split(',').reduce((acc, curr) => {
|
||||||
|
const els = curr.split("|")
|
||||||
|
acc[els[0]] = els[1] || els[0]
|
||||||
|
return acc
|
||||||
|
}, {})
|
||||||
},
|
},
|
||||||
|
|
||||||
getLayersBounds: function () {
|
getLayersBounds: function () {
|
||||||
|
|
|
@ -853,9 +853,6 @@ a.add-datalayer:hover,
|
||||||
.umap-browse-features .polygon .feature-color {
|
.umap-browse-features .polygon .feature-color {
|
||||||
background-position: -32px -16px;
|
background-position: -32px -16px;
|
||||||
}
|
}
|
||||||
.umap-facet-search .property-container:not(:first-child) {
|
|
||||||
margin-top: 14px;
|
|
||||||
}
|
|
||||||
.show-on-edit {
|
.show-on-edit {
|
||||||
display: none!important;
|
display: none!important;
|
||||||
}
|
}
|
||||||
|
|
|
@ -403,7 +403,7 @@ describe('L.U.DataLayer', function () {
|
||||||
assert.ok(qs('path[fill="DarkGoldenRod"]'))
|
assert.ok(qs('path[fill="DarkGoldenRod"]'))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
describe('#advanced-filters()', function () {
|
describe('#facet-search()', function () {
|
||||||
before(function () {
|
before(function () {
|
||||||
this.server.respondWith(
|
this.server.respondWith(
|
||||||
/\/datalayer\/63\/\?.*/,
|
/\/datalayer\/63\/\?.*/,
|
||||||
|
@ -413,7 +413,7 @@ describe('L.U.DataLayer', function () {
|
||||||
this.map.createDataLayer(RESPONSES.datalayer63_GET._umap_options)
|
this.map.createDataLayer(RESPONSES.datalayer63_GET._umap_options)
|
||||||
this.server.respond()
|
this.server.respond()
|
||||||
})
|
})
|
||||||
it('should show non browsable layer', function () {
|
it('should not impact non browsable layer', function () {
|
||||||
assert.ok(qs('path[fill="SteelBlue"]'))
|
assert.ok(qs('path[fill="SteelBlue"]'))
|
||||||
})
|
})
|
||||||
it('should allow advanced filter', function () {
|
it('should allow advanced filter', function () {
|
||||||
|
@ -428,10 +428,15 @@ describe('L.U.DataLayer', function () {
|
||||||
// This one comes from a non browsable layer
|
// This one comes from a non browsable layer
|
||||||
// so it should not be affected by the filter
|
// so it should not be affected by the filter
|
||||||
assert.ok(qs('path[fill="SteelBlue"]'))
|
assert.ok(qs('path[fill="SteelBlue"]'))
|
||||||
happen.click(qs('input[data-value="name poly"]')) // Undo
|
happen.click(qs('input[data-value="name poly"]')) // Undo
|
||||||
|
})
|
||||||
|
it('should allow to control facet label', function () {
|
||||||
|
this.map.options.facetKey = 'name|Nom'
|
||||||
|
this.map.openFacet()
|
||||||
|
assert.ok(qs('div.umap-facet-search h5'))
|
||||||
|
assert.equal(qs('div.umap-facet-search h5').textContent, 'Nom')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('#zoomEnd', function () {
|
describe('#zoomEnd', function () {
|
||||||
it('should honour the fromZoom option', function () {
|
it('should honour the fromZoom option', function () {
|
||||||
this.map.setZoom(6, {animate: false})
|
this.map.setZoom(6, {animate: false})
|
||||||
|
@ -453,5 +458,4 @@ describe('L.U.DataLayer', function () {
|
||||||
assert.ok(qs('path[fill="none"]'))
|
assert.ok(qs('path[fill="none"]'))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue