luci-mod-network: convert menu nodes to JSON
authorJo-Philipp Wich <jo@mein.io>
Fri, 6 Dec 2019 21:59:33 +0000 (22:59 +0100)
committerJo-Philipp Wich <jo@mein.io>
Mon, 16 Dec 2019 17:07:18 +0000 (18:07 +0100)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-mod-network/luasrc/controller/admin/network.lua
modules/luci-mod-network/root/usr/share/luci/menu.d/luci-mod-network.json [new file with mode: 0644]

index bd00235faafd934fd9868058f7bf1f12f1aed081..4e9d27e8a852e7ce949db8d1ba11a1b6a37865ed 100644 (file)
@@ -4,63 +4,6 @@
 
 module("luci.controller.admin.network", package.seeall)
 
-function index()
-       local page
-
---     if page.inreq then
-               page = entry({"admin", "network", "switch"}, view("network/switch"), _("Switch"), 20)
-               page.uci_depends = { network = { ["@switch[0]"] = "switch" } }
-
-               page = entry({"admin", "network", "wireless"}, view("network/wireless"), _('Wireless'), 15)
-               page.uci_depends = { wireless = { ["@wifi-device[0]"] = "wifi-device" } }
-               page.leaf = true
-
-               page = entry({"admin", "network", "remote_addr"}, call("remote_addr"), nil)
-               page.leaf = true
-
-               page = entry({"admin", "network", "network"}, view("network/interfaces"), _("Interfaces"), 10)
-               page.leaf   = true
-               page.subindex = true
-
-               page = node("admin", "network", "dhcp")
-               page.uci_depends = { dhcp = true }
-               page.target = view("network/dhcp")
-               page.title  = _("DHCP and DNS")
-               page.order  = 30
-
-               page = node("admin", "network", "hosts")
-               page.uci_depends = { dhcp = true }
-               page.target = view("network/hosts")
-               page.title  = _("Hostnames")
-               page.order  = 40
-
-               page  = node("admin", "network", "routes")
-               page.target = view("network/routes")
-               page.title  = _("Static Routes")
-               page.order  = 50
-
-               page = node("admin", "network", "diagnostics")
-               page.target = template("admin_network/diagnostics")
-               page.title  = _("Diagnostics")
-               page.order  = 60
-
-               page = entry({"admin", "network", "diag_ping"}, post("diag_ping"), nil)
-               page.leaf = true
-
-               page = entry({"admin", "network", "diag_nslookup"}, post("diag_nslookup"), nil)
-               page.leaf = true
-
-               page = entry({"admin", "network", "diag_traceroute"}, post("diag_traceroute"), nil)
-               page.leaf = true
-
-               page = entry({"admin", "network", "diag_ping6"}, post("diag_ping6"), nil)
-               page.leaf = true
-
-               page = entry({"admin", "network", "diag_traceroute6"}, post("diag_traceroute6"), nil)
-               page.leaf = true
---     end
-end
-
 local function addr2dev(addr, src)
        local ip = require "luci.ip"
        local route = ip.route(addr, src)
diff --git a/modules/luci-mod-network/root/usr/share/luci/menu.d/luci-mod-network.json b/modules/luci-mod-network/root/usr/share/luci/menu.d/luci-mod-network.json
new file mode 100644 (file)
index 0000000..990c5d3
--- /dev/null
@@ -0,0 +1,130 @@
+{
+       "admin/network/switch": {
+               "title": "Switch",
+               "order": 20,
+               "action": {
+                       "type": "view",
+                       "path": "network/switch"
+               },
+               "depends": {
+                       "fs": { "/sbin/swconfig": "executable" },
+                       "uci": { "network": { "@switch": true } }
+               }
+       },
+
+       "admin/network/wireless": {
+               "title": "Wireless",
+               "order": 15,
+               "action": {
+                       "type": "view",
+                       "path": "network/wireless"
+               },
+               "depends": {
+                       "uci": { "wireless": { "@wifi-device": true } }
+               }
+       },
+
+       "admin/network/remote_addr/*": {
+               "action": {
+                       "type": "call",
+                       "module": "luci.controller.admin.network",
+                       "function": "remote_addr"
+               }
+       },
+
+       "admin/network/network": {
+               "title": "Interfaces",
+               "order": 10,
+               "action": {
+                       "type": "view",
+                       "path": "network/interfaces"
+               }
+       },
+
+       "admin/network/dhcp": {
+               "title": "DHCP and DNS",
+               "order": 30,
+               "action": {
+                       "type": "view",
+                       "path": "network/dhcp"
+               },
+               "depends": {
+                       "uci": { "dhcp": true }
+               }
+       },
+
+       "admin/network/hosts": {
+               "title": "Hostnames",
+               "order": 40,
+               "action": {
+                       "type": "view",
+                       "path": "network/hosts"
+               },
+               "depends": {
+                       "uci": { "dhcp": true }
+               }
+       },
+
+       "admin/network/routes": {
+               "title": "Static Routes",
+               "order": 50,
+               "action": {
+                       "type": "view",
+                       "path": "network/routes"
+               }
+       },
+
+       "admin/network/diagnostics": {
+               "title": "Diagnostics",
+               "order": 60,
+               "action": {
+                       "type": "template",
+                       "path": "admin_network/diagnostics"
+               }
+       },
+
+       "admin/network/diag_ping/*": {
+               "action": {
+                       "post": true,
+                       "type": "call",
+                       "module": "luci.controller.admin.network",
+                       "function": "diag_ping"
+               }
+       },
+
+       "admin/network/diag_nslookup/*": {
+               "action": {
+                       "post": true,
+                       "type": "call",
+                       "module": "luci.controller.admin.network",
+                       "function": "diag_nslookup"
+               }
+       },
+
+       "admin/network/diag_traceroute/*": {
+               "action": {
+                       "post": true,
+                       "type": "call",
+                       "module": "luci.controller.admin.network",
+                       "function": "diag_traceroute"
+               }
+       },
+
+       "admin/network/diag_ping6/*": {
+               "action": {
+                       "post": true,
+                       "type": "call",
+                       "module": "luci.controller.admin.network",
+                       "function": "diag_ping6"
+               }
+       },
+
+       "admin/network/diag_traceroute6/*": {
+               "action": {
+                       "post": true,
+                       "type": "call",
+                       "module": "luci.controller.admin.network",
+                       "function": "diag_traceroute6"
+               }
+       }
+}