Module: check_mk
Branch: master
Commit: ec167be61ef982c6ae3c668fa1c0fe055ae3c3cc
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ec167be61ef982…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Jan 15 13:50:07 2015 +0100
#1815 Dashboard: Sidebar snapins can now be added as dashlets to dashboards
It is now possible to add sidebar snapins to dashboards using the dashboard
editor. Simply go to edit mode of a dashboard, then add a new dashlet of
the type "Sidebar Snapin". In the following dialog you can choose one from
all available snapins.
---
.werks/1815 | 12 +++++
ChangeLog | 1 +
web/htdocs/dashboard.py | 8 ++-
web/htdocs/images/dashlet_snapin.png | Bin 0 -> 3190 bytes
web/htdocs/sidebar.py | 7 ++-
web/plugins/dashboard/dashlets.py | 97 +++++++++++++++++++++++++++++++++-
6 files changed, 120 insertions(+), 5 deletions(-)
diff --git a/.werks/1815 b/.werks/1815
new file mode 100644
index 0000000..0f7f72d
--- /dev/null
+++ b/.werks/1815
@@ -0,0 +1,12 @@
+Title: Dashboard: Sidebar snapins can now be added as dashlets to dashboards
+Level: 1
+Component: multisite
+Compatible: compat
+Version: 1.2.7i1
+Date: 1421326059
+Class: feature
+
+It is now possible to add sidebar snapins to dashboards using the dashboard
+editor. Simply go to edit mode of a dashboard, then add a new dashlet of
+the type "Sidebar Snapin". In the following dialog you can choose one from
+all available snapins.
diff --git a/ChangeLog b/ChangeLog
index 7f7401b..bf0a7fe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -73,6 +73,7 @@
* 1210 New Downtime Filter for comments...
* 1811 Added new filter for regex based filtering of contacts to log based views...
* 1667 Sidebar snapin 'Tree of Folders' and 'WATO folder' filter now
available on slave sites...
+ * 1815 Dashboard: Sidebar snapins can now be added as dashlets to dashboards...
* 1781 FIX: Fix broken grouping by host/service group in availability
* 1783 FIX: Finish the view "History of Scheduled Downtimes"...
* 1206 FIX: Hostname not longer shown as column in host views
diff --git a/web/htdocs/dashboard.py b/web/htdocs/dashboard.py
index 106d1e8..cab9dff 100644
--- a/web/htdocs/dashboard.py
+++ b/web/htdocs/dashboard.py
@@ -567,7 +567,11 @@ def render_dashlet(name, board, nr, dashlet, wato_folder,
add_url_vars):
html.write('<div class="%s" id="dashlet_%d">' %
(' '.join(classes), nr))
- title = dashlet.get('title', dashlet_type.get('title'))
+ # Get the title of the dashlet type (might be dynamically defined)
+ title = dashlet_type.get('title')
+ if dashlet_type.get('title_func'):
+ title = dashlet_type.get('title_func')(dashlet)
+ title = dashlet.get('title', title)
if title and dashlet.get('show_title'):
url = dashlet.get("title_url", None)
if url:
@@ -609,7 +613,7 @@ def render_dashlet(name, board, nr, dashlet, wato_folder,
add_url_vars):
url = 'about:blank'
# Fix of iPad >:-P
- html.write('<div style="width: 100%; height: 100%;
-webkit-overflow-scrolling:touch; overflow: hidden;">')
+ html.write('<div style="width: 100%; height: 100%;
-webkit-overflow-scrolling:touch;">')
html.write('<iframe id="dashlet_iframe_%d"
allowTransparency="true" frameborder="0" width="100%%"
'
'height="100%%" src="%s">
</iframe>' % (nr, url))
html.write('</div>')
diff --git a/web/htdocs/images/dashlet_snapin.png b/web/htdocs/images/dashlet_snapin.png
new file mode 100644
index 0000000..19c2f23
Binary files /dev/null and b/web/htdocs/images/dashlet_snapin.png differ
diff --git a/web/htdocs/sidebar.py b/web/htdocs/sidebar.py
index 793dac0..17fa617 100644
--- a/web/htdocs/sidebar.py
+++ b/web/htdocs/sidebar.py
@@ -267,12 +267,15 @@ def page_side():
html.body_end()
-def render_snapin(name, state):
- snapin = sidebar_snapins.get(name)
+def render_snapin_styles(snapin):
styles = snapin.get("styles")
if styles:
html.write("<style>\n%s\n</style>\n" % styles)
+def render_snapin(name, state):
+ snapin = sidebar_snapins.get(name)
+ render_snapin_styles(snapin)
+
html.write("<div id=\"snapin_container_%s\"
class=snapin>\n" % name)
if state == "closed":
style = ' style="display:none"'
diff --git a/web/plugins/dashboard/dashlets.py b/web/plugins/dashboard/dashlets.py
index 367fb36..28d0640 100644
--- a/web/plugins/dashboard/dashlets.py
+++ b/web/plugins/dashboard/dashlets.py
@@ -560,7 +560,7 @@ def dashlet_view_handle_input(ident, dashlet):
dashlet_types["view"] = {
"title" : _("View"),
"sort_index" : 10,
- "description" : _("Displays a the content of a Multisite
view."),
+ "description" : _("Displays the content of a Multisite
view."),
"size" : (40, 20),
"iframe_render" : dashlet_view,
"allowed" : config.builtin_role_ids,
@@ -615,3 +615,98 @@ dashlet_types["url"] = {
"opt_params" : ['url', 'urlfunc'],
"validate_params" : dashlet_url_validate,
}
+
+#.
+# .--Snapin--------------------------------------------------------------.
+# | ____ _ |
+# | / ___| _ __ __ _ _ __ (_)_ __ |
+# | \___ \| '_ \ / _` | '_ \| | '_ \ |
+# | ___) | | | | (_| | |_) | | | | | |
+# | |____/|_| |_|\__,_| .__/|_|_| |_| |
+# | |_| |
+# +----------------------------------------------------------------------+
+# | Render sidebar snapins within the dashboard |
+# '----------------------------------------------------------------------'
+
+def dashlet_snapin(nr, dashlet):
+ import sidebar # FIXME: HACK, clean this up somehow
+ snapin = sidebar.sidebar_snapins.get(dashlet['snapin'])
+ if not snapin:
+ raise MKUserError(None, _('The configured snapin does not exist.'))
+
+ dashlet_type = dashlet_types[dashlet['type']]
+
+ overflow = ''
+ scroll_x, scroll_y = dashlet_type.get("iframe_scroll", (False, False))
+ if not scroll_x:
+ overflow += 'overflow-x: hidden;\n'
+ else:
+ overflow += 'overflow-x: auto;\n'
+ if not scroll_y:
+ overflow += 'overflow-y: hidden;\n'
+ else:
+ overflow += 'overflow-y: auto;\n'
+
+ html.set_browser_reload(dashlet_type['refresh'])
+ html.html_head(_('Snapin Dashlet'), javascripts=['sidebar'],
stylesheets=['sidebar', 'status'])
+ html.write('''<style>
+#side_content {
+ height: auto;
+ top: 0;
+ padding-top: 4px;
+ padding-left: 4px;
+}
+div.snapin:last-child {
+ margin-bottom: 0;
+}
+div.snapin div.content {
+ background-image: none;
+ background-color: #508AA1;
+}
+div.snapin {
+ margin: 0;
+ padding: 0;
+}
+body.side {
+ %s
+}
+</style>''' % overflow)
+ html.write('<body class="side">\n')
+ html.write('<div id="check_mk_sidebar">\n')
+ html.write('<div id="side_content">\n')
+ html.write("<div id=\"snapin_container_%s\"
class=snapin>\n" % dashlet['snapin'])
+ html.write("<div id=\"snapin_%s\"
class=\"content\">\n" % (dashlet['snapin']))
+ sidebar.render_snapin_styles(snapin)
+ snapin['render']()
+ html.write('</div>\n')
+ html.write('</div>\n')
+ html.write('</div>\n')
+ html.write('</div>\n')
+ html.body_end()
+
+def dashlet_snapin_get_snapins():
+ import sidebar # FIXME: HACK, clean this up somehow
+ return sorted([ (k, v['title']) for k, v in sidebar.sidebar_snapins.items()
], key=lambda x: x[1])
+
+def dashlet_snapin_title(dashlet):
+ import sidebar # FIXME: HACK, clean this up somehow
+ return sidebar.sidebar_snapins[dashlet['snapin']]['title']
+
+dashlet_types["snapin"] = {
+ "title" : _("Sidebar Snapin"),
+ "title_func" : dashlet_snapin_title,
+ "sort_index" : 55,
+ "description" : _("Displays a sidebar snapin."),
+ "size" : (27, 20),
+ "iframe_render" : dashlet_snapin,
+ "iframe_scroll" : (False, True),
+ "allowed" : config.builtin_role_ids,
+ "refresh" : 30,
+ "parameters" : [
+ ('snapin', DropdownChoice(
+ title = _('Snapin'),
+ help = _('Choose the snapin you like to show.'),
+ choices = dashlet_snapin_get_snapins,
+ )),
+ ],
+}