Module: check_mk
Branch: master
Commit: 635c593e0a54809bca8a7e255efa0bcd39a926ef
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=635c593e0a5480…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Jan 13 10:32:39 2014 +0100
Migrated painter options to valuespecs
---
web/htdocs/views.py | 38 +++++++++++++++-----------
web/plugins/views/bi.py | 59 ++++++++++++++++++++++++++---------------
web/plugins/views/painters.py | 52 +++++++++++++++++++++---------------
3 files changed, 92 insertions(+), 57 deletions(-)
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index 20d8591..ab2c303 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -141,10 +141,13 @@ def show_painter_options(painter_options):
html.begin_form("painteroptions")
forms.header(_("Display Options"))
for on in painter_options:
- opt = multisite_painter_options[on]
- forms.section(opt["title"])
- html.select(on, opt["values"], get_painter_option(on),
"submit();" )
+ vs = multisite_painter_options[on]['valuespec']
+ forms.section(vs.title())
+ vs.render_input('po_' + on, get_painter_option(on))
forms.end()
+
+ html.button("painter_options", _("Submit"), "submit")
+
html.hidden_fields()
html.end_form()
html.write('</div>')
@@ -1589,26 +1592,31 @@ def view_options(viewname):
if config.may("general.painter_options"):
for on, opt in multisite_painter_options.items():
- if html.has_var(on):
+ vs = opt['valuespec']
+ value = vs.from_html_vars('po_' + on)
+ if value is None:
+ value = vs.default_value()
+
+ old_value = v.get(on)
+
+ v[on] = value
+ opt['value'] = value
+
+ if v[on] != old_value:
must_save = True
- # Make sure only allowed values are returned
- value = html.var(on)
- for val, title in opt["values"]:
- if value == val:
- v[on] = value
- elif on not in v:
- v[on] = opt["default"]
- opt["value"] = v[on]
else:
for on, opt in multisite_painter_options.items():
if on in v:
del v[on]
- opt["value"] = None
+ must_save = True
+ if 'value' in opt:
+ del opt['value']
if must_save:
vo[viewname] = v
config.save_user_file("viewoptions", vo)
+
return v
@@ -2635,8 +2643,8 @@ def group_value(row, group_painters):
def get_painter_option(name):
opt = multisite_painter_options[name]
if not config.may("general.painter_options"):
- return opt["default"]
- return opt.get("value", opt["default"])
+ return opt['valuespec'].default_value()
+ return opt.get("value", opt['valuespec'].default_value())
def get_host_tags(row):
for name, val in zip(row["host_custom_variable_names"],
diff --git a/web/plugins/views/bi.py b/web/plugins/views/bi.py
index e86e76e..0d0ce6f 100644
--- a/web/plugins/views/bi.py
+++ b/web/plugins/views/bi.py
@@ -171,38 +171,55 @@ multisite_painters["aggr_hosts_services"] = {
}
multisite_painter_options["aggr_expand"] = {
- "title" : _("Initial expansion of aggregations"),
- "default" : "0",
- "values" : [ ("0", "collapsed"), ("1",
"first level"), ("2", "two levels"), ("3",
"three levels"), ("999", "complete")]
+ 'valuespec' : DropdownChoice(
+ title = _("Initial expansion of aggregations"),
+ default_value = "0",
+ choices = [
+ ("0", _("collapsed")),
+ ("1", _("first level")),
+ ("2", _("two levels")),
+ ("3", _("three levels")),
+ ("999", _("complete"))
+ ]
+ )
}
multisite_painter_options["aggr_onlyproblems"] = {
- "title" : _("Show only problems"),
- "default" : "0",
- "values" : [ ("0", "show all"), ("1",
"show only problems")]
+ 'valuespec' : DropdownChoice(
+ title = _("Show only problems"),
+ default_value = "0",
+ choices = [
+ ("0", _("show all")),
+ ("1", _("show only problems"))
+ ],
+ )
}
multisite_painter_options["aggr_treetype"] = {
- "title" : _("Type of tree layout"),
- "default" : "foldable",
- "values" : [
- ("foldable", _("foldable")),
- ("boxes", _("boxes")),
- ("boxes-omit-root", _("boxes (omit root)")),
- ("bottom-up", _("bottom up")),
- ("top-down", _("top down"))]
+ 'valuespec' : DropdownChoice(
+ title = _("Type of tree layout"),
+ default_value = "foldable",
+ choices = [
+ ("foldable", _("foldable")),
+ ("boxes", _("boxes")),
+ ("boxes-omit-root", _("boxes (omit root)")),
+ ("bottom-up", _("bottom up")),
+ ("top-down", _("top down")),
+ ],
+ )
}
multisite_painter_options["aggr_wrap"] = {
- "title" : _("Handling of too long texts"),
- "default" : "wrap",
- "values" : [ ("wrap", "wrap"), ("nowrap",
"don't wrap")]
+ 'valuespec' : DropdownChoice(
+ title = _("Handling of too long texts"),
+ default_value = "wrap",
+ choices = [
+ ("wrap", _("wrap")),
+ ("nowrap", _("don't wrap")),
+ ],
+ )
}
-
-
-
-
def paint_aggr_tree_ltr(row, mirror):
wrap = get_painter_option("aggr_wrap")
diff --git a/web/plugins/views/painters.py b/web/plugins/views/painters.py
index 3f28e1d..9df822e 100644
--- a/web/plugins/views/painters.py
+++ b/web/plugins/views/painters.py
@@ -75,33 +75,43 @@
import bi # needed for aggregation icon
multisite_painter_options["pnpview"] = {
- "title" : _("PNP Timerange"),
- "default" : "1",
- "values" : [ ("0", _("4 Hours")), ("1",
_("25 Hours")),
- ("2", _("One Week")), ("3", _("One
Month")),
- ("4", _("One Year")), ("",
_("All")) ]
+ 'valuespec' : DropdownChoice(
+ title = _("PNP Timerange"),
+ default_value = '1',
+ choices = [
+ ("0", _("4 Hours")), ("1", _("25
Hours")),
+ ("2", _("One Week")), ("3", _("One
Month")),
+ ("4", _("One Year")), ("", _("All"))
+ ],
+ )
}
multisite_painter_options["ts_format"] = {
- "title" : _("Time stamp format"),
- "default" : config.default_ts_format,
- "values" : [
- ("mixed", _("Mixed")),
- ("abs", _("Absolute")),
- ("rel", _("Relative")),
- ("both", _("Both")),
- ("epoch", _("Unix Timestamp (Epoch)")),
- ]
+ 'valuespec': DropdownChoice(
+ title = _("Time stamp format"),
+ default_value = config.default_ts_format,
+ choices = [
+ ("mixed", _("Mixed")),
+ ("abs", _("Absolute")),
+ ("rel", _("Relative")),
+ ("both", _("Both")),
+ ("epoch", _("Unix Timestamp (Epoch)")),
+ ],
+ )
}
multisite_painter_options["ts_date"] = {
- "title" : _("Date format"),
- "default" : "%Y-%m-%d",
- "values" : [ ("%Y-%m-%d", "1970-12-18"),
- ("%d.%m.%Y", "18.12.1970"),
- ("%m/%d/%Y", "12/18/1970"),
- ("%d.%m.", "18.12."),
- ("%m/%d", "12/18") ]
+ 'valuespec' : DropdownChoice(
+ title = _("Date format"),
+ default_value = "%Y-%m-%d",
+ choices = [
+ ("%Y-%m-%d", "1970-12-18"),
+ ("%d.%m.%Y", "18.12.1970"),
+ ("%m/%d/%Y", "12/18/1970"),
+ ("%d.%m.", "18.12."),
+ ("%m/%d", "12/18")
+ ],
+ )
}
# This helper function returns the value of the given custom var