2018-02-01 12:27:52 +00:00
|
|
|
angular.module('portainer.docker')
|
2018-05-06 07:15:57 +00:00
|
|
|
.controller('ContainersController', ['$q', '$scope', '$state', '$filter', '$transition$', 'ContainerService', 'SystemService', 'Notifications', 'ModalService', 'EndpointProvider', 'HttpRequestHelper',
|
|
|
|
function ($q, $scope, $state, $filter, $transition$, ContainerService, SystemService, Notifications, ModalService, EndpointProvider, HttpRequestHelper) {
|
2017-12-06 11:04:02 +00:00
|
|
|
$scope.state = {
|
|
|
|
publicURL: EndpointProvider.endpointPublicURL()
|
2016-06-02 05:34:03 +00:00
|
|
|
};
|
|
|
|
|
2017-12-06 11:04:02 +00:00
|
|
|
$scope.startAction = function(selectedItems) {
|
|
|
|
var successMessage = 'Container successfully started';
|
|
|
|
var errorMessage = 'Unable to start container';
|
|
|
|
executeActionOnContainerList(selectedItems, ContainerService.startContainer, successMessage, errorMessage);
|
2017-01-24 01:28:40 +00:00
|
|
|
};
|
|
|
|
|
2017-12-06 11:04:02 +00:00
|
|
|
$scope.stopAction = function(selectedItems) {
|
|
|
|
var successMessage = 'Container successfully stopped';
|
|
|
|
var errorMessage = 'Unable to stop container';
|
|
|
|
executeActionOnContainerList(selectedItems, ContainerService.stopContainer, successMessage, errorMessage);
|
2016-06-02 05:34:03 +00:00
|
|
|
};
|
|
|
|
|
2017-12-06 11:04:02 +00:00
|
|
|
$scope.restartAction = function(selectedItems) {
|
|
|
|
var successMessage = 'Container successfully restarted';
|
|
|
|
var errorMessage = 'Unable to restart container';
|
|
|
|
executeActionOnContainerList(selectedItems, ContainerService.restartContainer, successMessage, errorMessage);
|
2016-06-02 05:34:03 +00:00
|
|
|
};
|
|
|
|
|
2017-12-06 11:04:02 +00:00
|
|
|
$scope.killAction = function(selectedItems) {
|
|
|
|
var successMessage = 'Container successfully killed';
|
|
|
|
var errorMessage = 'Unable to kill container';
|
|
|
|
executeActionOnContainerList(selectedItems, ContainerService.killContainer, successMessage, errorMessage);
|
2016-06-02 05:34:03 +00:00
|
|
|
};
|
|
|
|
|
2017-12-06 11:04:02 +00:00
|
|
|
$scope.pauseAction = function(selectedItems) {
|
|
|
|
var successMessage = 'Container successfully paused';
|
|
|
|
var errorMessage = 'Unable to pause container';
|
|
|
|
executeActionOnContainerList(selectedItems, ContainerService.pauseContainer, successMessage, errorMessage);
|
2016-06-02 05:34:03 +00:00
|
|
|
};
|
|
|
|
|
2017-12-06 11:04:02 +00:00
|
|
|
$scope.resumeAction = function(selectedItems) {
|
|
|
|
var successMessage = 'Container successfully resumed';
|
|
|
|
var errorMessage = 'Unable to resume container';
|
|
|
|
executeActionOnContainerList(selectedItems, ContainerService.resumeContainer, successMessage, errorMessage);
|
2016-06-02 05:34:03 +00:00
|
|
|
};
|
2017-09-19 16:24:41 +00:00
|
|
|
|
2017-12-06 11:04:02 +00:00
|
|
|
$scope.confirmRemoveAction = function(selectedItems) {
|
2017-04-25 08:20:57 +00:00
|
|
|
var isOneContainerRunning = false;
|
2017-12-06 11:04:02 +00:00
|
|
|
for (var i = 0; i < selectedItems.length; i++) {
|
|
|
|
var container = selectedItems[i];
|
|
|
|
if (container.State === 'running') {
|
2017-04-25 08:20:57 +00:00
|
|
|
isOneContainerRunning = true;
|
2017-12-06 11:04:02 +00:00
|
|
|
break;
|
2017-04-25 08:20:57 +00:00
|
|
|
}
|
2017-12-06 11:04:02 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 10:18:06 +00:00
|
|
|
var title = 'You are about to remove one or more container.';
|
2017-04-25 08:20:57 +00:00
|
|
|
if (isOneContainerRunning) {
|
2017-12-06 11:04:02 +00:00
|
|
|
title = 'You are about to remove one or more running container.';
|
2017-04-25 08:20:57 +00:00
|
|
|
}
|
2017-12-06 11:04:02 +00:00
|
|
|
|
|
|
|
ModalService.confirmContainerDeletion(title, function (result) {
|
2017-05-01 10:18:06 +00:00
|
|
|
if(!result) { return; }
|
2017-12-06 11:04:02 +00:00
|
|
|
var cleanVolumes = false;
|
2017-05-01 10:18:06 +00:00
|
|
|
if (result[0]) {
|
2017-12-06 11:04:02 +00:00
|
|
|
cleanVolumes = true;
|
2017-05-01 10:18:06 +00:00
|
|
|
}
|
2017-12-06 11:04:02 +00:00
|
|
|
removeAction(selectedItems, cleanVolumes);
|
2017-05-01 10:18:06 +00:00
|
|
|
}
|
|
|
|
);
|
2017-04-25 08:20:57 +00:00
|
|
|
};
|
2017-07-12 14:11:11 +00:00
|
|
|
|
2017-12-06 11:04:02 +00:00
|
|
|
function executeActionOnContainerList(containers, action, successMessage, errorMessage) {
|
|
|
|
var actionCount = containers.length;
|
|
|
|
angular.forEach(containers, function (container) {
|
2018-05-06 07:15:57 +00:00
|
|
|
HttpRequestHelper.setPortainerAgentTargetHeader(container.NodeName);
|
2017-12-06 11:04:02 +00:00
|
|
|
action(container.Id)
|
|
|
|
.then(function success() {
|
|
|
|
Notifications.success(successMessage, container.Names[0]);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, errorMessage);
|
|
|
|
})
|
|
|
|
.finally(function final() {
|
|
|
|
--actionCount;
|
|
|
|
if (actionCount === 0) {
|
|
|
|
$state.transitionTo($state.current, { selectedContainers: containers }, { reload: true });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2017-07-08 08:07:08 +00:00
|
|
|
}
|
2017-07-12 14:11:11 +00:00
|
|
|
|
2017-12-06 11:04:02 +00:00
|
|
|
function removeAction(containers, cleanVolumes) {
|
|
|
|
var actionCount = containers.length;
|
|
|
|
angular.forEach(containers, function (container) {
|
2018-05-06 07:15:57 +00:00
|
|
|
HttpRequestHelper.setPortainerAgentTargetHeader(container.NodeName);
|
2017-12-06 11:04:02 +00:00
|
|
|
ContainerService.remove(container, cleanVolumes)
|
|
|
|
.then(function success() {
|
|
|
|
Notifications.success('Container successfully removed', container.Names[0]);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to remove container');
|
|
|
|
})
|
|
|
|
.finally(function final() {
|
|
|
|
--actionCount;
|
|
|
|
if (actionCount === 0) {
|
|
|
|
$state.reload();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2017-07-08 08:07:08 +00:00
|
|
|
}
|
2017-04-25 08:20:57 +00:00
|
|
|
|
2018-04-04 00:31:04 +00:00
|
|
|
function assignContainers(containers) {
|
2017-12-06 11:04:02 +00:00
|
|
|
var previouslySelectedContainers = $transition$.params().selectedContainers || [];
|
|
|
|
$scope.containers = containers.map(function (container) {
|
|
|
|
container.Status = $filter('containerstatus')(container.Status);
|
|
|
|
|
|
|
|
var previousContainer = _.find(previouslySelectedContainers, function(item) {
|
|
|
|
return item.Id === container.Id;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (previousContainer && previousContainer.Checked) {
|
|
|
|
container.Checked = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return container;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-06-20 11:00:32 +00:00
|
|
|
function initView() {
|
|
|
|
var provider = $scope.applicationState.endpoint.mode.provider;
|
2017-12-06 11:04:02 +00:00
|
|
|
|
2018-04-04 00:31:04 +00:00
|
|
|
ContainerService.containers(1)
|
2017-06-20 11:00:32 +00:00
|
|
|
.then(function success(data) {
|
2018-04-04 00:31:04 +00:00
|
|
|
assignContainers(data);
|
2017-06-20 11:00:32 +00:00
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2017-12-06 11:04:02 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve containers');
|
|
|
|
$scope.containers = [];
|
2017-06-20 11:00:32 +00:00
|
|
|
});
|
2017-06-01 08:14:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
initView();
|
2016-06-02 05:34:03 +00:00
|
|
|
}]);
|