diff --git a/app/docker/components/container-restart-policy/container-restart-policy-controller.js b/app/docker/components/container-restart-policy/container-restart-policy-controller.js
new file mode 100644
index 000000000..c9ece16d4
--- /dev/null
+++ b/app/docker/components/container-restart-policy/container-restart-policy-controller.js
@@ -0,0 +1,36 @@
+angular
+ .module('portainer.docker')
+ .controller('ContainerRestartPolicyController', [
+ function ContainerRestartPolicyController() {
+ var ctrl = this;
+
+ this.state = {
+ editMode :false,
+ editModel :{}
+ };
+
+
+ ctrl.toggleEdit = toggleEdit;
+ ctrl.save = save;
+
+ function toggleEdit() {
+ ctrl.state.editMode = true;
+ ctrl.state.editModel = {
+ name: ctrl.name,
+ maximumRetryCount: ctrl.maximumRetryCount
+ };
+ }
+
+ function save() {
+ if (ctrl.state.editModel.name === ctrl.name &&
+ ctrl.state.editModel.maximumRetryCount === ctrl.maximumRetryCount) {
+ ctrl.state.editMode = false;
+ return;
+ }
+ ctrl.updateRestartPolicy(ctrl.state.editModel)
+ .then(function onUpdateSucceed() {
+ ctrl.state.editMode = false;
+ });
+ }
+ }
+ ]);
diff --git a/app/docker/components/container-restart-policy/container-restart-policy.html b/app/docker/components/container-restart-policy/container-restart-policy.html
new file mode 100644
index 000000000..c5352b6e4
--- /dev/null
+++ b/app/docker/components/container-restart-policy/container-restart-policy.html
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+ Name
+ |
+ {{$ctrl.name }} |
+
+
+ Maximum Retry Count |
+
+ {{ $ctrl.maximumRetryCount }}
+ |
+
+
+
+
+
\ No newline at end of file
diff --git a/app/docker/components/container-restart-policy/container-restart-policy.js b/app/docker/components/container-restart-policy/container-restart-policy.js
new file mode 100644
index 000000000..0a8d7edf2
--- /dev/null
+++ b/app/docker/components/container-restart-policy/container-restart-policy.js
@@ -0,0 +1,10 @@
+angular.module('portainer.docker')
+.component('containerRestartPolicy', {
+ templateUrl: 'app/docker/components/container-restart-policy/container-restart-policy.html',
+ controller: 'ContainerRestartPolicyController',
+ bindings: {
+ 'name': '<',
+ 'maximumRetryCount': '<',
+ 'updateRestartPolicy': '&'
+ }
+});
diff --git a/app/docker/rest/container.js b/app/docker/rest/container.js
index d100d5a1c..d46d9e474 100644
--- a/app/docker/rest/container.js
+++ b/app/docker/rest/container.js
@@ -65,6 +65,9 @@ function ContainerFactory($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider) {
},
inspect: {
method: 'GET', params: { id: '@id', action: 'json' }
+ },
+ update: {
+ method: 'POST', params: { id: '@id', action: 'update'}
}
});
}]);
diff --git a/app/docker/services/containerService.js b/app/docker/services/containerService.js
index a0783d2d9..ce81cd8c5 100644
--- a/app/docker/services/containerService.js
+++ b/app/docker/services/containerService.js
@@ -63,6 +63,14 @@ function ContainerServiceFactory($q, Container, ResourceControlService, LogHelpe
return Container.rename({id: id, name: newContainerName }, {}).$promise;
};
+ service.updateRestartPolicy = updateRestartPolicy;
+
+ function updateRestartPolicy(id, restartPolicy, maximumRetryCounts) {
+ return Container.update({ id: id },
+ { RestartPolicy: { Name: restartPolicy, MaximumRetryCount: maximumRetryCounts } }
+ ).$promise;
+ }
+
service.createContainer = function(configuration) {
var deferred = $q.defer();
Container.create(configuration).$promise
diff --git a/app/docker/views/containers/edit/container.html b/app/docker/views/containers/edit/container.html
index 967d5321e..92815f9c0 100644
--- a/app/docker/views/containers/edit/container.html
+++ b/app/docker/views/containers/edit/container.html
@@ -223,21 +223,13 @@
-
+
Restart policies |
-
-
- Name |
- {{ container.HostConfig.RestartPolicy.Name }} |
-
-
- MaximumRetryCount |
-
- {{ container.HostConfig.RestartPolicy.MaximumRetryCount }}
- |
-
-
+
|
diff --git a/app/docker/views/containers/edit/containerController.js b/app/docker/views/containers/edit/containerController.js
index d77819136..22f56e7b7 100644
--- a/app/docker/views/containers/edit/containerController.js
+++ b/app/docker/views/containers/edit/containerController.js
@@ -15,6 +15,8 @@ function ($q, $scope, $state, $transition$, $filter, Commit, ContainerHelper, Co
leaveNetworkInProgress: false
};
+ $scope.updateRestartPolicy = updateRestartPolicy;
+
var update = function () {
var nodeName = $transition$.params().nodeName;
HttpRequestHelper.setPortainerAgentTargetHeader(nodeName);
@@ -308,6 +310,27 @@ function ($q, $scope, $state, $transition$, $filter, Commit, ContainerHelper, Co
});
};
+ function updateRestartPolicy(restartPolicy, maximumRetryCount) {
+ maximumRetryCount = restartPolicy === 'on-failure' ? maximumRetryCount : undefined;
+
+ return ContainerService
+ .updateRestartPolicy($scope.container.Id, restartPolicy, maximumRetryCount)
+ .then(onUpdateSuccess)
+ .catch(notifyOnError);
+
+ function onUpdateSuccess() {
+ $scope.container.HostConfig.RestartPolicy = {
+ Name: restartPolicy,
+ MaximumRetryCount: maximumRetryCount
+ };
+ }
+
+ function notifyOnError(err) {
+ Notifications.error('Failure', err, 'Unable to update restart policy');
+ return $q.reject(err);
+ }
+ }
+
var provider = $scope.applicationState.endpoint.mode.provider;
var apiVersion = $scope.applicationState.endpoint.apiVersion;
NetworkService.networks(