2018-02-01 12:27:52 +00:00
|
|
|
angular.module('portainer.docker')
|
2018-05-06 07:15:57 +00:00
|
|
|
.controller('ImagesController', ['$scope', '$state', 'ImageService', 'Notifications', 'ModalService', 'HttpRequestHelper',
|
|
|
|
function ($scope, $state, ImageService, Notifications, ModalService, HttpRequestHelper) {
|
2017-11-12 19:27:28 +00:00
|
|
|
$scope.state = {
|
2017-12-06 11:04:02 +00:00
|
|
|
actionInProgress: false
|
2017-11-12 19:27:28 +00:00
|
|
|
};
|
|
|
|
|
2017-06-20 11:00:32 +00:00
|
|
|
$scope.formValues = {
|
2016-07-08 03:31:09 +00:00
|
|
|
Image: '',
|
2018-05-06 07:15:57 +00:00
|
|
|
Registry: '',
|
|
|
|
NodeName: null
|
2016-07-06 04:32:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.pullImage = function() {
|
2017-06-20 11:00:32 +00:00
|
|
|
var image = $scope.formValues.Image;
|
|
|
|
var registry = $scope.formValues.Registry;
|
2017-11-12 19:27:28 +00:00
|
|
|
|
2018-05-06 07:15:57 +00:00
|
|
|
var nodeName = $scope.formValues.NodeName;
|
|
|
|
HttpRequestHelper.setPortainerAgentTargetHeader(nodeName);
|
|
|
|
|
2017-11-12 21:39:12 +00:00
|
|
|
$scope.state.actionInProgress = true;
|
2017-06-29 14:05:39 +00:00
|
|
|
ImageService.pullImage(image, registry, false)
|
2017-03-20 11:01:35 +00:00
|
|
|
.then(function success(data) {
|
2017-06-20 11:00:32 +00:00
|
|
|
Notifications.success('Image successfully pulled', image);
|
2017-03-20 11:01:35 +00:00
|
|
|
$state.reload();
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to pull image');
|
2017-03-20 11:01:35 +00:00
|
|
|
})
|
|
|
|
.finally(function final() {
|
2017-11-12 21:39:12 +00:00
|
|
|
$scope.state.actionInProgress = false;
|
2016-07-06 04:32:46 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-12-06 11:04:02 +00:00
|
|
|
$scope.confirmRemovalAction = function (selectedItems, force) {
|
2017-03-12 16:24:15 +00:00
|
|
|
ModalService.confirmImageForceRemoval(function (confirmed) {
|
|
|
|
if(!confirmed) { return; }
|
2017-12-06 11:04:02 +00:00
|
|
|
$scope.removeAction(selectedItems, force);
|
2017-02-15 22:14:56 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-12-06 11:04:02 +00:00
|
|
|
$scope.removeAction = function (selectedItems, force) {
|
|
|
|
var actionCount = selectedItems.length;
|
|
|
|
angular.forEach(selectedItems, function (image) {
|
2018-05-06 07:15:57 +00:00
|
|
|
HttpRequestHelper.setPortainerAgentTargetHeader(image.NodeName);
|
2017-12-06 11:04:02 +00:00
|
|
|
ImageService.deleteImage(image.Id, force)
|
|
|
|
.then(function success() {
|
|
|
|
Notifications.success('Image successfully removed', image.Id);
|
|
|
|
var index = $scope.images.indexOf(image);
|
|
|
|
$scope.images.splice(index, 1);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to remove image');
|
|
|
|
})
|
|
|
|
.finally(function final() {
|
|
|
|
--actionCount;
|
|
|
|
if (actionCount === 0) {
|
|
|
|
$state.reload();
|
|
|
|
}
|
|
|
|
});
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
|
|
|
};
|
2014-11-12 17:59:55 +00:00
|
|
|
|
2017-12-06 11:04:02 +00:00
|
|
|
function initView() {
|
2017-08-24 05:53:34 +00:00
|
|
|
ImageService.images(true)
|
2017-03-20 11:01:35 +00:00
|
|
|
.then(function success(data) {
|
|
|
|
$scope.images = data;
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve images');
|
2016-10-08 01:59:58 +00:00
|
|
|
$scope.images = [];
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-12-06 11:04:02 +00:00
|
|
|
initView();
|
2016-06-02 05:34:03 +00:00
|
|
|
}]);
|