mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-02-04 09:14:30 +00:00
Add ability to tag callsigns as worked. Closes #41
This commit is contained in:
@@ -105,6 +105,7 @@ function updateTable() {
|
||||
var showType = $("#tableShowType")[0].checked;
|
||||
var showRef = $("#tableShowRef")[0].checked;
|
||||
var showDE = $("#tableShowDE")[0].checked;
|
||||
var showWorkedCheckbox = $("#tableShowWorkedCheckbox")[0].checked;
|
||||
|
||||
// Populate table with headers
|
||||
let table = $("#table");
|
||||
@@ -136,12 +137,18 @@ function updateTable() {
|
||||
if (showDE) {
|
||||
table.find('thead tr').append(`<th class='hideonmobile'>DE</th>`);
|
||||
}
|
||||
if (showWorkedCheckbox) {
|
||||
table.find('thead tr').append(`<th class='hideonmobile'></th>`);
|
||||
}
|
||||
|
||||
table.find('tbody').empty();
|
||||
if (spots.length == 0) {
|
||||
table.find('tbody').append('<tr class="table-danger"><td colspan="100" style="text-align:center;">No spots match your filters.</td></tr>');
|
||||
}
|
||||
|
||||
// We are regenerating the entire table not just adding a new row, so reset the row counter
|
||||
rowCount = 0;
|
||||
|
||||
let spotsNewestFirst = spots.toReversed();
|
||||
spotsNewestFirst.forEach(s => addSpotToTopOfTable(s, false));
|
||||
}
|
||||
@@ -174,6 +181,7 @@ function createNewTableRowsForSpot(s, highlightNew) {
|
||||
var showType = $("#tableShowType")[0].checked;
|
||||
var showRef = $("#tableShowRef")[0].checked;
|
||||
var showDE = $("#tableShowDE")[0].checked;
|
||||
var showWorkedCheckbox = $("#tableShowWorkedCheckbox")[0].checked;
|
||||
|
||||
// Create row
|
||||
let $tr = $('<tr>');
|
||||
@@ -185,8 +193,9 @@ function createNewTableRowsForSpot(s, highlightNew) {
|
||||
$tr.addClass("table-active");
|
||||
}
|
||||
|
||||
// Show faded out if QRT
|
||||
if (s["qrt"] == true) {
|
||||
// Show faded out if QRT or already worked
|
||||
let alreadyWorkedThis = alreadyWorked(s["dx_call"], s["band"], s["mode"]);
|
||||
if (s["qrt"] == true || alreadyWorkedThis) {
|
||||
$tr.addClass("table-faded");
|
||||
}
|
||||
|
||||
@@ -308,6 +317,9 @@ function createNewTableRowsForSpot(s, highlightNew) {
|
||||
// Format band name
|
||||
var bandFullName = s['band'] ? s['band'] + " band": "Unknown band";
|
||||
|
||||
// Format "worked" checkbox
|
||||
var workedCheckbox = `<input type="checkbox" ${alreadyWorkedThis ? "checked" : ""} onClick="setWorkedState('${s['dx_call']}', '${s['band']}', '${s['mode']}', ${alreadyWorkedThis ? "false" : "true"});">`;
|
||||
|
||||
// Populate the row
|
||||
if (showTime) {
|
||||
$tr.append(`<td class='nowrap'>${time_formatted}</td>`);
|
||||
@@ -336,6 +348,9 @@ function createNewTableRowsForSpot(s, highlightNew) {
|
||||
if (showDE) {
|
||||
$tr.append(`<td class='nowrap hideonmobile'><span class='flag-wrapper' title='${de_country}'>${de_flag}</span>${de_call}</td>`);
|
||||
}
|
||||
if (showWorkedCheckbox) {
|
||||
$tr.append(`<td class='nowrap hideonmobile'>${workedCheckbox}</td>`);
|
||||
}
|
||||
|
||||
// Second row for mobile view only, containing type, ref & comment
|
||||
$tr2 = $("<tr class='hidenotonmobile'>");
|
||||
@@ -344,7 +359,7 @@ function createNewTableRowsForSpot(s, highlightNew) {
|
||||
if (rowCount % 2 == 1) {
|
||||
$tr2.addClass("table-active");
|
||||
}
|
||||
if (s["qrt"] == true) {
|
||||
if (s["qrt"] == true || alreadyWorkedThis) {
|
||||
$tr2.addClass("table-faded");
|
||||
}
|
||||
if (highlightNew) {
|
||||
@@ -367,6 +382,9 @@ function createNewTableRowsForSpot(s, highlightNew) {
|
||||
if (showDE) {
|
||||
$td2floatright.append(` de ${de_call} `);
|
||||
}
|
||||
if (showWorkedCheckbox) {
|
||||
$td2floatright.append(` ${workedCheckbox} `);
|
||||
}
|
||||
$td2.append($td2floatright);
|
||||
$td2.append(`</div><div style="clear: both;"></div>`);
|
||||
if (showComment) {
|
||||
@@ -481,6 +499,27 @@ function displayIntroBox() {
|
||||
});
|
||||
}
|
||||
|
||||
// Mark a callsign-band-mode combination as worked (or unmark it). Persist this to localStorage.
|
||||
function setWorkedState(callsign, band, mode, nowWorked) {
|
||||
let combo = callsign + "-" + band + "-" + mode;
|
||||
if (nowWorked && !worked.includes(combo)) {
|
||||
worked.push(combo);
|
||||
updateTable();
|
||||
localStorage.setItem("worked", JSON.stringify(worked));
|
||||
} else if (!nowWorked && worked.includes(combo)) {
|
||||
worked.splice(worked.indexOf(combo), 1);
|
||||
updateTable();
|
||||
localStorage.setItem("worked", JSON.stringify(worked));
|
||||
}
|
||||
}
|
||||
|
||||
// Clear the list of worked calls
|
||||
function clearWorked() {
|
||||
worked = [];
|
||||
updateTable();
|
||||
localStorage.setItem("worked", JSON.stringify(worked));
|
||||
}
|
||||
|
||||
// Startup
|
||||
$(document).ready(function() {
|
||||
// Call loadOptions(), this will then trigger loading spots and setting up timers.
|
||||
|
||||
Reference in New Issue
Block a user