// How often to query the server? const REFRESH_INTERVAL_SEC = 60; // Storage for the spot data that the server gives us. var spots = [] // Storage for the options that the server gives us. This will define our filters. var options = {}; // Last time we updated the spots list on display. var lastUpdateTime; // Load spots and populate the table. function loadSpots() { $.getJSON('/api/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; } // 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(","); } // 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 function updateTable() { // Populate table with headers let table = $('
| 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(``); $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 status function loadStatus() { $.getJSON('/api/status', function(jsonData) { $("#status-container").empty(); $("#status-container").append(generateStatusCard("Server Information", [ `Software Version: ${jsonData["software-version"]}`, `Server Owner Callsign: ${jsonData["server-owner-callsign"]}`, `Server Uptime: ${jsonData["uptime"]}`, `Memory Use: ${jsonData["mem_use_mb"]} MB`, `Total Spots: ${jsonData["num_spots"]}` ])); $("#status-container").append(generateStatusCard("Web Server", [ `Status: ${jsonData["webserver"]["status"]}`, `Last API Access: ${moment.utc(jsonData["webserver"]["last_api_access"], moment.ISO_8601).format("HH:mm")}`, `Last Page Access: ${moment.utc(jsonData["webserver"]["last_page_access"], moment.ISO_8601).format("HH:mm")}` ])); $("#status-container").append(generateStatusCard("Cleanup Service", [ `Status: ${jsonData["cleanup"]["status"]}`, `Last Ran: ${moment.utc(jsonData["cleanup"]["last_ran"], moment.ISO_8601).format("HH:mm")}` ])); jsonData["providers"].forEach(p => { $("#status-container").append(generateStatusCard("Provider: " + p["name"], [ `Status: ${p["status"]}`, `Last Updated: ${p["enabled"] ? moment.utc(p["last_updated"], moment.ISO_8601).format("HH:mm") : "N/A"}`, `Latest Spot: ${p["enabled"] ? moment.utc(p["last_spot"], moment.ISO_8601).format("HH:mm YYYY-MM-DD") : "N/A"}` ])); }); }); } // Generate a status card function generateStatusCard(title, textLines) { let $col = $("|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||