diff --git a/webassets/js/code.js b/webassets/js/code.js index 8304e8c..aee3161 100644 --- a/webassets/js/code.js +++ b/webassets/js/code.js @@ -10,7 +10,7 @@ var lastUpdateTime; // Load spots and populate the table. function loadSpots() { - $.getJSON('/api/spots', function(jsonData) { + $.getJSON('/api/spots' + buildQueryString(), function(jsonData) { // Store last updated time lastUpdateTime = moment.utc(); updateRefreshDisplay(); @@ -21,13 +21,38 @@ function loadSpots() { }); } +// Build a query string for the API, based on the filters that the user has selected. +function buildQueryString() { + var str = "?"; + var filterNames = ["dx_continent", "de_continent", "mode_type", "source", "band"]; + str = str + filterNames.map(n => { return getQueryStringFor(n); }).join("&"); + return str; +} + +// For a parameter, such as dx_continent, get the query string for the current filter options. +function getQueryStringFor(parameter) { + return parameter + "=" + encodeURIComponent(getSelectedFilterOptions(parameter)); +} + +// For a parameter, such as dx_continent, get the filter options that are currently selected in the UI. +function getSelectedFilterOptions(parameter) { + return $(".filter-button-" + parameter).filter(function() { + return this.checked; + }).map(function() { + return this.value; + }).get().join(","); +} + // Update the spots table function updateTable() { // Populate table with headers - let headers = Object.keys(spots[0]); let table = $('
| ${header} | `)); + if (spots.length == 0) { + table.find('tbody').append('|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| No spots match your filters. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||