From 908332e3e9ba183d2d18ce302fb1478a41d2631b Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Thu, 29 May 2008 00:59:58 +0000 Subject: [PATCH] * luci/statistics: generate submenus for plugins with multiple instances, i18n menu entries --- .../luci_statistics/luci_statistics.lua | 50 +++++++++++++++++-- .../luci-statistics/luasrc/i18n/statistics.en | 11 ++++ 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/applications/luci-statistics/luasrc/controller/luci_statistics/luci_statistics.lua b/applications/luci-statistics/luasrc/controller/luci_statistics/luci_statistics.lua index 871a3585e..76fb373da 100644 --- a/applications/luci-statistics/luasrc/controller/luci_statistics/luci_statistics.lua +++ b/applications/luci-statistics/luasrc/controller/luci_statistics/luci_statistics.lua @@ -1,13 +1,16 @@ module("luci.controller.luci_statistics.luci_statistics", package.seeall) local fs = require("luci.fs") +local i18n = require("luci.i18n") local tpl = require("luci.template") local rrd = require("luci.statistics.rrdtool") local data = require("luci.statistics.datatree").Instance() - function index() + -- XXX: fixme + i18n.load("statistics.en") + function _entry( path, ... ) local file = path[4] or path[3] if fs.isfile( "/usr/lib/collectd/" .. file .. ".so" ) then @@ -15,6 +18,9 @@ function index() end end + function _i18n( str ) + return i18n.translate( "stat_" .. str, str ) + end entry({"admin", "statistics"}, call("statistics_index"), "Statistiken", 80) entry({"admin", "statistics", "collectd"}, cbi("luci_statistics/collectd"), "Collectd", 10) @@ -47,7 +53,20 @@ function index() entry({"freifunk", "statistics"}, call("statistics_index"), "Statistiken", 80).i18n = "statistics" for i, plugin in ipairs( data:plugins() ) do - _entry({"freifunk", "statistics", plugin}, call("statistics_render"), plugin, i) + + -- get plugin instances + local instances = data:plugin_instances( plugin ) + + -- plugin menu entry + _entry( { "freifunk", "statistics", plugin }, call("statistics_render"), _i18n( plugin ), i ) + + -- if more then one instance is found then generate submenu + if #instances > 1 then + for j, inst in ipairs(instances) do + -- instance menu entry + entry( { "freifunk", "statistics", plugin, inst }, call("statistics_render"), inst, j ) + end + end end end @@ -94,10 +113,31 @@ end function statistics_render() - local plugin = luci.dispatcher.request[3] - local images = { } + local plugin = luci.dispatcher.request[3] + local instances = { luci.dispatcher.request[4] } + local images = { } + + -- no instance requested, find all instances + if #instances == 0 then + + instances = data:plugin_instances( plugin ) + + -- more than one available instance + if #instances > 1 then + + -- redirect to first instance and return + local r = luci.dispatcher.request + + luci.http.redirect( luci.dispatcher.build_url( { + r[1], r[2], r[3], instances[1] + } ) ) + + return + end + end - for i, inst in ipairs( data:plugin_instances( plugin ) ) do + -- render graphs + for i, inst in ipairs( instances ) do local graph = rrd.Graph() for i, img in ipairs( graph:render( plugin, inst ) ) do table.insert( images, img ) diff --git a/applications/luci-statistics/luasrc/i18n/statistics.en b/applications/luci-statistics/luasrc/i18n/statistics.en index 3c7514a47..a3d3a61a9 100644 --- a/applications/luci-statistics/luasrc/i18n/statistics.en +++ b/applications/luci-statistics/luasrc/i18n/statistics.en @@ -1,3 +1,14 @@ +-- plugins +stat_cpu = "Processor" +stat_ping = "Ping" +stat_iptables = "Firewall" +stat_netlink = "Netlink" +stat_processes = "Processes" +stat_wireless = "Wireless" +stat_tcpconns = "TCP Connections" +stat_interface = "Interfaces" + +-- diagrams stat_dg_title_wireless__signal_noise = "%H: Wireless - Signal Noise Ratio" stat_dg_label_wireless__signal_noise = "dBm" stat_ds_signal_noise = "Noise Level" -- 2.25.1