diff --git a/umap/models.py b/umap/models.py index 71f68144..c74e7c0e 100644 --- a/umap/models.py +++ b/umap/models.py @@ -11,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 @@ -193,6 +194,34 @@ class Map(NamedModel): objects = models.Manager() public = PublicManager() + @property + def preview_settings(self): + 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/static/umap/content.css b/umap/static/umap/content.css index 909501c1..ccdb250f 100644 --- a/umap/static/umap/content.css +++ b/umap/static/umap/content.css @@ -134,6 +134,9 @@ h2.section { padding-top: 28px; } h2.tabs a { + color: #666; +} +h2.tabs a:not(.selected) { font-weight: normal; color: #666; } @@ -296,9 +299,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; @@ -309,6 +312,42 @@ table.maps td { table.maps thead tr { line-height: 2em; } +table.maps .button { + margin-bottom: 2px; + padding:4px 6px; + height: 36px; + line-height: 23px; +} + +/* **************************** */ +/* Dialog */ +/* **************************** */ +dialog { + width: 90vw; + height: 90vh; +} +dialog::backdrop { + background: #fff5; + backdrop-filter: blur(4px); +} +.close-dialog { + text-align: center; + margin-bottom: 0; +} + +/* ********************************* */ +/* Pagination */ +/* ********************************* */ +.pagination { + display: flex; + flex-direction: row; + justify-content: space-around; + margin: 1rem; + border-top: 1px solid gray; +} +.pagination > * { + padding: 1rem; +} /* ************************************************* */ diff --git a/umap/static/umap/js/umap.ui.js b/umap/static/umap/js/umap.ui.js index 501ec3d2..053b4b53 100644 --- a/umap/static/umap/js/umap.ui.js +++ b/umap/static/umap/js/umap.ui.js @@ -64,8 +64,10 @@ L.U.UI = L.Evented.extend({ }, closePanel: function () { - L.DomUtil.removeClass(this.parent, 'umap-ui') - this.fire('panel:closed') + if (L.DomUtil.hasClass(this.parent, 'umap-ui')) { + L.DomUtil.removeClass(this.parent, 'umap-ui') + this.fire('panel:closed') + } }, alert: function (e) { diff --git a/umap/templates/auth/user_form.html b/umap/templates/auth/user_form.html index 67933eea..088b3be5 100644 --- a/umap/templates/auth/user_form.html +++ b/umap/templates/auth/user_form.html @@ -3,7 +3,7 @@ {% block maincontent %}

- {% trans "My Dashboard" %} | {% trans "My Profile" %} + {% trans "My Dashboard" %} | {% trans "My Profile" %}

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/map_list.html b/umap/templates/umap/map_list.html index b0c74325..473c7a42 100644 --- a/umap/templates/umap/map_list.html +++ b/umap/templates/umap/map_list.html @@ -1,4 +1,4 @@ -{% load umap_tags umap_tags i18n %} +{% load umap_tags i18n %} {% for map_inst in maps %}
diff --git a/umap/templates/umap/map_table.html b/umap/templates/umap/map_table.html index e4df76b7..8007598b 100644 --- a/umap/templates/umap/map_table.html +++ b/umap/templates/umap/map_table.html @@ -1,41 +1,73 @@ -{% load umap_tags umap_tags i18n %} +{% load umap_tags i18n %} - {% if not is_ajax %} - - - - - - - - - - - {% endif %} + + + + + + + + + + {% for map_inst in maps %} - - - - - - - - + {% 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 %}{% blocktrans %}Owner{% endblocktrans %}{% blocktrans %}Actions{% endblocktrans %}
{% blocktrans %}Name{% endblocktrans %}{% blocktrans %}Preview{% endblocktrans %}{% blocktrans %}Who can see / edit{% 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_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" %} +
-{% if maps.has_next %} - -{% endif %} + diff --git a/umap/templates/umap/user_dashboard.html b/umap/templates/umap/user_dashboard.html index 8cbc2710..6e5d4ac7 100644 --- a/umap/templates/umap/user_dashboard.html +++ b/umap/templates/umap/user_dashboard.html @@ -7,7 +7,7 @@ {% trans "Search my maps" as placeholder %}

- {% trans "My Dashboard" %} | {% trans "My profile" %} + {% trans "My Dashboard" %} | {% trans "My profile" %}

{% include "umap/search_bar.html" with action=request.get_full_path placeholder=placeholder %}
@@ -23,3 +23,25 @@
{% endblock maincontent %} + +{% block bottom_js %} + {{ block.super }} + +{% endblock bottom_js %} diff --git a/umap/templatetags/umap_tags.py b/umap/templatetags/umap_tags.py index 349e426e..2349c579 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 "" @@ -86,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) 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..1032bdf0 100644 --- a/umap/views.py +++ b/umap/views.py @@ -62,7 +62,7 @@ from .forms import ( UserProfileForm, ) from .models import DataLayer, Licence, Map, Pictogram, Star, TileLayer -from .utils import ConflictError, get_uri_template, gzip_file, is_ajax, merge_features +from .utils import ConflictError, _urls_for_js, gzip_file, is_ajax, merge_features User = get_user_model() @@ -270,7 +270,12 @@ class UserDashboard(PaginatorMixin, DetailView, SearchMixin): def get_context_data(self, **kwargs): kwargs.update( - {"maps": self.paginate(self.get_maps(), settings.UMAP_MAPS_PER_PAGE_OWNER)} + { + "q": self.request.GET.get("q"), + "maps": self.paginate( + self.get_maps(), settings.UMAP_MAPS_PER_PAGE_OWNER + ), + } ) return super().get_context_data(**kwargs) @@ -390,22 +395,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")