2015-06-05 15:21:52 +00:00
|
|
|
angular.module('pullImage', [])
|
|
|
|
.controller('PullImageController', ['$scope', '$log', 'Dockerfile', 'Messages', 'Image', 'ViewSpinner',
|
2015-08-25 05:59:54 +00:00
|
|
|
function ($scope, $log, Dockerfile, Messages, Image, ViewSpinner) {
|
2015-06-05 15:21:52 +00:00
|
|
|
$scope.template = 'app/components/pullImage/pullImage.html';
|
|
|
|
|
2015-08-25 05:59:54 +00:00
|
|
|
$scope.init = function () {
|
2015-06-22 21:30:16 +00:00
|
|
|
$scope.config = {
|
|
|
|
registry: '',
|
|
|
|
repo: '',
|
|
|
|
fromImage: '',
|
|
|
|
tag: 'latest'
|
2015-08-25 06:07:08 +00:00
|
|
|
};
|
|
|
|
};
|
2015-06-05 15:21:52 +00:00
|
|
|
|
2015-06-22 21:30:16 +00:00
|
|
|
$scope.init();
|
|
|
|
|
2015-06-05 15:21:52 +00:00
|
|
|
function failedRequestHandler(e, Messages) {
|
|
|
|
Messages.error('Error', errorMsgFilter(e));
|
|
|
|
}
|
|
|
|
|
2015-08-25 05:59:54 +00:00
|
|
|
$scope.pull = function () {
|
2015-06-05 15:21:52 +00:00
|
|
|
$('#error-message').hide();
|
|
|
|
var config = angular.copy($scope.config);
|
|
|
|
var imageName = (config.registry ? config.registry + '/' : '' ) +
|
|
|
|
(config.repo ? config.repo + '/' : '') +
|
|
|
|
(config.fromImage) +
|
|
|
|
(config.tag ? ':' + config.tag : '');
|
|
|
|
|
|
|
|
ViewSpinner.spin();
|
2015-06-22 21:30:16 +00:00
|
|
|
$('#pull-modal').modal('hide');
|
2015-08-25 05:59:54 +00:00
|
|
|
Image.create(config, function (data) {
|
2015-06-05 15:21:52 +00:00
|
|
|
ViewSpinner.stop();
|
|
|
|
if (data.constructor === Array) {
|
2015-08-25 05:59:54 +00:00
|
|
|
var f = data.length > 0 && data[data.length - 1].hasOwnProperty('error');
|
2015-06-05 15:21:52 +00:00
|
|
|
//check for error
|
|
|
|
if (f) {
|
|
|
|
var d = data[data.length - 1];
|
|
|
|
$scope.error = "Cannot pull image " + imageName + " Reason: " + d.error;
|
2015-06-22 21:30:16 +00:00
|
|
|
$('#pull-modal').modal('show');
|
2015-06-05 15:21:52 +00:00
|
|
|
$('#error-message').show();
|
|
|
|
} else {
|
|
|
|
Messages.send("Image Added", imageName);
|
2015-06-22 21:30:16 +00:00
|
|
|
$scope.init();
|
2015-06-05 15:21:52 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Messages.send("Image Added", imageName);
|
2015-06-22 21:30:16 +00:00
|
|
|
$scope.init();
|
2015-06-05 15:21:52 +00:00
|
|
|
}
|
2015-08-25 05:59:54 +00:00
|
|
|
}, function (e) {
|
2015-06-05 15:21:52 +00:00
|
|
|
ViewSpinner.stop();
|
|
|
|
$scope.error = "Cannot pull image " + imageName + " Reason: " + e.data;
|
2015-06-22 21:30:16 +00:00
|
|
|
$('#pull-modal').modal('show');
|
2015-06-05 15:21:52 +00:00
|
|
|
$('#error-message').show();
|
|
|
|
});
|
2015-08-25 06:07:08 +00:00
|
|
|
};
|
2015-06-05 15:21:52 +00:00
|
|
|
}]);
|