1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-25 23:21:29 +03:00

F #5209: Show schedule actions in service (#740)

Co-authored-by: Jorge Lobo <jlobo@opennebula.systems>
This commit is contained in:
Jorge Miguel Lobo Escalona 2021-02-02 13:31:19 +01:00 committed by GitHub
parent df5c10c91a
commit b319722855
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 22 deletions

View File

@ -7,6 +7,14 @@ distributed on an "AS IS" BASIS, }} {{! WITHOUT WARRANTIES OR CONDITIONS OF ANY
the License for the specific language governing permissions and }} {{! limitations under the License. }} {{! --------------------------------------------------------------------------
}}
<table>
<tr>
<td id="title" colspan="3">
<h6 class="title_label">{{tr "Schedule actions in service"}}:</h6>
</td>
</tr>
<tr>
<td colspan="3">{{{sched_actions_table}}}</td>
</tr>
<tr>
<td id="title" colspan="3">
<h6 class="title_label">{{tr "Perform an action"}}:</h6>

View File

@ -23,20 +23,22 @@ define(function(require) {
var Locale = require("utils/locale");
var Actions = require("opennebula/action");
var Notifier = require("utils/notifier");
var ScheduleActions = require("utils/schedule_action");
var TemplateUtils = require("utils/template-utils");
/*
TEMPLATES
*/
var TemplateHTML = require("hbs!./sched-actions/html");
/*
CONSTANTS
*/
var TAB_ID = require('../tabId');
var PANEL_ID = require('./sched-actions/panelId');
var TAB_ID = require("../tabId");
var PANEL_ID = require("./sched-actions/panelId");
var RESOURCE = "Service";
/*
@ -49,24 +51,24 @@ define(function(require) {
this.id = (info && info.DOCUMENT && info.DOCUMENT.ID) || "0";
this.data = (info && info.DOCUMENT && info.DOCUMENT.TEMPLATE && info.DOCUMENT.TEMPLATE.BODY && info.DOCUMENT.TEMPLATE.BODY.roles) || [];
this.actions = [
"terminate",
"terminate-hard",
"hold",
"release",
"stop",
"suspend",
"resume",
"reboot",
"reboot-hard",
"poweroff",
"poweroff-hard",
"undeploy",
"undeploy-hard",
"terminate",
"terminate-hard",
"hold",
"release",
"stop",
"suspend",
"resume",
"reboot",
"reboot-hard",
"poweroff",
"poweroff-hard",
"undeploy",
"undeploy-hard",
"snapshot-create",
"snapshot-delete",
"snapshot-revert",
"disk-snapshot-create",
"disk-snapshot-delete",
"snapshot-delete",
"snapshot-revert",
"disk-snapshot-create",
"disk-snapshot-delete",
"disk-snapshot-revert"
];
return this;
@ -83,6 +85,7 @@ define(function(require) {
*/
function _html() {
var sched_actions_table = "";
var optionsActions = this.actions.map(function(ac){
return "<option value='"+ac+"'>"+ac+"</option>";
}).join("");
@ -94,7 +97,36 @@ define(function(require) {
});
optionsRoles.unshift("<option value=''>"+Locale.tr("All Roles")+"</option>");
optionsRoles = optionsRoles.join("");
if(this.data && Array.isArray(this.data) && this.data[0] && this.data[0].vm_template_contents){
var parseData = TemplateUtils.stringToTemplate(this.data[0].vm_template_contents);
if(parseData && parseData.SCHED_ACTION){
var sched_actions = Array.isArray(parseData.SCHED_ACTION)? parseData.SCHED_ACTION : [parseData.SCHED_ACTION];
sched_actions_table = $("<table/>");
sched_actions.forEach(function(schedAction){
if(schedAction && schedAction.TIME && schedAction.ACTION){
if(schedAction.TIME.startsWith("+")){
time = ScheduleActions.parseTime(schedAction.TIME);
}else{
timeWithMiliSeconds = parseInt(schedAction.TIME,10) * 1000;
timeDate = new Date(timeWithMiliSeconds);
time = "on "+timeDate.getHours()+":"+timeDate.getMinutes()+":"+timeDate.getSeconds()+" "+timeDate.getDate() +"/"+(timeDate.getMonth()+1)+"/"+timeDate.getFullYear();
}
var nameAction = schedAction.ACTION;
sched_actions_table = sched_actions_table.append(
$("<tr/>").append(
$("<td/>").text(nameAction).add(
$("<td/>").text(time)
)
)
);
}
});
sched_actions_table = sched_actions_table.prop("outerHTML");
console.log("-->", sched_actions_table);
}
}
return TemplateHTML({
sched_actions_table: sched_actions_table,
actions: optionsActions,
res: RESOURCE,
roles: optionsRoles
@ -172,7 +204,7 @@ define(function(require) {
actionJSON.data.action.params.args = args;
}
}
if(role!=='' && role!==undefined){
if(role!=="" && role!==undefined){
actionJSON.data.roleName = role;
}
Actions.addFlowAction(actionJSON,RESOURCE);

View File

@ -105,7 +105,6 @@ define(function(require) {
var schedActionTime = parseInt(confLeases[schedAction].time,10);
var startTime = Math.round(now) + schedActionTime;
var time = "+"+(last === 0? startTime.toString() : startTime+last);
console.log(Math.round(now), schedActionTime, startTime, time );
var nameAction = schedAction;
rtn = rtn.append(
$("<tr/>").append(