From 5956aa376582384ea8c00e8fa11831a021ff34f2 Mon Sep 17 00:00:00 2001 From: Sergio Betanzos Date: Wed, 27 May 2020 18:37:19 +0200 Subject: [PATCH] B #3465: Fix VM log tab on federated oned (#4826) --- src/sunstone/public/app/sunstone-config.js | 1 + .../public/app/tabs/vms-tab/panels/log.js | 46 ++++++++++++------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/sunstone/public/app/sunstone-config.js b/src/sunstone/public/app/sunstone-config.js index b4d2a6cf77..73960b8653 100644 --- a/src/sunstone/public/app/sunstone-config.js +++ b/src/sunstone/public/app/sunstone-config.js @@ -183,6 +183,7 @@ define(function(require) { "high":_config["user_config"]["threshold_high"] }, "isExtendedVmInfo": _config["system_config"] && _config["system_config"]["get_extended_vm_info"] && _config["system_config"]["get_extended_vm_info"] === "true", + "isLogEnabled": _config["zone_id"] === _config["id_own_federation"] ? true : false, }; return Config; diff --git a/src/sunstone/public/app/tabs/vms-tab/panels/log.js b/src/sunstone/public/app/tabs/vms-tab/panels/log.js index 0ffab75f28..4d8da28fdf 100644 --- a/src/sunstone/public/app/tabs/vms-tab/panels/log.js +++ b/src/sunstone/public/app/tabs/vms-tab/panels/log.js @@ -22,6 +22,7 @@ define(function(require) { var Locale = require("utils/locale"); var Notifier = require("utils/notifier"); var OpenNebulaVM = require("opennebula/vm"); + var SunstoneConfig = require("sunstone-config"); /* CONSTANTS @@ -58,15 +59,17 @@ define(function(require) { */ function _html() { - return "
" + - "
" + - "
" + - "" + - "" + - "" + + if (SunstoneConfig.isLogEnabled) { + return "
" + + "
" + + "
" + + "" + + "" + + "" + + "
" + "
" + - "
" + - "
"; + "
"; + } } function _setup(context) { @@ -77,12 +80,18 @@ define(function(require) { OpenNebulaVM.log({ data: {id: that.element.ID}, success: function(req, response) { + // When log is empty + if (response.vm_log === "") { + $(".vm_log_container", context).html(secondaryCenterLabel(Locale.tr("Log file is empty"))); + return; + } + var log_lines = response["vm_log"].split("\n"); var colored_log = ""; for (var i = 0; i < log_lines.length; i++) { var line = escapeHtml(log_lines[i]); if (line.match(/\[E\]/)) { - line = "" + line + ""; + line = "" + line + ""; } colored_log += line + "
"; } @@ -97,20 +106,23 @@ define(function(require) { }, error: function(request, error_json) { - $(".vm_log_container", context).html( - "
" + - "
" + - "
" + - " "+Locale.tr("Some ad-block extensions are known to filter the '/log?id=' URL")+"" + - "
" + - "
" + - "
"); + $(".vm_log_container", context).html(secondaryCenterLabel(Locale.tr("Some ad-block extensions are known to filter the '/log?id=' URL"))); Notifier.onError(request, error_json); } }); } + function secondaryCenterLabel(text) { + return "
" + + "
" + + "
" + + " " + text + "" + + "
" + + "
" + + "
"; + } + function escapeHtml(log_line) { return log_line .replace(/&/g, "&")