// Storage for the alert data that the server gives us. var alerts = [] // Storage for the options that the server gives us. This will define our filters. var options = {}; // Last time we updated the alerts list on display. var lastUpdateTime; // Load alerts and populate the table. function loadAlerts() { $.getJSON('/api/alerts' + buildQueryString(), function(jsonData) { // Present loaded time $("#timing-container").text("Data loaded at " + moment.utc().format('HH:mm') + " UTC."); // Store data alerts = 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", "source"].forEach(fn => { if (!allFilterOptionsSelected(fn)) { str = str + getQueryStringFor(fn) + "&"; } }); str = str + "limit=" + $("#alerts-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 alerts table function updateTable() { // Populate table with headers let table = $('
| Start UTC | `); table.find('thead tr').append(`End UTC | `); table.find('thead tr').append(`DX | `); table.find('thead tr').append(`Frequencies & Modes | `); table.find('thead tr').append(`Comment | `); table.find('thead tr').append(`Source | `); table.find('thead tr').append(`Ref. | `); if (alerts.length == 0) { table.find('tbody').append('|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| No alerts match your filters. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ${start_time_formatted} | `); $tr.append(`${end_time_formatted} | `); $tr.append(`${s["dx_call"]} | `); $tr.append(`${freqsModesText} | `); $tr.append(`${commentText} | `); $tr.append(``); $tr.append(`${sig_refs} | `); table.find('tbody').append($tr); // Second row for mobile view only, containing source, ref, freqs/modes & comment $tr2 = $("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ${sig_refs} ${freqsModesText} ${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 alerts.
function loadOptions() {
$.getJSON('/api/options', function(jsonData) {
// Store options
options = jsonData;
// Populate the filters panel
$("#settings-container").append(generateFilterCard("DX Continent", "dx_continent", options["continents"]));
$("#settings-container").append(generateFilterCard("Sources", "source", options["spot_sources"]));
// Load settings from settings storage
loadSettings();
// Load alerts
loadAlerts();
});
}
// Generate filter card
function generateFilterCard(displayName, filterQuery, options) {
let $col = $("|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||