Module: check_mk
Branch: master
Commit: 262a7b5f7d1cce258afa4827208ad5c1bdedd9ba
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=262a7b5f7d1cce…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Dec 21 13:15:36 2018 +0100
Cleaned up dashboard dashlet JS code a bit
Change-Id: Iee39d4076163f696ab37e944844e507e8803e2f6
---
cmk/gui/dashboard.py | 10 +++++-----
cmk/gui/plugins/dashboard/utils.py | 4 +++-
web/htdocs/js/modules/dashboard.js | 8 ++++++--
3 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/cmk/gui/dashboard.py b/cmk/gui/dashboard.py
index a2e7d09..00caf70 100644
--- a/cmk/gui/dashboard.py
+++ b/cmk/gui/dashboard.py
@@ -554,7 +554,7 @@ def draw_dashboard(name):
refresh_dashlets = [] # Dashlets with automatic refresh, for Javascript
dashlet_coords = [] # Dimensions and positions of dashlet
- on_resize_dashlets = [] # javascript function to execute after ressizing the
dashlet
+ on_resize_dashlets = {} # javascript function to execute after ressizing the
dashlet
for nr, dashlet in enumerate(board["dashlets"]):
dashlet_content_html = ""
dashlet_title_html = ""
@@ -568,7 +568,7 @@ def draw_dashboard(name):
on_resize = get_dashlet_on_resize(dashlet_instance)
if on_resize:
- on_resize_dashlets.append(on_resize)
+ on_resize_dashlets[nr] = on_resize
dashlet_title_html = render_dashlet_title_html(dashlet_instance)
dashlet_content_html = render_dashlet_content(dashlet_instance,
is_update=False)
@@ -593,7 +593,7 @@ def draw_dashboard(name):
"dashlet_padding": dashlet_padding,
"dashlet_min_size": Dashlet.minimum_size,
"refresh_dashlets": refresh_dashlets,
- "on_resize_dashlets": dict(enumerate(on_resize_dashlets)),
+ "on_resize_dashlets": on_resize_dashlets,
"dashboard_name": name,
"dashboard_mtime": board['mtime'],
"dashlets": dashlet_coords,
@@ -819,7 +819,7 @@ def get_dashlet_refresh(dashlet_instance):
def get_dashlet_on_resize(dashlet_instance):
on_resize = dashlet_instance.on_resize()
if on_resize:
- return '%d: function() {%s}' % (dashlet_instance.dashlet_id, on_resize)
+ return '(function() {%s})' % on_resize
return None
@@ -901,7 +901,7 @@ def ajax_dashlet():
# prevent reloading on the dashboard which already has the current mtime,
# this is normally the user editing this dashboard. All others: reload
# the whole dashboard once.
- html.javascript('if (cmk.dashboard.dashlet_properties.dashboard_mtime <
%d) {\n'
+ html.javascript('if (cmk.dashboard.dashboard_properties.dashboard_mtime <
%d) {\n'
' parent.location.reload();\n'
'}' % board['mtime'])
diff --git a/cmk/gui/plugins/dashboard/utils.py b/cmk/gui/plugins/dashboard/utils.py
index 6eb96ee..0175d9e 100644
--- a/cmk/gui/plugins/dashboard/utils.py
+++ b/cmk/gui/plugins/dashboard/utils.py
@@ -26,6 +26,7 @@
"""Module to hold shared code for module internals and the
plugins"""
import abc
+import json
import cmk.utils.plugin_registry
@@ -350,7 +351,8 @@ class IFrameDashlet(Dashlet):
html.close_div()
if self.reload_on_resize():
- html.javascript('reload_on_resize["%d"] = "%s"' %
(self._dashlet_id, iframe_url))
+ html.javascript('cmk.dashboard.set_reload_on_resize(%s, %s);' %
(json.dumps(
+ self._dashlet_id), json.dumps(iframe_url)))
def _get_iframe_url(self):
if not self.is_iframe_dashlet():
diff --git a/web/htdocs/js/modules/dashboard.js b/web/htdocs/js/modules/dashboard.js
index d6b23a2..d4b4ea1 100644
--- a/web/htdocs/js/modules/dashboard.js
+++ b/web/htdocs/js/modules/dashboard.js
@@ -26,7 +26,11 @@ import * as utils from "utils";
import * as ajax from "ajax";
var reload_on_resize = {};
-var dashboard_properties = {};
+export var dashboard_properties = {};
+
+export function set_reload_on_resize(dashlet_id, url) {
+ reload_on_resize[dashlet_id] = url;
+}
export function set_dashboard_properties(properties) {
dashboard_properties = properties;
@@ -1158,7 +1162,7 @@ function dashlet_resized(nr, dashlet_obj) {
}
if (typeof dashboard_properties.on_resize_dashlets[nr] != "undefined") {
- dashboard_properties.on_resize_dashlets[nr]();
+ eval(dashboard_properties.on_resize_dashlets[nr])();
}
}