From dca19762526387300df6aa5910b3cf36c43336b1 Mon Sep 17 00:00:00 2001 From: Rahul Ruikar Date: Wed, 4 Apr 2018 19:45:35 +1000 Subject: [PATCH] feat(stack): Add the ability to scale services in stack-details (#1776) --- app/docker/views/stacks/edit/stack.html | 1 + app/docker/views/stacks/edit/stackController.js | 15 +++++++++++++++ .../stackServicesDatatable.html | 10 ++++++++++ .../stackServicesDatatable.js | 1 + 4 files changed, 27 insertions(+) diff --git a/app/docker/views/stacks/edit/stack.html b/app/docker/views/stacks/edit/stack.html index 8779e380a..9ec0404ad 100644 --- a/app/docker/views/stacks/edit/stack.html +++ b/app/docker/views/stacks/edit/stack.html @@ -27,6 +27,7 @@ nodes="nodes" public-url="state.publicURL" show-text-filter="true" + scale-action="scaleAction" > diff --git a/app/docker/views/stacks/edit/stackController.js b/app/docker/views/stacks/edit/stackController.js index 04bbe0c36..4c84d4db1 100644 --- a/app/docker/views/stacks/edit/stackController.js +++ b/app/docker/views/stacks/edit/stackController.js @@ -84,5 +84,20 @@ function ($q, $scope, $state, $transition$, StackService, NodeService, ServiceSe $scope.stackFileContent = cm.getValue(); }; + $scope.scaleAction = function scaleService(service) { + var config = ServiceHelper.serviceToConfig(service.Model); + config.Mode.Replicated.Replicas = service.Replicas; + ServiceService.update(service, config) + .then(function success(data) { + 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; + }); + }; + initView(); }]); diff --git a/app/portainer/components/datatables/stack-services-datatable/stackServicesDatatable.html b/app/portainer/components/datatables/stack-services-datatable/stackServicesDatatable.html index a5bcf30dc..651f2aeb9 100644 --- a/app/portainer/components/datatables/stack-services-datatable/stackServicesDatatable.html +++ b/app/portainer/components/datatables/stack-services-datatable/stackServicesDatatable.html @@ -63,6 +63,16 @@ {{ item.Mode }} {{ item.Tasks | runningtaskscount }} / {{ item.Mode === 'replicated' ? item.Replicas : ($ctrl.nodes | availablenodecount) }} + + + Scale + + + + + + + diff --git a/app/portainer/components/datatables/stack-services-datatable/stackServicesDatatable.js b/app/portainer/components/datatables/stack-services-datatable/stackServicesDatatable.js index 8de25b951..db28a3b76 100644 --- a/app/portainer/components/datatables/stack-services-datatable/stackServicesDatatable.js +++ b/app/portainer/components/datatables/stack-services-datatable/stackServicesDatatable.js @@ -9,6 +9,7 @@ angular.module('portainer.app').component('stackServicesDatatable', { orderBy: '@', reverseOrder: '<', nodes: '<', + scaleAction: '<', publicUrl: '<', showTextFilter: '<' }