This commit is contained in:
38
www/nav.js
38
www/nav.js
@@ -8,7 +8,8 @@
|
||||
|
||||
const MODULES = {
|
||||
dashboards: {
|
||||
items: [{ section: "dashboard", page: "dashboard" }],
|
||||
items: [{ section: "dashboard-list", page: "dashboard" }],
|
||||
dynamic: true,
|
||||
},
|
||||
setup: {
|
||||
items: [
|
||||
@@ -28,7 +29,7 @@
|
||||
};
|
||||
|
||||
const PAGE_NAV = {
|
||||
dashboard: { module: "dashboards", section: "dashboard" },
|
||||
dashboard: { module: "dashboards", section: "dashboard-list" },
|
||||
config: { module: "setup", section: "maps" },
|
||||
missions: { module: "setup", section: "missions" },
|
||||
integrations: { module: "system", section: "integrations" },
|
||||
@@ -54,10 +55,24 @@
|
||||
return true;
|
||||
}
|
||||
|
||||
function moduleItems(moduleId) {
|
||||
const mod = MODULES[moduleId];
|
||||
if (!mod) return [];
|
||||
if (mod.dynamic && moduleId === "dashboards" && window.DashboardApp?.getNavItems) {
|
||||
return window.DashboardApp.getNavItems();
|
||||
}
|
||||
return mod.items;
|
||||
}
|
||||
|
||||
function visibleItems(moduleId) {
|
||||
const mod = MODULES[moduleId];
|
||||
if (!mod) return [];
|
||||
return mod.items.filter((item) => canAccessPage(item.page));
|
||||
return moduleItems(moduleId).filter((item) => canAccessPage(item.page));
|
||||
}
|
||||
|
||||
function itemLabel(item) {
|
||||
if (item.label) return item.label;
|
||||
return t(item.section);
|
||||
}
|
||||
|
||||
function moduleHasAccess(moduleId) {
|
||||
@@ -89,7 +104,7 @@
|
||||
btn.className = "mirNavFlyoutItem";
|
||||
btn.dataset.section = item.section;
|
||||
btn.dataset.page = item.page;
|
||||
btn.textContent = t(item.section);
|
||||
btn.textContent = itemLabel(item);
|
||||
if (item.section === activeSection) {
|
||||
btn.classList.add("is-active");
|
||||
btn.setAttribute("aria-current", "page");
|
||||
@@ -159,6 +174,14 @@
|
||||
saveState();
|
||||
updateRailUI();
|
||||
navigateToPage(page);
|
||||
if (page === "dashboard") window.DashboardApp?.handleNav?.(section);
|
||||
}
|
||||
|
||||
function syncDashboardSection(section) {
|
||||
activeModule = "dashboards";
|
||||
activeSection = section.startsWith("dashboard-") || section === "dashboard-list" ? section : `dashboard-${section}`;
|
||||
saveState();
|
||||
updateRailUI();
|
||||
}
|
||||
|
||||
function navigateToPage(page) {
|
||||
@@ -172,6 +195,7 @@
|
||||
activeSection = nav.section;
|
||||
saveState();
|
||||
updateRailUI();
|
||||
if (page === "dashboard") window.DashboardApp?.handleNav?.(activeSection);
|
||||
}
|
||||
|
||||
function toggleFlyout() {
|
||||
@@ -231,6 +255,10 @@
|
||||
navigateToPage(page);
|
||||
}
|
||||
|
||||
function refreshFlyout() {
|
||||
updateRailUI();
|
||||
}
|
||||
|
||||
function refreshLabels() {
|
||||
window.I18n?.applyDOM?.();
|
||||
updateRailUI();
|
||||
@@ -260,9 +288,11 @@
|
||||
window.NavApp = {
|
||||
init,
|
||||
syncFromPage,
|
||||
syncDashboardSection,
|
||||
applyPermissions,
|
||||
selectModule,
|
||||
selectSection,
|
||||
toggleFlyout,
|
||||
refreshFlyout,
|
||||
};
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user