// 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/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(); str = str + "&max_duration=604800"; return str; } // 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. | `); // 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/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["alert_sources"]));
// Load settings from settings storage
loadSettings();
// Load alerts and set up the timer
loadAlerts();
setInterval(loadAlerts, REFRESH_INTERVAL_SEC * 1000);
});
}
// Method called when any filter is changed to reload the alerts and persist the filter settings.
function filtersUpdated() {
loadAlerts();
saveSettings();
}
// Set up UI element event listeners, after the document is ready
function setUpEventListeners() {
$("#settings-button").click(function() {
$("#settings-area").toggle();
});
$("#close-settings-button").click(function() {
$("#settings-button").button("toggle");
$("#settings-area").hide();
});
$("#alerts-to-fetch").click(function() {
filtersUpdated();
});
}
// Startup
$(document).ready(function() {
// Call loadOptions(), this will then trigger loading alerts and setting up timers.
loadOptions();
// Update the refresh timing display every second
setInterval(updateRefreshDisplay, 1000);
// Set up event listeners
setUpEventListeners();
});|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||