// 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 = $('').append(''); table.find('thead tr').append(``); table.find('thead tr').append(``); table.find('thead tr').append(``); table.find('thead tr').append(``); table.find('thead tr').append(``); table.find('thead tr').append(``); table.find('thead tr').append(``); // 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 (a["end_time"] != null && moment.unix(a["end_time"]).utc().isSameOrAfter() && moment.unix(a["start_time"]).utc().isBefore()) || (a["end_time"] == null && moment.unix(a["start_time"]).utc().add(1, 'hours').isSameOrAfter() && moment.unix(a["start_time"]).utc().isBefore())); next24h = alerts.filter(a => moment.unix(a["start_time"]).utc().isSameOrAfter() && moment.unix(a["start_time"]).utc().subtract(24, 'hours').isBefore()); later = alerts.filter(a => moment.unix(a["start_time"]).utc().subtract(24, 'hours').isSameOrAfter()); if (onNow.length > 0) { table.find('tbody').append(''); addAlertRowsToTable(table.find('tbody'), onNow); } if (next24h.length > 0) { table.find('tbody').append(''); addAlertRowsToTable(table.find('tbody'), next24h); } if (later.length > 0) { table.find('tbody').append(''); addAlertRowsToTable(table.find('tbody'), later); } if (onNow.length == 0 && next24h.length == 0 && later.length == 0) { table.find('tbody').append(''); } // Update DOM $('#table-container').html(table); } // Add a row to tbody for each alert in the provided list function addAlertRowsToTable(tbody, alerts) { alerts.forEach(a => { // Create row let $tr = $(''); // Format UTC times for display var start_time = moment.unix(a["start_time"]).utc(); var start_time_formatted = start_time.format("YYYY-MM-DD HH:mm"); var end_time = moment.unix(a["end_time"]).utc(); var end_time_formatted = (end_time != null) ? end_time.format("YYYY-MM-DD HH:mm") : "Not specified"; // Format dx country var dx_country = a["dx_country"] if (dx_country == null) { dx_country = "Unknown or not a country" } // Format freqs & modes var freqsModesText = ""; if (a["freqs_modes"] != null) { freqsModesText = escapeHtml(a["freqs_modes"]); } // Format comment var commentText = ""; if (a["comment"] != null) { commentText = escapeHtml(a["comment"]); } // Sig or fallback to source var sigSourceText = a["source"]; if (a["sig"]) { sigSourceText = a["sig"]; } // Format sig_refs var sig_refs = "" if (a["sig_refs"]) { sig_refs = a["sig_refs"].join(", ") } // Populate the row $tr.append(``); $tr.append(``); $tr.append(``); $tr.append(``); $tr.append(``); $tr.append(``); $tr.append(``); tbody.append($tr); // Second row for mobile view only, containing source, ref, freqs/modes & comment $tr2 = $(""); $tr2.append(``); 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(); });
Start UTCEnd UTCDXFrequencies & ModesCommentSourceRef.
On Now
Starting within 24 hours
Starting later
No alerts match your filters.
${start_time_formatted}${end_time_formatted}${a["dx_flag"]}${a["dx_call"]}${freqsModesText}${commentText} ${sigSourceText}${sig_refs}
${sig_refs} ${freqsModesText}
${commentText}