From 71bb1dc00652d06123d47613040c859a9f745c15 Mon Sep 17 00:00:00 2001 From: Samriti Sadhu Date: Tue, 7 Jan 2025 10:17:45 +0000 Subject: [PATCH 01/13] TESTING: API time without geometry --- application/templates/entity.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/templates/entity.html b/application/templates/entity.html index 9a1e61a0..4d9efa69 100644 --- a/application/templates/entity.html +++ b/application/templates/entity.html @@ -71,7 +71,7 @@

{{ row_name }}

{% for field in row.keys() %} - {% if field != 'entity' %} + {% if field != 'entity' and field != 'geometry' %} {%- if field not in ["geometry","point","organisation-entity","json"] or row[field] is not none %} @@ -96,7 +96,7 @@

{{ row_name }}

{% endcall %} {% set jsonHTML %} -
{{row|digital_land_to_json}}
+
{% endset %} {% set geojsonHTML %}
Loading...
From 9cc146ee9d214d13b5c08b7dff87870b7414b25c Mon Sep 17 00:00:00 2001 From: Samriti Sadhu Date: Tue, 7 Jan 2025 15:22:00 +0000 Subject: [PATCH 02/13] Adding load more button in Geometry --- application/core/filters.py | 6 +++- application/templates/entity.html | 60 +++++++++++++++++++++++-------- 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/application/core/filters.py b/application/core/filters.py index 6a511199..c6022167 100644 --- a/application/core/filters.py +++ b/application/core/filters.py @@ -166,7 +166,11 @@ def get_entity_name(entity): def digital_land_to_json(dict): - return json.dumps(dict, default=str, indent=4, cls=NoneToEmptyStringEncoder) + filtered_dict = {k: v for k, v in dict.items() if k != "geometry"} + # dict["geometry"] = dict["geometry"][:1000] + return json.dumps( + filtered_dict, default=str, indent=4, cls=NoneToEmptyStringEncoder + ) def uri_encode(uri_template, kwarg_list): diff --git a/application/templates/entity.html b/application/templates/entity.html index 4d9efa69..12a77aec 100644 --- a/application/templates/entity.html +++ b/application/templates/entity.html @@ -8,6 +8,18 @@ {%- from "components/entity-field/macro.jinja" import entityField %} {%- from "components/back-button/macro.jinja" import dlBackButton %} +{% if row['geometry'] %} + {% set truncated_geometry = row['geometry'][:10000] %} + {% set full_geometry = row['geometry'] %} +{% else %} + {% set truncated_geometry = "" %} + {% set full_geometry = "" %} +{% endif %} + + + + + {% if row['name'] %} {%- set row_name = row['name'] %} {%- elif row['reference'] %} @@ -71,19 +83,30 @@

{{ row_name }}

{% for field in row.keys() %} - {% if field != 'entity' and field != 'geometry' %} - {%- if field not in ["geometry","point","organisation-entity","json"] or row[field] is not none %} - - - {{ entityField(field,fields,dataset_fields) }} - - - {{ entityValue(field,row[field],fields,dataset_fields,organisation_entity,linked_entities)}} - - {% if field is not in['dataset','organisation-entity','start-date','end-date','typology'] %} - - Facts - + {% if field != 'entity'%} + {%- if field not in ["geometry","point","organisation-entity","json"] or row[field] is not none %} + + + {{ entityField(field, fields, dataset_fields) }} + + + {% if field == 'geometry' %} + + {% if row[field] is not none %} + {{ row[field][:10000] }}{% if row[field]|length > 10000 %}... Load More{% endif %} + {% endif %} + + + {% else %} + {{ entityValue(field, row[field], fields, dataset_fields, organisation_entity, linked_entities) }} + {% endif %} + + {% if field not in ['dataset', 'organisation-entity', 'start-date', 'end-date', 'typology'] %} + + Facts + {% else %} no fact link {% endif %} @@ -92,11 +115,18 @@

{{ row_name }}

{% endif %} {% endfor %} + + {% endcall %} {% set jsonHTML %} -
+
{{ row | digital_land_to_json | safe }}
{% endset %} {% set geojsonHTML %}
Loading...
@@ -340,6 +370,8 @@

