Allow the ?download option in URL

This commit is contained in:
David Larlet 2023-11-14 13:26:52 -05:00
parent 3a0bcd76da
commit 97fa8c2754
No known key found for this signature in database
GPG key ID: 3E2953A359E7E7BD
2 changed files with 10 additions and 10 deletions

View file

@ -272,7 +272,10 @@ L.U.Map.include({
url.searchParams.delete('edit') url.searchParams.delete('edit')
history.pushState({}, '', url) history.pushState({}, '', url)
} }
if (L.Util.queryString('download')) this.download() if (L.Util.queryString('download'))
window.location = L.Util.template(this.options.urls.map_download, {
map_id: this.options.umap_id,
})
}) })
window.onbeforeunload = () => this.isDirty || null window.onbeforeunload = () => this.isDirty || null
@ -396,7 +399,6 @@ L.U.Map.include({
}, },
loadDatalayers: function (force) { loadDatalayers: function (force) {
force = force || L.Util.queryString('download') // In case we are in download mode, let's go strait to loading all data
const total = this.datalayers_index.length const total = this.datalayers_index.length
// toload => datalayer metadata remaining to load (synchronous) // toload => datalayer metadata remaining to load (synchronous)
// dataToload => datalayer data remaining to load (asynchronous) // dataToload => datalayer data remaining to load (asynchronous)
@ -824,14 +826,8 @@ L.U.Map.include({
}) })
}, },
fullDownload: function () {
// Make sure all data is loaded before downloading
this.once('dataloaded', () => this.download())
this.loadDatalayers(true) // Force load
},
format: function (mode) { format: function (mode) {
const type = this.EXPORT_TYPES[mode || 'TODISCUSS'] const type = this.EXPORT_TYPES[mode]
const content = type.formatter(this) const content = type.formatter(this)
let name = this.options.name || 'data' let name = this.options.name || 'data'
name = name.replace(/[^a-z0-9]/gi, '_').toLowerCase() name = name.replace(/[^a-z0-9]/gi, '_').toLowerCase()

View file

@ -623,7 +623,11 @@ class MapDownload(DetailView):
layer["_umap_options"] = datalayer.settings layer["_umap_options"] = datalayer.settings
datalayers.append(layer) datalayers.append(layer)
geojson["layers"] = datalayers geojson["layers"] = datalayers
return simple_json_response(**geojson) response = simple_json_response(**geojson)
response[
"Content-Disposition"
] = f'attachment; filename="umap_backup_{self.object.slug}.umap"'
return response
class MapViewGeoJSON(MapView): class MapViewGeoJSON(MapView):