2018-02-01 12:27:52 +00:00
|
|
|
angular.module('portainer.docker')
|
2018-10-28 09:27:06 +00:00
|
|
|
.controller('ImagesController', ['$scope', '$state', 'ImageService', 'Notifications', 'ModalService', 'HttpRequestHelper', 'FileSaver', 'Blob', 'EndpointProvider',
|
|
|
|
function ($scope, $state, ImageService, Notifications, ModalService, HttpRequestHelper, FileSaver, Blob, EndpointProvider) {
|
2017-11-12 19:27:28 +00:00
|
|
|
$scope.state = {
|
2018-07-26 13:09:48 +00:00
|
|
|
actionInProgress: false,
|
|
|
|
exportInProgress: 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)
|
2018-08-22 15:33:06 +00:00
|
|
|
.then(function success() {
|
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
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-07-26 13:09:48 +00:00
|
|
|
function isAuthorizedToDownload(selectedItems) {
|
|
|
|
|
|
|
|
for (var i = 0; i < selectedItems.length; i++) {
|
|
|
|
var image = selectedItems[i];
|
|
|
|
|
|
|
|
var untagged = _.find(image.RepoTags, function (item) {
|
|
|
|
return item.indexOf('<none>') > -1;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (untagged) {
|
|
|
|
Notifications.warning('', 'Cannot download a untagged image');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_.uniqBy(selectedItems, 'NodeName').length > 1) {
|
|
|
|
Notifications.warning('', 'Cannot download images from different nodes at the same time');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function exportImages(images) {
|
|
|
|
HttpRequestHelper.setPortainerAgentTargetHeader(images[0].NodeName);
|
|
|
|
$scope.state.exportInProgress = true;
|
|
|
|
ImageService.downloadImages(images)
|
|
|
|
.then(function success(data) {
|
|
|
|
var downloadData = new Blob([data.file], { type: 'application/x-tar' });
|
|
|
|
FileSaver.saveAs(downloadData, 'images.tar');
|
|
|
|
Notifications.success('Image(s) successfully downloaded');
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to download image(s)');
|
|
|
|
})
|
|
|
|
.finally(function final() {
|
|
|
|
$scope.state.exportInProgress = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.downloadAction = function (selectedItems) {
|
|
|
|
if (!isAuthorizedToDownload(selectedItems)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ModalService.confirmImageExport(function (confirmed) {
|
|
|
|
if(!confirmed) { return; }
|
|
|
|
exportImages(selectedItems);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2018-10-28 09:27:06 +00:00
|
|
|
$scope.offlineMode = false;
|
|
|
|
|
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;
|
2018-10-28 09:27:06 +00:00
|
|
|
$scope.offlineMode = EndpointProvider.offlineMode();
|
2017-03-20 11:01:35 +00:00
|
|
|
})
|
|
|
|
.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
|
|
|
}]);
|