Don't supply query parameters to the API unless they are required

This commit is contained in:
Ian Renton
2025-10-03 14:07:59 +01:00
parent afc383c3d9
commit 5ac1697e08

View File

@@ -24,8 +24,12 @@ function loadSpots() {
// Build a query string for the API, based on the filters that the user has selected. // Build a query string for the API, based on the filters that the user has selected.
function buildQueryString() { function buildQueryString() {
var str = "?"; var str = "?";
var filterNames = ["dx_continent", "de_continent", "mode_type", "source", "band"]; ["dx_continent", "de_continent", "mode_type", "source", "band"].forEach(fn => {
str = str + filterNames.map(n => { return getQueryStringFor(n); }).join("&"); if (!allFilterOptionsSelected(fn)) {
str = str + getQueryStringFor(fn) + "&";
}
});
str = str + "limit=50";
return str; return str;
} }
@@ -43,6 +47,15 @@ function getSelectedFilterOptions(parameter) {
}).get().join(","); }).get().join(",");
} }
// For a parameter, such as dx_continent, return true if all possible options are enabled. (In this case, we don't need
// to bother sending this as one of the query parameters to the API; no parameter provided implies "send everything".)
function allFilterOptionsSelected(parameter) {
var filter = $(".filter-button-" + parameter).filter(function() {
return !this.checked;
}).get();
return filter.length == 0;
}
// Update the spots table // Update the spots table
function updateTable() { function updateTable() {
// Populate table with headers // Populate table with headers