Skip to content

Commit acdd687

Browse files
hrodmnoliverroick
andauthored
add text search to /collections html page (#37)
* add text search to /collections html page --------- Co-authored-by: Oliver Roick <[email protected]>
1 parent 6705a7c commit acdd687

File tree

1 file changed

+40
-9
lines changed

1 file changed

+40
-9
lines changed

runtimes/eoapi/stac/eoapi/stac/templates/collections.html

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,34 @@ <h1>Collections</h1>
2222
<p>You need to add STAC Collections and Items; for example by following the <a href="https://github.com/vincentsarago/MAXAR_opendata_to_pgstac">MAXAR open data demo</a> or <a href="https://github.com/developmentseed/eoAPI/tree/main/demo">other demos.</a></p>
2323
</div>
2424
{% else %}
25-
<div class="d-flex flex-row align-items-center mb-4">
26-
<div class="flex-grow-1">
25+
<div class="d-flex flex-row align-items-center mb-4 flex-wrap">
26+
<div class="mr-3">
2727
Showing {{ offset + 1 }} - {{ offset + response.numberReturned }} of {{ response.numberMatched }} collections
2828
</div>
29+
30+
<form id="search-form" class="d-flex flex-wrap flex-grow-1" style="gap: 8px">
31+
<div class="input-group input-group-sm" style="max-width: 180px">
32+
<input type="text" class="form-control" id="q" placeholder="Text search"
33+
value="{{ request.query_params.get('q', '') }}" title="Text search">
34+
</div>
35+
36+
<div class="btn-group btn-group-sm">
37+
<button type="submit" class="btn btn-primary">Search</button>
38+
<button type="button" id="clear-search" class="btn btn-secondary">Clear</button>
39+
</div>
40+
</form>
41+
2942
<div class="form-inline" style="gap: 10px">
3043
<div class="d-flex">
31-
<label for="limit">Page size: </label>
32-
<select class="form-control form-control-sm ml-1" id="limit" aria-label="Select page size"> <!-- TODO: dynamically populate the values based on oga_max_limit -->
44+
<label for="limit" class="mr-1 small">Page size:</label>
45+
<select class="form-control form-control-sm" id="limit" aria-label="Select page size" style="width: 70px">
3346
<option value="10" {% if limit == 10 %}selected{% endif %}>10</option>
3447
<option value="25" {% if limit == 25 %}selected{% endif %}>25</option>
3548
<option value="50" {% if limit == 50 %}selected{% endif %}>50</option>
3649
<option value="100" {% if limit == 100 %}selected{% endif %}>100</option>
3750
</select>
3851
</div>
52+
3953
{% if response.links|length > 0 %}
4054
<div class="btn-group btn-group-sm" role="group" aria-label="Paginate">
4155
{% for link in response.links %}
@@ -48,8 +62,8 @@ <h1>Collections</h1>
4862
<a class="btn btn-secondary" title="next page" href="{{ link.href }}">next »</a>
4963
{% endif %}
5064
{% endfor %}
51-
{% endif %}
5265
</div>
66+
{% endif %}
5367
</div>
5468
</div>
5569

@@ -74,14 +88,31 @@ <h1>Collections</h1>
7488

7589
<script>
7690
document.getElementById("limit").addEventListener("change", (event) => {
77-
// Set new page size
7891
const limit = event.target.value;
79-
var url = "{{ template.api_root }}/collections?";
8092
const searchParams = new URLSearchParams(window.location.search);
8193
searchParams.set('limit', limit);
8294
searchParams.set('offset', 0);
83-
url += searchParams.toString();
84-
window.location.href = url;
95+
window.location.href = "{{ template.api_root }}/collections?" + searchParams.toString();
96+
});
97+
98+
document.getElementById("search-form").addEventListener("submit", (event) => {
99+
event.preventDefault();
100+
const searchParams = new URLSearchParams();
101+
102+
const q = document.getElementById('q').value.trim();
103+
const limit = document.getElementById('limit').value;
104+
105+
if (q) searchParams.set('q', q);
106+
searchParams.set('limit', limit);
107+
108+
window.location.href = "{{ template.api_root }}/collections?" + searchParams.toString();
109+
return false;
110+
});
111+
112+
document.getElementById("clear-search").addEventListener("click", () => {
113+
const searchParams = new URLSearchParams();
114+
searchParams.set('limit', document.getElementById('limit').value);
115+
window.location.href = "{{ template.api_root }}/collections?" + searchParams.toString();
85116
});
86117
</script>
87118
{% endif %}

0 commit comments

Comments
 (0)