2014-11-12 17:59:55 +00:00
|
|
|
angular.module('images', [])
|
2017-02-15 22:14:56 +00:00
|
|
|
.controller('ImagesController', ['$scope', '$state', 'Config', 'Image', 'ImageHelper', 'Messages', 'Pagination', 'ModalService',
|
|
|
|
function ($scope, $state, Config, Image, ImageHelper, Messages, 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
|
|
|
|
2016-07-06 04:32:46 +00:00
|
|
|
$scope.config = {
|
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();
|
2016-12-31 00:25:42 +00:00
|
|
|
var image = $scope.config.Image;
|
|
|
|
var registry = $scope.config.Registry;
|
2016-12-13 20:33:24 +00:00
|
|
|
var imageConfig = ImageHelper.createImageConfigForContainer(image, registry);
|
2016-07-06 04:32:46 +00:00
|
|
|
Image.create(imageConfig, function (data) {
|
|
|
|
var err = data.length > 0 && data[data.length - 1].hasOwnProperty('error');
|
|
|
|
if (err) {
|
|
|
|
var detail = data[data.length - 1];
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#pullImageSpinner').hide();
|
2016-09-02 05:40:03 +00:00
|
|
|
Messages.error('Error', {}, detail.error);
|
2016-07-06 04:32:46 +00:00
|
|
|
} else {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#pullImageSpinner').hide();
|
2016-12-25 20:34:02 +00:00
|
|
|
$state.reload();
|
2016-07-06 04:32:46 +00:00
|
|
|
}
|
|
|
|
}, function (e) {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#pullImageSpinner').hide();
|
2016-09-02 05:40:03 +00:00
|
|
|
Messages.error("Failure", e, "Unable to pull image");
|
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-02-15 22:14:56 +00:00
|
|
|
Image.remove({id: i.Id, force: force}, function (d) {
|
2016-08-10 03:26:08 +00:00
|
|
|
if (d[0].message) {
|
2016-09-23 04:54:58 +00:00
|
|
|
$('#loadImagesSpinner').hide();
|
2016-09-02 05:40:03 +00:00
|
|
|
Messages.error("Unable to remove image", {}, d[0].message);
|
2016-08-10 03:26:08 +00:00
|
|
|
} else {
|
|
|
|
Messages.send("Image deleted", i.Id);
|
|
|
|
var index = $scope.images.indexOf(i);
|
|
|
|
$scope.images.splice(index, 1);
|
|
|
|
}
|
2016-06-02 05:34:03 +00:00
|
|
|
complete();
|
|
|
|
}, function (e) {
|
2016-09-02 05:40:03 +00:00
|
|
|
Messages.error("Failure", e, 'Unable to remove image');
|
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() {
|
|
|
|
Image.query({}, function (d) {
|
|
|
|
$scope.images = d.map(function (item) {
|
|
|
|
return new ImageViewModel(item);
|
|
|
|
});
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadImagesSpinner').hide();
|
2016-06-02 05:34:03 +00:00
|
|
|
}, function (e) {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadImagesSpinner').hide();
|
2016-09-02 05:40:03 +00:00
|
|
|
Messages.error("Failure", e, "Unable to retrieve images");
|
2016-10-08 01:59:58 +00:00
|
|
|
$scope.images = [];
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-07-08 03:31:09 +00:00
|
|
|
Config.$promise.then(function (c) {
|
|
|
|
fetchImages();
|
|
|
|
});
|
2016-06-02 05:34:03 +00:00
|
|
|
}]);
|