From c9b4b96c0107f5bdb5d12ca7a6a45b8b5064aef4 Mon Sep 17 00:00:00 2001 From: David Larlet Date: Tue, 19 Dec 2023 14:22:06 -0500 Subject: [PATCH 01/10] =?UTF-8?q?Preview=20map=20only=20on=20click=20in=20?= =?UTF-8?q?user=E2=80=99s=20dashboard?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs #1459 --- umap/models.py | 35 ++++++++++++++++++++++++ umap/templates/umap/map_table.html | 44 ++++++++++++++++++++++++++++-- umap/templatetags/umap_tags.py | 28 +------------------ 3 files changed, 77 insertions(+), 30 deletions(-) diff --git a/umap/models.py b/umap/models.py index 71f68144..7bf8494f 100644 --- a/umap/models.py +++ b/umap/models.py @@ -1,3 +1,4 @@ +import json import os import time @@ -193,6 +194,40 @@ class Map(NamedModel): objects = models.Manager() public = PublicManager() + @property + def unique_id(self): + return f"map_{self.pk}" + + @property + def preview_settings(self): + from .views import _urls_for_js + + layers = self.datalayer_set.all() + datalayer_data = [c.metadata() for c in layers] + map_settings = self.settings + if "properties" not in map_settings: + map_settings["properties"] = {} + map_settings["properties"].update( + { + "tilelayers": [TileLayer.get_default().json], + "datalayers": datalayer_data, + "urls": _urls_for_js(), + "STATIC_URL": settings.STATIC_URL, + "editMode": "disabled", + "hash": False, + "attributionControl": False, + "scrollWheelZoom": False, + "umapAttributionControl": False, + "noControl": True, + "umap_id": self.pk, + "onLoadPanel": "none", + "captionBar": False, + "default_iconUrl": "%sumap/img/marker.png" % settings.STATIC_URL, + "slideshow": {}, + } + ) + return map_settings + def get_absolute_url(self): return reverse("map", kwargs={"slug": self.slug or "map", "map_id": self.pk}) diff --git a/umap/templates/umap/map_table.html b/umap/templates/umap/map_table.html index e4df76b7..d5721d15 100644 --- a/umap/templates/umap/map_table.html +++ b/umap/templates/umap/map_table.html @@ -1,9 +1,8 @@ -{% load umap_tags umap_tags i18n %} +{% load umap_tags i18n %} {% if not is_ajax %} - @@ -14,10 +13,19 @@ {% endif %} {% for map_inst in maps %} + {{ map_inst.preview_settings|json_script:map_inst.unique_id }} - @@ -39,3 +47,33 @@ class="button more_button neutral">{% trans "More" %} {% endif %} + + + + diff --git a/umap/templatetags/umap_tags.py b/umap/templatetags/umap_tags.py index 349e426e..70728ffa 100644 --- a/umap/templatetags/umap_tags.py +++ b/umap/templatetags/umap_tags.py @@ -4,9 +4,6 @@ from copy import copy from django import template from django.conf import settings -from ..models import DataLayer, TileLayer -from ..views import _urls_for_js - register = template.Library() @@ -22,30 +19,7 @@ def umap_js(locale=None): @register.inclusion_tag("umap/map_fragment.html") def map_fragment(map_instance, **kwargs): - layers = DataLayer.objects.filter(map=map_instance) - datalayer_data = [c.metadata() for c in layers] - map_settings = map_instance.settings - if "properties" not in map_settings: - map_settings["properties"] = {} - map_settings["properties"].update( - { - "tilelayers": [TileLayer.get_default().json], - "datalayers": datalayer_data, - "urls": _urls_for_js(), - "STATIC_URL": settings.STATIC_URL, - "editMode": "disabled", - "hash": False, - "attributionControl": False, - "scrollWheelZoom": False, - "umapAttributionControl": False, - "noControl": True, - "umap_id": map_instance.pk, - "onLoadPanel": "none", - "captionBar": False, - "default_iconUrl": "%sumap/img/marker.png" % settings.STATIC_URL, - "slideshow": {}, - } - ) + map_settings = map_instance.preview_settings map_settings["properties"].update(kwargs) prefix = kwargs.pop("prefix", None) or "map" page = kwargs.pop("page", None) or "" From 7ff543e1d581009869ac642e49487abbd9e64f96 Mon Sep 17 00:00:00 2001 From: David Larlet Date: Tue, 19 Dec 2023 20:50:30 -0500 Subject: [PATCH 02/10] Create the unique_id in the template (vs. model) --- umap/models.py | 4 --- umap/templates/umap/map_table.html | 52 ++++++++++++++++-------------- umap/templatetags/umap_tags.py | 6 ++++ 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/umap/models.py b/umap/models.py index 7bf8494f..e3e11e1c 100644 --- a/umap/models.py +++ b/umap/models.py @@ -194,10 +194,6 @@ class Map(NamedModel): objects = models.Manager() public = PublicManager() - @property - def unique_id(self): - return f"map_{self.pk}" - @property def preview_settings(self): from .views import _urls_for_js diff --git a/umap/templates/umap/map_table.html b/umap/templates/umap/map_table.html index d5721d15..6da94810 100644 --- a/umap/templates/umap/map_table.html +++ b/umap/templates/umap/map_table.html @@ -13,31 +13,33 @@ {% endif %} {% for map_inst in maps %} - {{ map_inst.preview_settings|json_script:map_inst.unique_id }} - - - - - - - + {% with unique_id="map_"|addstr:map_inst.pk %} + {{ map_inst.preview_settings|json_script:unique_id }} + + + + + + + + {% endwith %} {% endfor %}
{% blocktrans %}Map{% endblocktrans %} {% blocktrans %}Name{% endblocktrans %} {% blocktrans %}Who can see / edit{% endblocktrans %} {% blocktrans %}Last save{% endblocktrans %}
{% map_fragment map_inst prefix=prefix page=request.GET.p %} {{ map_inst.name }} + + +
+
+

