1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

B #5758: Fix service perform action (#1825)

This commit is contained in:
Frederick Borges 2022-03-03 18:09:57 +01:00 committed by GitHub
parent cc8842aa17
commit b2a2e53d2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 151 additions and 34 deletions

View File

@ -23,29 +23,5 @@
<tr>
<td colspan="3" class="sched_place">{{{sched_actions_table}}}</td>
</tr>
<tr>
<td id="title" colspan="3">
<h6 class="title_label">{{tr "Perform an action"}}:</h6>
</td>
</tr>
<tr id="tr_schedule_base" style="vertical-align: top;">
<td style="width:50%;">
<select style="width: 100%" id="select_new_action" class="select_new_action" name="select_action">{{{actions}}}</select>
</td>
<td colspan="2">
<div style="display:flex;">
<select id="role_name" class="select_role" name="select_action" style="width: 100%">{{{roles}}}</select>
</div>
<div style="display:flex;">
<input type="number" class="hide" id="diskid" placeholder="{{tr 'Disk Id'}}" style="width: 100%">
<input type="number" class="hide" id="snapid" placeholder="{{tr 'Snap Id'}}" style="width: 100%">
<input type="text" id="snapname" class="hide" placeholder="{{tr 'Snap Name'}}" style="width: 100%">
</div>
</td>
</tr>
<tr>
<td>
<button style="margin-top: 15px;" id="add_{{res}}_action_json" class="button small success secondary radius">{{tr "Perform"}}</button>
</td>
</tr>
{{{perform_action}}}
</table>

View File

