240 lines
8.3 KiB
JavaScript
240 lines
8.3 KiB
JavaScript
/*
|
|
Copyright (c) 2023-forever Douglas Malnati. All rights reserved.
|
|
|
|
See the /faq/tos page for details.
|
|
|
|
(If this generated header is stamped on a file which is a 3rd party file or under a different license or copyright, then ignore this copyright statement and use that file's terms.)
|
|
*/
|
|
|
|
export class WsprSearchUiDataTableVisibility
|
|
{
|
|
static GetStoredToggle(storageKey, defaultValue)
|
|
{
|
|
let storedVal = localStorage.getItem(storageKey);
|
|
if (storedVal == null)
|
|
{
|
|
return defaultValue;
|
|
}
|
|
|
|
return storedVal == "yes";
|
|
}
|
|
|
|
static GetDateTimeSpecList()
|
|
{
|
|
return [
|
|
{ col: "DateTimeUtc", checked: true },
|
|
{ col: "DateTimeLocal", checked: true },
|
|
];
|
|
}
|
|
|
|
static GetCheckboxSpecListMap()
|
|
{
|
|
return new Map([
|
|
["basicTelemetryVisible", [
|
|
{ col: "BtGpsValid", checked: true },
|
|
{ col: "BtGrid56", checked: false },
|
|
{ col: "BtGrid6", checked: false },
|
|
{ col: "BtLat", checked: false },
|
|
{ col: "BtLng", checked: false },
|
|
{ col: "BtTempC", checked: false },
|
|
{ col: "BtTempF", checked: false },
|
|
{ col: "BtVoltage", checked: false },
|
|
{ col: "BtAltM", checked: false },
|
|
{ col: "BtAltFt", checked: false },
|
|
{ col: "BtKPH", checked: false },
|
|
{ col: "BtMPH", checked: false },
|
|
]],
|
|
["expandedBasicTelemetryVisible", [
|
|
{ col: "EbtGpsValid", checked: true },
|
|
{ col: "EbtVoltage", checked: true },
|
|
{ col: "EbtLat", checked: false },
|
|
{ col: "EbtLng", checked: false },
|
|
{ col: "EbtLatitudeIdx", checked: false },
|
|
{ col: "EbtLongitudeIdx", checked: false },
|
|
{ col: "EbtTempF", checked: false },
|
|
{ col: "EbtAltFt", checked: false },
|
|
{ col: "EbtTempC", checked: false },
|
|
{ col: "EbtAltM", checked: false },
|
|
]],
|
|
["highResLocationVisible", [
|
|
{ col: "HiResLat", checked: true },
|
|
{ col: "HiResLng", checked: true },
|
|
{ col: "HiResReference", checked: false },
|
|
{ col: "HiResLatitudeIdx", checked: false },
|
|
{ col: "HiResLongitudeIdx", checked: false },
|
|
]],
|
|
["resolvedVisible", [
|
|
{ col: "Lat", checked: true },
|
|
{ col: "Lng", checked: true },
|
|
{ col: "TempF", checked: true },
|
|
{ col: "TempC", checked: false },
|
|
{ col: "Voltage", checked: true },
|
|
{ col: "AltFt", checked: true },
|
|
{ col: "AltM", checked: false },
|
|
{ col: "KPH", checked: false },
|
|
{ col: "MPH", checked: true },
|
|
{ col: "AltChgFpm", checked: true },
|
|
{ col: "GpsMPH", checked: true },
|
|
{ col: "DistMi", checked: true },
|
|
{ col: "AltChgMpm", checked: false },
|
|
{ col: "GpsKPH", checked: false },
|
|
{ col: "DistKm", checked: false },
|
|
{ col: "SolAngle", checked: true },
|
|
{ col: "RxStationCount", checked: true },
|
|
{ col: "WinFreqDrift", checked: true },
|
|
]],
|
|
["regularType1Visible", [
|
|
{ col: "RegCall", checked: true },
|
|
{ col: "RegGrid", checked: false },
|
|
{ col: "RegPower", checked: true },
|
|
{ col: "RegLat", checked: false },
|
|
{ col: "RegLng", checked: false },
|
|
]],
|
|
["heartbeatVisible", [
|
|
{ col: "UptimeMinutes", checked: true },
|
|
{ col: "GpsLockType", checked: true },
|
|
{ col: "GpsTryLockSeconds", checked: true },
|
|
{ col: "GpsSatsInViewCount", checked: true },
|
|
{ col: "TxFreqHzIdx", checked: false },
|
|
{ col: "TxFreqMhz", checked: false },
|
|
]],
|
|
]);
|
|
}
|
|
|
|
static GetCheckboxSpecList(storageKey)
|
|
{
|
|
return [... (this.GetCheckboxSpecListMap().get(storageKey) ?? [])];
|
|
}
|
|
|
|
static GetVisibleColumnsForStorageKey(storageKey)
|
|
{
|
|
let specList = [];
|
|
|
|
if (storageKey == "dateTimeVisible")
|
|
{
|
|
specList = this.GetDateTimeSpecList();
|
|
}
|
|
else
|
|
{
|
|
specList = this.GetCheckboxSpecList(storageKey);
|
|
}
|
|
|
|
let visibleColSet = new Set();
|
|
let visibilityMap = this.#GetStoredCheckboxMap(`checkbox.${storageKey}`, specList);
|
|
|
|
for (let spec of specList)
|
|
{
|
|
if (visibilityMap.get(spec.col))
|
|
{
|
|
visibleColSet.add(spec.col);
|
|
}
|
|
}
|
|
|
|
if (storageKey == "dateTimeVisible" && localStorage.getItem("checkbox.dateTimeVisible") == null)
|
|
{
|
|
let dateTimeVisible = localStorage.getItem("dateTimeVisible") ?? "both";
|
|
if (dateTimeVisible == "utc")
|
|
{
|
|
visibleColSet.delete("DateTimeLocal");
|
|
}
|
|
else if (dateTimeVisible == "local")
|
|
{
|
|
visibleColSet.delete("DateTimeUtc");
|
|
}
|
|
}
|
|
|
|
return visibleColSet;
|
|
}
|
|
|
|
static GetVisibleColumnSet(allColList)
|
|
{
|
|
let visibleColSet = new Set(allColList);
|
|
|
|
let hideFromSpec = (storageKey, defaultSpecList) => {
|
|
let visibilityMap = this.#GetStoredCheckboxMap(storageKey, defaultSpecList);
|
|
for (let spec of defaultSpecList)
|
|
{
|
|
if (!visibilityMap.get(spec.col))
|
|
{
|
|
visibleColSet.delete(spec.col);
|
|
}
|
|
}
|
|
};
|
|
|
|
for (let [storageKey, specList] of this.GetCheckboxSpecListMap())
|
|
{
|
|
hideFromSpec(`checkbox.${storageKey}`, specList);
|
|
}
|
|
|
|
hideFromSpec(`checkbox.dateTimeVisible`, this.GetDateTimeSpecList());
|
|
|
|
// Backward compatibility with the prior radio-button DateTime setting.
|
|
// Only apply this if the new checkbox state has never been stored.
|
|
if (localStorage.getItem("checkbox.dateTimeVisible") == null)
|
|
{
|
|
let dateTimeVisible = localStorage.getItem("dateTimeVisible") ?? "both";
|
|
if (dateTimeVisible == "utc")
|
|
{
|
|
visibleColSet.delete("DateTimeLocal");
|
|
}
|
|
else if (dateTimeVisible == "local")
|
|
{
|
|
visibleColSet.delete("DateTimeUtc");
|
|
}
|
|
}
|
|
|
|
let udDecodedVisible = this.GetStoredToggle("udDecodedVisible", true);
|
|
let udRawVisible = this.GetStoredToggle("udRawVisible", false);
|
|
let vdDecodedVisible = this.GetStoredToggle("vdDecodedVisible", true);
|
|
let vdRawVisible = this.GetStoredToggle("vdRawVisible", false);
|
|
|
|
for (let col of allColList)
|
|
{
|
|
if (col.startsWith("slot") && col.includes(".ud."))
|
|
{
|
|
let isRaw = col.endsWith(".EncMsg");
|
|
if ((isRaw && !udRawVisible) || (!isRaw && !udDecodedVisible))
|
|
{
|
|
visibleColSet.delete(col);
|
|
}
|
|
}
|
|
|
|
if (col.startsWith("slot") && col.includes(".vd."))
|
|
{
|
|
let isRaw = col.endsWith(".EncMsg");
|
|
if ((isRaw && !vdRawVisible) || (!isRaw && !vdDecodedVisible))
|
|
{
|
|
visibleColSet.delete(col);
|
|
}
|
|
}
|
|
}
|
|
|
|
return visibleColSet;
|
|
}
|
|
|
|
static #GetStoredCheckboxMap(storageKey, defaultSpecList)
|
|
{
|
|
let storedMap = new Map(defaultSpecList.map(spec => [spec.col, !!spec.checked]));
|
|
let storedVal = localStorage.getItem(storageKey);
|
|
|
|
if (storedVal == null)
|
|
{
|
|
return storedMap;
|
|
}
|
|
|
|
try
|
|
{
|
|
let obj = JSON.parse(storedVal);
|
|
for (let [col, checked] of Object.entries(obj))
|
|
{
|
|
storedMap.set(col, !!checked);
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
|
|
return storedMap;
|
|
}
|
|
}
|