From 6264782a3bbd012e7c2e76361de1abda3d72c640 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Mon, 2 Dec 2024 19:27:06 +0100 Subject: [PATCH] feat: display importers in a dialog instead of direclty in the form The goal is to keep the form smaller, specifically to keep the submit button visible as much as possible. --- umap/static/umap/base.css | 3 ++ umap/static/umap/css/form.css | 3 ++ umap/static/umap/css/icon.css | 3 ++ umap/static/umap/js/modules/importer.js | 48 +++++++++++++++---------- 4 files changed, 38 insertions(+), 19 deletions(-) diff --git a/umap/static/umap/base.css b/umap/static/umap/base.css index e8321da75..a9f3929b5 100644 --- a/umap/static/umap/base.css +++ b/umap/static/umap/base.css @@ -157,6 +157,9 @@ dt { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); } +.grid-container.by4 { + grid-template-columns: repeat(4, minmax(0, 1fr)); +} .grid-container > * { text-align: center; } diff --git a/umap/static/umap/css/form.css b/umap/static/umap/css/form.css index 912c27978..e2f536eef 100644 --- a/umap/static/umap/css/form.css +++ b/umap/static/umap/css/form.css @@ -602,3 +602,6 @@ input[type=hidden].blur + [type="button"] { input.highlightable:not(:placeholder-shown) { border: 1px solid var(--color-brightCyan); } +.umap-upload [type=url] { + margin-bottom: 0; +} diff --git a/umap/static/umap/css/icon.css b/umap/static/umap/css/icon.css index 43042a540..96bd85e91 100644 --- a/umap/static/umap/css/icon.css +++ b/umap/static/umap/css/icon.css @@ -110,6 +110,9 @@ html[dir="rtl"] .icon { .icon-list { background-position: var(--tile) calc(var(--tile) * 4); } +.icon-magic { + background-position: calc(var(--tile) * 7) 0; +} .icon-marker { background-position: calc(var(--tile) * 3) calc(var(--tile) * 5); } diff --git a/umap/static/umap/js/modules/importer.js b/umap/static/umap/js/modules/importer.js index 9ea95233f..43560e3d7 100644 --- a/umap/static/umap/js/modules/importer.js +++ b/umap/static/umap/js/modules/importer.js @@ -11,13 +11,9 @@ const TEMPLATE = `
${translate('Choose data')} - - + +
${translate( @@ -49,6 +45,14 @@ const TEMPLATE = ` ` +const GRID_TEMPLATE = ` +
+

${translate('Import helpers')}

+

${translate('Import helpers will fill the URL field for you.')}

+
    +
    +` + export default class Importer extends Utils.WithTemplate { constructor(umap) { super() @@ -56,7 +60,7 @@ export default class Importer extends Utils.WithTemplate { this.TYPES = ['geojson', 'csv', 'gpx', 'kml', 'osm', 'georss', 'umap'] this.IMPORTERS = [] this.loadImporters() - this.dialog = new Dialog() + this.dialog = new Dialog({ className: 'importers dark' }) } loadImporters() { @@ -149,20 +153,26 @@ export default class Importer extends Utils.WithTemplate { ) } + showImporters() { + if (!this.IMPORTERS.length) return + const [element, { grid }] = Utils.loadTemplateWithRefs(GRID_TEMPLATE) + for (const plugin of this.IMPORTERS.sort((a, b) => (a.id > b.id ? 1 : -1))) { + const button = Utils.loadTemplate( + `
  • ` + ) + button.addEventListener('click', () => plugin.open(this)) + grid.appendChild(button) + } + this.dialog.open({ template: element, cancel: false, accept: false }) + } + build() { - this.container = DomUtil.create('div', 'umap-upload') - this.container.innerHTML = TEMPLATE + this.container = this.loadTemplate(TEMPLATE) if (this.IMPORTERS.length) { - const parent = this.container.querySelector('.importers ul') - for (const plugin of this.IMPORTERS.sort((a, b) => (a.id > b.id ? 1 : -1))) { - L.DomUtil.createButton( - plugin.id, - DomUtil.element({ tagName: 'li', parent }), - plugin.name, - () => plugin.open(this) - ) - } - this.qs('.importers').toggleAttribute('hidden', false) + // TODO use this.elements instead of this.qs + const button = this.qs('[data-ref=importersButton]') + button.addEventListener('click', () => this.showImporters()) + button.toggleAttribute('hidden', false) } for (const type of this.TYPES) { DomUtil.element({