@ -80,11 +80,14 @@ define(function(require) {
);
}
function _html() {
var optionsActions = ScheduleActions.defaultActions.map(function(ac){
return "<option value='"+ac+"'>"+ac+"</option>";
}).join("");
function _htmlPerformAction(optionsRoles){
return ScheduleActions.htmlPerformAction(
RESOURCE,
optionsRoles
);
}
function _html() {
var optionsRoles = this.data
.filter(function(role) {
return role && role.name;
@ -106,9 +109,7 @@ define(function(require) {
return TemplateHTML({
sched_actions_table: _htmlSchedActions(),
actions: optionsActions,
res: RESOURCE,
roles: optionsRoles
perform_action: _htmlPerformAction(optionsRoles)
});
}
@ -121,5 +122,10 @@ define(function(require) {
context,
that
);
ScheduleActions.setupPerformAction(
RESOURCE,
that.id //service ID
);
}
});

View File

@ -18,20 +18,22 @@ define(function (require) {
/*
IMPORTS
*/
var Actions = require("opennebula/action");
var Config = require("sunstone-config");
var Humanize = require("utils/humanize");
var Locale = require("utils/locale");
var Notifier = require("utils/notifier");
var OpenNebulaVM = require("opennebula/vm");
var Sunstone = require("sunstone");
var TemplateUtils = require("utils/template-utils");
var Tips = require("utils/tips");
var Sunstone = require("sunstone");
var OpenNebulaVM = require("opennebula/vm");
/*
TEMPLATES
*/
var TemplateHTML = require("hbs!./schedule_action/html");
var TemplateTableHTML = require("hbs!./schedule_action/table");
var TemplatePerformHTML = require("hbs!./schedule_action/perform-action");
var TemplateTableRowHTML = require("hbs!./schedule_action/table-row");
var TemplateCharterTableHTML = require("hbs!./schedule_action/charter-table");
var TemplateCharterTableRowHTML = require("hbs!./schedule_action/charter-table-row");
@ -130,6 +132,96 @@ define(function (require) {
});
}
function _htmlPerformAction(resource, optionsRoles){
var optionsActions = defaultActions.map(function(ac){
return "<option value='"+ac+"'>"+ac+"</option>";
}).join("");
return TemplatePerformHTML({
res: resource,
actions: optionsActions,
roles: optionsRoles
});
}
function _setupPerformAction(resource, service_id){
$("select#select_new_action").off("change").on("change",function(){
var snap_name = $("#snapname");
var snap_id = $("#snapid");
var disk_id = $("#diskid");
switch ($(this).val()) {
case "snapshot-create":
snap_name.removeClass("hide");
snap_id.addClass("hide").val("");
disk_id.addClass("hide").val("");
break;
case "snapshot-revert":
snap_name.addClass("hide").val("");
snap_id.removeClass("hide");
disk_id.addClass("hide").val("");
break;
case "snapshot-delete":
snap_name.addClass("hide").val("");
snap_id.removeClass("hide");
disk_id.addClass("hide").val("");
break;
case "disk-snapshot-create":
snap_name.removeClass("hide");
snap_id.addClass("hide").val("");
disk_id.removeClass("hide");
break;
case "disk-snapshot-revert":
snap_name.addClass("hide").val("");
snap_id.removeClass("hide");
disk_id.removeClass("hide");
break;
case "disk-snapshot-delete":
snap_name.addClass("hide").val("");
snap_id.removeClass("hide");
disk_id.removeClass("hide");
break;
default:
snap_name.addClass("hide").val("");
snap_id.addClass("hide").val("");
disk_id.addClass("hide").val("");
break;
}
});
$("#perform_"+resource+"_action_json").off("click").on("click", function(){
var new_action = $("select#select_new_action").val();
var role = $("select#role_name").val();
var snap_name = $("#snapname").val();
var snap_id = $("#snapid").val();
var disk_id = $("#diskid").val();
if(new_action){
var actionJSON = {};
actionJSON.error = function(e){
Notifier.notifyError((e && e.error && e.error.message) || Locale.tr("Error"));
};
actionJSON.success = function(e){
Notifier.notifyMessage(Locale.tr("Bulk Action Created"));
};
actionJSON.data = {};
actionJSON.data.id = service_id;
actionJSON.data.action = {perform: new_action};
actionJSON.data.action.params = {};
if(defaultActions.includes(new_action)){
var rawData = [disk_id,snap_id,snap_name];
var args = rawData.filter(function (e) {return e;}).join();
if(args){
actionJSON.data.action.params.args = args;
}
}
if(role!=="" && role!==undefined){
actionJSON.data.roleName = role;
}
Actions.addFlowAction(actionJSON,resource);
}
return false;
});
}
function formatDate( date, type = "full") {
var d = date? new Date(date): new Date();
var month = "" + (d.getMonth() + 1);
@ -1424,5 +1516,7 @@ define(function (require) {
"updateServiceHTMLTable": _updateServiceHTMLTable,
"getScheduleActionTableContent": _getScheduleActionTableContent,
"sendSchedActionToServiceRoles": sendSchedActionToServiceRoles,
"htmlPerformAction": _htmlPerformAction,
"setupPerformAction": _setupPerformAction
};
});

View File

@ -0,0 +1,41 @@
{{! -------------------------------------------------------------------------- }}
{{! 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. }}
{{! -------------------------------------------------------------------------- }}
<tr>
<td id="title" colspan="3">
<h6 class="title_label">{{tr "Perform an action"}}:</h6>
</td>
</tr>
<tr id="tr_schedule_base" style="vertical-align: top;">
<td style="width:50%;">
<select style="width: 100%" id="select_new_action" class="select_new_action" name="select_action">{{{actions}}}</select>
</td>
<td colspan="2">
<div style="display:flex;">
<select id="role_name" class="select_role" name="select_action" style="width: 100%">{{{roles}}}</select>
</div>
<div style="display:flex;">
<input type="number" class="hide" id="diskid" placeholder="{{tr 'Disk Id'}}" style="width: 100%">
<input type="number" class="hide" id="snapid" placeholder="{{tr 'Snap Id'}}" style="width: 100%">
<input type="text" id="snapname" class="hide" placeholder="{{tr 'Snap Name'}}" style="width: 100%">
</div>
</td>
</tr>
<tr>
<td>
<button style="margin-top: 15px;" id="perform_{{res}}_action_json" class="button small success secondary radius">{{tr "Perform"}}</button>
</td>
</tr>