fix: honour old_id in datalayers= query string parameter

fix #1714
This commit is contained in:
Yohan Boniface 2024-03-27 22:10:38 +01:00
parent c92d24100f
commit 90ced76a11
4 changed files with 39 additions and 12 deletions

View file

@ -443,6 +443,8 @@ class DataLayer(NamedModel):
"name": self.name,
"displayOnLoad": self.display_on_load,
}
if self.old_id:
obj["old_id"] = self.old_id
obj["id"] = self.pk
obj["permissions"] = {"edit_status": self.edit_status}
obj["editMode"] = "advanced" if self.can_edit(user, request) else "disabled"

View file

@ -69,13 +69,13 @@ U.Map = L.Map.extend({
this.options.zoomControl = zoomControl !== undefined ? zoomControl : true
this.options.fullscreenControl =
fullscreenControl !== undefined ? fullscreenControl : true
this.datalayersOnLoad = L.Util.queryString('datalayers')
if (this.datalayersOnLoad) {
this.datalayersOnLoad = this.datalayersOnLoad.toString().split(',')
this.datalayersFromQueryString = L.Util.queryString('datalayers')
if (this.datalayersFromQueryString) {
this.datalayersFromQueryString = this.datalayersFromQueryString
.toString()
.split(',')
}
if (L.Browser.ielt9) this.options.editMode = 'disabled' // TODO include ie9
let editedFeature = null
const self = this
try {
@ -1527,7 +1527,9 @@ U.Map = L.Map.extend({
metadataFields = ['options.name', 'options.description'],
title = L.DomUtil.create('h3', '', container)
title.textContent = L._('Edit map properties')
const builder = new U.FormBuilder(this, metadataFields, {className: 'map-metadata'})
const builder = new U.FormBuilder(this, metadataFields, {
className: 'map-metadata',
})
const form = builder.build()
container.appendChild(form)
this._editControls(container)

View file

@ -609,12 +609,13 @@ U.DataLayer = L.Evented.extend({
},
autoLoaded: function () {
return (
(this.map.datalayersOnLoad &&
this.umap_id &&
this.map.datalayersOnLoad.indexOf(this.umap_id.toString()) !== -1) ||
(!this.map.datalayersOnLoad && this.options.displayOnLoad)
)
if (!this.map.datalayersFromQueryString) return this.options.displayOnLoad
const datalayerIds = this.map.datalayersFromQueryString
let loadMe = datalayerIds.includes(this.umap_id.toString())
if (this.options.old_id) {
loadMe = loadMe || datalayerIds.includes(this.options.old_id.toString())
}
return loadMe
},
insertBefore: function (other) {

View file

@ -106,3 +106,25 @@ def test_should_honour_color_variable(live_server, map, page):
expect(page.locator(".leaflet-overlay-pane path[fill='tomato']"))
markers = page.locator(".leaflet-marker-icon .icon_container")
expect(markers).to_have_css("background-color", "rgb(240, 248, 255)")
def test_datalayers_in_query_string(live_server, datalayer, map, page):
with_old_id = DataLayerFactory(old_id=134, map=map, name="with old id")
set_options(with_old_id, name="with old id")
visible = page.locator(".leaflet-control-browse li:not(.off) span")
hidden = page.locator(".leaflet-control-browse li.off span")
page.goto(f"{live_server.url}{map.get_absolute_url()}")
expect(visible).to_have_count(2)
expect(hidden).to_have_count(0)
page.goto(f"{live_server.url}{map.get_absolute_url()}?datalayers={datalayer.pk}")
expect(visible).to_have_count(1)
expect(visible).to_have_text(datalayer.name)
expect(hidden).to_have_count(1)
expect(hidden).to_have_text(with_old_id.name)
page.goto(
f"{live_server.url}{map.get_absolute_url()}?datalayers={with_old_id.old_id}"
)
expect(visible).to_have_count(1)
expect(visible).to_have_text(with_old_id.name)
expect(hidden).to_have_count(1)
expect(hidden).to_have_text(datalayer.name)