Skip to content

Commit 9cc146e

Browse files
committed
Adding load more button in Geometry
1 parent 71bb1dc commit 9cc146e

File tree

2 files changed

+51
-15
lines changed

2 files changed

+51
-15
lines changed

application/core/filters.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,11 @@ def get_entity_name(entity):
166166

167167

168168
def digital_land_to_json(dict):
169-
return json.dumps(dict, default=str, indent=4, cls=NoneToEmptyStringEncoder)
169+
filtered_dict = {k: v for k, v in dict.items() if k != "geometry"}
170+
# dict["geometry"] = dict["geometry"][:1000]
171+
return json.dumps(
172+
filtered_dict, default=str, indent=4, cls=NoneToEmptyStringEncoder
173+
)
170174

171175

172176
def uri_encode(uri_template, kwarg_list):

application/templates/entity.html

+46-14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@
88
{%- from "components/entity-field/macro.jinja" import entityField %}
99
{%- from "components/back-button/macro.jinja" import dlBackButton %}
1010

11+
{% if row['geometry'] %}
12+
{% set truncated_geometry = row['geometry'][:10000] %}
13+
{% set full_geometry = row['geometry'] %}
14+
{% else %}
15+
{% set truncated_geometry = "" %}
16+
{% set full_geometry = "" %}
17+
{% endif %}
18+
19+
20+
21+
22+
1123
{% if row['name'] %}
1224
{%- set row_name = row['name'] %}
1325
{%- elif row['reference'] %}
@@ -71,19 +83,30 @@ <h1 class="govuk-heading-xl">{{ row_name }}</h1>
7183
</thead>
7284
<tbody class="govuk-table__body">
7385
{% for field in row.keys() %}
74-
{% if field != 'entity' and field != 'geometry' %}
75-
{%- if field not in ["geometry","point","organisation-entity","json"] or row[field] is not none %}
76-
<tr class="govuk-table__row">
77-
<th scope="row" class="app-table__header app-table__header--row">
78-
{{ entityField(field,fields,dataset_fields) }}
79-
</th>
80-
<td class="govuk-table__cell app-table__cell">
81-
{{ entityValue(field,row[field],fields,dataset_fields,organisation_entity,linked_entities)}}
82-
</td>
83-
{% if field is not in['dataset','organisation-entity','start-date','end-date','typology'] %}
84-
<td class="govuk-table__cell govuk-!-font-size-14 govuk-!-text-align-right">
85-
<a href="/fact?dataset={{row['dataset']}}&entity={{row['entity']}}&field={{field}}" class="govuk-link">Facts</a>
86-
</td>
86+
{% if field != 'entity'%}
87+
{%- if field not in ["geometry","point","organisation-entity","json"] or row[field] is not none %}
88+
<tr class="govuk-table__row">
89+
<th scope="row" class="app-table__header app-table__header--row">
90+
{{ entityField(field, fields, dataset_fields) }}
91+
</th>
92+
<td class="govuk-table__cell app-table__cell">
93+
{% if field == 'geometry' %}
94+
<code class ="app-code-block" id="geometry-content">
95+
{% if row[field] is not none %}
96+
{{ row[field][:10000] }}{% if row[field]|length > 10000 %}... <a href="javascript:void(0);" onclick="expandGeometry()">Load More</a>{% endif %}
97+
{% endif %}
98+
</code>
99+
<code class ="app-code-block" id="geometry-full-content" style="display: none;">
100+
{{ row[field] }}
101+
</code>
102+
{% else %}
103+
{{ entityValue(field, row[field], fields, dataset_fields, organisation_entity, linked_entities) }}
104+
{% endif %}
105+
</td>
106+
{% if field not in ['dataset', 'organisation-entity', 'start-date', 'end-date', 'typology'] %}
107+
<td class="govuk-table__cell govuk-!-font-size-14 govuk-!-text-align-right">
108+
<a href="/fact?dataset={{ row['dataset'] }}&entity={{ row['entity'] }}&field={{ field }}" class="govuk-link">Facts</a>
109+
</td>
87110
{% else %}
88111
<td class="govuk-table__cell govuk-!-font-size-14 govuk-!-text-align-right"><span class='govuk-visually-hidden'>no fact link</span></td>
89112
{% endif %}
@@ -92,11 +115,18 @@ <h1 class="govuk-heading-xl">{{ row_name }}</h1>
92115
{% endif %}
93116
{% endfor %}
94117
</tbody>
118+
<script>
119+
function expandGeometry() {
120+
document.getElementById('geometry-content').style.display = 'none';
121+
document.getElementById('geometry-full-content').style.display = 'block';
122+
}
123+
</script>
124+
95125
</table>
96126
{% endcall %}
97127

98128
{% set jsonHTML %}
99-
<pre class="govuk-!-margin-0"><code class="language-json app-code-block app-code-block-overflow" tabindex="0"></code></pre>
129+
<pre class="govuk-!-margin-0"><code class="language-json app-code-block app-code-block-overflow" tabindex="0">{{ row | digital_land_to_json | safe }}</code></pre>
100130
{% endset %}
101131
{% set geojsonHTML %}
102132
<pre class="govuk-!-margin-0"><code class="language-json app-code-block app-code-block-overflow" id="geojson-content" tabindex="0">Loading...</code></pre>
@@ -340,6 +370,8 @@ <h3 class="govuk-heading-s">{{ type|capitalize }}</h3>
340370

341371
{%- block pageScripts %}
342372

373+
374+
343375
<script>
344376
document.addEventListener('DOMContentLoaded', function () {
345377
// Function to handle loading GeoJSON content

0 commit comments

Comments
 (0)