Module: check_mk
Branch: master
Commit: 4126bbf186e13f2e8f5fdbe9958234adadf27774
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4126bbf186e13f…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Tue Feb 28 10:06:54 2017 +0100
4477 Now graph time ranges are configurable
Change-Id: Ib053606af0356908f029ea05512eab88b1535aeb
---
.werks/4477 | 11 +++++++++++
web/htdocs/valuespec.py | 51 ++++++++++++++++++++++++++++++-------------------
2 files changed, 42 insertions(+), 20 deletions(-)
diff --git a/.werks/4477 b/.werks/4477
new file mode 100644
index 0000000..279dd7d
--- /dev/null
+++ b/.werks/4477
@@ -0,0 +1,11 @@
+Title: Now graph time ranges are configurable
+Level: 1
+Component: metrics
+Class: feature
+Compatible: compat
+Edition: cee
+State: unknown
+Version: 1.5.0i1
+Date: 1488272765
+
+
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 13743bf..ef175a4 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -2724,23 +2724,21 @@ class TimeHelper(object):
class Timerange(CascadingDropdown):
def __init__(self, **kwargs):
- self._title = _('Time range')
+ self._title = _('Time range')
+ self._allow_empty = kwargs.get("allow_empty", False)
+ self._include_time = kwargs.get("include_time", False)
+ self._fixed_choices = kwargs.get("choices", [])
+ kwargs['choices'] = self._prepare_choices
+ CascadingDropdown.__init__(self, **kwargs)
- if 'choices' not in kwargs:
- kwargs['choices'] = []
- if kwargs.get('allow_empty', False):
- kwargs['choices'] += [
- (None, ''),
- ]
+ def _prepare_choices(self):
+ choices = list(self._fixed_choices)
- kwargs['choices'] += [
- ( "4h", _("The last 4 hours")),
- ( "25h", _("The last 25 hours")),
- ( "8d", _("The last 8 days")),
- ( "35d", _("The last 35 days")),
- ( "400d", _("The last 400 days")),
+ if self._allow_empty:
+ choices += [ (None, '') ]
+ choices += self._get_graph_timeranges() + [
( "d0", _("Today") ),
( "d1", _("Yesterday") ),
@@ -2761,13 +2759,11 @@ class Timerange(CascadingDropdown):
elements = [
AbsoluteDate(title = _("From:")),
AbsoluteDate(title = _("To:")),
- ],
- ),
- ),
+ ])),
]
- if kwargs.get('include_time', False):
- kwargs['choices'].append(
+ if self._include_time:
+ choices += [
( "time", _("Date & time range"),
Tuple(
orientation = "horizontal",
@@ -2784,9 +2780,24 @@ class Timerange(CascadingDropdown):
],
),
)
- )
+ ]
+ return choices
+
+
+
+ def _get_graph_timeranges(self):
+ try:
+ import config # FIXME
+ return [ (('age', timerange_attrs["duration"]),
timerange_attrs['title'])
+ for timerange_attrs in config.graph_timeranges ]
+
+ except AttributeError: # only available in cee
+ return [ ( "4h", _("The last 4 hours")),
+ ( "25h", _("The last 25 hours")),
+ ( "8d", _("The last 8 days")),
+ ( "35d", _("The last 35 days")),
+ ( "400d", _("The last 400 days")), ]
- CascadingDropdown.__init__(self, **kwargs)
def compute_range(self, rangespec):
if rangespec == None: