forked from ManageIQ/manageiq-ui-service
/
details.state.js
215 lines (183 loc) · 6.64 KB
/
details.state.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
(function() {
'use strict';
angular.module('app.states')
.run(appRun);
/** @ngInject */
function appRun(routerHelper) {
routerHelper.configureStates(getStates());
}
function getStates() {
return {
'services.details': {
url: '/:serviceId',
templateUrl: 'app/states/services/details/details.html',
controller: StateController,
controllerAs: 'vm',
title: N_('Service Details'),
resolve: {
service: resolveService,
},
},
};
}
/** @ngInject */
function resolveService($stateParams, CollectionsApi) {
var requestAttributes = [
'picture',
'picture.image_href',
'evm_owner.name',
'miq_group.description',
'aggregate_all_vm_cpus',
'aggregate_all_vm_memory',
'aggregate_all_vm_disk_count',
'aggregate_all_vm_disk_space_allocated',
'aggregate_all_vm_disk_space_used',
'aggregate_all_vm_memory_on_disk',
'actions',
'custom_actions',
'provision_dialog',
'service_template',
'chargeback_report',
'power_state',
];
var options = {
attributes: requestAttributes,
decorators: [ 'vms.supports_console?', 'vms.supports_cockpit?' ],
expand: 'vms',
};
return CollectionsApi.get('services', $stateParams.serviceId, options);
}
/** @ngInject */
function StateController($state, service, CollectionsApi, EditServiceModal, RetireServiceModal, OwnershipServiceModal,
EventNotifications, Consoles, Chargeback, PowerOperations) {
var vm = this;
setInitialVars(vm);
if (angular.isUndefined(vm.service.vms)) {
vm.vms = [];
} else {
vm.vms = vm.service.vms;
}
var actions = vm.service.actions;
if (angular.isDefined(actions)) {
for (var i = 0; i < actions.length; i++) {
if (actions[i].name === "reconfigure") {
vm.service.reconfigure = true;
}
}
}
function reconfigureService(service) {
$state.go('services.reconfigure', {serviceId: service});
}
vm.listConfig = {
selectItems: false,
showSelectBox: false,
onClick: maybeOpenConsole,
};
activate();
function activate() {
Chargeback.processReports(vm.service);
}
function setInitialVars(vm) {
vm.showRemoveService = $state.actionFeatures.serviceDelete.show;
vm.showRetireService = $state.actionFeatures.serviceRetireNow.show;
vm.showScheduleRetirementService = $state.actionFeatures.serviceRetire.show;
vm.showEditService = $state.actionFeatures.serviceEdit.show;
vm.showReconfigureService = $state.actionFeatures.serviceReconfigure.show;
vm.showSetOwnership = $state.actionFeatures.serviceOwnership.show;
vm.service = service;
vm.activate = activate;
vm.removeService = removeService;
vm.editServiceModal = editServiceModal;
vm.retireServiceNow = retireServiceNow;
vm.retireServiceLater = retireServiceLater;
vm.ownershipServiceModal = ownershipServiceModal;
vm.reconfigureService = reconfigureService;
vm.startService = PowerOperations.startService;
vm.stopService = PowerOperations.stopService;
vm.suspendService = PowerOperations.suspendService;
vm.powerOperationOffState = PowerOperations.powerOperationOffState;
vm.powerOperationUnknownState = PowerOperations.powerOperationUnknownState;
vm.powerOperationInProgressState = PowerOperations.powerOperationInProgressState;
vm.powerOperationTimeoutState = PowerOperations.powerOperationTimeoutState;
vm.powerOperationSuspendState = PowerOperations.powerOperationSuspendState;
}
function removeService() {
var removeAction = {action: 'retire'};
CollectionsApi.post('services', vm.service.id, {}, removeAction).then(removeSuccess, removeFailure);
function removeSuccess() {
EventNotifications.success(vm.service.name + __(' was removed.'));
$state.go('services.list');
}
function removeFailure(data) {
EventNotifications.error(__('There was an error removing this service.'));
}
}
/*
FIXME
this is a hack because it's impossible to access the current scope inside of
pf-list-view, and pf-list-view's actionButtons doesn't support hiding buttons
based on a condition
so the button gets .open-console-button instead of ng-click="vm.openConsole(item)"
and we're abusing onClick to verify the event came from that button and call
openConsole if so
*/
function maybeOpenConsole(item, event) {
var $target = angular.element(event.target);
if ($target.is('.open-console-button') || $target.is('.open-console-button *')) {
Consoles.open(item.id);
}
}
function editServiceModal() {
EditServiceModal.showModal(vm.service);
}
function ownershipServiceModal() {
OwnershipServiceModal.showModal(vm.service);
}
function retireServiceNow() {
var data = {action: 'retire'};
CollectionsApi.post('services', vm.service.id, {}, data).then(retireSuccess, retireFailure);
function retireSuccess() {
EventNotifications.success(vm.service.name + __(' was retired.'));
$state.go('services.list');
}
function retireFailure() {
EventNotifications.error(__('There was an error retiring this service.'));
}
}
function retireServiceLater() {
RetireServiceModal.showModal(vm.service);
}
function disableStopButton(item) {
return (vm.powerOperationOffState(item)
|| vm.powerOperationUnknownState(item)
|| vm.powerOperationInProgressState(item))
&& !vm.powerOperationTimeoutState(item);
}
function disableSuspendButton(item) {
return (vm.powerOperationSuspendState(item)
|| vm.powerOperationUnknownState(item)
|| vm.powerOperationInProgressState(item))
&& !vm.powerOperationTimeoutState(item);
}
vm.enableStartButton = function(item) {
return vm.powerOperationUnknownState(item)
|| vm.powerOperationOffState(item)
|| vm.powerOperationSuspendState(item)
|| vm.powerOperationTimeoutState(item);
};
vm.checkDisabled = function(action, item) {
if (action === 'stop') {
return disableStopButton(item);
} else if (action === 'suspend') {
return disableSuspendButton(item);
}
};
vm.handlePowerOperation = function(action, item) {
if (action === 'stop' && !vm.checkDisabled(action, item)) {
vm.stopService(item);
} else if (action === 'suspend' && !vm.checkDisabled(action, item)) {
vm.suspendService(item);
}
};
}
})();