Module: check_mk
Branch: master
Commit: bfa74d8fd4a0602a387cf8620ae5eeb6c397aff1
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=bfa74d8fd4a060…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Sep 5 16:15:50 2011 +0200
Implemented extra_custom_links to be used in views to register custom context links
---
ChangeLog | 1 +
web/htdocs/views.py | 25 +++++++++++++++++++++++++
2 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 9cd5e57..4b690a3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -21,6 +21,7 @@
* Sort titles in views can be enabled by clicking on the whole cells now
* Submitting the view editor via ENTER key saves the view now instead of try mode
* Host comments have red backgrounded rows when host is down
+ * Implemented extra_custom_links to be used in views to register custom context
links
WATO:
* Changed row selection in WATO to new row selection mechanism
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index ac20417..3e2f2c4 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -49,6 +49,7 @@ multisite_sorters = {}
multisite_builtin_views = {}
multisite_painter_options = {}
ubiquitary_filters = [] # Always show this filters
+extra_context_links = []
# Load all view plugins
def load_plugins():
@@ -1587,6 +1588,30 @@ def show_context_links(thisview, active_filters):
vars_values = [ (var, html.var(var)) for var in set(used_contextvars) ]
html.context_button(view_linktitle(view),
html.makeuri_contextless(vars_values + [("view_name", name)]),
view.get("icon"))
+ # Add the plugin registered context links when the var requirements can be met
+ # custom context links can be registered in view plugins like this:
+ #
+ # def get_my_link_url(view):
+ # (...)
+ # return '/url/to/link/to'
+ #
+ # extra_context_links = [
+ # ([], 'The Title', get_my_link_url, 'map'),
+ # ]
+ #
+ # The first element is a list of required var names to show this button
+ # The fourth element it the name of the icon (icon_<name>.png)
+ #
+ # The url render function needs to return the target URL as string but can
+ # also return None to disable this link for the current view
+ for needed_vars, title, url_func, icon in extra_context_links:
+ miss = [ v for v in needed_vars if v not in active_filter_vars ]
+ if miss:
+ break
+ url = url_func(view)
+ if url is not None:
+ html.context_button(title, url, icon)
+
if not first:
html.end_context_buttons()