luci-app-statisctis: only include lua modules in rrd statistics into local scope
[project/luci.git] / applications / luci-app-statistics / luasrc / statistics / i18n.lua
1 -- Copyright 2008 Freifunk Leipzig / Jo-Philipp Wich <jow@openwrt.org>
2 -- Licensed to the public under the Apache License 2.0.
3
4 module("luci.statistics.i18n", package.seeall)
5
6 local util = require("luci.util")
7 local i18n = require("luci.i18n")
8
9
10 Instance = util.class()
11
12 function Instance.__init__( self, graph )
13 self.i18n = i18n
14 self.graph = graph
15 end
16
17 function Instance._subst( self, str, val )
18 str = str:gsub( "%%H", self.graph.opts.host or "" )
19 str = str:gsub( "%%pn", val.plugin or "" )
20 str = str:gsub( "%%pi", val.pinst or "" )
21 str = str:gsub( "%%dt", val.dtype or "" )
22 str = str:gsub( "%%di", val.dinst or "" )
23 str = str:gsub( "%%ds", val.dsrc or "" )
24
25 return str
26 end
27
28 function Instance.title( self, plugin, pinst, dtype, dinst, user_title )
29
30 local title = user_title or
31 "p=%s/pi=%s/dt=%s/di=%s" % {
32 plugin,
33 (pinst and #pinst > 0) and pinst or "(nil)",
34 (dtype and #dtype > 0) and dtype or "(nil)",
35 (dinst and #dinst > 0) and dinst or "(nil)"
36 }
37
38 return self:_subst( title, {
39 plugin = plugin,
40 pinst = pinst,
41 dtype = dtype,
42 dinst = dinst
43 } )
44
45 end
46
47 function Instance.label( self, plugin, pinst, dtype, dinst, user_label )
48
49 local label = user_label or
50 "dt=%s/di=%s" % {
51 (dtype and #dtype > 0) and dtype or "(nil)",
52 (dinst and #dinst > 0) and dinst or "(nil)"
53 }
54
55 return self:_subst( label, {
56 plugin = plugin,
57 pinst = pinst,
58 dtype = dtype,
59 dinst = dinst
60 } )
61
62 end
63
64 function Instance.ds( self, source )
65
66 local label = source.title or
67 "dt=%s/di=%s/ds=%s" % {
68 (source.type and #source.type > 0) and source.type or "(nil)",
69 (source.instance and #source.instance > 0) and source.instance or "(nil)",
70 (source.ds and #source.ds > 0) and source.ds or "(nil)"
71 }
72
73 return self:_subst( label, {
74 dtype = source.type,
75 dinst = source.instance,
76 dsrc = source.ds
77 } ):gsub(":", "\\:")
78
79 end