From 1563476aa1a33056a4f1da6f88c3f37d1be9af5e Mon Sep 17 00:00:00 2001 From: Jorge Miguel Lobo Escalona Date: Tue, 25 Oct 2022 18:48:12 +0200 Subject: [PATCH] B #~: update schedule icon (#2324) --- .../form-panels/instantiate.js | 6 +-- .../public/app/utils/schedule_action.js | 46 +++++++++++++++++-- 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/instantiate.js b/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/instantiate.js index 380bd3bc63..735d701ccb 100644 --- a/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/instantiate.js +++ b/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/instantiate.js @@ -291,7 +291,7 @@ define(function(require) { } if (that.service_template_json.DOCUMENT.TEMPLATE.BODY.roles) { var charters = ""; - var scheduleActionsList = ScheduleActions.retrieve(context, true) + var scheduleActionsList = ScheduleActions.retrieve(context, true); $.each(scheduleActionsList, function(_,sched_action){ charters += TemplateUtils.templateToString(sched_action); @@ -338,9 +338,7 @@ define(function(require) { } }); if(charters.length){ - (temp_role.vm_template_contents !== undefined) - ? temp_role.vm_template_contents += charters - : temp_role.vm_template_contents = charters; + temp_role.vm_template_contents = charters; } extra_info.merge_template.roles.push(temp_role); }); diff --git a/src/sunstone/public/app/utils/schedule_action.js b/src/sunstone/public/app/utils/schedule_action.js index f5077c314a..f414cc5fc8 100644 --- a/src/sunstone/public/app/utils/schedule_action.js +++ b/src/sunstone/public/app/utils/schedule_action.js @@ -145,7 +145,7 @@ define(function (require) { roles: optionsRoles }); } - + function _setupPerformAction(resource, service_id){ $("select#select_new_action").off("change").on("change",function(){ var snap_name = $("#snapname"); @@ -727,7 +727,7 @@ define(function (require) { $("#sched_" + this.res + "_actions_table .create", context).remove(); var actionsJSON = []; - $("#sched_" + this.res + "_actions_table tbody tr").each(function (index) { + $("#sched_" + this.res + "_actions_table tbody tr", context).each(function (index) { var first = $(this).children("td")[0]; if (!$("select", first).html()) { //table header var actionJSON = {}; @@ -1016,14 +1016,14 @@ define(function (require) { sched_obj.end_str = Locale.tr("None"); break; case "1": - sched_obj.end_str = Locale.tr("After") + + sched_obj.end_str = Locale.tr("After") + " " + schedule_action.END_VALUE + " " + Locale.tr("times"); break; case "2": - sched_obj.end_str = Locale.tr("On") + + sched_obj.end_str = Locale.tr("On") + " " + Humanize.prettyTime(schedule_action.END_VALUE); break; @@ -1095,6 +1095,39 @@ define(function (require) { }); } + /** + * This function updates the Service vm_template_contents with the scheduled + * actions of the first service vm. + * + * @param {object} service - Service object. + */ + function _updateVmTemplateContents(service){ + if ( + service && + service.data && + service.data[0] && + service.data[0].nodes && + service.data[0].nodes[0] && + service.data[0].nodes[0].deploy_id >= 0){ + OpenNebulaVM.show({ + data : { + id: service.data[0].nodes[0].deploy_id + }, + success: function(_, vmTemplate){ + var sched_action = { SCHED_ACTION: vmTemplate.VM.TEMPLATE.SCHED_ACTION }; + var sched_template = TemplateUtils.templateToString(sched_action); + service.body.roles.forEach(role => { + role.vm_template_contents = sched_template; + }); + Sunstone.runAction("Service.update",service.id, JSON.stringify(service.body)); + }, + error: function(error){ + Notifier.onError("VM: " +error); + } + }); + } + } + /** * This function updates the Service datatable with the services information * of the first service vm. @@ -1189,6 +1222,7 @@ define(function (require) { callback: function() { var selector = "#sched_" + resource + "_actions_body"; _updateServiceHTMLTable(that, selector, _getScheduleActionTableContent); + _updateVmTemplateContents(that); } }; sendSchedActionToServiceRoles(roles, "VM.sched_action_add", sched_template, extraParams); @@ -1247,6 +1281,7 @@ define(function (require) { callback: function() { var selector = "#sched_" + resource + "_actions_body"; _updateServiceHTMLTable(that, selector, _getScheduleActionTableContent); + _updateVmTemplateContents(that); } }; sendSchedActionToServiceRoles(roles, "VM.sched_action_update", obj, extraParams); @@ -1286,6 +1321,7 @@ define(function (require) { callback: function() { var selector = "#sched_" + resource + "_actions_body"; _updateServiceHTMLTable(that, selector, _getScheduleActionTableContent); + _updateVmTemplateContents(that); } }; sendSchedActionToServiceRoles(roles, "VM.sched_action_delete", null, extraParams); @@ -1523,7 +1559,7 @@ define(function (require) { }); } } - + return TemplateCharterTableHTML({ "res": resource,