{{ type|capitalize }}

{%- block pageScripts %} + + {%- endblock %} From 8d16574b6d3888f10dc97d0cff9eae8cc2c3865b Mon Sep 17 00:00:00 2001 From: Samriti Sadhu Date: Tue, 14 Jan 2025 09:18:54 +0000 Subject: [PATCH 09/13] small fixes --- application/templates/entity.html | 2 -- 1 file changed, 2 deletions(-) diff --git a/application/templates/entity.html b/application/templates/entity.html index 784eb9a7..4249dfff 100644 --- a/application/templates/entity.html +++ b/application/templates/entity.html @@ -453,7 +453,6 @@

{{ type|capitalize }}

const url = URL.createObjectURL(blob); const a = document.createElement("a"); a.href = url; - a.download = "geometry.json"; // Optional: specify the file name document.body.appendChild(a); a.click(); document.body.removeChild(a); @@ -462,7 +461,6 @@

{{ type|capitalize }}

URL.revokeObjectURL(url); } catch (error) { console.error("Error during download:", error); - alert("An error occurred while downloading the file."); } finally { // Restore button and hide spinner downloadButton.disabled = false; From d0f12712825aa4b5ce7c2190b53e09f7a2cac484 Mon Sep 17 00:00:00 2001 From: Samriti Sadhu Date: Tue, 14 Jan 2025 11:19:08 +0000 Subject: [PATCH 10/13] change message --- application/templates/entity.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/templates/entity.html b/application/templates/entity.html index 4249dfff..a860a957 100644 --- a/application/templates/entity.html +++ b/application/templates/entity.html @@ -406,7 +406,7 @@

{{ type|capitalize }}

}) .catch(error => { console.error('Error loading GeoJSON:', error); - geojsonContentElement.innerHTML = 'Error loading GeoJSON content'; + geojsonContentElement.innerHTML = 'Too large to display. Download GeoJSON instead. '; // Create and append the download button const downloadButton = document.createElement('a'); downloadButton.href = '{{ geometry_url }}'; From 73f292860c66e1da4012956e712ae33e28859363 Mon Sep 17 00:00:00 2001 From: Samriti Sadhu Date: Thu, 16 Jan 2025 15:04:23 +0000 Subject: [PATCH 11/13] Adding green button and inset --- application/core/filters.py | 2 +- application/templates/entity.html | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/application/core/filters.py b/application/core/filters.py index e6075157..b0dd1eab 100644 --- a/application/core/filters.py +++ b/application/core/filters.py @@ -173,7 +173,7 @@ def digital_land_to_json(dict): if "geometry" in filtered_dict: filtered_dict[ "geometry" - ] = "Too large to display. Download JSON for full geometry." + ] = "Too large to display. Download JSON for full geometry." # dict["geometry"] = dict["geometry"][:1000] return json.dumps( filtered_dict, default=str, indent=4, cls=NoneToEmptyStringEncoder diff --git a/application/templates/entity.html b/application/templates/entity.html index a860a957..c5807465 100644 --- a/application/templates/entity.html +++ b/application/templates/entity.html @@ -131,12 +131,15 @@

{{ row_name }}

} %} {% set jsonHTML %} {% if is_truncated %} +
+ The geometry is too large to be included in the JSON below. Download JSON for the full geometry. +
- Download JSON + class="govuk-button" + style="margin-bottom: 10px; margin-top: -10px;" + download> + Download JSON @@ -406,12 +409,13 @@

