* luci/statistics: generate submenus for plugins with multiple instances, i18n menu...
authorJo-Philipp Wich <jow@openwrt.org>
Thu, 29 May 2008 00:59:58 +0000 (00:59 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Thu, 29 May 2008 00:59:58 +0000 (00:59 +0000)
applications/luci-statistics/luasrc/controller/luci_statistics/luci_statistics.lua
applications/luci-statistics/luasrc/i18n/statistics.en

index 871a3585ed3f518906b53e8a97e7d025868ce867..76fb373da59453db7dd5ff9888462362c7c8ef29 100644 (file)
@@ -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 )
index 3c7514a47cd4f1efad714185cdb5b1e4ede1c549..a3d3a61a9dca0dca3443016ebbe1bf30c2342ac2 100644 (file)
@@ -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"