From 6a68e55ac44b72d4f729a2d468482d0231a7b3a4 Mon Sep 17 00:00:00 2001 From: Erwin Dondorp Date: Thu, 26 Nov 2020 02:10:42 +0100 Subject: [PATCH 01/15] delay lookup until needed, and this after the item is (re)created --- saltgui/static/scripts/Router.js | 4 ++-- saltgui/static/scripts/pages/Page.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/saltgui/static/scripts/Router.js b/saltgui/static/scripts/Router.js index dc9a9a103..1c2e07dad 100644 --- a/saltgui/static/scripts/Router.js +++ b/saltgui/static/scripts/Router.js @@ -220,7 +220,7 @@ export class Router { menuItem.classList.remove("menu-item-active"); }); - const elem1 = pPage.menuItemElement1; + const elem1 = document.getElementById(pPage.menuItemElement1); if (elem1) { elem1.classList.add("menu-item-active"); // activate also parent menu item if child element is selected @@ -243,7 +243,7 @@ export class Router { } } - const elem2 = pPage.menuItemElement2; + const elem2 = document.getElementById(pPage.menuItemElement2); if (elem2) { elem2.classList.add("menu-item-active"); } diff --git a/saltgui/static/scripts/pages/Page.js b/saltgui/static/scripts/pages/Page.js index ea4b4d32d..122347894 100644 --- a/saltgui/static/scripts/pages/Page.js +++ b/saltgui/static/scripts/pages/Page.js @@ -23,8 +23,8 @@ export class Page { this.pageElement = div; this.router = pRouter; if (pMenuItemSelector) { - this.menuItemElement1 = document.getElementById(pMenuItemSelector + "1"); - this.menuItemElement2 = document.getElementById(pMenuItemSelector + "2"); + this.menuItemElement1 = pMenuItemSelector + "1"; + this.menuItemElement2 = pMenuItemSelector + "2"; } this.panels = []; From 0ff5afc85e3cdd2393b2e97b5340e0e02a78281a Mon Sep 17 00:00:00 2001 From: Erwin Dondorp Date: Thu, 26 Nov 2020 11:07:46 +0100 Subject: [PATCH 02/15] don't let pages be aware that they are the default page --- saltgui/static/scripts/Router.js | 6 ++++++ saltgui/static/scripts/pages/Minions.js | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/saltgui/static/scripts/Router.js b/saltgui/static/scripts/Router.js index 1c2e07dad..45bd7f751 100644 --- a/saltgui/static/scripts/Router.js +++ b/saltgui/static/scripts/Router.js @@ -153,6 +153,11 @@ export class Router { pQuery = {"reason": "no-session"}; } + if (pPath === "/") { + // go to the concrete default page + pPath = "/minions"; + } + // save the details from the parent const parentHash = document.location.hash.replace(/^#/, ""); const search = window.location.search; @@ -201,6 +206,7 @@ export class Router { this._showPage(route); return; } + // route could not be found // just go to the main page if (pHash === "") { diff --git a/saltgui/static/scripts/pages/Minions.js b/saltgui/static/scripts/pages/Minions.js index ee930d7a9..11279b605 100644 --- a/saltgui/static/scripts/pages/Minions.js +++ b/saltgui/static/scripts/pages/Minions.js @@ -7,7 +7,7 @@ import {Page} from "./Page.js"; export class MinionsPage extends Page { constructor (pRouter) { - super("", "Minions", "page-minions", "button-minions", pRouter); + super("minions", "Minions", "page-minions", "button-minions", pRouter); this.minions = new MinionsPanel(); super.addPanel(this.minions); From 8e04e015007f89473813010a852fcb7b713fb924 Mon Sep 17 00:00:00 2001 From: Erwin Dondorp Date: Thu, 26 Nov 2020 11:22:33 +0100 Subject: [PATCH 03/15] cache the list of allowed pages --- saltgui/static/scripts/panels/Login.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/saltgui/static/scripts/panels/Login.js b/saltgui/static/scripts/panels/Login.js index eac0b996c..0199d40bf 100644 --- a/saltgui/static/scripts/panels/Login.js +++ b/saltgui/static/scripts/panels/Login.js @@ -215,6 +215,9 @@ export class LoginPanel extends Panel { const reactors = wheelConfigValuesData.reactor; Utils.setStorageItem("session", "reactors", JSON.stringify(reactors)); + const pages = wheelConfigValuesData.saltgui_pages; + Utils.setStorageItem("session", "pages", JSON.stringify(pages)); + const publicPillars = wheelConfigValuesData.saltgui_public_pillars; Utils.setStorageItem("session", "public_pillars", JSON.stringify(publicPillars)); From 28b5e4eabe8fb10dec77f6b959223a3975a9f95d Mon Sep 17 00:00:00 2001 From: Erwin Dondorp Date: Thu, 26 Nov 2020 13:33:02 +0100 Subject: [PATCH 04/15] use the first allowed page as landing page --- saltgui/static/scripts/Router.js | 38 +++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/saltgui/static/scripts/Router.js b/saltgui/static/scripts/Router.js index 45bd7f751..5f6f034bf 100644 --- a/saltgui/static/scripts/Router.js +++ b/saltgui/static/scripts/Router.js @@ -141,6 +141,37 @@ export class Router { } } + static _getUserName () { + const loginResponseStr = Utils.getStorageItem("session", "login-response", "{}"); + try { + const loginResponse = JSON.parse(loginResponseStr); + return loginResponse.user; + } catch (err) { + console.error("error in object login-response=" + loginResponseStr + " --> " + err.name + ": " + err.message); + return null; + } + } + + static _getPagesList () { + const pagesText = Utils.getStorageItem("session", "pages", "{}"); + let pages; + try { + pages = JSON.parse(pagesText); + } catch (err) { + console.error("error in object saltgui_pages=" + pagesText + " --> " + err.name + ": " + err.message); + return {}; + } + const userName = Router._getUserName(); + if (!userName || typeof pages !== "object" || !(userName in pages)) { + return []; + } + const ret = pages[userName]; + if (!ret || ret[0] === "*") { + return []; + } + return ret; + } + // pForward = 0 --> normal navigation // pForward = 1 --> back navigation using regular gui // pForward = 2 --> back navigation using browser @@ -153,9 +184,14 @@ export class Router { pQuery = {"reason": "no-session"}; } + const pages = Router._getPagesList(); if (pPath === "/") { // go to the concrete default page - pPath = "/minions"; + if (pages.length) { + pPath = "/" + pages[0]; + } else { + pPath = "/minions"; + } } // save the details from the parent From 26acf72383cd5e3f0844c7580be2425233d317cd Mon Sep 17 00:00:00 2001 From: Erwin Dondorp Date: Thu, 26 Nov 2020 13:42:55 +0100 Subject: [PATCH 05/15] build menu dynamically and with only the allowed options --- saltgui/index.html | 40 +-------- saltgui/static/scripts/Router.js | 140 ++++++++++++++++++++++--------- 2 files changed, 102 insertions(+), 78 deletions(-) diff --git a/saltgui/index.html b/saltgui/index.html index b18f9042f..2d2ac5839 100644 --- a/saltgui/index.html +++ b/saltgui/index.html @@ -24,31 +24,7 @@