// How often to query the server? const REFRESH_INTERVAL_SEC = 60 * 30; // Storage for the alert data that the server gives us. var alerts = [] // Load alerts and populate the table. function loadAlerts() { $.getJSON('/api/v1/alerts' + buildQueryString(), function(jsonData) { // Store last updated time lastUpdateTime = moment.utc(); updateRefreshDisplay(); // 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(); var maxDur = $("#max-duration option:selected").val(); if (maxDur != "9999999999") { str = str + "&max_duration=" + maxDur; } return str; } // Update the alerts table function updateTable() { // Use local time instead of UTC? var useLocalTime = $("#useLocalTime")[0].checked; // Populate table with headers let table = $('
| ${useLocalTime ? "Start (Local)" : "Start UTC"} | `); table.find('thead tr').append(`${useLocalTime ? "End (Local)" : "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. | `); // Split alerts into three types, each of which will get its own table header: On now, next 24h, and later. "On now" // is considered to be events with an end_time where start|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| On Now | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Starting within 24 hours | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Starting later | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| No alerts match your filters. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ${start_time_formatted} | `); $tr.append(`${end_time_formatted} | `); $tr.append(`${a["dx_call"]} | `); $tr.append(`${freqsModesText} | `); $tr.append(`${commentText} | `); $tr.append(``); $tr.append(`${sig_refs} | `); tbody.append($tr); // Second row for mobile view only, containing source, ref, freqs/modes & comment $tr2 = $("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ${sig_refs} ${freqsModesText} ${commentText} | `);
tbody.append($tr2);
});
}
// Load server options. Once a successful callback is made from this, we then query alerts.
function loadOptions() {
$.getJSON('/api/v1/options', function(jsonData) {
// Store options
options = jsonData;
// Populate the filters panel
$("#filters-container").append(generateMultiToggleFilterCard("DX Continent", "dx_continent", options["continents"]));
$("#filters-container").append(generateMultiToggleFilterCard("Sources", "source", options["alert_sources"]));
// Options doesn't give us anything for Max Duration as it's a free numeric input, but we generate our own
// filter card for this.
$("#filters-container").append(generateMaxDurationDropdownFilterCard(options["alert_sources"]));
// Load filters from settings storage
loadSettings();
// Load alerts and set up the timer
loadAlerts();
setInterval(loadAlerts, REFRESH_INTERVAL_SEC * 1000);
});
}
// Generate maximum duration drop-down filter card. This one is a special case.
function generateMaxDurationDropdownFilterCard(band_options) {
let $col = $("|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||