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>
Sat, 18 Apr 2020 21:25:22 +0000 (23:25 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/ui.js

index 625363811c448b888db2801f9ac99140c206ec72..4219932b9ac3d3bdd316b1fcd18f78fd3b6dff5b 100644 (file)
@@ -2944,6 +2944,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.
  *
@@ -2979,7 +3000,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;