Module: check_mk
Branch: master
Commit: 7923900c7d48e106d5a648dae5f91342dc57fa3f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7923900c7d48e1…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Jan 24 14:26:54 2014 +0100
Cleaned up new graph search view option to have only one time range specifier
---
web/htdocs/valuespec.py | 21 ++++++++++++++++++---
web/plugins/views/painters.py | 32 +++++++++++---------------------
2 files changed, 29 insertions(+), 24 deletions(-)
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 43e4ce9..ab619d4 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -1779,12 +1779,13 @@ class Timerange(CascadingDropdown):
def __init__(self, **kwargs):
self._title = _('Time range')
+ if 'choices' not in kwargs:
+ kwargs['choices'] = []
+
if kwargs.get('allow_empty', False):
- kwargs['choices'] = [
+ kwargs['choices'] += [
(None, ''),
]
- else:
- kwargs['choices'] = []
kwargs['choices'] += [
( "d0", _("Today") ),
@@ -1897,6 +1898,20 @@ class Timerange(CascadingDropdown):
from_broken[0] -= 1
return (time.mktime(from_broken), until_time), titles[1]
+class PNPTimerange(Timerange):
+ def __init__(self, **kwargs):
+ kwargs['choices'] = [
+ ('pnp_view', _("PNP View"), DropdownChoice(
+ default_value = '1',
+ choices = [
+ ("0", _("4 Hours")), ("1", _("25
Hours")),
+ ("2", _("One Week")), ("3", _("One
Month")),
+ ("4", _("One Year")), ("",
_("All"))
+ ],
+ )),
+ ]
+ Timerange.__init__(self, **kwargs)
+
# Make a configuration value optional, i.e. it may be None.
# The user has a checkbox for activating the option. Example:
diff --git a/web/plugins/views/painters.py b/web/plugins/views/painters.py
index 873f27b..48178a7 100644
--- a/web/plugins/views/painters.py
+++ b/web/plugins/views/painters.py
@@ -74,23 +74,10 @@
import bi # needed for aggregation icon
-multisite_painter_options["pnpview"] = {
- 'valuespec' : DropdownChoice(
- title = _("PNP View"),
- default_value = '1',
- choices = [
- ("0", _("4 Hours")), ("1", _("25
Hours")),
- ("2", _("One Week")), ("3", _("One
Month")),
- ("4", _("One Year")), ("", _("All"))
- ],
- )
-}
-
multisite_painter_options["pnp_timerange"] = {
- 'valuespec' : Timerange(
+ 'valuespec' : PNPTimerange(
title = _("PNP Timerange"),
default_value = None,
- allow_empty = True,
include_time = True,
)
}
@@ -683,14 +670,17 @@ def paint_pnpgraph(sitename, host, service = "_HOST_"):
with_link = 'true'
else:
with_link = 'false'
- pnpview = get_painter_option("pnpview")
pnp_timerange = get_painter_option("pnp_timerange")
+
+ pnpview = '1'
+ from_ts, to_ts = 'null', 'null'
if pnp_timerange != None:
- vs = multisite_painter_options["pnp_timerange"]['valuespec']
- from_ts, to_ts = map(int, vs.compute_range(pnp_timerange)[0])
- else:
- from_ts, to_ts = 'null', 'null'
+ if pnp_timerange[0] != 'pnp_view':
+ vs =
multisite_painter_options["pnp_timerange"]['valuespec']
+ from_ts, to_ts = map(int, vs.compute_range(pnp_timerange)[0])
+ else:
+ pnpview = pnp_timerange[1]
return "pnpgraph", "<div id=\"%s\"></div>"
\
"<script>render_pnp_graphs('%s', '%s',
'%s', '%s', '%s', '%s', '%s', %s, %s,
%s)</script>" % \
@@ -701,7 +691,7 @@ multisite_painters["svc_pnpgraph" ] = {
"title" : _("PNP service graph"),
"short" : _("PNP graph"),
"columns" : [ "host_name", "service_description" ],
- "options" : [ "pnpview", 'pnp_timerange' ],
+ "options" : [ 'pnp_timerange' ],
"paint" : lambda row: paint_pnpgraph(row["site"],
row["host_name"], row["service_description"]),
}
@@ -1043,7 +1033,7 @@ multisite_painters["host_pnpgraph" ] = {
"title" : _("PNP host graph"),
"short" : _("PNP graph"),
"columns" : [ "host_name" ],
- "options" : [ "pnpview", 'pnp_timerange' ],
+ "options" : [ 'pnp_timerange' ],
"paint" : lambda row: paint_pnpgraph(row["site"],
row["host_name"])
}