Files
portainer/app/docker/components/datatables/services-datatable/actions/servicesDatatableActionsController.js
T
cong meng f9cf76234f feat(rbac): EE-226 Add a new RBAC "Operator" Role (#191)
* feat(rbac): EE-226 Add a new RBAC "Operator" Role

* feat(rbac): EE-226 prioritize Operator after EndpointAdmin and before Helpdesk

* feat(rbac): EE-226 access viewer shows incorrect effective role after introduce of Operator

* feat(rbac): EE-226 show roles order by priority other than name

* feat(rbac): EE-226 remove OperationK8sVolumeDetailsW authorization from operator role

* feat(rbac): EE-226 always increase bucket next sequence when create a role

Co-authored-by: Simon Meng <simon.meng@portainer.io>
2021-04-06 11:34:54 +12:00

101 lines
3.5 KiB
JavaScript

angular.module('portainer.docker').controller('ServicesDatatableActionsController', [
'$q',
'$state',
'ServiceService',
'ServiceHelper',
'Notifications',
'ModalService',
'ImageHelper',
'WebhookService',
'EndpointProvider',
'EndpointService',
function ($q, $state, ServiceService, ServiceHelper, Notifications, ModalService, ImageHelper, WebhookService, EndpointProvider, EndpointService) {
this.scaleAction = function scaleService(service) {
var config = ServiceHelper.serviceToConfig(service.Model);
config.Mode.Replicated.Replicas = service.Replicas;
ServiceService.update(service, config)
.then(function success() {
Notifications.success('Service successfully scaled', 'New replica count: ' + service.Replicas);
$state.reload();
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to scale service');
service.Scale = false;
service.Replicas = service.ReplicaCount;
});
};
this.removeAction = function (selectedItems) {
ModalService.confirmDeletion(
'Do you want to remove the selected service(s)? All the containers associated to the selected service(s) will be removed too.',
function onConfirm(confirmed) {
if (!confirmed) {
return;
}
removeServices(selectedItems);
}
);
};
this.updateAction = function (selectedItems) {
ModalService.confirmServiceForceUpdate(
'Do you want to force an update of the selected service(s)? All the tasks associated to the selected service(s) will be recreated.',
function (result) {
if (!result) {
return;
}
var pullImage = false;
if (result[0]) {
pullImage = true;
}
forceUpdateServices(selectedItems, pullImage);
}
);
};
function forceUpdateServices(services, pullImage) {
var actionCount = services.length;
angular.forEach(services, function (service) {
EndpointService.forceUpdateService(EndpointProvider.endpointID(), service.Id, pullImage)
.then(function success() {
Notifications.success('Service successfully updated', service.Name);
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to force update service', service.Name);
})
.finally(function final() {
--actionCount;
if (actionCount === 0) {
$state.reload();
}
});
});
}
function removeServices(services) {
var actionCount = services.length;
angular.forEach(services, function (service) {
ServiceService.remove(service)
.then(function success() {
return WebhookService.webhooks(service.Id, EndpointProvider.endpointID());
})
.then(function success(data) {
return $q.when(data.length !== 0 && WebhookService.deleteWebhook(data[0].Id));
})
.then(function success() {
Notifications.success('Service successfully removed', service.Name);
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to remove service');
})
.finally(function final() {
--actionCount;
if (actionCount === 0) {
$state.reload();
}
});
});
}
},
]);