Module: check_mk
Branch: master
Commit: 8c38c662bb0ace4fc43f113f649ba97976ca4793
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8c38c662bb0aceā¦
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Oct 9 13:59:14 2014 +0200
Feature for showing context buttons also for non-single contexts
---
web/htdocs/views.py | 6 +++--
web/htdocs/visuals.py | 67 +++++++++++++++++++++++++++++++------------------
2 files changed, 46 insertions(+), 27 deletions(-)
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index 7eaaf03..4c30441 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -711,7 +711,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_context_html_vars(view)))
+ html.set_page_context(dict(visuals.get_singlecontext_html_vars(view)))
show_view(view, True, True, True)
@@ -1421,8 +1421,8 @@ def show_context_links(thisview, show_filters, display_options,
view_optiondial_off("refresh")
- # WATO: If we have a host context, then show button to WATO, if permissions allow
this
if 'B' in display_options:
+ # WATO: If we have a host context, then show button to WATO, if permissions allow
this
if html.has_var("host") \
and config.wato_enabled \
and config.may("wato.use") \
@@ -1436,9 +1436,11 @@ def show_context_links(thisview, show_filters, display_options,
html.context_button(_("WATO"), url, "wato",
id="wato",
bestof = config.context_buttons_to_show)
+ # Button for creating an instant report (if reporting is available)
if config.reporting_available():
html.context_button(_("Export as PDF"), html.makeuri([],
filename="report_instant.py"), "report")
+ # Buttons to other views, dashboards, etc.
links = visuals.collect_context_links(thisview)
for linktitle, uri, icon, buttonid in links:
html.context_button(linktitle, url=uri, icon=icon, id=buttonid,
bestof=config.context_buttons_to_show)
diff --git a/web/htdocs/visuals.py b/web/htdocs/visuals.py
index 95d6f24..1a2b118 100644
--- a/web/htdocs/visuals.py
+++ b/web/htdocs/visuals.py
@@ -32,18 +32,22 @@ import config, table
visual_types = {
'views': {
- 'ident_attr': 'view_name',
- 'title': _("view"),
- 'plural_title': _("views"),
- 'module_name': 'views',
+ 'show_url' : 'view.py',
+ 'ident_attr' : 'view_name',
+ 'title' : _("view"),
+ 'plural_title' : _("views"),
+ 'module_name' : 'views',
+ 'multicontext_links' : False,
},
'dashboards': {
- 'ident_attr': 'name',
- 'title': _("dashboard"),
- 'plural_title': _("dashboards"),
- 'module_name': 'dashboard',
- 'popup_add_handler': 'popup_list_dashboards',
- 'add_visual_handler': 'popup_add_dashlet',
+ 'show_url' : 'dashboard.py',
+ 'ident_attr' : 'name',
+ 'title' : _("dashboard"),
+ 'plural_title' : _("dashboards"),
+ 'module_name' : 'dashboard',
+ 'popup_add_handler' : 'popup_list_dashboards',
+ 'add_visual_handler' : 'popup_add_dashlet',
+ 'multicontext_links' : False,
},
}
@@ -1089,7 +1093,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_context_html_vars(visual) if v != None ]
+ extra_titles = [ v for k, v in get_singlecontext_html_vars(visual) 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() ]
@@ -1130,7 +1134,7 @@ def get_single_info_keys(visual):
keys += info_params(info_key)
return list(set(keys))
-def get_context_html_vars(visual):
+def get_singlecontext_html_vars(visual):
vars = []
for key in get_single_info_keys(visual):
vars.append((key, html.var(key, visual['context'].get(key))))
@@ -1141,7 +1145,7 @@ def get_context_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_context_html_vars(this_visual):
+ for var, val in get_singlecontext_html_vars(this_visual):
if html.has_var(var):
active_filter_vars.add(var)
@@ -1151,14 +1155,15 @@ def collect_context_links(this_visual, mobile = False, only_types
= []):
context_links += collect_context_links_of(what, this_visual,
active_filter_vars, mobile)
return context_links
-def collect_context_links_of(what, this_visual, active_filter_vars, mobile):
+def collect_context_links_of(visual_type_name, this_visual, active_filter_vars, mobile):
context_links = []
# FIXME: Make this cross module access cleaner
- module_name = visual_types[what]["module_name"]
+ visual_type = visual_types[visual_type_name]
+ module_name = visual_type["module_name"]
thing_module = __import__(module_name)
- thing_module.__dict__['load_%s'% what]()
- available = thing_module.__dict__['permitted_%s' % what]()
+ thing_module.__dict__['load_%s'% visual_type_name]()
+ available = thing_module.__dict__['permitted_%s' % visual_type_name]()
# sort buttons somehow
visuals = available.values()
@@ -1178,23 +1183,35 @@ def collect_context_links_of(what, this_visual,
active_filter_vars, mobile):
or mobile and not visual.get('mobile'):
continue
- if not visual['single_infos']:
- continue # skip non single visuals
+ # For dashboards and views we currently only show a link button,
+ # if the target dashboard/view shares a single info with the
+ # current visual.
+ if not visual['single_infos'] and not
visual_type["multicontext_links"]:
+ continue # skip non single visuals for dashboard, views
- needed_vars = get_context_html_vars(visual)
+ # We can show a button only if all single contexts of the
+ # target visual are known currently
+ needed_vars = get_singlecontext_html_vars(visual)
skip = False
vars_values = []
for var, val in needed_vars:
if var not in active_filter_vars:
- skip = True
+ skip = True # At least one single context missing
break
-
vars_values.append((var, val))
if not skip:
- # add context link to this visual
- uri = html.makeuri_contextless(vars_values +
[(visual_types[what]['ident_attr'], name)],
- filename = what[:-1] + '.py')
+ # add context link to this visual. For reports we put in
+ # the *complete* context, even the non-single one.
+ if visual_type["multicontext_links"]:
+ uri = html.makeuri([(visual_type['ident_attr'], name)],
+ filename = visual_type["show_url"])
+
+ # For views and dashboards currently the current filter
+ # settings
+ else:
+ uri = html.makeuri_contextless(vars_values +
[(visual_type['ident_attr'], name)],
+ filename =
visual_type["show_url"])
icon = visual.get("icon")
buttonid = "cb_" + name
context_links.append((_u(linktitle), uri, icon, buttonid))