+ +

+
+
{{ map_inst.get_share_status_display }} / {{ map_inst.get_edit_status_display }} {{ map_inst.modified_at }}
- {{ map_inst.name }} - - -
-
-

- -

-
-
-
{{ map_inst.get_share_status_display }} / {{ map_inst.get_edit_status_display }}{{ map_inst.modified_at }} - {{ map_inst.owner }} - - {% translate "Share" %} | - {% translate "Edit" %} | - {% translate "Download" %} -
+ {{ map_inst.name }} + + +
+
+

+ +

+
+
+
{{ map_inst.get_share_status_display }} / {{ map_inst.get_edit_status_display }}{{ map_inst.modified_at }} + {{ map_inst.owner }} + + {% translate "Share" %} | + {% translate "Edit" %} | + {% translate "Download" %} +
diff --git a/umap/templatetags/umap_tags.py b/umap/templatetags/umap_tags.py index 70728ffa..2349c579 100644 --- a/umap/templatetags/umap_tags.py +++ b/umap/templatetags/umap_tags.py @@ -60,3 +60,9 @@ def ipdb(what): ipdb.set_trace() return "" + + +@register.filter +def addstr(arg1, arg2): + # Necessity: https://stackoverflow.com/a/23783666 + return str(arg1) + str(arg2) From 8d1181562502acc4c79d893bbc521a917d669afa Mon Sep 17 00:00:00 2001 From: David Larlet Date: Tue, 19 Dec 2023 20:55:19 -0500 Subject: [PATCH 03/10] Move _urls_for_js to utils.py (circular imports) --- umap/models.py | 4 +--- umap/utils.py | 17 +++++++++++++++++ umap/views.py | 16 ---------------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/umap/models.py b/umap/models.py index e3e11e1c..c74e7c0e 100644 --- a/umap/models.py +++ b/umap/models.py @@ -1,4 +1,3 @@ -import json import os import time @@ -12,6 +11,7 @@ from django.urls import reverse from django.utils.translation import gettext_lazy as _ from .managers import PublicManager +from .utils import _urls_for_js # Did not find a clean way to do this in Django @@ -196,8 +196,6 @@ class Map(NamedModel): @property def preview_settings(self): - from .views import _urls_for_js - layers = self.datalayer_set.all() datalayer_data = [c.metadata() for c in layers] map_settings = self.settings diff --git a/umap/utils.py b/umap/utils.py index d7dfa6fb..2a51fe4e 100644 --- a/umap/utils.py +++ b/umap/utils.py @@ -1,9 +1,26 @@ import gzip import os +from django.conf import settings from django.urls import URLPattern, URLResolver, get_resolver +def _urls_for_js(urls=None): + """ + Return templated URLs prepared for javascript. + """ + if urls is None: + # prevent circular import + from .urls import i18n_urls, urlpatterns + + urls = [ + url.name for url in urlpatterns + i18n_urls if getattr(url, "name", None) + ] + urls = dict(zip(urls, [get_uri_template(url) for url in urls])) + urls.update(getattr(settings, "UMAP_EXTRA_URLS", {})) + return urls + + def get_uri_template(urlname, args=None, prefix=""): """ Utility function to return an URI Template from a named URL in django diff --git a/umap/views.py b/umap/views.py index d20b924a..08631cb0 100644 --- a/umap/views.py +++ b/umap/views.py @@ -390,22 +390,6 @@ ajax_proxy = AjaxProxy.as_view() # ############## # -def _urls_for_js(urls=None): - """ - Return templated URLs prepared for javascript. - """ - if urls is None: - # prevent circular import - from .urls import i18n_urls, urlpatterns - - urls = [ - url.name for url in urlpatterns + i18n_urls if getattr(url, "name", None) - ] - urls = dict(zip(urls, [get_uri_template(url) for url in urls])) - urls.update(getattr(settings, "UMAP_EXTRA_URLS", {})) - return urls - - def simple_json_response(**kwargs): return HttpResponse(json.dumps(kwargs), content_type="application/json") From ded244c9ff024c8c65620c549781b855ce6d34d7 Mon Sep 17 00:00:00 2001 From: David Larlet Date: Wed, 20 Dec 2023 22:02:00 -0500 Subject: [PATCH 04/10] Put CSS and JS blocks to their dedicated places --- umap/static/umap/content.css | 19 ++++++++++++++-- umap/templates/umap/map_table.html | 30 ------------------------- umap/templates/umap/user_dashboard.html | 16 +++++++++++++ 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/umap/static/umap/content.css b/umap/static/umap/content.css index 909501c1..dfd3848c 100644 --- a/umap/static/umap/content.css +++ b/umap/static/umap/content.css @@ -296,9 +296,9 @@ table.maps { width: 100%; } table.maps .map_fragment { - height: 100px; + display: block; + height: 80vh; width: 100%; - min-width: 200px; } table.maps tbody tr:nth-child(odd) { background-color: #f4f4f4; @@ -310,6 +310,21 @@ table.maps thead tr { line-height: 2em; } +/* **************************** */ +/* Dialog */ +/* **************************** */ +dialog { + width: 90vw; + height: 90vh; +} +dialog::backdrop { + background: #fff5; + backdrop-filter: blur(4px); +} +.close-dialog { + text-align: center; +} + /* ************************************************* */ /* ********************* MOBILE ******************** */ diff --git a/umap/templates/umap/map_table.html b/umap/templates/umap/map_table.html index 6da94810..5ad884a0 100644 --- a/umap/templates/umap/map_table.html +++ b/umap/templates/umap/map_table.html @@ -49,33 +49,3 @@ class="button more_button neutral">{% trans "More" %} {% endif %} - - - - diff --git a/umap/templates/umap/user_dashboard.html b/umap/templates/umap/user_dashboard.html index 8cbc2710..3c4f897b 100644 --- a/umap/templates/umap/user_dashboard.html +++ b/umap/templates/umap/user_dashboard.html @@ -23,3 +23,19 @@ {% endblock maincontent %} + +{% block bottom_js %} + {{ block.super }} + +{% endblock bottom_js %} From c3cb813c230443ab940952048793810389be02bd Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Fri, 22 Dec 2023 17:16:06 +0100 Subject: [PATCH 05/10] Allow to reopen a dialog in dashboard previews --- umap/templates/umap/content.html | 2 +- umap/templates/umap/user_dashboard.html | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/umap/templates/umap/content.html b/umap/templates/umap/content.html index 7ae6c00c..f3315db2 100644 --- a/umap/templates/umap/content.html +++ b/umap/templates/umap/content.html @@ -67,7 +67,7 @@ const container = this.parentNode container.innerHTML = data Array.prototype.forEach.call( - container.querySelectorAll('script'), + container.querySelectorAll('script:not([type="application/json"])'), function (item) { eval(item.firstChild.textContent) } diff --git a/umap/templates/umap/user_dashboard.html b/umap/templates/umap/user_dashboard.html index 3c4f897b..cb3d540a 100644 --- a/umap/templates/umap/user_dashboard.html +++ b/umap/templates/umap/user_dashboard.html @@ -28,12 +28,18 @@ {{ block.super }}