diff --git a/umap/static/umap/content.css b/umap/static/umap/content.css index 5e468f8c..3f51571b 100644 --- a/umap/static/umap/content.css +++ b/umap/static/umap/content.css @@ -282,6 +282,29 @@ ul.umap-autocomplete { } +/* **************************** */ +/* Dashboard */ +/* **************************** */ +table.maps { + width: 100%; +} +table.maps .map_fragment { + height: 100px; + width: 100%; + min-width: 200px; +} +table.maps tbody tr:nth-child(odd) { + background-color: #f4f4f4; +} +table.maps td { + text-align: center; +} +table.maps thead tr { + line-height: 2em; +} + + + /* **************************** */ /* Override Leaflet.Storage */ /* **************************** */ diff --git a/umap/static/umap/js/umap.controls.js b/umap/static/umap/js/umap.controls.js index 31abcea8..82f3863a 100644 --- a/umap/static/umap/js/umap.controls.js +++ b/umap/static/umap/js/umap.controls.js @@ -1019,6 +1019,39 @@ L.U.Map.include({ this.ui.openPanel({ data: { html: container }, actions: actions }) }, + EXPORT_TYPES: { + geojson: { + formatter: function (map) { + return JSON.stringify(map.toGeoJSON(), null, 2) + }, + ext: '.geojson', + filetype: 'application/json', + }, + gpx: { + formatter: function (map) { + return togpx(map.toGeoJSON()) + }, + ext: '.gpx', + filetype: 'application/xml', + }, + kml: { + formatter: function (map) { + return tokml(map.toGeoJSON()) + }, + ext: '.kml', + filetype: 'application/vnd.google-earth.kml+xml', + }, + umap: { + name: L._('Full map data'), + formatter: function (map) { + return map.serialize() + }, + ext: '.umap', + filetype: 'application/json', + selected: true, + }, + }, + renderShareBox: function () { const container = L.DomUtil.create('div', 'umap-share') const embedTitle = L.DomUtil.add('h4', '', container, L._('Embed the map')) @@ -1091,66 +1124,36 @@ L.U.Map.include({ else exportCaveat.style.display = 'inherit' } L.DomEvent.on(typeInput, 'change', toggleCaveat) - const types = { - geojson: { - formatter: function (map) { - return JSON.stringify(map.toGeoJSON(), null, 2) - }, - ext: '.geojson', - filetype: 'application/json', - }, - gpx: { - formatter: function (map) { - return togpx(map.toGeoJSON()) - }, - ext: '.gpx', - filetype: 'application/xml', - }, - kml: { - formatter: function (map) { - return tokml(map.toGeoJSON()) - }, - ext: '.kml', - filetype: 'application/vnd.google-earth.kml+xml', - }, - umap: { - name: L._('Full map data'), - formatter: function (map) { - return map.serialize() - }, - ext: '.umap', - filetype: 'application/json', - selected: true, - }, - } - for (const key in types) { - if (types.hasOwnProperty(key)) { + for (const key in this.EXPORT_TYPES) { + if (this.EXPORT_TYPES.hasOwnProperty(key)) { option = L.DomUtil.create('option', '', typeInput) option.value = key - option.textContent = types[key].name || key - if (types[key].selected) option.selected = true + option.textContent = this.EXPORT_TYPES[key].name || key + if (this.EXPORT_TYPES[key].selected) option.selected = true } } toggleCaveat() const download = L.DomUtil.create('a', 'button', container) download.textContent = L._('Download data') - L.DomEvent.on( - download, - 'click', - () => { - const type = types[typeInput.value] - const content = type.formatter(this) - let name = this.options.name || 'data' - name = name.replace(/[^a-z0-9]/gi, '_').toLowerCase() - download.download = name + type.ext - window.URL = window.URL || window.webkitURL - const blob = new Blob([content], { type: type.filetype }) - download.href = window.URL.createObjectURL(blob) - }, - this - ) + L.DomEvent.on(download, 'click', () => this.download(typeInput.value), this) this.ui.openPanel({ data: { html: container } }) }, + + download: function (mode) { + const type = this.EXPORT_TYPES[mode || 'umap'] + const content = type.formatter(this) + let name = this.options.name || 'data' + name = name.replace(/[^a-z0-9]/gi, '_').toLowerCase() + window.URL = window.URL || window.webkitURL + const blob = new Blob([content], { type: type.filetype }) + const el = document.createElement('a') + el.download = name + type.ext + el.href = window.URL.createObjectURL(blob) + el.style.display = 'none' + document.body.appendChild(el) + el.click() + document.body.removeChild(el) + }, }) L.U.TileLayerControl = L.Control.extend({ diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js index 7733e29d..5f8224c8 100644 --- a/umap/static/umap/js/umap.js +++ b/umap/static/umap/js/umap.js @@ -91,12 +91,8 @@ L.U.Map.include({ this.ui = new L.U.UI(this._container) this.xhr = new L.U.Xhr(this.ui) - this.xhr.on('dataloding', function (e) { - this.fire('dataloding', e) - }) - this.xhr.on('datalaod', function (e) { - this.fire('datalaod', e) - }) + this.xhr.on('dataloading', (e) => this.fire('dataloading', e)) + this.xhr.on('dataload', (e) => this.fire('dataload', e)) this.initLoader() this.name = this.options.name @@ -255,13 +251,16 @@ L.U.Map.include({ } this.initShortcuts() this.onceDatalayersLoaded(function () { - if (this.options.onLoadPanel === 'databrowser') this.openBrowser() + if (L.Util.queryString('share')) this.renderShareBox() + else if (this.options.onLoadPanel === 'databrowser') this.openBrowser() else if (this.options.onLoadPanel === 'caption') this.displayCaption() else if (this.options.onLoadPanel === 'datafilters') this.openFilter() }) this.onceDataLoaded(function () { const slug = L.Util.queryString('feature') if (slug && this.features_index[slug]) this.features_index[slug].view() + if (L.Util.queryString('edit')) this.enableEdit() + if (L.Util.queryString('download')) this.download() }) window.onbeforeunload = (e) => { diff --git a/umap/templates/umap/map_table.html b/umap/templates/umap/map_table.html new file mode 100644 index 00000000..965521db --- /dev/null +++ b/umap/templates/umap/map_table.html @@ -0,0 +1,41 @@ +{% load umap_tags umap_tags i18n %} +
{% blocktrans %}Map{% endblocktrans %} | +{% blocktrans %}Name{% endblocktrans %} | +{% blocktrans %}Status{% endblocktrans %} | +{% blocktrans %}Last save{% endblocktrans %} | +{% blocktrans %}Owner{% endblocktrans %} | +{% blocktrans %}Actions{% endblocktrans %} | +
---|---|---|---|---|---|
{% map_fragment map_inst prefix=prefix page=request.GET.p %} | ++ {{ map_inst.name }} + | +{{ map_inst.get_edit_status_display }} | +{{ map_inst.modified_at }} | ++ {{ map_inst.owner }} + | ++ {% translate "Share" %} + {% translate "Edit" %} + {% translate "Download" %} + | +