luci-base: ui: resolve aliases and rewrites on obtaining menu node children
authorJo-Philipp Wich <jo@mein.io>
Thu, 28 Apr 2022 14:06:25 +0000 (16:06 +0200)
committerJo-Philipp Wich <jo@mein.io>
Thu, 28 Apr 2022 14:06:25 +0000 (16:06 +0200)
Extend LuCI.ui.menu.getChildren() to resolve aliases and rewrites prior to
returning the menu nodes. This allows aliasing entire menu trees instead of
just single pages.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/ui.js

index 5abd3b388d157c880d0fcef9b5347c7730cbf5cb..b8763ef160537a9e33b197a7e4ce186517f0f2c9 100644 (file)
@@ -3125,7 +3125,24 @@ var UIMenu = baseclass.singleton(/** @lends LuCI.ui.menu.prototype */ {
                        if (!node.children[k].hasOwnProperty('title'))
                                continue;
 
-                       children.push(Object.assign(node.children[k], { name: k }));
+                       var subnode = Object.assign(node.children[k], { name: k });
+
+                       if (L.isObject(subnode.action) && subnode.action.path != null &&
+                           (subnode.action.type == 'alias' || subnode.action.type == 'rewrite')) {
+                               var root = this.menu,
+                                   path = subnode.action.path.split('/');
+
+                               for (var i = 0; root != null && i < path.length; i++)
+                                       root = L.isObject(root.children) ? root.children[path[i]] : null;
+
+                               if (root)
+                                       subnode = Object.assign({}, subnode, {
+                                               children: root.children,
+                                               action: root.action
+                                       });
+                       }
+
+                       children.push(subnode);
                }
 
                return children.sort(function(a, b) {