reports is now respecing all set filters
Message-ID: <554b78ba.NjMIMiWRRUWyOrr8%lm(a)mathias-kettner.de>
User-Agent: Heirloom mailx 12.5 6/20/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Module: check_mk
Branch: master
Commit: 4fea7878a071df1b1ff68f7c27e77b36eabf7b9a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4fea7878a071df…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu May 7 16:37:25 2015 +0200
#2251 FIX Adding views to dashboards / reports is now respecing all set filters
In previous versions only the filters used by single contexts were used. This
has been cleaned up now to get the exact same context information on the view
which is being added.
---
.werks/2251 | 11 +++++++++++
ChangeLog | 1 +
web/htdocs/htmllib.py | 2 +-
web/htdocs/js/checkmk.js | 16 ++--------------
web/htdocs/views.py | 7 ++++++-
web/htdocs/visuals.py | 16 +++++++---------
6 files changed, 28 insertions(+), 25 deletions(-)
diff --git a/.werks/2251 b/.werks/2251
new file mode 100644
index 0000000..ffb8c31
--- /dev/null
+++ b/.werks/2251
@@ -0,0 +1,11 @@
+Title: Adding views to dashboards / reports is now respecing all set filters
+Level: 1
+Component: multisite
+Compatible: compat
+Version: 1.2.7i1
+Date: 1431009374
+Class: fix
+
+In previous versions only the filters used by single contexts were used. This
+has been cleaned up now to get the exact same context information on the view
+which is being added.
diff --git a/ChangeLog b/ChangeLog
index c70a930..0f6b50a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -425,6 +425,7 @@
* 1957 FIX: Fixed default value for text input fields in notification plugins...
* 2233 FIX: Fixed WATO folder view and Host Tags search with HTML Entity encoding...
* 2074 FIX: pnptemplate netapp_api_volume: fixed title
+ * 2251 FIX: Adding views to dashboards / reports is now respecing all set filters...
WATO:
* 1760 Added search form to manual checks page
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 5510ec4..64d9ac2 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -984,7 +984,7 @@ class html:
encoded_vars[k] = v
self.popup_trigger(
- '<img class=statusicon
src="images/status_add_dashlet.png" title="%s">\n' %
_("Add this view to..."),
+ '<img class=statusicon src="images/icon_menu.png"
title="%s">\n' % _("Add this view to..."),
'add_visual', 'add_visual', data='[\'%s\',
%s, {\'name\': \'%s\'}]' %
(mode_name,
self.attrencode(repr(encoded_vars)),
self.var('view_name')))
diff --git a/web/htdocs/js/checkmk.js b/web/htdocs/js/checkmk.js
index f531836..a0db9da 100644
--- a/web/htdocs/js/checkmk.js
+++ b/web/htdocs/js/checkmk.js
@@ -2472,23 +2472,11 @@ function add_to_visual(visual_type, visual_name)
{
close_popup();
- var context_txt = [];
- for (var key in popup_data[1]) {
- var ty = typeof(popup_data[1][key]);
- context_txt.push(key+':'+ty+':'+popup_data[1][key]);
- }
-
- var params_txt = [];
- for (var key in popup_data[2]) {
- var ty = typeof(popup_data[2][key]);
- params_txt.push(key+':'+ty+':'+popup_data[2][key]);
- }
-
response = get_url_sync('ajax_add_visual.py?visual_type=' + visual_type
+ '&visual_name=' + visual_name
+ '&type=' + popup_data[0]
- + '&context=' +
encodeURIComponent(context_txt.join('|'))
- + '¶ms=' +
encodeURIComponent(params_txt.join('|')));
+ + '&context=' +
encodeURIComponent(JSON.stringify(popup_data[1]))
+ + '¶ms=' +
encodeURIComponent(JSON.stringify(popup_data[2])));
popup_data = null;
// After adding a dashlet, go to the choosen dashboard
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index ee0fcb3..8ab1507 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -786,7 +786,12 @@ def page_view():
if not view:
raise MKGeneralException(_("No view defined with the name
'%s'.") % html.attrencode(view_name))
- html.set_page_context(visuals.get_singlecontext_html_vars(view))
+ # Gather the page context which is needed for the "add to visual" popup
menu
+ # to add e.g. views to dashboards or reports
+ datasource = multisite_datasources[view['datasource']]
+ context = visuals.get_context_from_uri_vars(datasource['infos'])
+ context.update(visuals.get_singlecontext_html_vars(view))
+ html.set_page_context(context)
show_view(view, True, True, True)
diff --git a/web/htdocs/visuals.py b/web/htdocs/visuals.py
index 60208a2..573c5c9 100644
--- a/web/htdocs/visuals.py
+++ b/web/htdocs/visuals.py
@@ -26,6 +26,11 @@
import os, copy
+try:
+ import simplejson as json
+except ImportError:
+ import json
+
from lib import *
from valuespec import *
import config, table
@@ -1366,14 +1371,7 @@ def ajax_add_visual():
extra_data = []
for what in [ 'context', 'params' ]:
value = html.var(what)
- data = {}
- extra_data.append(data)
- if value == '':
- continue
- for entry in value.split('|'):
- key, vartype, value = entry.split(':', 2)
- if vartype == 'number':
- value = int(value)
- data[key] = value
+ if value:
+ extra_data.append(json.loads(value))
handler(visual_name, element_type, *extra_data)