Start of web interface

This commit is contained in:
Ian Renton
2025-09-27 16:55:17 +01:00
parent 78871902ad
commit 9d9687adbf
4 changed files with 58 additions and 6 deletions

View File

@@ -1,13 +1,45 @@
// TODO get all data into JS
// TODO populate table more nicely
// TODO track last received time and use API since call, merge and sort local data, refresh display
// TODO filtering (applied locally)
// TODO look and feel
$.getJSON('/api/spots', function(jsonData) {
let headers = Object.keys(jsonData[0]);
let table = $('<table>').append('<thead><tr></tr></thead><tbody></tbody>');
headers.forEach(header => table.find('thead tr').append(`<th>${header}</th>`));
["Time", "DX", "Frequency", "Mode", "Comment", "Source", "DE"].forEach(header => table.find('thead tr').append(`<th>${header}</th>`));
jsonData.forEach(row => {
let $tr = $('<tr>');
headers.forEach(header => $tr.append(`<td>${row[header]}</td>`));
$tr.append(`<td>${row["time"]}</td>`);
$tr.append(`<td>${row["dx_call"]}</td>`);
$tr.append(`<td>${row["freq"]}</td>`);
$tr.append(`<td>${row["mode"]}</td>`);
$tr.append('<td>').append(escapeHtml(`${row["comment"]}`)).append('</td>');
$tr.append(`<td>${row["source"]}</td>`);
$tr.append(`<td>${row["de_call"]}</td>`);
table.find('tbody').append($tr);
});
$('#table-container').html(table);
});
});
function escapeHtml(str) {
if (typeof str !== 'string') {
return '';
}
const escapeCharacter = (match) => {
switch (match) {
case '&': return '&amp;';
case '<': return '&lt;';
case '>': return '&gt;';
case '"': return '&quot;';
case '\'': return '&#039;';
case '`': return '&#096;';
default: return match;
}
};
return str.replace(/[&<>"'`]/g, escapeCharacter);
}