2014-11-12 17:59:55 +00:00
|
|
|
angular.module('images', [])
|
2016-07-07 01:17:44 +00:00
|
|
|
.controller('ImagesController', ['$scope', '$state', 'Image', 'Messages',
|
|
|
|
function ($scope, $state, Image, Messages) {
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.state = {};
|
|
|
|
$scope.sortType = 'Created';
|
|
|
|
$scope.sortReverse = true;
|
|
|
|
$scope.state.toggle = false;
|
|
|
|
$scope.state.selectedItemCount = 0;
|
2016-03-19 22:45:45 +00:00
|
|
|
|
2016-07-06 04:32:46 +00:00
|
|
|
$scope.config = {
|
2016-07-07 23:57:24 +00:00
|
|
|
Image: '',
|
2016-07-08 04:20:31 +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
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.toggleSelectAll = function () {
|
|
|
|
angular.forEach($scope.state.filteredImages, function (i) {
|
|
|
|
i.Checked = $scope.state.toggle;
|
|
|
|
});
|
|
|
|
if ($scope.state.toggle) {
|
|
|
|
$scope.state.selectedItemCount = $scope.state.filteredImages.length;
|
|
|
|
} else {
|
|
|
|
$scope.state.selectedItemCount = 0;
|
|
|
|
}
|
|
|
|
};
|
2014-11-12 17:59:55 +00:00
|
|
|
|
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-07 23:57:24 +00:00
|
|
|
function createImageConfig(imageName, registry) {
|
2016-07-06 04:32:46 +00:00
|
|
|
var imageNameAndTag = imageName.split(':');
|
2016-07-07 23:57:24 +00:00
|
|
|
var image = imageNameAndTag[0];
|
|
|
|
if (registry) {
|
|
|
|
image = registry + '/' + imageNameAndTag[0];
|
|
|
|
}
|
2016-07-06 04:32:46 +00:00
|
|
|
var imageConfig = {
|
2016-07-07 23:57:24 +00:00
|
|
|
fromImage: image,
|
2016-07-06 04:32:46 +00:00
|
|
|
tag: imageNameAndTag[1] ? imageNameAndTag[1] : 'latest'
|
|
|
|
};
|
|
|
|
return imageConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.pullImage = function() {
|
2016-07-07 01:17:44 +00:00
|
|
|
$('#pullImageSpinner').show();
|
2016-07-06 04:32:46 +00:00
|
|
|
var image = _.toLower($scope.config.Image);
|
2016-07-07 23:57:24 +00:00
|
|
|
var registry = _.toLower($scope.config.Registry);
|
|
|
|
var imageConfig = createImageConfig(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 01:17:44 +00:00
|
|
|
$('#pullImageSpinner').hide();
|
2016-07-06 04:32:46 +00:00
|
|
|
Messages.error('Error', detail.error);
|
|
|
|
} else {
|
2016-07-07 01:17:44 +00:00
|
|
|
$('#pullImageSpinner').hide();
|
2016-07-06 04:32:46 +00:00
|
|
|
$state.go('images', {}, {reload: true});
|
|
|
|
}
|
|
|
|
}, function (e) {
|
2016-07-07 01:17:44 +00:00
|
|
|
$('#pullImageSpinner').hide();
|
2016-07-06 04:32:46 +00:00
|
|
|
Messages.error('Error', 'Unable to pull image ' + image);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.removeAction = function () {
|
2016-07-07 01:17:44 +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 01:17:44 +00:00
|
|
|
$('#loadImagesSpinner').hide();
|
2016-06-02 05:34:03 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
angular.forEach($scope.images, function (i) {
|
|
|
|
if (i.Checked) {
|
|
|
|
counter = counter + 1;
|
|
|
|
Image.remove({id: i.Id}, function (d) {
|
|
|
|
angular.forEach(d, function (resource) {
|
|
|
|
Messages.send("Image deleted", resource.Deleted);
|
|
|
|
});
|
|
|
|
var index = $scope.images.indexOf(i);
|
|
|
|
$scope.images.splice(index, 1);
|
|
|
|
complete();
|
|
|
|
}, function (e) {
|
|
|
|
Messages.error("Failure", e.data);
|
2016-07-07 01:17:44 +00:00
|
|
|
$('#loadImagesSpinner').hide();
|
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 01:17:44 +00:00
|
|
|
$('#loadImagesSpinner').hide();
|
2016-06-02 05:34:03 +00:00
|
|
|
}, function (e) {
|
|
|
|
Messages.error("Failure", e.data);
|
2016-07-07 01:17:44 +00:00
|
|
|
$('#loadImagesSpinner').hide();
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchImages();
|
|
|
|
}]);
|