Skip to content

Commit d1cc4af

Browse files
committed
Trigger semantic lookups via click
1 parent 7644d1d commit d1cc4af

File tree

2 files changed

+46
-26
lines changed

2 files changed

+46
-26
lines changed

pygeoapi/templates/collections/items/item.html

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ <h1>{{ ptitle }}</h1>
8080
</div>
8181
</div>
8282
<div class="col-md-6 col-sm-12">
83+
{% if linked_data and linked_data.get('context') | length %}
84+
<div class="text-end mb-2">
85+
<a href="#" class="btn btn-primary" id="semantic-lookup-btn" data-target="#item-properties-table">
86+
{% trans %}Semantic lookup{% endtrans %}
87+
</a>
88+
</div>
89+
{% endif %}
8390
<table class="table table-striped table-bordered object-table" id="item-properties-table">
8491
<thead>
8592
<tr>
@@ -148,19 +155,22 @@ <h1>{{ ptitle }}</h1>
148155
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/rdflib.min.js"></script>
149156
<script src="https://github.com/avillar/jsonld-ui-utils/releases/latest/download/jsonld-ui-utils.min.js"></script>
150157
<script>
151-
const rootElem = document.getElementById('item-properties-table');
152-
if (rootElem) {
153-
const linkedDataConfig = {{ linked_data | tojson }}
154-
const options = {};
155-
if (linkedDataConfig.fallback_sparql_endpoint) {
156-
options.fallbackSparqlEndpoint = linkedDataConfig.fallback_sparql_endpoint;
157-
}
158-
const context = { '@context': linkedDataConfig['context'] };
159-
jsonldUIUtils.loadContext(context)
160-
.then(loadedContext => {
161-
jsonldUIUtils.augment(rootElem, loadedContext, options);
162-
});
163-
}
158+
document.getElementById('semantic-lookup-btn').addEventListener('click', function(e) {
159+
e.target.style.display = 'none';
160+
var rootElem = document.getElementById('item-properties-table');
161+
if (rootElem) {
162+
var linkedDataConfig = {{ linked_data | tojson }}
163+
var options = {};
164+
if (linkedDataConfig.fallback_sparql_endpoint) {
165+
options.fallbackSparqlEndpoint = linkedDataConfig.fallback_sparql_endpoint;
166+
}
167+
var context = {'@context': linkedDataConfig['context']};
168+
jsonldUIUtils.loadContext(context)
169+
.then(loadedContext => {
170+
jsonldUIUtils.augment(rootElem, loadedContext, options);
171+
});
172+
}
173+
});
164174
</script>
165175
{% endif %}
166176
{% endblock %}

pygeoapi/templates/stac/item.html

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ <h4>{% trans %}Assets{% endtrans %}</h4>
8181
</div>
8282
</div>
8383
<div class="col-md-6 col-sm-12">
84+
{% if linked_data and linked_data.get('context') | length %}
85+
<div class="text-end mb-2">
86+
<a href="#" class="btn btn-primary" id="semantic-lookup-btn" data-target="#item-properties-table">
87+
{% trans %}Semantic lookup{% endtrans %}
88+
</a>
89+
</div>
90+
{% endif %}
8491
<table class="table table-striped table-bordered object-table" id="item-properties-table">
8592
<thead>
8693
<tr>
@@ -139,19 +146,22 @@ <h4>{% trans %}Assets{% endtrans %}</h4>
139146
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/rdflib.min.js"></script>
140147
<script src="https://github.com/avillar/jsonld-ui-utils/releases/latest/download/jsonld-ui-utils.min.js"></script>
141148
<script>
142-
const rootElem = document.getElementById('item-properties-table');
143-
if (rootElem) {
144-
const linkedDataConfig = {{ linked_data | tojson }}
145-
const options = {};
146-
if (linkedDataConfig.fallback_sparql_endpoint) {
147-
options.fallbackSparqlEndpoint = linkedDataConfig.fallback_sparql_endpoint;
148-
}
149-
const context = { '@context': linkedDataConfig['context'] };
150-
jsonldUIUtils.loadContext(context)
151-
.then(loadedContext => {
152-
jsonldUIUtils.augment(rootElem, loadedContext, options);
153-
});
154-
}
149+
document.getElementById('semantic-lookup-btn').addEventListener('click', function(e) {
150+
e.target.style.display = 'none';
151+
var rootElem = document.getElementById('item-properties-table');
152+
if (rootElem) {
153+
var linkedDataConfig = {{ linked_data | tojson }}
154+
var options = {};
155+
if (linkedDataConfig.fallback_sparql_endpoint) {
156+
options.fallbackSparqlEndpoint = linkedDataConfig.fallback_sparql_endpoint;
157+
}
158+
var context = {'@context': linkedDataConfig['context']};
159+
jsonldUIUtils.loadContext(context)
160+
.then(loadedContext => {
161+
jsonldUIUtils.augment(rootElem, loadedContext, options);
162+
});
163+
}
164+
});
155165
</script>
156166
{% endif %}
157167
{% endblock %}

0 commit comments

Comments
 (0)