1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-24 21:34:01 +03:00

L #~: lint schedule_action.js (#1682)

This commit is contained in:
Jorge Miguel Lobo Escalona 2022-01-05 15:21:13 +01:00 committed by GitHub
parent ffe0d8ba70
commit de138312f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,7 +25,7 @@ define(function (require) {
var TemplateUtils = require("utils/template-utils");
var Tips = require("utils/tips");
var Sunstone = require("sunstone");
var OpenNebulaVM = require('opennebula/vm');
var OpenNebulaVM = require("opennebula/vm");
/*
TEMPLATES
@ -77,12 +77,12 @@ define(function (require) {
];
var actionsWithARGS = [
'snapshot-create',
'snapshot-revert',
'snapshot-delete',
'disk-snapshot-create',
'disk-snapshot-revert',
'disk-snapshot-delete'
"snapshot-create",
"snapshot-revert",
"snapshot-delete",
"disk-snapshot-create",
"disk-snapshot-revert",
"disk-snapshot-delete"
];
var clearEmptySpaces = function(e){
@ -95,7 +95,7 @@ define(function (require) {
minDate: currentDate,
showOptions: { direction: "down" }
};
var options_hour_picker = {
title: Locale.tr("Hour"),
twentyFour: "true",
@ -110,10 +110,10 @@ define(function (require) {
/**
* This functions returns the HTML string for the Schedule Action Table.
*
*
* @param {('vms'|'inst'|'temp'|'flow'|'service_create')} resource - Resource.
* @param {boolean} leases - Can add leases?
* @param {boolean} header - Should generate the table header?
* @param {boolean} header - Should generate the table header?
* @param {string} body - Body HTML string.
* @param {boolean} isVM - is it the VM view?
* @param {boolean} canAdd - Can add schedule actions?
@ -130,34 +130,34 @@ define(function (require) {
});
}
function formatDate( date, type = 'full') {
function formatDate( date, type = "full") {
var d = date? new Date(date): new Date();
var month = '' + (d.getMonth() + 1);
var day = '' + d.getDate();
var month = "" + (d.getMonth() + 1);
var day = "" + d.getDate();
var year = d.getFullYear();
var hour = d.getHours();
var minutes = d.getMinutes();
if (hour.length < 2)
hour = '0' + hour;
hour = "0" + hour;
if (minutes.length < 2)
minutes = '0' + minutes;
minutes = "0" + minutes;
if (month.length < 2)
month = '0' + month;
month = "0" + month;
if (day.length < 2)
day = '0' + day;
day = "0" + day;
var date = [];
switch (type) {
case 'hour':
case "hour":
date = [hour+":"+minutes];
break;
case 'date':
case "date":
date = [year, month, day];
break;
default:
date = [year, month, day, hour+":"+minutes];
break;
}
return date.join('-');
return date.join("-");
}
function addPickers(schedule,context){
@ -386,8 +386,8 @@ define(function (require) {
var relative = true;
Object.keys(dataJSON).forEach(function(key){
valuesForRelative = ['ACTION','ID','TIME'];
if(key!=='ARGS' && !valuesForRelative.includes(key)){
valuesForRelative = ["ACTION","ID","TIME"];
if(key!=="ARGS" && !valuesForRelative.includes(key)){
relative = false;
}
});
@ -447,7 +447,7 @@ define(function (require) {
}
//relative check
if(relative){
$('#relative_time').prop('checked', true);
$("#relative_time").prop("checked", true);
$("#relative_time_form").removeClass("hide");
$("#no_relative_time_form").addClass("hide");
if(dataJSON.TIME){
@ -458,25 +458,25 @@ define(function (require) {
$("#time_number").val(relativeDate[0]);
}
if(relativeDate[1]){
$('#time_unit').val(relativeDate[1].toLowerCase());
$("#time_unit").val(relativeDate[1].toLowerCase());
}
}
}
}else{
$('#relative_time').prop('checked', false);
$("#relative_time").prop("checked", false);
$("#relative_time_form").addClass("hide");
$("#no_relative_time_form").removeClass("hide");
//periodic check
if(dataJSON.DAYS || dataJSON.REPEAT){
$('#schedule_type').click().attr('checked', true);
$("#schedule_type").click().attr("checked", true);
}
if(dataJSON.TIME && dataJSON.TIME > 1){
var end_value = parseInt(dataJSON.TIME,10) * 1000;
$("#date_input").val(
formatDate(end_value,'date')
formatDate(end_value,"date")
);
$("#time_input").val(
formatDate(end_value, 'hour')
formatDate(end_value, "hour")
);
}else{
_resetInputs();
@ -484,8 +484,8 @@ define(function (require) {
if(dataJSON.REPEAT && dataJSON.REPEAT.length){
_resetRepeatValues();
switch (dataJSON.REPEAT) {
case '0':
$("#repeat").val('week').change();
case "0":
$("#repeat").val("week").change();
if(dataJSON.DAYS && dataJSON.DAYS.length){
var days = $("#days_week_value input[name=days]");
var dataDays = dataJSON.DAYS.split(",");
@ -496,20 +496,20 @@ define(function (require) {
});
}
break;
case '1':
$("#repeat").val('month').change();
case "1":
$("#repeat").val("month").change();
if(dataJSON.DAYS && dataJSON.DAYS.length){
$("#days_month_value").val(dataJSON.DAYS);
}
break;
case '2':
$("#repeat").val('year').change();
case "2":
$("#repeat").val("year").change();
if(dataJSON.DAYS && dataJSON.DAYS.length){
$("#days_year_value").val(dataJSON.DAYS);
}
break;
case '3':
$("#repeat").val('hour').change();
case "3":
$("#repeat").val("hour").change();
if(dataJSON.DAYS && dataJSON.DAYS.length){
$("#days_hour_value").val(dataJSON.DAYS);
}
@ -536,7 +536,7 @@ define(function (require) {
if(dataJSON.END_VALUE && dataJSON.END_VALUE.length){
var end_value = parseInt(dataJSON.END_VALUE,10) * 1000;
$("#end_value_date").val(
formatDate(end_value,'date')
formatDate(end_value,"date")
);
}
break;
@ -574,12 +574,12 @@ define(function (require) {
}
function _resetRepeat(){
$("#repeat").val('week').change();
$("#repeat").val("week").change();
}
function _resetInputs(){
$("#date_input").val(
formatDate(false, 'date')
formatDate(false, "date")
);
$("#time_input").val(defaultHour);
}
@ -597,12 +597,12 @@ define(function (require) {
actionJSON.ID = String(index);
}
}
if (!$.isEmptyObject(actionJSON)) {
var sched_action = isService ?
if (!$.isEmptyObject(actionJSON)) {
var sched_action = isService ?
{ SCHED_ACTION: actionJSON}
:
actionJSON;
actionsJSON.push(sched_action);
};
});
@ -664,7 +664,7 @@ define(function (require) {
}
end_type = 2;
var timeCal = date_input_value + " " + time_input_value;
var time = dateToEpoch(new Date(timeCal))
var time = dateToEpoch(new Date(timeCal));
sched_action.END_TYPE = end_type;
sched_action.END_VALUE = time;
sched_action.TIME = time;
@ -708,7 +708,7 @@ define(function (require) {
return false;
}
var time_value = end_date + " 12:00";
end_value = dateToEpoch(new Date(time_value))
end_value = dateToEpoch(new Date(time_value));
}
sched_action.DAYS = String(days);
sched_action.REPEAT = String(rep);
@ -741,22 +741,22 @@ define(function (require) {
function validateScheduleInputsEmpty(action, snap_name, snap_id, disk_id){
switch (action) {
case 'snapshot-create':
case "snapshot-create":
rtn = snap_name.length<=0;
break;
case 'snapshot-revert':
case "snapshot-revert":
rtn = snap_id.length<=0;
break;
case 'snapshot-delete':
case "snapshot-delete":
rtn = snap_id.length<=0;
break;
case 'disk-snapshot-create':
case "disk-snapshot-create":
rtn = snap_name.length<=0 || disk_id.length<=0;
break;
case 'disk-snapshot-revert':
case "disk-snapshot-revert":
rtn = snap_id.length<=0 || disk_id.length<=0;
break;
case 'disk-snapshot-delete':
case "disk-snapshot-delete":
rtn = snap_id.length<=0 || disk_id.length<=0;
break;
default:
@ -827,10 +827,10 @@ define(function (require) {
}
}
}
/**
* This functions creates the HTML for the schedule actions rows.
*
*
* @param {object} schedule_action - Schedule action object.
* @param {boolean} canEdit - Is edit allowed?
* @param {bool ean} canDelete - Is delete allowed?
@ -872,14 +872,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;
@ -904,17 +904,17 @@ define(function (require) {
sched_obj.action = JSON.stringify(schedule_action);
sched_obj.name = schedule_action.ACTION;
sched_obj.canEdit = canEdit && sched_obj.id;
sched_obj.canDelete = canDelete && sched_obj.id;
sched_obj.canEditOrDelete = (canEdit || canDelete) && sched_obj.id;
sched_obj.canEditOrDelete = (canEdit || canDelete) && sched_obj.id;
return TemplateTableRowHTML(sched_obj);
}
/**
* This function gets the function
*
* This function gets the function
*
* @param {object} data - Schedule action information.
* @returns {string} - Schedule action string.
*/
@ -924,7 +924,7 @@ define(function (require) {
/**
* This function send the schedule action to each role.
*
*
* @param {Array} roles - Service Roles.
* @param {string} action - Action name.
* @param {object} sched_obj - Schedule action object.
@ -944,7 +944,7 @@ define(function (require) {
case "VM.sched_action_add":
case "VM.sched_action_update":
Sunstone.runAction(action, node.vm_info.VM.ID , sched_obj, callback);
break
break;
case "VM.sched_action_delete":
Sunstone.runAction(action, node.vm_info.VM.ID, sched_id, callback);
break;
@ -952,14 +952,14 @@ define(function (require) {
break;
}
}
})
});
});
}
/**
* This function updates the Service datatable with the services information
* of the first service vm.
*
* of the first service vm.
*
* @param {object} that - Service object.
* @param {string} selector - JQuery selector text.
* @param {Function} htmlFunction - Function to execute to get the HTML.
@ -988,7 +988,7 @@ define(function (require) {
/**
* This function setup the buttons in the Actions view.
*
*
* @param {('vms'|'inst'|'temp'|'flow'|'service_create')} resource - Resource.
* @param {object} context - Context object.
* @param {object} that - Object.
@ -1024,8 +1024,8 @@ define(function (require) {
context.on("click" , "#add_"+resource+"_action_json", function(e) {
e.preventDefault();
var sched_action = { SCHED_ACTION: _retrieveNewAction(context) };
if (sched_action['SCHED_ACTION'] == false) {
if (sched_action["SCHED_ACTION"] == false) {
return false;
}
@ -1039,7 +1039,7 @@ define(function (require) {
case "service_create":
case "temp":
validateAndInitVariables(resource);
scheduleActionsArray.push(sched_action['SCHED_ACTION']);
scheduleActionsArray.push(sched_action["SCHED_ACTION"]);
$("#sched_" + resource + "_actions_body").html(
_getScheduleActionTableContent(scheduleActionsArray)
);
@ -1050,8 +1050,8 @@ define(function (require) {
callback: function() {
var selector = "#sched_" + resource + "_actions_body";
_updateServiceHTMLTable(that, selector, _getScheduleActionTableContent);
}
}
}
};
sendSchedActionToServiceRoles(roles, "VM.sched_action_add", sched_template, extraParams);
break;
default:
@ -1074,19 +1074,19 @@ define(function (require) {
});
// Edit Schedule action
context.off("click" , "#edit_"+ resource +"_action_json")
context.off("click" , "#edit_"+ resource +"_action_json");
context.on("click" , "#edit_"+ resource +"_action_json", function(e){
e.preventDefault();
var id = $(this).attr("data_id");
if(id && id.length){
$(".wickedpicker").hide();
var sched_action = { SCHED_ACTION: _retrieveNewAction(context) };
if (sched_action['SCHED_ACTION'] != false) {
if (sched_action["SCHED_ACTION"] != false) {
sched_action.SCHED_ACTION.ID = id;
var obj = {
"sched_id" : id,
"sched_template" : TemplateUtils.templateToString(sched_action)
}
};
switch (resource) {
case "vms":
Sunstone.runAction("VM.sched_action_update", that.element.ID, obj);
@ -1097,7 +1097,7 @@ define(function (require) {
case "temp":
validateAndInitVariables(resource);
delete sched_action.SCHED_ACTION.ID;
scheduleActionsArray[id] = sched_action['SCHED_ACTION'];
scheduleActionsArray[id] = sched_action["SCHED_ACTION"];
$("#sched_" + resource + "_actions_body").html(
_getScheduleActionTableContent(scheduleActionsArray)
);
@ -1108,8 +1108,8 @@ define(function (require) {
callback: function() {
var selector = "#sched_" + resource + "_actions_body";
_updateServiceHTMLTable(that, selector, _getScheduleActionTableContent);
}
}
}
};
sendSchedActionToServiceRoles(roles, "VM.sched_action_update", obj, extraParams);
break;
default:
@ -1128,7 +1128,7 @@ define(function (require) {
var id = $(this).attr("data_id");
switch (resource) {
case "vms":
Sunstone.runAction("VM.sched_action_delete", that.element.ID, id);
Sunstone.runAction("VM.sched_action_delete", that.element.ID, id);
break;
case "inst":
case "inst_flow":
@ -1147,9 +1147,9 @@ define(function (require) {
callback: function() {
var selector = "#sched_" + resource + "_actions_body";
_updateServiceHTMLTable(that, selector, _getScheduleActionTableContent);
}
}
sendSchedActionToServiceRoles(roles, "VM.sched_action_delete", null, extraParams);
}
};
sendSchedActionToServiceRoles(roles, "VM.sched_action_delete", null, extraParams);
break;
default:
break;
@ -1159,13 +1159,13 @@ define(function (require) {
context.off("click", "#leases_btn");
context.on("click", "#leases_btn", function(e) {
var confLeases = config.system_config.leases;
displayAlertCreateLeases(resource, that, confLeases);
displayAlertCreateLeases(resource, that, confLeases);
});
}
/**
* Returns an HTML string with the json keys and values
*
*
* @param {Object[]} actions_array - Schedule action array.
* @returns {string} - HTML string with the json keys and values
*/
@ -1180,7 +1180,7 @@ define(function (require) {
if (!actions_array) {
return empty;
}
if (!sched_actions.length) {
return empty;
}
@ -1203,7 +1203,7 @@ define(function (require) {
/**
* This function adds the leases to an instantiated VM.
*
*
* @param {object[]} leasesArray - Array with all the actions to be added.
* @param {string} vm_id - ID from the VM to send the action.
*/
@ -1216,7 +1216,7 @@ define(function (require) {
/**
* This function adds the leases to an instantiated Service.
*
*
* @param {Object[]} leassesArray - Array with all the actions to be added.
* @param {Object[]} roles - Service roles.
*/
@ -1226,8 +1226,8 @@ define(function (require) {
var extraParams = {
callback: function() {
Sunstone.runAction("Service.refresh");
}
}
}
};
sendSchedActionToServiceRoles(
roles,
"VM.sched_action_add",
@ -1239,7 +1239,7 @@ define(function (require) {
/**
* This function converts the given date to epoch.
*
*
* @returns - Current date and hour in epoch format.
*/
function dateToEpoch(date){
@ -1267,7 +1267,7 @@ define(function (require) {
function addSchedActionTable(leasesArray, resource){
$.each(leasesArray, function(_, sched_action){
scheduleActionsArray.push(sched_action['SCHED_ACTION']);
scheduleActionsArray.push(sched_action["SCHED_ACTION"]);
});
$("#sched_" + resource + "_actions_body").html(
@ -1277,14 +1277,14 @@ define(function (require) {
/**
* This function shows the modal to confirm the leases creation.
*
*
* @param {('vms'|'inst'|'temp'|'flow'|'service_create')} resource - Resource.
* @param {object} template - Resource template.
*/
function displayAlertCreateLeases(resource, that, confLeases){
var template = that.element;
var now = 0;
var stime = 0
var stime = 0;
var confLeasesCopy = JSON.parse(JSON.stringify(confLeases));
if (template && template.STIME){
stime = parseInt(template.STIME,10);
@ -1316,13 +1316,13 @@ define(function (require) {
confLeasesCopy[actionName].time = "+" + (epochDate - stime);
});
switch (resource) {
case 'vms':
case "vms":
addLeasesToVM(
_leasesToScheduleActions(confLeasesCopy, now),
template.ID
);
break;
case 'flow':
case "flow":
var roles = Array.isArray(that.data)? that.data : [that.data];
addLeasesToService(
_leasesToScheduleActions(confLeasesCopy, now),
@ -1342,7 +1342,7 @@ define(function (require) {
/**
* This function generates the content for the confirm dialog body.
*
*
* @param {number} now - Now time.
* @param {Object} confLeases - Object with the configured leases.
* @param {number} stime - Template start time.
@ -1366,31 +1366,31 @@ define(function (require) {
var hour = (datetime.split(" ")[0]).split(":");
// This variable have [Day, Month, Year]
var date = (datetime.split(" ")[1]).split("/");
var dateValue = date[2] + "-" + date[1] + "-" + date[0];
var hourValue = hour[0] + ":" + hour[1];
body += TemplateCharterTableRowHTML({
'actionName': actionName,
'dateValue': dateValue,
'hourValue': hourValue
"actionName": actionName,
"dateValue": dateValue,
"hourValue": hourValue
});
last = schedActionTime;
}
});
}
return TemplateCharterTableHTML({
'res': resource,
'body': body
"res": resource,
"body": body
});
}
/**
* This functions initializes the global variables with the current
* schedule actions.
*
*
* @param {('vms'|'inst'|'temp'|'flow'|'service_create')} resource - Resource.
*/
function validateAndInitVariables(resource){