2014-11-12 18:11:36 +00:00
|
|
|
angular.module('image', [])
|
2015-08-25 05:59:54 +00:00
|
|
|
.controller('ImageController', ['$scope', '$q', '$routeParams', '$location', 'Image', 'Container', 'Messages', 'LineChart',
|
|
|
|
function ($scope, $q, $routeParams, $location, Image, Container, Messages, LineChart) {
|
|
|
|
$scope.history = [];
|
2015-11-27 06:19:38 +00:00
|
|
|
$scope.tagInfo = {repo: '', version: '', force: false};
|
|
|
|
$scope.id = '';
|
|
|
|
$scope.repoTags = [];
|
2014-11-12 18:11:36 +00:00
|
|
|
|
2015-11-27 06:19:38 +00:00
|
|
|
$scope.removeImage = function (id) {
|
|
|
|
Image.remove({id: id}, function (d) {
|
|
|
|
d.forEach(function(msg){
|
|
|
|
var key = Object.keys(msg)[0];
|
|
|
|
Messages.send(key, msg[key]);
|
|
|
|
});
|
|
|
|
// If last message key is 'Deleted' then assume the image is gone and send to images page
|
|
|
|
if (d[d.length-1].Deleted) {
|
|
|
|
$location.path('/images');
|
|
|
|
} else {
|
|
|
|
$location.path('/images/' + $scope.id); // Refresh the current page.
|
|
|
|
}
|
2015-08-25 05:59:54 +00:00
|
|
|
}, function (e) {
|
|
|
|
$scope.error = e.data;
|
|
|
|
$('#error-message').show();
|
|
|
|
});
|
|
|
|
};
|
2014-11-12 18:11:36 +00:00
|
|
|
|
2015-08-25 05:59:54 +00:00
|
|
|
$scope.getHistory = function () {
|
|
|
|
Image.history({id: $routeParams.id}, function (d) {
|
|
|
|
$scope.history = d;
|
|
|
|
});
|
|
|
|
};
|
2014-11-12 18:11:36 +00:00
|
|
|
|
2015-11-27 06:19:38 +00:00
|
|
|
$scope.addTag = function () {
|
|
|
|
var tag = $scope.tagInfo;
|
|
|
|
Image.tag({
|
|
|
|
id: $routeParams.id,
|
|
|
|
repo: tag.repo,
|
|
|
|
tag: tag.version,
|
|
|
|
force: tag.force ? 1 : 0
|
|
|
|
}, function (d) {
|
2015-08-25 05:59:54 +00:00
|
|
|
Messages.send("Tag Added", $routeParams.id);
|
2015-11-27 06:19:38 +00:00
|
|
|
$location.path('/images/' + $scope.id);
|
2015-08-25 05:59:54 +00:00
|
|
|
}, function (e) {
|
|
|
|
$scope.error = e.data;
|
|
|
|
$('#error-message').show();
|
|
|
|
});
|
|
|
|
};
|
2014-11-12 18:11:36 +00:00
|
|
|
|
2015-11-27 06:19:38 +00:00
|
|
|
function getContainersFromImage($q, Container, imageId) {
|
2015-08-25 05:59:54 +00:00
|
|
|
var defer = $q.defer();
|
|
|
|
|
|
|
|
Container.query({all: 1, notruc: 1}, function (d) {
|
|
|
|
var containers = [];
|
|
|
|
for (var i = 0; i < d.length; i++) {
|
|
|
|
var c = d[i];
|
2015-11-27 06:19:38 +00:00
|
|
|
if (c.ImageID === imageId) {
|
2015-08-25 05:59:54 +00:00
|
|
|
containers.push(new ContainerViewModel(c));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
defer.resolve(containers);
|
|
|
|
});
|
2014-11-29 06:06:06 +00:00
|
|
|
|
2015-08-25 05:59:54 +00:00
|
|
|
return defer.promise;
|
|
|
|
}
|
2014-11-29 06:06:06 +00:00
|
|
|
|
2015-12-14 05:28:28 +00:00
|
|
|
/**
|
|
|
|
* Get RepoTags from the /images/query endpoint instead of /image/json,
|
|
|
|
* for backwards compatibility with Docker API versions older than 1.21
|
|
|
|
* @param {string} imageId
|
|
|
|
*/
|
|
|
|
function getRepoTags(imageId) {
|
|
|
|
Image.query({}, function (d) {
|
|
|
|
d.forEach(function(image) {
|
|
|
|
if (image.Id === imageId && image.RepoTags[0] !== '<none>:<none>') {
|
|
|
|
$scope.RepoTags = image.RepoTags;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-08-25 05:59:54 +00:00
|
|
|
Image.get({id: $routeParams.id}, function (d) {
|
|
|
|
$scope.image = d;
|
2015-11-27 06:19:38 +00:00
|
|
|
$scope.id = d.Id;
|
2015-12-14 05:28:28 +00:00
|
|
|
if (d.RepoTags) {
|
|
|
|
$scope.RepoTags = d.RepoTags;
|
|
|
|
} else {
|
|
|
|
getRepoTags($scope.id);
|
|
|
|
}
|
2014-11-12 18:11:36 +00:00
|
|
|
|
2015-11-27 06:19:38 +00:00
|
|
|
getContainersFromImage($q, Container, $scope.id).then(function (containers) {
|
|
|
|
LineChart.build('#containers-started-chart', containers, function (c) {
|
|
|
|
return new Date(c.Created * 1000).toLocaleDateString();
|
2015-08-25 05:59:54 +00:00
|
|
|
});
|
2015-11-27 06:19:38 +00:00
|
|
|
});
|
2015-08-25 05:59:54 +00:00
|
|
|
}, function (e) {
|
|
|
|
if (e.status === 404) {
|
|
|
|
$('.detail').hide();
|
|
|
|
$scope.error = "Image not found.<br />" + $routeParams.id;
|
|
|
|
} else {
|
|
|
|
$scope.error = e.data;
|
|
|
|
}
|
|
|
|
$('#error-message').show();
|
2014-11-12 18:11:36 +00:00
|
|
|
});
|
|
|
|
|
2015-08-25 05:59:54 +00:00
|
|
|
$scope.getHistory();
|
|
|
|
}]);
|