luci-base: ui: resolve aliases and rewrites on obtaining menu node children
authorJo-Philipp Wich <[email protected]>
Thu, 28 Apr 2022 14:06:25 +0000 (16:06 +0200)
committerJo-Philipp Wich <[email protected]>
Mon, 5 Dec 2022 09:43:14 +0000 (10:43 +0100)
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 <[email protected]>
(cherry picked from commit 180d39dcd2427e3c32c0ec7ecc3c7bfb48c0d0ab)

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

index a66f2519c548926f0638780bc8a9ff6fdd0f8b36..447bcbae09afb3539b532fdda62e3f07a7b19f25 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) {