2014-11-12 17:59:55 +00:00
|
|
|
angular.module('images', [])
|
2017-06-01 08:14:55 +00:00
|
|
|
.controller('ImagesController', ['$scope', '$state', 'ImageService', 'Notifications', 'Pagination', 'ModalService',
|
|
|
|
function ($scope, $state, ImageService, Notifications, Pagination, ModalService) {
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.state = {};
|
2017-01-24 01:28:40 +00:00
|
|
|
$scope.state.pagination_count = Pagination.getPaginationCount('images');
|
2016-07-06 07:04:45 +00:00
|
|
|
$scope.sortType = 'RepoTags';
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.sortReverse = true;
|
|
|
|
$scope.state.selectedItemCount = 0;
|
2016-03-19 22:45:45 +00:00
|
|
|
|
2017-06-20 11:00:32 +00:00
|
|
|
$scope.formValues = {
|
2016-07-08 03:31:09 +00:00
|
|
|
Image: '',
|
2016-07-08 03:50:16 +00:00
|
|
|
Registry: ''
|
2016-07-06 04:32:46 +00:00
|
|
|
};
|
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.order = function(sortType) {
|
|
|
|
$scope.sortReverse = ($scope.sortType === sortType) ? !$scope.sortReverse : false;
|
|
|
|
$scope.sortType = sortType;
|
|
|
|
};
|
2014-11-12 17:59:55 +00:00
|
|
|
|
2017-01-24 01:28:40 +00:00
|
|
|
$scope.changePaginationCount = function() {
|
|
|
|
Pagination.setPaginationCount('images', $scope.state.pagination_count);
|
|
|
|
};
|
|
|
|
|
2017-01-04 20:15:41 +00:00
|
|
|
$scope.selectItems = function (allSelected) {
|
|
|
|
angular.forEach($scope.state.filteredImages, function (image) {
|
|
|
|
if (image.Checked !== allSelected) {
|
|
|
|
image.Checked = allSelected;
|
|
|
|
$scope.selectItem(image);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.selectItem = function (item) {
|
|
|
|
if (item.Checked) {
|
|
|
|
$scope.state.selectedItemCount++;
|
|
|
|
} else {
|
|
|
|
$scope.state.selectedItemCount--;
|
|
|
|
}
|
|
|
|
};
|
2014-11-12 17:59:55 +00:00
|
|
|
|
2016-07-06 04:32:46 +00:00
|
|
|
$scope.pullImage = function() {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#pullImageSpinner').show();
|
2017-06-20 11:00:32 +00:00
|
|
|
var image = $scope.formValues.Image;
|
|
|
|
var registry = $scope.formValues.Registry;
|
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() {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#pullImageSpinner').hide();
|
2016-07-06 04:32:46 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-02-15 22:14:56 +00:00
|
|
|
$scope.confirmRemovalAction = function (force) {
|
2017-03-12 16:24:15 +00:00
|
|
|
ModalService.confirmImageForceRemoval(function (confirmed) {
|
|
|
|
if(!confirmed) { return; }
|
|
|
|
$scope.removeAction(force);
|
2017-02-15 22:14:56 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.removeAction = function (force) {
|
|
|
|
force = !!force;
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadImagesSpinner').show();
|
2016-06-02 05:34:03 +00:00
|
|
|
var counter = 0;
|
|
|
|
var complete = function () {
|
|
|
|
counter = counter - 1;
|
|
|
|
if (counter === 0) {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadImagesSpinner').hide();
|
2016-06-02 05:34:03 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
angular.forEach($scope.images, function (i) {
|
|
|
|
if (i.Checked) {
|
|
|
|
counter = counter + 1;
|
2017-03-20 11:01:35 +00:00
|
|
|
ImageService.deleteImage(i.Id, force)
|
|
|
|
.then(function success(data) {
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.success('Image deleted', i.Id);
|
2017-03-20 11:01:35 +00:00
|
|
|
var index = $scope.images.indexOf(i);
|
|
|
|
$scope.images.splice(index, 1);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to remove image');
|
2017-03-20 11:01:35 +00:00
|
|
|
})
|
|
|
|
.finally(function final() {
|
2016-06-02 05:34:03 +00:00
|
|
|
complete();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2014-11-12 17:59:55 +00:00
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
function fetchImages() {
|
2017-03-20 11:01:35 +00:00
|
|
|
$('#loadImagesSpinner').show();
|
2017-07-12 14:11:11 +00:00
|
|
|
var endpointProvider = $scope.applicationState.endpoint.mode.provider;
|
2017-07-24 17:11:12 +00:00
|
|
|
var apiVersion = $scope.applicationState.endpoint.apiVersion;
|
2017-08-13 11:31:50 +00:00
|
|
|
ImageService.images(apiVersion >= 1.25 && endpointProvider !== 'DOCKER_SWARM' && endpointProvider !== 'VMWARE_VIC')
|
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 = [];
|
2017-03-20 11:01:35 +00:00
|
|
|
})
|
|
|
|
.finally(function final() {
|
|
|
|
$('#loadImagesSpinner').hide();
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-03-20 11:01:35 +00:00
|
|
|
fetchImages();
|
2016-06-02 05:34:03 +00:00
|
|
|
}]);
|