{{ type|capitalize }}

}) .catch(error => { console.error('Error loading GeoJSON:', error); - geojsonContentElement.innerHTML = 'Too large to display. Download GeoJSON instead. '; + geojsonContentElement.innerHTML = 'Too large to display. Download GeoJSON instead.{{ type|capitalize }} }); document.getElementById('download-json-button').addEventListener('click', async function (event) { + event.preventDefault(); const downloadButton = document.getElementById("download-json-button"); //const downloadText = document.getElementById("download-text"); const spinner = document.getElementById("spinner"); @@ -448,12 +453,13 @@

{{ type|capitalize }}

throw new Error("Failed to fetch the file"); } const blob = await response.blob(); - // Create a Blob URL and trigger the download const url = URL.createObjectURL(blob); const a = document.createElement("a"); a.href = url; + a.download = "{{ row['entity'] }}.json"; document.body.appendChild(a); + a.click(); document.body.removeChild(a); @@ -465,7 +471,7 @@

{{ type|capitalize }}

// Restore button and hide spinner downloadButton.disabled = false; spinner.style.display = "none"; - downloadText.style.display = "inline"; + //downloadText.style.display = "inline"; } }); From d7ad4f3741349f879deb0a93ac5a148f317310e3 Mon Sep 17 00:00:00 2001 From: Samriti Sadhu Date: Thu, 16 Jan 2025 15:13:04 +0000 Subject: [PATCH 12/13] move artifact to v4 --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index dc7691de..09804fe7 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -81,7 +81,7 @@ jobs: echo "## Accessibility Tests" >> $GITHUB_STEP_SUMMARY cat accessibility-tests.md >> $GITHUB_STEP_SUMMARY - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 if: always() with: name: playwright-report From 683097fcfdb35ab52257e6af5e52354f44ce8417 Mon Sep 17 00:00:00 2001 From: Samriti Sadhu Date: Thu, 16 Jan 2025 15:52:57 +0000 Subject: [PATCH 13/13] Adding spinner to download geojson button --- .github/workflows/security-scan.yml | 2 +- application/templates/entity.html | 54 +++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/.github/workflows/security-scan.yml b/.github/workflows/security-scan.yml index 8254d25e..d4f34343 100644 --- a/.github/workflows/security-scan.yml +++ b/.github/workflows/security-scan.yml @@ -38,7 +38,7 @@ jobs: cat zap-working-dir/zap-report.md >> $GITHUB_STEP_SUMMARY - name: upload log - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 if: always() with: name: zap.log diff --git a/application/templates/entity.html b/application/templates/entity.html index c5807465..b3e9ff1d 100644 --- a/application/templates/entity.html +++ b/application/templates/entity.html @@ -417,8 +417,62 @@

{{ type|capitalize }}

downloadButton.style.marginTop = '10px'; downloadButton.style.marginBottom = '10px'; downloadButton.textContent = 'Download GeoJSON'; + downloadButton.setAttribute('id','download-geojson-button') downloadButton.setAttribute('download', '{{ row["entity"] }}.geojson'); geojsonContentElement.parentElement.appendChild(downloadButton); + + const spinnerDiv = document.createElement('div'); + spinnerDiv.id = 'spinner1'; + spinnerDiv.style.display = 'none'; // Hide the spinner initially + + // Create the spinner loader + const spinnerLoader = document.createElement('div'); + spinnerLoader.className = 'dl-map__spinning-loader'; + spinnerLoader.style.width = '10px'; + spinnerLoader.style.height = '10px'; + spinnerLoader.style.marginTop = '-25px'; + + // Append the spinner loader inside the spinner div + spinnerDiv.appendChild(spinnerLoader); + + // Append the spinner div to the geojsonContentElement + downloadButton.appendChild(spinnerDiv); + + downloadButton.addEventListener('click', async function(event) { + console.info("hello") + event.preventDefault(); + + // Show the spinner and disable the download button + spinnerDiv.style.display = 'block'; + downloadButton.disabled = true; + + try { + // Simulate downloading the GeoJSON (you can replace this with the actual download logic) + const response = await fetch('{{ geometry_url }}'); + if (!response.ok) { + throw new Error('Failed to fetch the file'); + } + const blob = await response.blob(); + + // Create a Blob URL and trigger the download + const url = URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = url; + a.download = '{{ row["entity"] }}.geojson'; // Set the file name + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + + // Clean up the Blob URL + URL.revokeObjectURL(url); + } catch (error) { + console.error('Error during download:', error); + } finally { + // Hide the spinner and enable the download button after download + spinnerDiv.style.display = 'none'; + downloadButton.disabled = false; + } + }); }); } }