Module: check_mk
Branch: master
Commit: 2aa2d805e4d5dc638eb1176ea49499a89a8878c9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2aa2d805e4d5dc…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Dec 2 10:36:24 2014 +0100
#1580 FIX Views: Hardcoded single context filters are not shown in filter form anymore
When a view has a single context and the value of the filters hard coded in the view,
the filter elements are not shown to the user in the filter form anymore.
---
.werks/1580 | 10 ++++++++++
ChangeLog | 1 +
web/htdocs/views.py | 10 +++++++---
web/htdocs/visuals.py | 31 +++++++++++++++++++++++--------
web/plugins/dashboard/dashlets.py | 4 ++--
5 files changed, 43 insertions(+), 13 deletions(-)
diff --git a/.werks/1580 b/.werks/1580
new file mode 100644
index 0000000..0a6c0f4
--- /dev/null
+++ b/.werks/1580
@@ -0,0 +1,10 @@
+Title: Views: Hardcoded single context filters are not shown in filter form anymore
+Level: 1
+Component: multisite
+Compatible: compat
+Version: 1.2.5i7
+Date: 1417512923
+Class: fix
+
+When a view has a single context and the value of the filters hard coded in the view,
+the filter elements are not shown to the user in the filter form anymore.
diff --git a/ChangeLog b/ChangeLog
index 5d7e4e5..e0e9bf7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -91,6 +91,7 @@
* 1557 FIX: Fix sorting of hostnames that only differ in lower/uppercaseness
* 1577 FIX: Fixed editing of views using the "Downtime for host/service"
sorter or column...
* 1578 FIX: Folding states of containers with umlauts in titles are now persisted...
+ * 1580 FIX: Views: Hardcoded single context filters are not shown in filter form
anymore...
WATO:
* 1170 Added buttons to move rules to top/bottom of the list to ruleset edit dialog
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index e330b32..3e6745e 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -930,10 +930,14 @@ def show_view(view, show_heading = False, show_buttons = True,
datasource = multisite_datasources[view["datasource"]]
tablename = datasource["table"]
- # Filters to show in the view
+ # Filters to use in the view
# In case of single object views, the needed filters are fixed, but not always
present
# in context. In this case, take them from the context type definition.
- show_filters = visuals.show_filters(view, datasource['infos'],
all_filters_active)
+ use_filters = visuals.filters_of_visual(view, datasource['infos'],
all_filters_active)
+
+ # Not all filters are really shown later in show_filter_form(), because filters
which
+ # have a hardcoded value are not changeable by the user
+ show_filters = visuals.visible_filters_of_visual(view, use_filters)
visuals.add_context_to_uri_vars(view, datasource["infos"], only_count)
@@ -944,7 +948,7 @@ def show_view(view, show_heading = False, show_buttons = True,
# Prepare Filter headers for Livestatus
filterheaders = ""
only_sites = None
- all_active_filters = [ f for f in show_filters if f.available() ]
+ all_active_filters = [ f for f in use_filters if f.available() ]
for filt in all_active_filters:
header = filt.filter(tablename)
if header.startswith("Sites:"):
diff --git a/web/htdocs/visuals.py b/web/htdocs/visuals.py
index f7115a7..0fd8a81 100644
--- a/web/htdocs/visuals.py
+++ b/web/htdocs/visuals.py
@@ -869,22 +869,22 @@ def filters_allowed_for_info(info):
allowed[fname] = filt
return allowed
-# Collects all filters to be shown for the given visual
-def show_filters(visual, info_keys, show_all=False):
- show_filters = []
+# Collects all filters to be used for the given visual
+def filters_of_visual(visual, info_keys, show_all=False):
+ filters = []
for info_key in info_keys:
if info_key in visual['single_infos']:
for key in info_params(info_key):
- show_filters.append(get_filter(key))
+ filters.append(get_filter(key))
elif not show_all:
for key, val in visual['context'].items():
if type(val) == dict: # this is a real filter
- show_filters.append(get_filter(key))
+ filters.append(get_filter(key))
if show_all: # add *all* available filters of these infos
for filter_name, filter in multisite_filters.items():
if filter.info in info_keys:
- show_filters.append(filter)
+ filters.append(filter)
# add ubiquitary_filters that are possible for these infos
for fn in ubiquitary_filters:
@@ -893,10 +893,25 @@ def show_filters(visual, info_keys, show_all=False):
continue
filter = get_filter(fn)
if not filter.info or filter.info in info_keys:
- show_filters.append(filter)
+ filters.append(filter)
+
+ return list(set(filters)) # remove duplicates
+
+# Reduces the list of the visuals used filters. The result are the ones
+# which are really presented to the user later.
+# For the moment we only remove the single context filters which have a
+# hard coded default value which is treated as enforced value.
+def visible_filters_of_visual(visual, use_filters):
+ show_filters = []
+
+ single_keys = get_single_info_keys(visual)
- return list(set(show_filters)) # remove duplicates
+ for f in use_filters:
+ if f.name not in single_keys or \
+ not visual['context'].get(f.name):
+ show_filters.append(f)
+ return show_filters
def add_context_to_uri_vars(visual, only_infos=None, only_count=False):
if only_infos == None:
diff --git a/web/plugins/dashboard/dashlets.py b/web/plugins/dashboard/dashlets.py
index 34685fb..5ed326b 100644
--- a/web/plugins/dashboard/dashlets.py
+++ b/web/plugins/dashboard/dashlets.py
@@ -209,8 +209,8 @@ def render_statistics(pie_id, what, table, filter, dashlet):
pie_right_aspect = 0.8
info = what == 'hosts' and 'host' or 'service'
- show_filters = visuals.show_filters(dashlet, [info])
- for filt in show_filters:
+ use_filters = visuals.filters_of_visual(dashlet, [info])
+ for filt in use_filters:
if filt.available():
filter += filt.filter(info)