From f095978e481d49765325bf5002db69c2328802b3 Mon Sep 17 00:00:00 2001 From: Ariana Barzinpour Date: Thu, 17 Nov 2022 06:39:08 +0000 Subject: [PATCH 1/5] include dataset thumbnail as popup on map. also resolved console error and updated broken readme link --- README.md | 4 +- cubedash/templates/dataset.html | 108 ++++++++++++++++------------ cubedash/templates/layout/base.html | 26 +++---- 3 files changed, 78 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index 6196e9287..b24f951e1 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,8 @@ It will now be viewable on [http://localhost:8090](https://localhost:8090) These directions are for running from a local folder in development. But it will run from any typical Python WSGI server. -Firstly, install the Open Data Cube. Use of a [Data Cube conda environment](https://datacube-core.readthedocs.io/en/latest/ops/conda.html) -is recommended. +Firstly, install the Open Data Cube. Use of a [Data Cube conda environment](https://datacube-core.readthedocs.io/en/latest/installation/setup/common_install.html) +is recommended. You may need to also `conda install -c conda-forge postgis` Test that you can run `datacube system check`, and that it's connecting to the correct datacube instance. diff --git a/cubedash/templates/dataset.html b/cubedash/templates/dataset.html index 4e4cea26a..4de741421 100644 --- a/cubedash/templates/dataset.html +++ b/cubedash/templates/dataset.html @@ -3,6 +3,7 @@ {% block title %}{{ dataset | printable_dataset }}{% endblock %} {% set extent_geojson = dataset_footprint.__geo_interface__ %} +{% set thumbnail_url = [] %} {% block head %} {{ super() }} @@ -57,51 +58,18 @@

{{ dataset | printable_dataset }}

{% if dataset_region_code %} - Region - - {{- dataset_region_code -}} - - {% endif %} + Region + + {{- dataset_region_code -}} + + {% endif %} for {{ dataset | dataset_day_link(grouping_timezone) }}
- {% if source_datasets or derived_datasets %} -
- {% for classifier, s_dataset in source_datasets.items() %} -
- - - - {{ s_dataset | printable_dataset }} - - -
- {% endfor %} - {% if source_dataset_overflow %} - ... {{ source_dataset_overflow }} more - {% endif %} -
- - - {{ dataset | printable_dataset }} - - {% for d_dataset in derived_datasets %} - - {% endfor %} - {% if derived_dataset_overflow %} - ... {{ derived_dataset_overflow}} more - {% endif %} -
-
+ {% if extent_geojson %} +
{% endif %}
@@ -117,11 +85,48 @@

) }}

- {% if extent_geojson %} -
+ {% if source_datasets or derived_datasets %} +
+

+ Related Datasets + {{ hanchor('related-datasets') }} +

+ {% for classifier, s_dataset in source_datasets.items() %} +
+ + + + {{ s_dataset | printable_dataset }} + + +
+ {% endfor %} + {% if source_dataset_overflow %} + ... {{ source_dataset_overflow }} more + {% endif %} +
+ + + {{ dataset | printable_dataset }} + + {% for d_dataset in derived_datasets %} + + {% endfor %} + {% if derived_dataset_overflow %} + ... {{ derived_dataset_overflow}} more + {% endif %} +
+
{% endif %} -
+

Location{% if dataset.uris | length > 1 %}s{% endif %} {{ hanchor('locations') }} @@ -142,6 +147,11 @@

