From 556e14c74307a9b93291e7c25d5eb71ab3260ab6 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Thu, 6 Feb 2020 12:07:08 +0100 Subject: luci-app-statistics: convert plugin definitions to JSON Signed-off-by: Jo-Philipp Wich --- .../luasrc/controller/luci_statistics/luci_statistics.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'applications/luci-app-statistics/luasrc/controller') diff --git a/applications/luci-app-statistics/luasrc/controller/luci_statistics/luci_statistics.lua b/applications/luci-app-statistics/luasrc/controller/luci_statistics/luci_statistics.lua index 4c5db17d83..529cc2335a 100644 --- a/applications/luci-app-statistics/luasrc/controller/luci_statistics/luci_statistics.lua +++ b/applications/luci-app-statistics/luasrc/controller/luci_statistics/luci_statistics.lua @@ -9,6 +9,7 @@ function index() require("nixio.fs") require("luci.util") require("luci.statistics.datatree") + require("luci.jsonc") -- override entry(): check for existence .so where is derived from the called path function _entry( path, ... ) @@ -31,14 +32,14 @@ function index() network = { } } - local plugin_dir = "/usr/lib/lua/luci/statistics/plugins/" + local plugin_dir = "/usr/share/luci/statistics/plugins/" for filename in nixio.fs.dir(plugin_dir) do - local plugin_fun = loadfile(plugin_dir .. filename) - setfenv(plugin_fun, { _ = luci.i18n.translate }) - local plugin = plugin_fun() - local name = filename:gsub("%.lua", "") - table.insert(collectd_menu[plugin.category], name) - labels[name] = plugin.label + local plugin_def = luci.jsonc.parse(nixio.fs.readfile(plugin_dir .. filename)) + if type(plugin_def) == "table" then + local name = filename:gsub("%.json", "") + table.insert(collectd_menu[plugin_def.category], name) + labels[name] = plugin_def.title + end end -- create toplevel menu nodes -- cgit v1.2.3