feat: adapt browser counter to the currently displayed features

This commit is contained in:
Yohan Boniface 2024-01-31 08:06:21 +01:00
parent 8336dd2b78
commit 60832797d0
2 changed files with 8 additions and 2 deletions

View file

@ -62,8 +62,6 @@ L.U.Browser = L.Class.extend({
container.id = `browse_data_datalayer_${datalayer.umap_id}` container.id = `browse_data_datalayer_${datalayer.umap_id}`
datalayer.renderToolbox(headline) datalayer.renderToolbox(headline)
L.DomUtil.add('span', '', headline, datalayer.options.name) L.DomUtil.add('span', '', headline, datalayer.options.name)
const counter = L.DomUtil.add('span', 'datalayer-counter', headline, datalayer.count())
counter.title = L._('{count} features in this layer', {count: datalayer.count()})
const ul = L.DomUtil.create('ul', '', container) const ul = L.DomUtil.create('ul', '', container)
L.DomUtil.classIf(container, 'off', !datalayer.isVisible()) L.DomUtil.classIf(container, 'off', !datalayer.isVisible())
@ -82,6 +80,11 @@ L.U.Browser = L.Class.extend({
} }
build() build()
let total = datalayer.count(),
current = ul.querySelectorAll('li').length,
count = total == current ? total : `${current}/${total}`
const counter = L.DomUtil.add('span', 'datalayer-counter', headline, count)
counter.title = L._('Features in this layer: {count}', {count: count})
datalayer.on('datachanged', build) datalayer.on('datachanged', build)
datalayer.map.ui.once('panel:closed', () => { datalayer.map.ui.once('panel:closed', () => {
datalayer.off('datachanged', build) datalayer.off('datachanged', build)

View file

@ -71,6 +71,7 @@ def test_data_browser_should_be_open(live_server, page, bootstrap, map):
def test_data_browser_should_be_filterable(live_server, page, bootstrap, map): def test_data_browser_should_be_filterable(live_server, page, bootstrap, map):
page.goto(f"{live_server.url}{map.get_absolute_url()}") page.goto(f"{live_server.url}{map.get_absolute_url()}")
expect(page.get_by_title("Features in this layer: 3")).to_be_visible()
markers = page.locator(".leaflet-marker-icon") markers = page.locator(".leaflet-marker-icon")
paths = page.locator(".leaflet-overlay-pane path") paths = page.locator(".leaflet-overlay-pane path")
expect(markers).to_have_count(1) expect(markers).to_have_count(1)
@ -78,6 +79,8 @@ def test_data_browser_should_be_filterable(live_server, page, bootstrap, map):
filter_ = page.locator("input[name='filter']") filter_ = page.locator("input[name='filter']")
expect(filter_).to_be_visible() expect(filter_).to_be_visible()
filter_.type("poly") filter_.type("poly")
expect(page.get_by_title("Features in this layer: 1/3")).to_be_visible()
expect(page.get_by_title("Features in this layer: 1/3")).to_have_text("1/3")
expect(page.get_by_text("one point in france")).to_be_hidden() expect(page.get_by_text("one point in france")).to_be_hidden()
expect(page.get_by_text("one line in new zeland")).to_be_hidden() expect(page.get_by_text("one line in new zeland")).to_be_hidden()
expect(page.get_by_text("one polygon in greenland")).to_be_visible() expect(page.get_by_text("one polygon in greenland")).to_be_visible()