{{ offset }} + {% if 'thumbnail:nbart' == name %} + {# workaround for jinja preventin global varaibles from being updated inside + for loops and if/else statements #} + {% set _ = thumbnail_url.append(offset | resolve_remote_url(uri)) %} + {% endif %} @@ -166,7 +176,7 @@

-
+

Metadata Document {{ hanchor('metadata-doc') }} @@ -194,10 +204,9 @@

' © CartoDB' } ); - + const dataset_data = L.geoJson({{ extent_geojson | torapidjson }}, { - interactive: false, style: function (feature) { return { color: "#1d81a7", @@ -219,6 +228,13 @@

}); L.control.zoom({position: "bottomright"}).addTo(map); map.fitBounds(dataset_data.getBounds(), {animate: false, maxZoom: 5}); + const paths = '{{ (dataset|dataset_file_paths)|tojson }}'; + if (JSON.parse(paths)['thumbnail:nbart']) { + dataset_data.bindPopup( + ``, + { offset: L.point(0, -20)} + ).openPopup(); + } window.MAP = map; diff --git a/cubedash/templates/layout/base.html b/cubedash/templates/layout/base.html index 5c7c59099..a2138add6 100644 --- a/cubedash/templates/layout/base.html +++ b/cubedash/templates/layout/base.html @@ -226,19 +226,21 @@ ); var showHiddenProduct = document.getElementById("show-hidden-product"); - showHiddenProduct.addEventListener("click", function(event) { - if (showHiddenProduct.innerHTML === "Show hidden products") { - showHiddenProduct.innerHTML = "Show non-hidden products"; - } else { - showHiddenProduct.innerHTML = "Show hidden products"; - } - document.querySelectorAll(".datacube-product-name").forEach(function(el) { - el.classList.toggle("hide"); - }); - document.querySelectorAll(".configured-hide-product").forEach(function(el) { - el.classList.toggle("hide"); + if (showHiddenProduct) { + showHiddenProduct.addEventListener("click", function(event) { + if (showHiddenProduct.innerHTML === "Show hidden products") { + showHiddenProduct.innerHTML = "Show non-hidden products"; + } else { + showHiddenProduct.innerHTML = "Show hidden products"; + } + document.querySelectorAll(".datacube-product-name").forEach(function(el) { + el.classList.toggle("hide"); + }); + document.querySelectorAll(".configured-hide-product").forEach(function(el) { + el.classList.toggle("hide"); + }); }); - }); + } From fc878829e9cc06bd28f6b92086eaad1a480bf2f4 Mon Sep 17 00:00:00 2001 From: Ariana Barzinpour Date: Thu, 17 Nov 2022 06:45:51 +0000 Subject: [PATCH 2/5] switch to image overlay instead of popup --- cubedash/templates/dataset.html | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/cubedash/templates/dataset.html b/cubedash/templates/dataset.html index 4de741421..8eddf4748 100644 --- a/cubedash/templates/dataset.html +++ b/cubedash/templates/dataset.html @@ -204,7 +204,7 @@

' © CartoDB' } ); - + var coords = []; const dataset_data = L.geoJson({{ extent_geojson | torapidjson }}, { style: function (feature) { @@ -230,10 +230,7 @@

map.fitBounds(dataset_data.getBounds(), {animate: false, maxZoom: 5}); const paths = '{{ (dataset|dataset_file_paths)|tojson }}'; if (JSON.parse(paths)['thumbnail:nbart']) { - dataset_data.bindPopup( - ``, - { offset: L.point(0, -20)} - ).openPopup(); + L.imageOverlay("{{ thumbnail_url[0]|e }}", dataset_data.getBounds()).addTo(map); } window.MAP = map; From 20cc2b7211c3e5a2bec8847229a4a7e4fb53a43d Mon Sep 17 00:00:00 2001 From: Ariana Barzinpour Date: Fri, 18 Nov 2022 00:02:00 +0000 Subject: [PATCH 3/5] check for 'thumbnail' tag as well, make a little cleaner --- cubedash/templates/dataset.html | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cubedash/templates/dataset.html b/cubedash/templates/dataset.html index 8eddf4748..f0c394a52 100644 --- a/cubedash/templates/dataset.html +++ b/cubedash/templates/dataset.html @@ -144,13 +144,14 @@

- {{ offset }} - {% if 'thumbnail:nbart' == name %} - {# workaround for jinja preventin global varaibles from being updated inside + {% if 'thumbnail:nbart' == name or 'thumbnail' == name %} + {# workaround for jinja preventing global varaibles from being updated inside for loops and if/else statements #} - {% set _ = thumbnail_url.append(offset | resolve_remote_url(uri)) %} + {% set _ = thumbnail_url.append(offset_url) %} {% endif %} @@ -228,8 +229,8 @@

}); L.control.zoom({position: "bottomright"}).addTo(map); map.fitBounds(dataset_data.getBounds(), {animate: false, maxZoom: 5}); - const paths = '{{ (dataset|dataset_file_paths)|tojson }}'; - if (JSON.parse(paths)['thumbnail:nbart']) { + const has_thumbnail = '{{ thumbnail_url|length >= 1 }}'; + if (has_thumbnail === "True") { L.imageOverlay("{{ thumbnail_url[0]|e }}", dataset_data.getBounds()).addTo(map); } From a8e81656c5cb84c68cf6810522c58bd37505b36a Mon Sep 17 00:00:00 2001 From: Ariana Barzinpour Date: Fri, 18 Nov 2022 03:28:39 +0000 Subject: [PATCH 4/5] make thumbnail url a jinja filter --- cubedash/_filters.py | 11 +++++++++++ cubedash/templates/dataset.html | 15 ++++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/cubedash/_filters.py b/cubedash/_filters.py index f28c9b369..54c9c97cf 100644 --- a/cubedash/_filters.py +++ b/cubedash/_filters.py @@ -121,6 +121,17 @@ def _dataset_created(dataset: Dataset): def _dataset_file_paths(dataset: Dataset): return utils.get_dataset_file_offsets(dataset) +@bp.app_template_filter("dataset_thumbnail_url") +def _dataset_thumbnail_url(dataset: Dataset): + file_paths = _dataset_file_paths(dataset) + if "thumbnail:nbart" in file_paths: + offset = file_paths['thumbnail:nbart'] + elif "thumbnail" in file_paths: + offset = file_paths['thumbnail'] + else: + return "" + return _to_remote_url(offset, dataset.uris[0]) + @bp.app_template_filter("resolve_remote_url") def _to_remote_url(offset: str, base_uri: str = None): diff --git a/cubedash/templates/dataset.html b/cubedash/templates/dataset.html index f0c394a52..603b655be 100644 --- a/cubedash/templates/dataset.html +++ b/cubedash/templates/dataset.html @@ -3,7 +3,7 @@ {% block title %}{{ dataset | printable_dataset }}{% endblock %} {% set extent_geojson = dataset_footprint.__geo_interface__ %} -{% set thumbnail_url = [] %} +{% set thumbnail_url = dataset | dataset_thumbnail_url %} {% block head %} {{ super() }} @@ -144,15 +144,9 @@

- {% set offset_url = offset | resolve_remote_url(uri) %} - {{ offset }} - {% if 'thumbnail:nbart' == name or 'thumbnail' == name %} - {# workaround for jinja preventing global varaibles from being updated inside - for loops and if/else statements #} - {% set _ = thumbnail_url.append(offset_url) %} - {% endif %} @@ -229,9 +223,8 @@

}); L.control.zoom({position: "bottomright"}).addTo(map); map.fitBounds(dataset_data.getBounds(), {animate: false, maxZoom: 5}); - const has_thumbnail = '{{ thumbnail_url|length >= 1 }}'; - if (has_thumbnail === "True") { - L.imageOverlay("{{ thumbnail_url[0]|e }}", dataset_data.getBounds()).addTo(map); + if ("{{ thumbnail_url }}") { + L.imageOverlay("{{ thumbnail_url }}", dataset_data.getBounds()).addTo(map); } window.MAP = map; From 1850555196166929527b0b3099814ae512ac37ee Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 18 Nov 2022 03:29:19 +0000 Subject: [PATCH 5/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- cubedash/_filters.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cubedash/_filters.py b/cubedash/_filters.py index 54c9c97cf..913e0e8f2 100644 --- a/cubedash/_filters.py +++ b/cubedash/_filters.py @@ -121,13 +121,14 @@ def _dataset_created(dataset: Dataset): def _dataset_file_paths(dataset: Dataset): return utils.get_dataset_file_offsets(dataset) + @bp.app_template_filter("dataset_thumbnail_url") def _dataset_thumbnail_url(dataset: Dataset): file_paths = _dataset_file_paths(dataset) if "thumbnail:nbart" in file_paths: - offset = file_paths['thumbnail:nbart'] + offset = file_paths["thumbnail:nbart"] elif "thumbnail" in file_paths: - offset = file_paths['thumbnail'] + offset = file_paths["thumbnail"] else: return "" return _to_remote_url(offset, dataset.uris[0])