Module: check_mk
Branch: master
Commit: e260539e51ad833fa41b059f3f99b9cec745cd44
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e260539e51ad83…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Jan 31 16:20:02 2012 +0100
WATO Foldertree snapin links now to the views selected in the snapin
---
ChangeLog | 1 +
web/htdocs/js/sidebar.js | 52 ++++++++++++++++++++++++++++-------
web/plugins/pages/wato.py | 1 +
web/plugins/sidebar/shipped.py | 55 ++++++++++++++++++++++++-------------
web/plugins/sidebar/wato.py | 58 ++++++++++++++++++++++++++++++++++++++++
5 files changed, 137 insertions(+), 30 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ce1bd0d..994b3af 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -60,6 +60,7 @@
* Replaced "wato" sidebar snapin which mixed up WATO and status GUIs with
the new "wato_foldertree" snapin which only links to the status views
filtered by the WATO folder.
+ * Added "Dashboard" section to views snapin which shows a list of all
dashboards
* FIX: Fixed auth problem when following logwatch icon links while using
the form based auth
* FIX: Fix problem with Umlaut in contact alias
diff --git a/web/htdocs/js/sidebar.js b/web/htdocs/js/sidebar.js
index 6829fe2..f5a3065 100644
--- a/web/htdocs/js/sidebar.js
+++ b/web/htdocs/js/sidebar.js
@@ -733,20 +733,50 @@ function storeScrollPos() {
/* Foldable Tree in snapin */
function wato_tree_click(folderpath) {
- // Get the URL in the main frame. If that is a view or a dashboard,
- // then reload that view with an updated "filename" variable. If that is
- // a wato.py page, navigate to the according wato page. In all other
- // cases, select the view "allhosts" with the according path.
- var href = parent.frames[1].location + ""; // adding "" converts
url from something magic to string
- if (href.indexOf("/view.py") >= 0)
- href = add_html_var(href, "wato_folder", folderpath);
- else if (href.indexOf("/dashboard.py") >= 0)
- href = add_html_var(href, "wato_folder", folderpath);
- else
- href = "view.py?view_name=allhosts&wato_folder=" +
escape(folderpath);
+ var topic = document.getElementById('topic').value;
+ var target = document.getElementById('target_' + topic).value;
+
+ if(target.substr(0, 9) == 'dashboard') {
+ dashboard_name = target.substr(9, target.length);
+ href = 'dashboard.py?name=' + escape(dashboard_name);
+ } else {
+ href = 'view.py?view_name=' + escape(target);
+ }
+
+ href += '&wato_folder=' + escape(folderpath);
+
parent.frames[1].location = href;
}
+function wato_tree_topic_changed(topic_field) {
+ // First toggle the topic dropdown field
+ var topic = topic_field.value;
+
+ // Hide all select fields but the wanted one
+ var select_fields = document.getElementsByTagName('select');
+ for(var i = 0; i < select_fields.length; i++) {
+ if(select_fields[i].id && select_fields[i].id.substr(0, 7) ==
'target_') {
+ select_fields[i].selected = '';
+ if(select_fields[i].id == 'target_' + topic) {
+ select_fields[i].style.display = 'inline';
+ } else {
+ select_fields[i].style.display = 'none';
+ }
+ }
+ }
+
+ // Then send the info to python code via ajax call for persistance
+ get_url('ajax_set_foldertree.py?topic=' + escape(topic) +
'&target=');
+}
+
+function wato_tree_target_changed(target_field) {
+ var topic = target_field.id.substr(7, target_field.id.length);
+ var target = target_field.value;
+
+ // Send the info to python code via ajax call for persistance
+ get_url('ajax_set_foldertree.py?topic=' + escape(topic) +
'&target=' + escape(target));
+}
+
// adds a variable to a GET url, but tries to remove that
// variable, if it is already existing in the URL. In order
// to simplify the thing, we just look at the *end* of the
diff --git a/web/plugins/pages/wato.py b/web/plugins/pages/wato.py
index 393a631..ffe6379 100644
--- a/web/plugins/pages/wato.py
+++ b/web/plugins/pages/wato.py
@@ -33,4 +33,5 @@ pagehandlers.update({
"automation_login" : wato.page_automation_login,
"automation" : wato.page_automation,
"user_profile" : wato.page_user_profile,
+ "ajax_set_foldertree" : sidebar.ajax_set_foldertree,
})
diff --git a/web/plugins/sidebar/shipped.py b/web/plugins/sidebar/shipped.py
index b28346c..821b490 100644
--- a/web/plugins/sidebar/shipped.py
+++ b/web/plugins/sidebar/shipped.py
@@ -24,7 +24,7 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
-import views, time, defaults
+import views, time, defaults, dashboard
import weblib
from lib import *
@@ -70,6 +70,36 @@ sidebar_snapins["about"] = {
# --------------------------------------------------------------
visible_views = [ "allhosts", "searchsvc" ]
+def views_by_topic():
+ s = [ (view.get("topic", _("Other")), view["title"],
name)
+ for name, view
+ in html.available_views.items()
+ if not view["hidden"] and not view.get("mobile")]
+
+ # Add all the dashboards to the views list
+ s += [ (_('Dashboards'), d['title'], d_name)
+ for d_name, d
+ in dashboard.dashboards.items()
+ ]
+
+ s.sort()
+
+ # Enforce a certain order on the topics
+ known_topics = [ _('Dashboards'), "Hosts", "Hostgroups",
"Services", "Servicegroups",
+ _("Business Intelligence"), _("Problems"),
_("Addons") ]
+
+ result = []
+ for topic in known_topics:
+ result.append((topic, s))
+
+ rest = list(set([ t for (t, _t, _v) in s if t not in known_topics ]))
+ rest.sort()
+ for topic in rest:
+ if topic:
+ result.append((topic, s))
+
+ return result
+
def render_views():
def render_topic(topic, s):
first = True
@@ -82,29 +112,16 @@ def render_views():
if first:
html.begin_foldable_container("views", topic, False, topic,
indent=True)
first = False
- bulletlink(title, "view.py?view_name=%s" % name)
+ if topic == _('Dashboards'):
+ bulletlink(title, 'dashboard.py?name=%s' % name)
+ else:
+ bulletlink(title, "view.py?view_name=%s" % name)
if not first: # at least one item rendered
html.end_foldable_container()
- s = [ (view.get("topic", _("Other")), view["title"],
name)
- for name, view
- in html.available_views.items()
- if not view["hidden"] and not view.get("mobile")]
- s.sort()
-
- # Enforce a certain order on the topics
- known_topics = [ "Hosts", "Hostgroups", "Services",
"Servicegroups",
- _("Business Intelligence"), _("Problems"),
_("Addons") ]
- for topic in known_topics:
+ for topic, s in views_by_topic():
render_topic(topic, s)
- rest = list(set([ t for (t, _t, _v) in s if t not in known_topics ]))
- rest.sort()
- for topic in rest:
- if topic:
- render_topic(topic, s)
-
-
links = []
if config.may("edit_views"):
if config.debug:
diff --git a/web/plugins/sidebar/wato.py b/web/plugins/sidebar/wato.py
index 185a96c..9e3ab52 100644
--- a/web/plugins/sidebar/wato.py
+++ b/web/plugins/sidebar/wato.py
@@ -139,9 +139,46 @@ def render_wato_foldertree():
del f['.folders'][subfolder['.path']]
update_foldertree(folder_tree)
+ #
+ # Render link target selection
+ #
+ selected_topic, selected_target = config.load_user_file("foldertree",
(_('Hosts'), 'allhosts'))
+
+ topic_views = views_by_topic()
+ topics = [ (t, t) for t, s in topic_views ]
+ html.select("topic", topics, selected_topic, onchange =
'wato_tree_topic_changed(this)')
+ html.write('<span class=left>%s</span>' % _('Topic'))
+
+ for topic, views in topic_views:
+ targets = []
+ for t, title, name in views:
+ if config.visible_views and name not in config.visible_views:
+ continue
+ if config.hidden_views and name in config.hidden_views:
+ continue
+ if t == topic:
+ if topic == _('Dashboards'):
+ name = 'dashboard|' + name
+ targets.append((name, title))
+
+ attrs = {}
+ if topic != selected_topic:
+ attrs['style'] = 'display:none'
+ default = ''
+ else:
+ default = selected_target
+
+ html.select("target_%s" % topic, targets, default, attrs = attrs,
onchange = 'wato_tree_target_changed(this)')
+
+ html.write('<span class=left>%s</span>' % _('View'))
+ html.write('<hr />')
+
# Now render the whole tree
render_tree_folder(folder_tree)
+def ajax_set_foldertree():
+ config.save_user_file("foldertree", (html.var('topic'),
html.var('target')))
+
def render_tree_folder(f):
subfolders = f.get(".folders", {})
is_leaf = len(subfolders) == 0
@@ -171,4 +208,25 @@ sidebar_snapins['wato_foldertree'] = {
'author' : 'Lars Michelsen',
'render' : render_wato_foldertree,
'allowed' : [ 'admin', 'user', 'guest' ],
+ 'styles' : """
+#snapin_wato_foldertree select {
+ float: right;
+ padding: 0;
+ width: 190px;
+}
+#snapin_wato_foldertree span {
+ display: block;
+ color: #ffffff;
+ height: 19px;
+}
+#snapin_wato_foldertree hr {
+ background-color: #fff;
+ height: 1px;
+ padding: 0;
+ margin: 4px;
+ border: 0;
+ /* Needed for older IE versions */
+ color: #fff;
+}
+"""
}