From e5331ccb1da201748e77441a1681218ab791d189 Mon Sep 17 00:00:00 2001 From: Frederick Borges Date: Mon, 6 Sep 2021 12:10:59 +0200 Subject: [PATCH] F #5479: Add scheduled actions errors in vm info view (#1435) --- .../public/app/tabs/vms-tab/panels/info.js | 64 +++++++++++++------ .../public/app/utils/info-error/html.hbs | 38 +++++++++++ 2 files changed, 82 insertions(+), 20 deletions(-) create mode 100644 src/sunstone/public/app/utils/info-error/html.hbs diff --git a/src/sunstone/public/app/tabs/vms-tab/panels/info.js b/src/sunstone/public/app/tabs/vms-tab/panels/info.js index cc4d65c762..7cfb23b6e2 100644 --- a/src/sunstone/public/app/tabs/vms-tab/panels/info.js +++ b/src/sunstone/public/app/tabs/vms-tab/panels/info.js @@ -34,6 +34,7 @@ define(function(require) { */ var TemplateInfo = require("hbs!./info/html"); + var TemplateInfoError = require("hbs!utils/info-error/html"); /* CONSTANTS @@ -118,26 +119,31 @@ define(function(require) { if (this.element && this.element.USER_TEMPLATE && this.element.USER_TEMPLATE.ERROR){ - errorMessageHTML = - "
" + - "
" + - "
" + - "
"+ - "
" + - ""+ - "
"+ - "
"+ - "

" + this.element.USER_TEMPLATE.ERROR + "

" + - "
"+ - "
" + - "" + - "Dismiss"+ - "" + - "
" + - "
" + - "
" + - "
" + - "
"; + errorMessageHTML = TemplateInfoError( + { + error_msg: this.element.USER_TEMPLATE.ERROR, + error_title: Locale.tr("Driver Error"), + canDismiss: true, + dismisId: "close_vm_async_error" + } + ); + } + + if (this.element && + this.element.TEMPLATE && + this.element.TEMPLATE.SCHED_ACTION){ + var arraySchedActions = Array.isArray(this.element.TEMPLATE.SCHED_ACTION) ? + this.element.TEMPLATE.SCHED_ACTION : + [this.element.TEMPLATE.SCHED_ACTION]; + var lastErrorAndId = getLastSchedErrorAndId(arraySchedActions); + errorMessageHTML += TemplateInfoError( + { + error_msg: lastErrorAndId.error, + error_title: Locale.tr("Scheduled Action Error") + " (ID: #" + lastErrorAndId.id + ")", + canDismiss: false, + dismisId: "" + } + ); } return TemplateInfo({ @@ -162,6 +168,24 @@ define(function(require) { }); } + function getLastSchedErrorAndId(sched_array){ + var lastErrorAndId = { + error: "", + id: 0 + } + var lastEnd = 0; + $.each(sched_array, function(_, sched_action){ + if (sched_action.MESSAGE && + sched_action.END_VALUE && + parseInt(sched_action.END_VALUE) > lastEnd){ + lastErrorAndId.error = sched_action.MESSAGE; + lastErrorAndId.id = parseInt(sched_action.ID); + lastEnd = parseInt(sched_action.END_VALUE); + } + }); + return lastErrorAndId; + } + function _setup(context) { var that = this; diff --git a/src/sunstone/public/app/utils/info-error/html.hbs b/src/sunstone/public/app/utils/info-error/html.hbs new file mode 100644 index 0000000000..6c92886f82 --- /dev/null +++ b/src/sunstone/public/app/utils/info-error/html.hbs @@ -0,0 +1,38 @@ +{{! -------------------------------------------------------------------------- }} +{{! Copyright 2002-2021, OpenNebula Project, OpenNebula Systems }} +{{! }} +{{! Licensed under the Apache License, Version 2.0 (the "License"); you may }} +{{! not use this file except in compliance with the License. You may obtain }} +{{! a copy of the License at }} +{{! }} +{{! http://www.apache.org/licenses/LICENSE-2.0 }} +{{! }} +{{! Unless required by applicable law or agreed to in writing, software }} +{{! distributed under the License is distributed on an "AS IS" BASIS, }} +{{! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. }} +{{! See the License for the specific language governing permissions and }} +{{! limitations under the License. }} +{{! -------------------------------------------------------------------------- }} + +
+
+
+
+
+ +
+
+ {{error_title}}
+ {{error_msg}} +
+
+ {{#if canDismiss}} + + Dismiss + + {{/if}} +
+
+
+
+
\ No newline at end of file