// How often to query the server? const REFRESH_INTERVAL_SEC = 60; // Storage for the spot data that the server gives us. var spots = [] // Load spots and populate the table. function loadSpots() { $.getJSON('/api/v1/spots' + buildQueryString(), function(jsonData) { // Store last updated time lastUpdateTime = moment.utc(); updateRefreshDisplay(); // Store data spots = jsonData; // Update table updateTable(); }); } // Build a query string for the API, based on the filters that the user has selected. function buildQueryString() { var str = "?"; ["dx_continent", "de_continent", "mode_type", "source", "band"].forEach(fn => { if (!allFilterOptionsSelected(fn)) { str = str + getQueryStringFor(fn) + "&"; } }); str = str + "limit=" + $("#spots-to-fetch option:selected").val(); return str; } // Update the spots table function updateTable() { // Use local time instead of UTC? var useLocalTime = $("#useLocalTime")[0].checked; // Populate table with headers let table = $('
| ${useLocalTime ? "Local" : "UTC"} | `); table.find('thead tr').append(`DX | `); table.find('thead tr').append(`Frequency | `); table.find('thead tr').append(`Mode | `); table.find('thead tr').append(`Comment | `); table.find('thead tr').append(`Source | `); table.find('thead tr').append(`Ref. | `); table.find('thead tr').append(`DE | `); if (spots.length == 0) { table.find('tbody').append('||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| No spots match your filters. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ${time_formatted} | `); $tr.append(`${s["dx_call"]} | `); $tr.append(`■${freq_string} | `); $tr.append(`${mode_string} | `); $tr.append(`${commentText} | `); $tr.append(``); $tr.append(`${sig_refs} | `); $tr.append(``); table.find('tbody').append($tr); // Second row for mobile view only, containing source, ref & comment $tr2 = $("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ${sig_refs} ${commentText} | `); table.find('tbody').append($tr2); }); // Update DOM $('#table-container').html(table); } // Load server options. Once a successful callback is made from this, we then query spots and set up the timer to query // spots repeatedly. function loadOptions() { $.getJSON('/api/v1/options', function(jsonData) { // Store options options = jsonData; // Add CSS for band bullets and band toggle buttons addBandColourCSS(options["bands"]); // Populate the filters panel $("#filters-container-1").append(generateBandsMultiToggleFilterCard(options["bands"])); $("#filters-container-2").append(generateMultiToggleFilterCard("DX Continent", "dx_continent", options["continents"])); $("#filters-container-2").append(generateMultiToggleFilterCard("DE Continent", "de_continent", options["continents"])); $("#filters-container-2").append(generateMultiToggleFilterCard("Modes", "mode_type", options["mode_types"])); $("#filters-container-2").append(generateMultiToggleFilterCard("Sources", "source", options["spot_sources"])); // Load filters from settings storage loadSettings(); // Load spots and set up the timer loadSpots(); setInterval(loadSpots, REFRESH_INTERVAL_SEC * 1000); }); } // Dynamically add CSS code for the band bullets and band toggle buttons to be in the appropriate colour. // Some band names contain decimal points which are not allowed in CSS classes, so we text-replace them to "p". function addBandColourCSS(band_options) { var $style = $('|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||