Skip to content

feat: use conformance classes to enable/disable collection search box #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 46 additions & 18 deletions stac_fastapi/html/templates/collections.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ <h1>Collections</h1>
Showing {{ template.params.get("offset", 0)|int + 1 }} - {{ template.params.get("offset", 0)|int + response.numberReturned }} of {{ response.numberMatched }} collections
</div>

<!-- Enable collection-search ? -->
<!-- <form id="search-form" class="d-flex flex-wrap flex-grow-1" style="gap: 8px">
<form id="search-form" class="d-flex flex-wrap flex-grow-1" style="gap: 8px; display: none;">
<div class="input-group input-group-sm" style="max-width: 180px">
<input type="text" class="form-control" id="q" placeholder="Text search"
value="{{ request.query_params.get('q', '') }}" title="Text search">
Expand All @@ -44,7 +43,7 @@ <h1>Collections</h1>
<button type="submit" class="btn btn-primary">Search</button>
<button type="button" id="clear-search" class="btn btn-secondary">Clear</button>
</div>
</form> -->
</form>

<div class="form-inline" style="gap: 10px">
<div class="d-flex">
Expand Down Expand Up @@ -94,6 +93,32 @@ <h1>Collections</h1>
</div>

<script>
// Check conformance for collection search support
async function checkCollectionSearchSupport() {
try {
const response = await fetch("{{ template.api_root }}/conformance");
const data = await response.json();

if (data.conformsTo && Array.isArray(data.conformsTo)) {
const hasCollectionSearch = data.conformsTo.some(conformance =>
conformance.endsWith("/collection-search#free-text")
);

if (hasCollectionSearch) {
const searchForm = document.getElementById("search-form");
if (searchForm) {
searchForm.style.display = "flex";
}
}
}
} catch (error) {
console.warn("Could not check conformance for collection search:", error);
}
}

// Initialize collection search check
checkCollectionSearchSupport();

document.getElementById("limit").addEventListener("change", (event) => {
const limit = event.target.value;
const searchParams = new URLSearchParams(window.location.search);
Expand All @@ -102,25 +127,28 @@ <h1>Collections</h1>
window.location.href = "{{ template.api_root }}/collections?" + searchParams.toString();
});

document.getElementById("search-form").addEventListener("submit", (event) => {
event.preventDefault();
const searchParams = new URLSearchParams();
const searchForm = document.getElementById("search-form");
if (searchForm) {
searchForm.addEventListener("submit", (event) => {
event.preventDefault();
const searchParams = new URLSearchParams();

const q = document.getElementById('q').value.trim();
const limit = document.getElementById('limit').value;
const q = document.getElementById('q').value.trim();
const limit = document.getElementById('limit').value;

if (q) searchParams.set('q', q);
searchParams.set('limit', limit);
if (q) searchParams.set('q', q);
searchParams.set('limit', limit);

window.location.href = "{{ template.api_root }}/collections?" + searchParams.toString();
return false;
});
window.location.href = "{{ template.api_root }}/collections?" + searchParams.toString();
return false;
});

document.getElementById("clear-search").addEventListener("click", () => {
const searchParams = new URLSearchParams();
searchParams.set('limit', document.getElementById('limit').value);
window.location.href = "{{ template.api_root }}/collections?" + searchParams.toString();
});
document.getElementById("clear-search").addEventListener("click", () => {
const searchParams = new URLSearchParams();
searchParams.set('limit', document.getElementById('limit').value);
window.location.href = "{{ template.api_root }}/collections?" + searchParams.toString();
});
}
</script>
{% endif %}
{% endblock %}
Loading