2014-11-12 17:59:55 +00:00
|
|
|
angular.module('images', [])
|
2016-07-08 03:31:09 +00:00
|
|
|
.controller('ImagesController', ['$scope', '$state', 'Config', 'Image', 'Messages',
|
|
|
|
function ($scope, $state, Config, Image, Messages) {
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.state = {};
|
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
|
|
|
|
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-08 03:31:09 +00:00
|
|
|
function createImageConfig(imageName, registry) {
|
2016-07-06 04:32:46 +00:00
|
|
|
var imageNameAndTag = imageName.split(':');
|
2016-07-08 03:31:09 +00:00
|
|
|
var image = imageNameAndTag[0];
|
|
|
|
if (registry) {
|
|
|
|
image = registry + '/' + imageNameAndTag[0];
|
|
|
|
}
|
2016-07-06 04:32:46 +00:00
|
|
|
var imageConfig = {
|
2016-07-08 03:31:09 +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 00:44:58 +00:00
|
|
|
$('#pullImageSpinner').show();
|
2016-07-06 04:32:46 +00:00
|
|
|
var image = _.toLower($scope.config.Image);
|
2016-08-17 05:25:42 +00:00
|
|
|
var registry = _.toLower($scope.config.Registry);
|
2016-07-08 03:31:09 +00:00
|
|
|
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 00:44:58 +00:00
|
|
|
$('#pullImageSpinner').hide();
|
2016-07-06 04:32:46 +00:00
|
|
|
Messages.error('Error', detail.error);
|
|
|
|
} else {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#pullImageSpinner').hide();
|
2016-07-06 04:32:46 +00:00
|
|
|
$state.go('images', {}, {reload: true});
|
|
|
|
}
|
|
|
|
}, function (e) {
|
2016-07-07 00:44:58 +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 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;
|
|
|
|
Image.remove({id: i.Id}, function (d) {
|
2016-08-10 03:26:08 +00:00
|
|
|
if (d[0].message) {
|
|
|
|
$('#loadingViewSpinner').hide();
|
|
|
|
Messages.error("Unable to remove image", d[0].message);
|
|
|
|
} 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-08-10 03:26:08 +00:00
|
|
|
Messages.error("Unable to remove image", e.data);
|
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) {
|
|
|
|
Messages.error("Failure", e.data);
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadImagesSpinner').hide();
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-07-08 03:31:09 +00:00
|
|
|
Config.$promise.then(function (c) {
|
|
|
|
$scope.availableRegistries = c.registries;
|
|
|
|
fetchImages();
|
|
|
|
});
|
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
}]);
|