Skip to content

Commit

Permalink
Merge pull request #205 from alces-flight/fix/device-right-click-actions
Browse files Browse the repository at this point in the history
Remove status change actions for volumes and networks
  • Loading branch information
timalces authored Apr 5, 2024
2 parents 0025e23 + 0396767 commit a09eff0
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 59 deletions.
11 changes: 9 additions & 2 deletions app/javascript/canvas/irv/view/ContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,14 @@ class ContextMenu {
var view_devices;
var idx = parsed.length;
parsed.push([]);
let total_options = null;

var total_options = [].concat(ContextMenu.OPTIONS[option_set]);
if(option_set === "devices") {
let typeOptions = ContextMenu.OPTIONS["devices"][device.type] || [];
total_options = [].concat(ContextMenu.OPTIONS["devices"]["common"].concat(typeOptions));
} else {
total_options = [].concat(ContextMenu.OPTIONS[option_set]);
}

if (option_set === "racks") {
if (device.children.length > 0) {
Expand All @@ -125,6 +131,7 @@ class ContextMenu {
var option_url = option.url;
var disabled = false;
var on_click = disabled ? null : option.onClick;
let newTab = option.newTab;

piece = Util.substitutePhrase(piece, 'view_devices', view_devices);
piece = Util.substitutePhrase(piece, 'device_id', device_id);
Expand Down Expand Up @@ -185,7 +192,7 @@ class ContextMenu {
parsed[idx].push(`<a href='${option_url}' onclick=\"${on_click}\" ><div class='context_menu_item ${div_class}'>${piece}</div></a>`);
} else {
total_clickable_options_added += 1;
parsed[idx].push(`<a href='${option_url}'><div class='context_menu_item ${div_class}'>${piece}</div></a>`);
parsed[idx].push(`<a href='${option_url}'${newTab ? ' target="_blank"' : ''}><div class='context_menu_item ${div_class}'>${piece}</div></a>`);
}
} else {
parsed[idx].push(piece);
Expand Down
1 change: 1 addition & 0 deletions app/javascript/canvas/irv/view/Machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Machine extends RackObject {
this.slot_id = null;
this.selected = false;
this.assets = [];
this.type = def.type;

if (RackObject.MODEL.metricLevel !== undefined) {
this.metric = new BarMetric(this.componentClassName, this.id, this, this.x, this.y, this.width, this.height, RackObject.MODEL);
Expand Down
6 changes: 6 additions & 0 deletions app/models/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,15 @@ class Device < ApplicationRecord
####################################

def valid_action?(action)
return false unless compute_device?

VALID_STATUS_ACTION_MAPPINGS[status].include?(action)
end

def compute_device?
self.details_type == "Device::ComputeDetails"
end

def openstack_id
metadata['openstack_instance_id']
end
Expand Down
3 changes: 2 additions & 1 deletion app/models/interactive_rack_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ def generate_sql(racks, user)
XmlAttributes( D.id AS "id",
D.name AS "name",
D.status AS "buildStatus",
cast(D.cost as money) AS "cost"
cast(D.cost as money) AS "cost",
D.details_type AS "type"
)
))
FROM devices D WHERE D.id = S.id
Expand Down
3 changes: 2 additions & 1 deletion app/views/api/v1/irv/racks/show.rabl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ child(:chassis, root: 'Chassis') do |foo|
id: chassis.device.id,
name: chassis.device.name,
buildStatus: chassis.device.status,
cost: chassis.device.currency_cost
cost: chassis.device.currency_cost,
type: chassis.device.details_type
},
}
end
Expand Down
113 changes: 58 additions & 55 deletions app/views/interactive_rack_views/_configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,12 @@
{
"caption" : "View details",
"url" : "/racks/[[rack_id]]",
"rbacAction" : "view"
"rbacAction" : "view",
"newTab": true
},
{
{
"caption": "[[spacer]]"
},
},
{
"caption" : "Destroy",
"url" : "internal::statusChangeRequest,destroy,racks,[[rack_id]],[[rack_name]]",
Expand All @@ -431,58 +432,60 @@
],

"devices":
[
{
"content" : "<h1>Device [[device_name]]</h1>"
},
{
"caption" : "Focus",
"url" : "internal::focusOn,devices,[[device_id]]",
"rbacAction" : "view"
},
{
"caption" : "View details",
"url" : "/devices/[[device_id]]",
"rbacAction" : "view"
},
{
"caption": "[[spacer]]"
},
{
"caption" : "Switch off",
"url" : "internal::statusChangeRequest,off,devices,[[device_id]],[[device_name]]",
"availableToBuildStatuses": ["ACTIVE"],
"rbacAction" : "manage"
},
{
"caption" : "Switch on",
"url" : "internal::statusChangeRequest,on,devices,[[device_id]],[[device_name]]",
"availableToBuildStatuses": ["STOPPED"],
"rbacAction" : "manage"
},
{
"caption" : "Suspend",
"url" : "internal::statusChangeRequest,suspend,devices,[[device_id]],[[device_name]]",
"availableToBuildStatuses": ["ACTIVE"],
"rbacAction" : "manage"
},
{
"caption" : "Resume",
"url" : "internal::statusChangeRequest,resume,devices,[[device_id]],[[device_name]]",
"availableToBuildStatuses": ["SUSPENDED"],
"rbacAction" : "manage"
},
{
"caption" : "Destroy",
"url" : "internal::statusChangeRequest,destroy,devices,[[device_id]],[[device_name]]",
"availableToBuildStatuses": ["STOPPED", "ACTIVE", "SUSPENDED", "FAILED"],
"rbacAction" : "manage"
}
],

"common":
[
]
{
"common": [
{
"content" : "<h1>Device [[device_name]]</h1>"
},
{
"caption" : "Focus",
"url" : "internal::focusOn,devices,[[device_id]]",
"rbacAction" : "view"
},
{
"caption" : "View details",
"url" : "/devices/[[device_id]]",
"rbacAction" : "view",
"newTab": true
}
],
"Device::ComputeDetails": [
{
"caption": "[[spacer]]"
},
{
"caption" : "Switch off",
"url" : "internal::statusChangeRequest,off,devices,[[device_id]],[[device_name]]",
"availableToBuildStatuses": ["ACTIVE"],
"rbacAction" : "manage"
},
{
"caption" : "Switch on",
"url" : "internal::statusChangeRequest,on,devices,[[device_id]],[[device_name]]",
"availableToBuildStatuses": ["STOPPED"],
"rbacAction" : "manage"
},
{
"caption" : "Suspend",
"url" : "internal::statusChangeRequest,suspend,devices,[[device_id]],[[device_name]]",
"availableToBuildStatuses": ["ACTIVE"],
"rbacAction" : "manage"
},
{
"caption" : "Resume",
"url" : "internal::statusChangeRequest,resume,devices,[[device_id]],[[device_name]]",
"availableToBuildStatuses": ["SUSPENDED"],
"rbacAction" : "manage"
},
{
"caption" : "Destroy",
"url" : "internal::statusChangeRequest,destroy,devices,[[device_id]],[[device_name]]",
"availableToBuildStatuses": ["STOPPED", "ACTIVE", "SUSPENDED", "FAILED"],
"rbacAction" : "manage"
}
]
},
"common": []
},

"actionPaths":
Expand Down

0 comments on commit a09eff0

Please sign in to comment.