Module: check_mk
Branch: master
Commit: 2ae9f34f59416bcb138346045d2692d53855f0ef
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2ae9f34f59416b…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Dec 21 10:08:38 2018 +0100
Moved profile replication to dedicated module
Change-Id: I1f3aaef3c7d38144b1bb931a0c207b9ca8c18b04
---
cmk/gui/wato/user_profile.py | 4 +-
web/htdocs/js/index.js | 2 +
web/htdocs/js/modules/profile_replication.js | 103 +++++++++++++++++++++++++++
web/htdocs/js/wato.js | 84 ----------------------
4 files changed, 107 insertions(+), 86 deletions(-)
diff --git a/cmk/gui/wato/user_profile.py b/cmk/gui/wato/user_profile.py
index 2059b6e..0f1ca79 100644
--- a/cmk/gui/wato/user_profile.py
+++ b/cmk/gui/wato/user_profile.py
@@ -89,7 +89,7 @@ def user_profile_async_replication_dialog(sites):
estimated_duration = changes_manager.get_activation_time(
site_id, watolib.ACTIVATION_TIME_PROFILE_SYNC, 2.0)
html.javascript(
- 'wato_do_profile_replication(\'%s\', %d,
\'%s\');' %
+ 'cmk.profile_replication.start(\'%s\', %d,
\'%s\');' %
(site_id, int(estimated_duration * 1000.0), _('Replication in
progress')))
num_replsites += 1
else:
@@ -98,7 +98,7 @@ def user_profile_async_replication_dialog(sites):
html.close_div()
- html.javascript('var g_num_replsites = %d;\n' % num_replsites)
+ html.javascript('cmk.profile_replication.prepare(%d);\n' % num_replsites)
html.close_div()
diff --git a/web/htdocs/js/index.js b/web/htdocs/js/index.js
index 78683fa..fc593f3 100644
--- a/web/htdocs/js/index.js
+++ b/web/htdocs/js/index.js
@@ -42,6 +42,7 @@ import * as backup from "backup";
import * as hover from "hover";
import * as service_discovery from "service_discovery";
import * as host_diagnose from "host_diagnose";
+import * as profile_replication from "profile_replication";
import * as dashboard from "dashboard";
require("script-loader!./checkmk.js");
@@ -80,6 +81,7 @@ export default {
hover: hover,
service_discovery: service_discovery,
host_diagnose: host_diagnose,
+ profile_replication: profile_replication,
dashboard: dashboard
},
// TODO: Compatibility for not yet modularized JS code
diff --git a/web/htdocs/js/modules/profile_replication.js
b/web/htdocs/js/modules/profile_replication.js
new file mode 100644
index 0000000..ba72e0f
--- /dev/null
+++ b/web/htdocs/js/modules/profile_replication.js
@@ -0,0 +1,103 @@
+// +------------------------------------------------------------------+
+// | ____ _ _ __ __ _ __ |
+// | / ___| |__ ___ ___| | __ | \/ | |/ / |
+// | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+// | | |___| | | | __/ (__| < | | | | . \ |
+// | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+// | |
+// | Copyright Mathias Kettner 2014 mk(a)mathias-kettner.de |
+// +------------------------------------------------------------------+
+//
+// This file is part of Check_MK.
+// The official homepage is at
http://mathias-kettner.de/check_mk.
+//
+// check_mk is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation in version 2. check_mk is distributed
+// in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+// out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+// PARTICULAR PURPOSE. See the GNU General Public License for more de-
+// ails. You should have received a copy of the GNU General Public
+// License along with GNU Make; see the file COPYING. If not, write
+// to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+// Boston, MA 02110-1301 USA.
+
+import * as utils from "utils";
+import * as ajax from "ajax";
+
+var g_num_replsites = 0;
+var profile_replication_progress = {};
+
+export function prepare(num) {
+ g_num_replsites = num;
+}
+
+export function start(siteid, est, progress_text) {
+ ajax.call_ajax("wato_ajax_profile_repl.py", {
+ response_handler : function (handler_data, response_json) {
+ var response = JSON.parse(response_json);
+ var success = response.result_code === 0;
+ var msg = response.result;
+
+ set_result(handler_data["site_id"], success, msg);
+ },
+ error_handler : function (handler_data, status_code, error_msg) {
+ set_result(handler_data["site_id"], false,
+ "Failed to perform profile replication [" + status_code +
"]: " + error_msg);
+ },
+ method : "POST",
+ post_data : "request=" + encodeURIComponent(JSON.stringify({
+ "site": siteid
+ })),
+ handler_data : {
+ "site_id": siteid
+ },
+ add_ajax_id : false
+ });
+
+ profile_replication_progress[siteid] = 20; // 10 of 10 10ths
+ setTimeout("cmk.profile_replication.step('"+siteid+"',
"+est+", '"+progress_text+"');", est/20);
+}
+
+function set_status(siteid, image, text) {
+ var oImg = document.getElementById("site-" + siteid).childNodes[0];
+ oImg.title = text;
+ oImg.src = "images/icon_"+image+".png";
+}
+
+export function step(siteid, est, progress_text) {
+ if (profile_replication_progress[siteid] > 0) {
+ profile_replication_progress[siteid]--;
+ var perc = (20.0 - profile_replication_progress[siteid]) * 100 / 20;
+ var img;
+ if (perc >= 75)
+ img = "repl_75";
+ else if (perc >= 50)
+ img = "repl_50";
+ else if (perc >= 25)
+ img = "repl_25";
+ else
+ img = "repl_pending";
+ set_status(siteid, img, progress_text);
+
setTimeout("cmk.profile_replication.step('"+siteid+"',"+est+",
'"+progress_text+"');", est/20);
+ }
+}
+
+function set_result(site_id, success, msg) {
+ profile_replication_progress[site_id] = 0;
+
+ var icon_name = success ? "repl_success" : "repl_failed";
+
+ set_status(site_id, icon_name, msg);
+
+ g_num_replsites--;
+ if (g_num_replsites == 0) {
+ setTimeout(finish, 1000);
+ }
+}
+
+function finish() {
+ // check if we have a sidebar-main frame setup
+ if (this.parent && parent && parent.frames[1] == this)
+ utils.reload_sidebar();
+}
diff --git a/web/htdocs/js/wato.js b/web/htdocs/js/wato.js
index f1babd1..3b72ab6 100644
--- a/web/htdocs/js/wato.js
+++ b/web/htdocs/js/wato.js
@@ -261,90 +261,6 @@ function update_bulk_moveto(val) {
fields[i].options[a].selected = true;
}
-// .-Profile Repl----------------------------------------------------------.
-// | ____ __ _ _ ____ _ |
-// | | _ \ _ __ ___ / _(_) | ___ | _ \ ___ _ __ | | |
-// | | |_) | '__/ _ \| |_| | |/ _ \ | |_) / _ \ '_ \| | |
-// | | __/| | | (_) | _| | | __/ | _ < __/ |_) | | |
-// | |_| |_| \___/|_| |_|_|\___| |_| \_\___| .__/|_| |
-// | |_| |
-// +-----------------------------------------------------------------------+
-
-var profile_replication_progress = new Array();
-
-function wato_do_profile_replication(siteid, est, progress_text) {
- call_ajax("wato_ajax_profile_repl.py", {
- response_handler : function (handler_data, response_json) {
- var response = JSON.parse(response_json);
- var success = response.result_code === 0;
- var msg = response.result;
-
- set_profile_replication_result(handler_data["site_id"], success,
msg);
- },
- error_handler : function (handler_data, status_code, error_msg) {
- set_profile_replication_result(handler_data["site_id"], false,
- "Failed to perform profile replication [" + status_code +
"]: " + error_msg);
- },
- method : "POST",
- post_data : "request=" + encodeURIComponent(JSON.stringify({
- "site": siteid
- })),
- handler_data : {
- "site_id": siteid
- },
- add_ajax_id : false
- });
-
- profile_replication_progress[siteid] = 20; // 10 of 10 10ths
- setTimeout("profile_replication_step('"+siteid+"',
"+est+", '"+progress_text+"');", est/20);
-}
-
-function profile_replication_set_status(siteid, image, text) {
- var oImg = document.getElementById("site-" + siteid).childNodes[0];
- oImg.title = text;
- oImg.src = "images/icon_"+image+".png";
-}
-
-function profile_replication_step(siteid, est, progress_text) {
- if (profile_replication_progress[siteid] > 0) {
- profile_replication_progress[siteid]--;
- var perc = (20.0 - profile_replication_progress[siteid]) * 100 / 20;
- var img;
- if (perc >= 75)
- img = "repl_75";
- else if (perc >= 50)
- img = "repl_50";
- else if (perc >= 25)
- img = "repl_25";
- else
- img = "repl_pending";
- profile_replication_set_status(siteid, img, progress_text);
-
setTimeout("profile_replication_step('"+siteid+"',"+est+",
'"+progress_text+"');", est/20);
- }
-}
-
-function set_profile_replication_result(site_id, success, msg) {
- profile_replication_progress[site_id] = 0;
-
- var icon_name = success ? "repl_success" : "repl_failed";
-
- profile_replication_set_status(site_id, icon_name, msg);
-
- // g_num_replsites is set by the page code in wato.py to the number async jobs
started
- // in total
- g_num_replsites--;
-
- if (0 == g_num_replsites) {
- setTimeout(wato_profile_replication_finish, 1000);
- }
-}
-
-function wato_profile_replication_finish() {
- // check if we have a sidebar-main frame setup
- if (this.parent && parent && parent.frames[1] == this)
- cmk.utils.reload_sidebar();
-}
-
// ----------------------------------------------------------------------------
// Folderlist
// ----------------------------------------------------------------------------