// 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; } if ($("#dxpeditions_skip_max_duration_check")[0].checked) { str = str + "&dxpeditions_skip_max_duration_check=true"; } return str; } // Update the alerts table function updateTable() { // Use local time instead of UTC? var useLocalTime = $("#timeZone")[0].value == "local"; // Table data toggles var showStartTime = $("#tableShowStartTime")[0].checked; var showEndTime = $("#tableShowEndTime")[0].checked; var showDX = $("#tableShowDX")[0].checked; var showFreqsModes = $("#tableShowFreqsModes")[0].checked; var showComment = $("#tableShowComment")[0].checked; var showSource = $("#tableShowSource")[0].checked; var showRef = $("#tableShowRef")[0].checked; // Populate table with headers let table = $('
| ${useLocalTime ? "Start (Local)" : "Start UTC"} | `); } if (showEndTime) { table.find('thead tr').append(`${useLocalTime ? "End (Local)" : "End UTC"} | `); } if (showDX) { table.find('thead tr').append(`DX | `); } if (showFreqsModes) { table.find('thead tr').append(`Frequencies & Modes | `); } if (showComment) { table.find('thead tr').append(`Comment | `); } if (showSource) { table.find('thead tr').append(`Source | `); } if (showRef) { 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} | `); } if (showEndTime) { $tr.append(`${end_time_formatted} | `); } if (showDX) { $tr.append(`${dx_calls_html}${dx_country_html} | `); } if (showFreqsModes) { $tr.append(`${freqsModesText} | `); } if (showComment) { $tr.append(`${commentText} | `); } if (showSource) { $tr.append(``); } if (showRef) { $tr.append(`${sig_refs} | `); } tbody.append($tr); // Second row for mobile view only, containing source, ref, freqs/modes & comment $tr2 = $("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ");
if (showSource) {
$td2.append(` `);
}
if (showRef) {
$td2.append(`${sig_refs} `);
}
if (showFreqsModes) {
$td2.append(`${freqsModesText} `);
}
if (showComment) {
$td2.append(` ${commentText} `); } $tr2.append($td2); 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 generateMultiToggleFilterCard("#dx-continent-options", "dx_continent", options["continents"]); generateMultiToggleFilterCard("#source-options", "source", options["alert_sources"]); // Load filters 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(); } // React to toggling/closing panels function toggleFiltersPanel() { // If we are going to display the filters panel, hide the display panel if (!$("#filters-area").is(":visible") && $("#display-area").is(":visible")) { $("#display-area").hide(); $("#display-button").button("toggle"); } $("#filters-area").toggle(); } function closeFiltersPanel() { $("#filters-button").button("toggle"); $("#filters-area").hide(); } function toggleDisplayPanel() { // If we are going to display status, load the data for the status panel, and hide the filters panel if (!$("#display-area").is(":visible") && $("#filters-area").is(":visible")) { $("#filters-area").hide(); $("#filters-button").button("toggle"); } $("#display-area").toggle(); } function closeDisplayPanel() { $("#display-button").button("toggle"); $("#display-area").hide(); } // 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); }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||