luci-base: ui.js: hide unsatisfied firstchild menu nodes
authorJo-Philipp Wich <jo@mein.io>
Sat, 18 Apr 2020 21:05:01 +0000 (23:05 +0200)
committerJo-Philipp Wich <jo@mein.io>
Thu, 7 May 2020 17:40:50 +0000 (19:40 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit 7882f3ebdde0364314a45aa6dd8fbc4e766e8ea8)

modules/luci-base/htdocs/luci-static/resources/ui.js

index 06520f7f8ccd3caef4d88b35c677e66200be6bd8..d860638e96861d7b4487471ac1942e5e4d08fcef 100644 (file)
@@ -2951,6 +2951,27 @@ var UIFileUpload = UIElement.extend(/** @lends LuCI.ui.FileUpload.prototype */ {
        }
 });
 
+
+function scrubMenu(node) {
+       var hasSatisfiedChild = false;
+
+       if (L.isObject(node.children)) {
+               for (var k in node.children) {
+                       var child = scrubMenu(node.children[k]);
+
+                       if (child.title)
+                               hasSatisfiedChild = hasSatisfiedChild || child.satisfied;
+               }
+       }
+
+       if (L.isObject(node.action) &&
+           node.action.type == 'firstchild' &&
+           hasSatisfiedChild == false)
+               node.satisfied = false;
+
+       return node;
+};
+
 /**
  * Handle menu.
  *
@@ -2986,7 +3007,7 @@ var UIMenu = baseclass.singleton(/** @lends LuCI.ui.menu.prototype */ {
 
                if (!L.isObject(this.menu)) {
                        this.menu = request.get(L.url('admin/menu')).then(L.bind(function(menu) {
-                               this.menu = menu.json();
+                               this.menu = scrubMenu(menu.json());
                                session.setLocalData('menu', this.menu);
 
                                return this.menu;