Module: check_mk
Branch: master
Commit: 508e434b3bff2e331aa333be95fec998155bd9f8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=508e434b3bff2e…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Dec 19 09:41:43 2014 +0100
#1799 FIX Dashboards: Existing views added to dashboards now get a correct title /
title_url
---
.werks/1799 | 10 ++++++++++
ChangeLog | 1 +
web/htdocs/dashboard.py | 16 ++++++++++++----
web/htdocs/views.py | 2 +-
web/htdocs/visuals.py | 20 ++++++++++++++------
5 files changed, 38 insertions(+), 11 deletions(-)
diff --git a/.werks/1799 b/.werks/1799
new file mode 100644
index 0000000..f7b79ab
--- /dev/null
+++ b/.werks/1799
@@ -0,0 +1,10 @@
+Title: Dashboards: Existing views added to dashboards now get a correct title /
title_url
+Level: 1
+Component: multisite
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.7i1
+Date: 1418978475
+
+
diff --git a/ChangeLog b/ChangeLog
index 2a97522..b0130c2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -48,6 +48,7 @@
* 1774 FIX: IE: Always use the latest available rendering enginge of the used
browser...
* 1777 FIX: Fixed js error making the "add to visual" link break on pages
with context...
* 1798 FIX: Filters are now retained when adding a view to a dashboard...
+ * 1799 FIX: Dashboards: Existing views added to dashboards now get a correct title /
title_url
WATO:
* 1760 Added search form to manual checks page
diff --git a/web/htdocs/dashboard.py b/web/htdocs/dashboard.py
index 2c71a1b..a58367b 100644
--- a/web/htdocs/dashboard.py
+++ b/web/htdocs/dashboard.py
@@ -206,12 +206,21 @@ def transform_builtin_dashboards():
dashboard.setdefault('description', dashboard.get('title',
''))
builtin_dashboards_transformed = True
-def load_view_into_dashlet(dashlet, nr, view_name):
+def load_view_into_dashlet(dashlet, nr, view_name, add_context=None):
import views
views.load_views()
views = views.permitted_views()
if view_name in views:
- dashlet.update(views[view_name])
+ view = copy.deepcopy(views[view_name])
+ dashlet.update(view)
+ if add_context:
+ dashlet['context'].update(add_context)
+
+ # Overwrite the views default title with the context specific title
+ dashlet['title'] = visuals.visual_title('view', view)
+ dashlet['title_url'] = html.makeuri_contextless(
+ [('view_name', view_name)] +
visuals.get_singlecontext_vars(view).items(),
+ filename='view.py')
dashlet['type'] = 'view'
dashlet['name'] = 'dashlet_%d' % nr
@@ -1186,8 +1195,7 @@ def popup_add_dashlet(dashboard_name, dashlet_type, context,
params):
if dashlet_type == 'view':
# save the original context and override the context provided by the view
context = dashlet['context']
- load_view_into_dashlet(dashlet, len(dashboard['dashlets']), view_name)
- dashlet['context'].update(context)
+ load_view_into_dashlet(dashlet, len(dashboard['dashlets']), view_name,
add_context=context)
add_dashlet(dashlet, dashboard)
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index 6ff18a2..6aa1c7f 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -780,7 +780,7 @@ def page_view():
if not view:
raise MKGeneralException(_("No view defined with the name
'%s'.") % html.attrencode(view_name))
- html.set_page_context(dict(visuals.get_singlecontext_html_vars(view)))
+ html.set_page_context(visuals.get_singlecontext_html_vars(view))
show_view(view, True, True, True)
diff --git a/web/htdocs/visuals.py b/web/htdocs/visuals.py
index 6d48598..4972117 100644
--- a/web/htdocs/visuals.py
+++ b/web/htdocs/visuals.py
@@ -1118,7 +1118,7 @@ def unpack_context_after_editing(packed_context):
# '----------------------------------------------------------------------'
def verify_single_contexts(what, visual):
- for k, v in get_singlecontext_html_vars(visual):
+ for k, v in get_singlecontext_html_vars(visual).items():
if v == None:
raise MKUserError(k, _('This %s can not be displayed, because the '
'necessary context information "%s" is
missing.') %
@@ -1130,7 +1130,7 @@ def visual_title(what, visual):
# Beware: if a single context visual is being visited *without* a context, then
# the value of the context variable(s) is None. In order to avoid exceptions,
# we simply drop these here.
- extra_titles = [ v for k, v in get_singlecontext_html_vars(visual) if v != None ]
+ extra_titles = [ v for k, v in get_singlecontext_html_vars(visual).items() if v !=
None ]
# FIXME: Is this really only needed for visuals without single infos?
if not visual['single_infos']:
used_filters = [ multisite_filters[fn] for fn in
visual["context"].keys() ]
@@ -1176,10 +1176,18 @@ def get_single_info_keys(visual):
keys += info_params(info_key)
return list(set(keys))
+def get_singlecontext_vars(visual):
+ vars = {}
+ for key in get_single_info_keys(visual):
+ vars[key] = visual['context'].get(key)
+ return vars
+
def get_singlecontext_html_vars(visual):
- vars = []
+ vars = get_singlecontext_vars(visual)
for key in get_single_info_keys(visual):
- vars.append((key, html.var_utf8(key, visual['context'].get(key))))
+ val = html.var_utf8(key)
+ if val != None:
+ vars[key] = val
return vars
# Collect all visuals that share a context with visual. For example
@@ -1187,7 +1195,7 @@ def get_singlecontext_html_vars(visual):
def collect_context_links(this_visual, mobile = False, only_types = []):
# compute list of html variables needed for this visual
active_filter_vars = set([])
- for var, val in get_singlecontext_html_vars(this_visual):
+ for var, val in get_singlecontext_html_vars(this_visual).items():
if html.has_var(var):
active_filter_vars.add(var)
@@ -1236,7 +1244,7 @@ def collect_context_links_of(visual_type_name, this_visual,
active_filter_vars,
# We can show a button only if all single contexts of the
# target visual are known currently
- needed_vars = get_singlecontext_html_vars(visual)
+ needed_vars = get_singlecontext_html_vars(visual).items()
skip = False
vars_values = []
for var, val in needed_vars: