Fix some IDE warnings

This commit is contained in:
Ian Renton
2026-06-19 19:31:56 +01:00
parent 725eb619b4
commit 05ac652cee
22 changed files with 310 additions and 356 deletions

View File

@@ -2,7 +2,7 @@
const REFRESH_INTERVAL_SEC = 60 * 10;
// Storage for the alert data that the server gives us.
var alerts = []
let alerts = [];
// Load alerts and populate the table.
function loadAlerts() {
@@ -19,15 +19,15 @@ function loadAlerts() {
// Build a query string for the API, based on the filters that the user has selected.
function buildQueryString(includeCredentials) {
var str = "?";
let 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") {
const maxDur = $("#max-duration option:selected").val();
if (maxDur !== "9999999999") {
str = str + "&max_duration=" + maxDur;
}
if ($("#dxpeditions_skip_max_duration_check")[0].checked) {
@@ -42,16 +42,16 @@ function buildQueryString(includeCredentials) {
// Update the alerts table
function updateTable() {
// Use local time instead of UTC?
var useLocalTime = $("#timeZone")[0].value == "local";
const 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;
const showStartTime = $("#tableShowStartTime")[0].checked;
const showEndTime = $("#tableShowEndTime")[0].checked;
const showDX = $("#tableShowDX")[0].checked;
const showFreqsModes = $("#tableShowFreqsModes")[0].checked;
const showComment = $("#tableShowComment")[0].checked;
const showSource = $("#tableShowSource")[0].checked;
const showRef = $("#tableShowRef")[0].checked;
// Populate table with headers
let table = $("#table");
@@ -83,10 +83,10 @@ function updateTable() {
// 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<now<end, or events with no end time that started in the
// last hour.
onNow = alerts.filter(a => (a["end_time"] != null && a["end_time"] != 0 && moment.unix(a["end_time"]).utc().isSameOrAfter() && moment.unix(a["start_time"]).utc().isBefore())
|| ((a["end_time"] == null || a["end_time"] == 0) && 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());
const onNow = alerts.filter(a => (a["end_time"] != null && a["end_time"] !== 0 && moment.unix(a["end_time"]).utc().isSameOrAfter() && moment.unix(a["start_time"]).utc().isBefore())
|| ((a["end_time"] == null || a["end_time"] === 0) && moment.unix(a["start_time"]).utc().add(1, 'hours').isSameOrAfter() && moment.unix(a["start_time"]).utc().isBefore()));
const next24h = alerts.filter(a => moment.unix(a["start_time"]).utc().isSameOrAfter() && moment.unix(a["start_time"]).utc().subtract(24, 'hours').isBefore());
const later = alerts.filter(a => moment.unix(a["start_time"]).utc().subtract(24, 'hours').isSameOrAfter());
if (onNow.length > 0) {
table.find('tbody').append('<tr><td colspan="100" class="bg-primary-subtle" style="text-align:center;">On Now</td></tr>');
@@ -103,14 +103,14 @@ function updateTable() {
addAlertRowsToTable(table.find('tbody'), later);
}
if (onNow.length == 0 && next24h.length == 0 && later.length == 0) {
if (onNow.length === 0 && next24h.length === 0 && later.length === 0) {
table.find('tbody').append('<tr class="bg-danger-subtle"><td colspan="100" style="text-align:center;">No alerts match your filters.</td></tr>');
}
}
// Add a row to tbody for each alert in the provided list
function addAlertRowsToTable(tbody, alerts) {
var count = 0;
let count = 0;
alerts.forEach(a => {
// Create row
let $tr = $('<tr>');
@@ -118,29 +118,29 @@ function addAlertRowsToTable(tbody, alerts) {
// Apply striping to the table. We can't just use Bootstrap's table-striped class because we have all sorts of
// extra faff to deal with, like the mobile view having extra rows, and the On Now / Next 24h / Later banners
// which cause the table-striped colouring to go awry.
if (count % 2 == 1) {
if (count % 2 === 1) {
$tr.addClass("table-active");
}
// Use local time instead of UTC?
var useLocalTime = $("#timeZone")[0].value == "local";
const 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;
const showStartTime = $("#tableShowStartTime")[0].checked;
const showEndTime = $("#tableShowEndTime")[0].checked;
const showDX = $("#tableShowDX")[0].checked;
const showFreqsModes = $("#tableShowFreqsModes")[0].checked;
const showComment = $("#tableShowComment")[0].checked;
const showSource = $("#tableShowSource")[0].checked;
const showRef = $("#tableShowRef")[0].checked;
// Get times for the alert, and convert to local time if necessary.
var start_time_utc = moment.unix(a["start_time"]).utc();
var start_time_local = start_time_utc.clone().local();
start_time = useLocalTime ? start_time_local : start_time_utc;
var end_time_utc = moment.unix(a["end_time"]).utc();
var end_time_local = end_time_utc.clone().local();
end_time = useLocalTime ? end_time_local : end_time_utc;
const start_time_utc = moment.unix(a["start_time"]).utc();
const start_time_local = start_time_utc.clone().local();
const start_time = useLocalTime ? start_time_local : start_time_utc;
const end_time_utc = moment.unix(a["end_time"]).utc();
const end_time_local = end_time_utc.clone().local();
const end_time = useLocalTime ? end_time_local : end_time_utc;
// Format the times for display. Start time is displayed as e.g. 7 Oct 12:34 unless the time is in a
// different year to the current year, in which case the year is inserted between month and hour.
@@ -150,22 +150,22 @@ function addAlertRowsToTable(tbody, alerts) {
// Overriding all of that, if the start time is 00:00 and the end time is 23:59 when considered in UTC, the
// hours and minutes are stripped out from the display, as we assume the server is just giving us full days.
// Finally, if there is no end date set, "---" is displayed.
var whole_days = start_time_utc.format("HH:mm") == "00:00" &&
(end_time_utc != null || end_time_utc > 0 || end_time_utc.format("HH:mm") == "23:59");
var hours_minutes_format = whole_days ? "" : " HH:mm";
var start_time_formatted = start_time.format("D MMM" + hours_minutes_format);
if (start_time.format("YYYY") != moment().format("YYYY")) {
const whole_days = start_time_utc.format("HH:mm") === "00:00" &&
(end_time_utc === 0 || end_time_utc.format("HH:mm") === "23:59");
const hours_minutes_format = whole_days ? "" : " HH:mm";
let start_time_formatted = start_time.format("D MMM" + hours_minutes_format);
if (start_time.format("YYYY") !== moment().format("YYYY")) {
start_time_formatted = start_time.format("D MMM YYYY" + hours_minutes_format);
} else if (useLocalTime && start_time.format("D MMM YYYY") == moment().format("D MMM YYYY")) {
} else if (useLocalTime && start_time.format("D MMM YYYY") === moment().format("D MMM YYYY")) {
start_time_formatted = start_time.format("[Today]" + hours_minutes_format);
}
var end_time_formatted = "---";
if (end_time_utc != null && end_time_utc > 0 && end_time != null) {
var end_time_formatted = whole_days ? start_time_formatted : end_time.format("HH:mm");
if (end_time.format("D MMM") != start_time.format("D MMM")) {
if (end_time.format("YYYY") != moment().format("YYYY")) {
let end_time_formatted = "---";
if (end_time_utc > 0 && end_time != null) {
end_time_formatted = whole_days ? start_time_formatted : end_time.format("HH:mm");
if (end_time.format("D MMM") !== start_time.format("D MMM")) {
if (end_time.format("YYYY") !== moment().format("YYYY")) {
end_time_formatted = end_time.format("D MMM YYYY" + hours_minutes_format);
} else if (useLocalTime && end_time.format("D MMM YYYY") == moment().format("D MMM YYYY")) {
} else if (useLocalTime && end_time.format("D MMM YYYY") === moment().format("D MMM YYYY")) {
end_time_formatted = end_time.format("[Today]" + hours_minutes_format);
} else {
end_time_formatted = end_time.format("D MMM" + hours_minutes_format);
@@ -174,52 +174,52 @@ function addAlertRowsToTable(tbody, alerts) {
}
// Format dx country
var dx_country = a["dx_country"]
let dx_country = a["dx_country"];
if (dx_country == null) {
dx_country = "Unknown or not a country"
}
// Format DX flag
var dx_flag = "<i class='fa-solid fa-globe-africa'></i>";
if (a["dx_dxcc_id"] && a["dx_dxcc_id"] != null && a["dx_dxcc_id"] != 0) {
let dx_flag = "<i class='fa-solid fa-globe-africa'></i>";
if (a["dx_dxcc_id"] && a["dx_dxcc_id"] != null && a["dx_dxcc_id"] !== 0) {
dx_flag = `<img src="img/flags/${a['dx_dxcc_id']}.png" class="flag" width="24" alt="${dx_country}" title="${dx_country}"/>`;
}
// Format dx calls
var dx_calls_html = "";
let dx_calls_html = "";
if (a["dx_calls"] != null) {
dx_calls_html = a["dx_calls"].map(call => `<a class='dx-link' href='https://qrz.com/db/${call}' target='_new'>${call}</a>`).join(", ");
}
// Format DXpedition country
var dx_country_html = "";
if (a["is_dxpedition"] == true && a["dx_country"] != null && a["dx_country"] != "") {
let dx_country_html = "";
if (a["is_dxpedition"] === true && a["dx_country"] != null && a["dx_country"] !== "") {
dx_country_html = `<br/>${a["dx_country"]}`;
}
// Format freqs & modes
var freqsModesText = "";
let freqsModesText = "";
if (a["freqs_modes"] != null) {
freqsModesText = escapeHtml(a["freqs_modes"]);
}
// Format comment
var commentText = "";
let commentText = "";
if (a["comment"] != null) {
commentText = escapeHtml(a["comment"]);
}
// Sig or fallback to source
var sigSourceText = a["source"];
let sigSourceText = a["source"];
if (a["sig"]) {
sigSourceText = a["sig"];
}
// Format sig_refs
var sig_refs = "";
let sig_refs = "";
if (a["sig_refs"] != null) {
var items = []
for (var i = 0; i < a["sig_refs"].length; i++) {
const items = [];
for (let i = 0; i < a["sig_refs"].length; i++) {
if (a["sig_refs"][i]["url"] != null) {
items[i] = `<a href='${encodeURI(a["sig_refs"][i]["url"])}' title='${escapeHtml(a["sig_refs"][i]["name"])}' target='_new' class='sig-ref-link'>${escapeHtml(a["sig_refs"][i]["id"])}</a>`
} else {
@@ -254,11 +254,11 @@ function addAlertRowsToTable(tbody, alerts) {
tbody.append($tr);
// Second row for mobile view only, containing source, ref, freqs/modes & comment
$tr2 = $("<tr class='hidenotonmobile'>");
if (count % 2 == 1) {
const $tr2 = $("<tr class='hidenotonmobile'>");
if (count % 2 === 1) {
$tr2.addClass("table-active");
}
$td2 = $("<td colspan='100'>");
const $td2 = $("<td colspan='100'>");
if (showSource) {
$td2.append(`<span class='icon-wrapper'><i class='fa-solid ${sigToIcon(a["sig"], "fa-globe-africa")}'></i></span> `);
}
@@ -319,7 +319,7 @@ $(document).ready(function() {
// Reload alerts on becoming visible. This forces a refresh when used as a PWA and the user switches back to the PWA
// after some time has passed with it in the background.
addEventListener("visibilitychange", (event) => {
addEventListener("visibilitychange", () => {
if (!document.hidden) {
loadAlerts();
}