Module: check_mk
Branch: master
Commit: 8ef9cc7139d45c41124a6dee076b0db4750973d9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8ef9cc7139d45c…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Oct 24 09:13:30 2013 +0200
Added new snapin "Folders", which interacts with the views snapin
---
ChangeLog | 2 +
web/htdocs/js/sidebar.js | 57 +++++++++++++++++++++++++++-
web/htdocs/sidebar.py | 10 +++--
web/plugins/sidebar/shipped.py | 4 +-
web/plugins/sidebar/wato.py | 82 ++++++++++++++++++++++++----------------
5 files changed, 115 insertions(+), 40 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 8f25894..3424ed6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -28,6 +28,8 @@
* Wiki Sidebar Snapin: showing navigation and quicksearch. OMD only.
* Sidebar can now be folded. Simply click somewhere at the left 10 pixels.
* Foldable sections now have an animated triangle icon that shows the folding state
+ * Added new snapin "Folders", which interacts with the views snapin when
+ both are enabled. You can use it to open views in a specific folder context
* LDAP: Added option to make group and role sync plugin handle nested
groups (only in Active Directory at the moment). Enabling this
feature might increase the sync time a lot - use only when really needed.
diff --git a/web/htdocs/js/sidebar.js b/web/htdocs/js/sidebar.js
index 0aa98c8..7e295d8 100644
--- a/web/htdocs/js/sidebar.js
+++ b/web/htdocs/js/sidebar.js
@@ -791,8 +791,63 @@ function storeScrollPos() {
setCookie('sidebarScrollPos',
document.getElementById('side_content').scrollTop, null);
}
+/************************************************
+ * WATO Folders snapin handling
+ *************************************************/
+
+// FIXME: Make this somehow configurable - use the start url?
+g_last_view = 'dashboard.py?name=main';
+g_last_folder = '';
+
+// highlight the followed link (when both needed snapins are available)
+function highlight_link(link_obj, container_id) {
+ var this_snapin = document.getElementById(container_id);
+ if (container_id == 'snapin_container_wato_folders')
+ var other_snapin = document.getElementById('snapin_container_views');
+ else
+ var other_snapin =
document.getElementById('snapin_container_wato_folders');
+
+ if (this_snapin && other_snapin) {
+ if (this_snapin.getElementsByClassName)
+ var links = this_snapin.getElementsByClassName('link');
+ else
+ var links = document.getElementsByClassName('link', this_snapin);
+
+ for (var i = 0; i < links.length; i++) {
+ links[i].style = 'font-weight:normal;';
+ }
+
+ link_obj.style = 'font-weight:bold;';
+ }
+}
+
+function wato_folders_clicked(link_obj, folderpath) {
+ g_last_folder = folderpath;
+ highlight_link(link_obj, 'snapin_container_wato_folders');
+ parent.frames[1].location = g_last_view + '&wato_folder=' +
escape(g_last_folder);
+}
+
+function wato_views_clicked(link_obj) {
+ g_last_view = link_obj.href;
+
+ highlight_link(link_obj, 'snapin_container_views');
+
+ if (g_last_folder != '') {
+ // Navigate by using javascript, cancel following the default link
+ parent.frames[1].location = g_last_view + '&wato_folder=' +
escape(g_last_folder);
+ return false;
+ } else {
+ // Makes use the url stated in href attribute
+ return true;
+ }
+}
+
+/************************************************
+ * WATO Foldertree (Standalone) snapin handling
+ *************************************************/
+
/* Foldable Tree in snapin */
-function wato_tree_click(folderpath) {
+function wato_tree_click(link_obj, folderpath) {
var topic = document.getElementById('topic').value;
var target = document.getElementById('target_' + topic).value;
diff --git a/web/htdocs/sidebar.py b/web/htdocs/sidebar.py
index 1fe55bd..1bb7f4c 100644
--- a/web/htdocs/sidebar.py
+++ b/web/htdocs/sidebar.py
@@ -63,7 +63,7 @@ def load_plugins():
snapin["allowed"])
# Helper functions to be used by snapins
-def link(text, url, target="main"):
+def link(text, url, target="main", onclick = None):
# Convert relative links into absolute links. We have three kinds
# of possible links and we change only [3]
# [1] protocol://hostname/url/link.py
@@ -71,14 +71,16 @@ def link(text, url, target="main"):
# [3] relative.py
if not (":" in url[:10]) and url[0] != '/':
url = defaults.url_prefix + "check_mk/" + url
+ onclick = onclick and (' onclick="%s"' % html.attrencode(onclick))
or ''
return '<a onfocus="if (this.blur) this.blur();"
target="%s" ' \
- 'class=link href="%s">%s</a>' %
(html.attrencode(target), html.attrencode(url), html.attrencode(text))
+ 'class=link href="%s"%s>%s</a>' % \
+ (html.attrencode(target), html.attrencode(url), onclick,
html.attrencode(text))
def simplelink(text, url, target="main"):
html.write(link(text, url, target) + "<br>\n")
-def bulletlink(text, url, target="main"):
- html.write("<li class=sidebar>" + link(text, url, target) +
"</li>\n")
+def bulletlink(text, url, target="main", onclick = None):
+ html.write("<li class=sidebar>" + link(text, url, target, onclick) +
"</li>\n")
def iconlink(text, url, icon):
linktext = '<img class=iconlink src="images/icon_%s.png">%s'
% \
diff --git a/web/plugins/sidebar/shipped.py b/web/plugins/sidebar/shipped.py
index 97e6320..f526090 100644
--- a/web/plugins/sidebar/shipped.py
+++ b/web/plugins/sidebar/shipped.py
@@ -111,9 +111,9 @@ def render_views():
html.begin_foldable_container("views", topic, False, topic,
indent=True)
first = False
if topic == _('Dashboards'):
- bulletlink(title, 'dashboard.py?name=%s' % name)
+ bulletlink(title, 'dashboard.py?name=%s' % name, onclick =
"return wato_views_clicked(this)")
else:
- bulletlink(title, "view.py?view_name=%s" % name)
+ bulletlink(title, "view.py?view_name=%s" % name, onclick =
"return wato_views_clicked(this)")
if not first: # at least one item rendered
html.end_foldable_container()
diff --git a/web/plugins/sidebar/wato.py b/web/plugins/sidebar/wato.py
index cf124f5..539eed3 100644
--- a/web/plugins/sidebar/wato.py
+++ b/web/plugins/sidebar/wato.py
@@ -105,13 +105,7 @@ sidebar_snapins["admin_mini"] = {
# | |
# '----------------------------------------------------------------------'
-def render_wato_foldertree():
- if not config.wato_enabled:
- html.write(_("WATO is disabled in
<tt>multisite.mk</tt>."))
- else:
- render_wato_foldertree()
-
-def render_wato_foldertree():
+def compute_foldertree():
html.live.set_prepend_site(True)
query = "GET hosts\n" \
"Stats: state >= 0\n" \
@@ -184,6 +178,35 @@ def render_wato_foldertree():
reduce_tree(folders)
reduce_tree(user_folders)
+ return user_folders
+
+
+def render_tree_folder(f, js_func):
+ subfolders = f.get(".folders", {})
+ is_leaf = len(subfolders) == 0
+
+ # Suppress indentation for non-emtpy root folder
+ if f['.path'] == '' and is_leaf:
+ html.write("<ul>") # empty root folder
+ elif f and f['.path'] != '':
+ html.write("<ul style='padding-left: 0px;'>")
+
+ title = '<a class="link" href="#" onclick="%s(this,
\'%s\');">%s (%d)</a>' % (
+ js_func, f[".path"], f["title"],
f[".num_hosts"])
+
+ if not is_leaf:
+ html.begin_foldable_container('wato-hosts', "/" +
f[".path"], False, title)
+ for sf in wato.api.sort_by_title(subfolders.values()):
+ render_tree_folder(sf, js_func)
+ html.end_foldable_container()
+ else:
+ html.write("<li>" + title + "</li>")
+
+ html.write("</ul>")
+
+
+def render_wato_foldertree():
+ user_folders = compute_foldertree()
#
# Render link target selection
@@ -220,34 +243,11 @@ def render_wato_foldertree():
# Now render the whole tree
if user_folders:
- render_tree_folder(user_folders.values()[0])
-
-def render_tree_folder(f):
- subfolders = f.get(".folders", {})
- is_leaf = len(subfolders) == 0
-
- # Suppress indentation for non-emtpy root folder
- if f['.path'] == '' and is_leaf:
- html.write("<ul>") # empty root folder
- elif f and f['.path'] != '':
- html.write("<ul style='padding-left: 0px;'>")
-
- title = '<a href="#"
onclick="wato_tree_click(\'%s\');">%s (%d)</a>' % (
- f[".path"], f["title"], f[".num_hosts"])
-
- if not is_leaf:
- html.begin_foldable_container('wato-hosts', "/" +
f[".path"], False, title)
- for sf in wato.api.sort_by_title(subfolders.values()):
- render_tree_folder(sf)
- html.end_foldable_container()
- else:
- html.write("<li>" + title + "</li>")
-
- html.write("</ul>")
+ render_tree_folder(user_folders.values()[0], 'wato_tree_click')
sidebar_snapins['wato_foldertree'] = {
- 'title' : _('Foldertree'),
- 'description' : _('This snapin shows the folders defined in WATO. It can
be used to open views filtered by the WATO folder.'),
+ 'title' : _('Foldertree (standalone)'),
+ 'description' : _('This snapin shows the folders defined in WATO. It can
be used to open views filtered by the WATO folder. It works standalone, without
interaction with any other snapin.'),
'render' : render_wato_foldertree,
'allowed' : [ 'admin', 'user', 'guest' ],
'styles' : """
@@ -273,3 +273,19 @@ sidebar_snapins['wato_foldertree'] = {
}
"""
}
+
+def render_wato_folders():
+ user_folders = compute_foldertree()
+
+ if user_folders:
+ render_tree_folder(user_folders.values()[0], 'wato_folders_clicked')
+
+sidebar_snapins['wato_folders'] = {
+ 'title' : _('Folders'),
+ 'description' : _('This snapin shows the folders defined in WATO. It can
'
+ 'be used to open views filtered by the WATO folder. This '
+ 'snapin interacts with the "Views" snapin, when both
are '
+ 'enabled.'),
+ 'render' : render_wato_folders,
+ 'allowed' : [ 'admin', 'user', 'guest' ],
+}