Module: check_mk
Branch: master
Commit: 0fc58418f7f4cff8e62821a12ebbea2e0f7e3534
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0fc58418f7f4cf…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Nov 28 10:54:27 2014 +0100
Now really fixed refreshing of pnp graph dashlets
---
web/htdocs/dashboard.py | 13 +++++++++----
web/htdocs/js/dashboard.js | 7 ++++++-
web/plugins/dashboard/dashlets.py | 8 ++++++--
3 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/web/htdocs/dashboard.py b/web/htdocs/dashboard.py
index aaf083f..d01f3ef 100644
--- a/web/htdocs/dashboard.py
+++ b/web/htdocs/dashboard.py
@@ -379,8 +379,13 @@ def render_dashboard(name):
url = dashlet.get("url",
"dashboard_dashlet.py?name="+name+"&id="+ str(nr))
refresh = dashlet.get("refresh",
dashlet_type.get("refresh"))
if refresh:
- # FIXME: remove add_wato_folder_to_url
- refresh_dashlets.append([nr, refresh, str(add_wato_folder_to_url(url,
wato_folder))])
+ if 'on_refresh' in dashlet_type:
+ action = 'function() {%s}' %
dashlet_type['on_refresh'](nr, dashlet)
+ else:
+ # FIXME: remove add_wato_folder_to_url
+ action = '"%s"' % add_wato_folder_to_url(url,
wato_folder) # url to dashboard_dashlet.py
+ refresh_dashlets.append('[%d, %d, %s]' % (nr, refresh, action))
+
# Update the dashlets context with the dashboard global context when there are
# useful information
@@ -482,7 +487,7 @@ var title_height = %d;
var dashlet_padding = Array%s;
var dashlet_min_size = Array%s;
var corner_overlap = %d;
-var refresh_dashlets = %r;
+var refresh_dashlets = [%s];
var on_resize_dashlets = {%s};
var dashboard_name = '%s';
var dashboard_mtime = %d;
@@ -493,7 +498,7 @@ calculate_dashboard();
window.onresize = function () { calculate_dashboard(); }
dashboard_scheduler(1);
""" % (MAX, GROW, raster, header_height, screen_margin, title_height,
dashlet_padding, dashlet_min_size,
- corner_overlap, refresh_dashlets, ','.join(on_resize), name,
board['mtime'],
+ corner_overlap, ','.join(refresh_dashlets),
','.join(on_resize), name, board['mtime'],
html.makeuri([('edit', '1')]), repr(dashlets_js)))
if mode == 'edit':
diff --git a/web/htdocs/js/dashboard.js b/web/htdocs/js/dashboard.js
index e7878b3..929c6b8 100644
--- a/web/htdocs/js/dashboard.js
+++ b/web/htdocs/js/dashboard.js
@@ -294,7 +294,12 @@ function dashboard_scheduler(initial) {
if ((initial && document.getElementById("dashlet_inner_" +
nr).innerHTML == '')
|| (refresh > 0 && timestamp % refresh == 0)) {
- get_url(url + "&mtime=" + dashboard_mtime,
dashboard_update_contents, "dashlet_inner_" + nr);
+ if (typeof(url) === 'string') {
+ get_url(url + "&mtime=" + dashboard_mtime,
dashboard_update_contents, "dashlet_inner_" + nr);
+ }
+ else {
+ url(); // Execute "on_refresh" javascript function
+ }
}
}
diff --git a/web/plugins/dashboard/dashlets.py b/web/plugins/dashboard/dashlets.py
index db1e8e7..34685fb 100644
--- a/web/plugins/dashboard/dashlets.py
+++ b/web/plugins/dashboard/dashlets.py
@@ -336,9 +336,9 @@ def make_pnp_url(dashlet, what):
else:
base_url = html.site_status[site]["site"]["url_prefix"]
base_url += "pnp4nagios/index.php/"
- var_part =
"?host=%s&srv=%s&source=%d&view=%s&theme=multisite&_t=%d" %
\
+ var_part =
"?host=%s&srv=%s&source=%d&view=%s&theme=multisite" % \
(pnp_cleanup(dashlet['context']['host']),
pnp_cleanup(service),
- dashlet['source'], dashlet['timerange'], int(time.time()))
+ dashlet['source'], dashlet['timerange'])
return base_url + what + var_part
def dashlet_pnpgraph(nr, dashlet):
@@ -378,6 +378,9 @@ dashlet_types["pnpgraph"] = {
""",
"on_resize" : lambda nr, dashlet: 'dashboard_render_pnpgraph(%d,
\'%s\');' %
(nr, make_pnp_url(dashlet,
'image')),
+ # execute this js handler instead of refreshing the dashlet by calling
"render" again
+ "on_refresh" : lambda nr, dashlet: 'dashboard_render_pnpgraph(%d,
\'%s\');' %
+ (nr, make_pnp_url(dashlet,
'image')),
"script": """
var dashlet_offsets = {};
function dashboard_render_pnpgraph(nr, img_url)
@@ -436,6 +439,7 @@ function load_graph_img(nr, img, img_url, c_w, c_h)
img_url += '&graph_width='+(c_w - dashlet_offsets[nr][0])
+'&graph_height='+(c_h - dashlet_offsets[nr][1]);
}
+ img_url += '&_t='+Math.floor(Date.parse(new Date()) / 1000); // prevent
caching
img.src = img_url;
}
"""