feat(ui): remember workspaces per rig
This commit is contained in:
@@ -1282,6 +1282,7 @@ function applyRigList(activeRigId, rigIds, displayNames) {
|
||||
const disableSwitch = lastRigIds.length === 0 || !authRole || authRole === "rx";
|
||||
populateRigPicker(headerRigSwitchSelect, lastRigIds, lastActiveRigId, disableSwitch);
|
||||
updateRigSubtitle(lastActiveRigId);
|
||||
window.trxUi?.setActiveRig(lastActiveRigId);
|
||||
if (rigListChanged) {
|
||||
if (typeof setSchedulerRig === "function") setSchedulerRig(lastActiveRigId);
|
||||
if (typeof setBackgroundDecodeRig === "function") setBackgroundDecodeRig(lastActiveRigId);
|
||||
|
||||
@@ -132,6 +132,15 @@
|
||||
full: { label: "Full controls", description: "Every control supported by the selected rig", advanced: true, preferredTab: "main" },
|
||||
};
|
||||
const layoutCapabilities = { broadcast: false, digital: false };
|
||||
let activeRigId = null;
|
||||
|
||||
function layoutStorageKey() {
|
||||
return activeRigId ? `trxOperatorLayout:${activeRigId}` : "trxOperatorLayout";
|
||||
}
|
||||
|
||||
function savedLayoutName() {
|
||||
return localStorage.getItem(layoutStorageKey()) || localStorage.getItem("trxOperatorLayout") || "compact";
|
||||
}
|
||||
|
||||
function layoutAvailable(layout) {
|
||||
return !layout.capability || layoutCapabilities[layout.capability] === true;
|
||||
@@ -148,7 +157,7 @@
|
||||
});
|
||||
const available = Array.from(select.options).some(option => option.value === previous);
|
||||
select.value = available ? previous : "compact";
|
||||
if (!available && previous === "broadcast") api.applyLayout("compact");
|
||||
if (!available && previous !== "compact") api.applyLayout("compact", { persist: false });
|
||||
}
|
||||
|
||||
api.setLayoutCapabilities = function setLayoutCapabilities(capabilities = {}) {
|
||||
@@ -156,6 +165,20 @@
|
||||
if (name in capabilities) layoutCapabilities[name] = Boolean(capabilities[name]);
|
||||
});
|
||||
refreshLayoutOptions();
|
||||
const select = document.getElementById("operator-layout-select");
|
||||
const saved = savedLayoutName();
|
||||
if (select && Array.from(select.options).some(option => option.value === saved)) {
|
||||
select.value = saved;
|
||||
api.applyLayout(saved, { persist: false });
|
||||
}
|
||||
};
|
||||
|
||||
api.setActiveRig = function setActiveRig(rigId) {
|
||||
activeRigId = typeof rigId === "string" && rigId ? rigId : null;
|
||||
const saved = savedLayoutName();
|
||||
const select = document.getElementById("operator-layout-select");
|
||||
if (select) select.value = Array.from(select.options).some(option => option.value === saved) ? saved : "compact";
|
||||
api.applyLayout(select?.value || saved, { persist: false });
|
||||
};
|
||||
|
||||
api.applyLayout = function applyLayout(name, options = {}) {
|
||||
@@ -163,7 +186,7 @@
|
||||
const permittedName = requestedLayout && layoutAvailable(requestedLayout) ? name : "compact";
|
||||
const layout = layouts[permittedName];
|
||||
document.body.dataset.operatorLayout = permittedName in layouts ? permittedName : "compact";
|
||||
localStorage.setItem("trxOperatorLayout", document.body.dataset.operatorLayout);
|
||||
if (options.persist !== false) localStorage.setItem(layoutStorageKey(), document.body.dataset.operatorLayout);
|
||||
const details = document.getElementById("advanced-radio-controls");
|
||||
if (details) details.open = layout.advanced;
|
||||
const description = document.getElementById("operator-layout-description");
|
||||
@@ -180,7 +203,7 @@
|
||||
label.className = "operator-layout-picker";
|
||||
label.innerHTML = '<span class="visually-hidden">Operator layout</span><select id="operator-layout-select" aria-label="Operator layout" aria-describedby="operator-layout-description"></select><span id="operator-layout-description" class="operator-layout-description"></span>';
|
||||
const select = label.querySelector("select");
|
||||
const savedLayout = localStorage.getItem("trxOperatorLayout") || "compact";
|
||||
const savedLayout = savedLayoutName();
|
||||
actions.insertBefore(label, actions.firstChild);
|
||||
select.value = savedLayout;
|
||||
refreshLayoutOptions();
|
||||
@@ -201,7 +224,7 @@
|
||||
if (element) body.appendChild(element);
|
||||
});
|
||||
tray.appendChild(details);
|
||||
api.applyLayout(localStorage.getItem("trxOperatorLayout") || "compact");
|
||||
api.applyLayout(savedLayoutName(), { persist: false });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user