mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2025-10-27 08:49:27 +00:00
Add max_duration filter for alerts #17
This commit is contained in:
@@ -26,7 +26,10 @@ function buildQueryString() {
|
||||
}
|
||||
});
|
||||
str = str + "limit=" + $("#alerts-to-fetch option:selected").val();
|
||||
str = str + "&max_duration=604800";
|
||||
var maxDur = $("#max-duration option:selected").val();
|
||||
if (maxDur != "") {
|
||||
str = str + "&max_duration=" + maxDur;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
@@ -139,8 +142,12 @@ function loadOptions() {
|
||||
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"]));
|
||||
$("#settings-container").append(generateMultiToggleFilterCard("DX Continent", "dx_continent", options["continents"]));
|
||||
$("#settings-container").append(generateMultiToggleFilterCard("Sources", "source", options["alert_sources"]));
|
||||
|
||||
// Options doesn't give us anything for Max Duration as it's a free numeric input, but we generate our own
|
||||
// filter card for this.
|
||||
$("#settings-container").append(generateMaxDurationDropdownFilterCard(options["alert_sources"]));
|
||||
|
||||
// Load settings from settings storage
|
||||
loadSettings();
|
||||
@@ -151,6 +158,30 @@ function loadOptions() {
|
||||
});
|
||||
}
|
||||
|
||||
// Generate maximum duration drop-down filter card. This one is a special case.
|
||||
function generateMaxDurationDropdownFilterCard(band_options) {
|
||||
let $col = $("<div class='col'>")
|
||||
let $card = $("<div class='card'>");
|
||||
let $card_body = $("<div class='card-body'>");
|
||||
$card_body.append(`<h5 class='card-title'>Duration Limit</h5>`);
|
||||
$p = $("<p class='card-text filter-card-text'>");
|
||||
$p.append("Hide any alerts lasting more than:<br/>");
|
||||
$p.append(`<select id="max-duration" class="storeable-select form-select" onclick="filtersUpdated();" style="width: 8em; display: inline-block;">
|
||||
<option value="10800">3 hours</option>
|
||||
<option value="43200">12 hours</option>
|
||||
<option value="86400" selected>24 hours</option>
|
||||
<option value="604800">1 week</option>
|
||||
<option value="2419200">4 weeks</option>
|
||||
<option value="">No limit</option>
|
||||
</select>`);
|
||||
$p.append(" <i class='fa-solid fa-circle-question' title='Some users create long-duration alerts for the period they will be generally in and around xOTA references, not just the times they are specifically on the air. Use this control to restrict the maximum duration of spots that the software will display, and exclude any with a long duration.'></i>");
|
||||
// Compile HTML elements to return
|
||||
$card_body.append($p);
|
||||
$card.append($card_body);
|
||||
$col.append($card);
|
||||
return $col;
|
||||
}
|
||||
|
||||
// Method called when any filter is changed to reload the alerts and persist the filter settings.
|
||||
function filtersUpdated() {
|
||||
loadAlerts();
|
||||
@@ -165,9 +196,6 @@ function setUpEventListeners() {
|
||||
$("#settings-button").button("toggle");
|
||||
$("#settings-area").hide();
|
||||
});
|
||||
$("#alerts-to-fetch").click(function() {
|
||||
filtersUpdated();
|
||||
});
|
||||
}
|
||||
|
||||
// Startup
|
||||
|
||||
@@ -28,8 +28,8 @@ function allFilterOptionsSelected(parameter) {
|
||||
}
|
||||
|
||||
|
||||
// Generate filter card
|
||||
function generateFilterCard(displayName, filterQuery, options) {
|
||||
// Generate a filter card with multiple toggle buttons plus All/None buttons
|
||||
function generateMultiToggleFilterCard(displayName, filterQuery, options) {
|
||||
let $col = $("<div class='col'>")
|
||||
let $card = $("<div class='card'>");
|
||||
let $card_body = $("<div class='card-body'>");
|
||||
|
||||
@@ -193,11 +193,11 @@ function loadOptions() {
|
||||
addBandColourCSS(options["bands"]);
|
||||
|
||||
// Populate the filters panel
|
||||
$("#settings-container-1").append(generateBandsFilterCard("Bands", "band", options["bands"]));
|
||||
$("#settings-container-2").append(generateFilterCard("DX Continent", "dx_continent", options["continents"]));
|
||||
$("#settings-container-2").append(generateFilterCard("DE Continent", "de_continent", options["continents"]));
|
||||
$("#settings-container-2").append(generateFilterCard("Modes", "mode_type", options["mode_types"]));
|
||||
$("#settings-container-2").append(generateFilterCard("Sources", "source", options["spot_sources"]));
|
||||
$("#settings-container-1").append(generateBandsMultiToggleFilterCard(options["bands"]));
|
||||
$("#settings-container-2").append(generateMultiToggleFilterCard("DX Continent", "dx_continent", options["continents"]));
|
||||
$("#settings-container-2").append(generateMultiToggleFilterCard("DE Continent", "de_continent", options["continents"]));
|
||||
$("#settings-container-2").append(generateMultiToggleFilterCard("Modes", "mode_type", options["mode_types"]));
|
||||
$("#settings-container-2").append(generateMultiToggleFilterCard("Sources", "source", options["spot_sources"]));
|
||||
|
||||
// Load settings from settings storage
|
||||
loadSettings();
|
||||
@@ -223,21 +223,21 @@ function addBandColourCSS(band_options) {
|
||||
}
|
||||
|
||||
// Generate bands filter card. This one is a special case.
|
||||
function generateBandsFilterCard(displayName, filterQuery, band_options) {
|
||||
function generateBandsMultiToggleFilterCard(band_options) {
|
||||
let $col = $("<div class='col'>")
|
||||
let $card = $("<div class='card'>");
|
||||
let $card_body = $("<div class='card-body'>");
|
||||
$card_body.append(`<h5 class='card-title'>${displayName}</h5>`);
|
||||
$card_body.append(`<h5 class='card-title'>Bands</h5>`);
|
||||
$p = $("<p class='card-text filter-card-text'>");
|
||||
// Create a button for each option
|
||||
band_options.forEach(o => {
|
||||
// CSS doesn't like IDs with decimal points in, so we need to replace that in the same way as when we originally
|
||||
// queried the options endpoint and set our CSS.
|
||||
var cssFormattedBandName = o['name'] ? o['name'].replace('.', 'p') : "unknown";
|
||||
$p.append(`<input type="checkbox" class="btn-check filter-button-${filterQuery} storeable-checkbox" name="options" id="filter-button-${filterQuery}-${cssFormattedBandName}" value="${o['name']}" autocomplete="off" onClick="filtersUpdated()" checked><label class="btn btn-outline" id="filter-button-label-${filterQuery}-${cssFormattedBandName}" for="filter-button-${filterQuery}-${cssFormattedBandName}">${o['name']}</label> `);
|
||||
$p.append(`<input type="checkbox" class="btn-check filter-button-bands storeable-checkbox" name="options" id="filter-button-bands-${cssFormattedBandName}" value="${o['name']}" autocomplete="off" onClick="filtersUpdated()" checked><label class="btn btn-outline" id="filter-button-label-bands-${cssFormattedBandName}" for="filter-button-bands-${cssFormattedBandName}">${o['name']}</label> `);
|
||||
});
|
||||
// Create All/None buttons
|
||||
$p.append(` <span style="display: inline-block"><button id="filter-button-${filterQuery}-all" type="button" class="btn btn-outline-secondary" onclick="toggleFilterButtons('${filterQuery}', true);">All</button> <button id="filter-button-${filterQuery}-none" type="button" class="btn btn-outline-secondary" onclick="toggleFilterButtons('${filterQuery}', false);">None</button></span>`);
|
||||
$p.append(` <span style="display: inline-block"><button id="filter-button-bands-all" type="button" class="btn btn-outline-secondary" onclick="toggleFilterButtons('bands', true);">All</button> <button id="filter-button-bands-none" type="button" class="btn btn-outline-secondary" onclick="toggleFilterButtons('bands', false);">None</button></span>`);
|
||||
// Compile HTML elements to return
|
||||
$card_body.append($p);
|
||||
$card.append($card_body);
|
||||
@@ -280,9 +280,6 @@ function setUpEventListeners() {
|
||||
$("#settings-button").button("toggle");
|
||||
$("#settings-area").hide();
|
||||
});
|
||||
$("#spots-to-fetch").click(function() {
|
||||
filtersUpdated();
|
||||
});
|
||||
}
|
||||
|
||||
// Display the intro box, unless the user has already dismissed it once.
|
||||
|
||||
Reference in New Issue
Block a user