Change tag_view to avoid a DB lookup and only return the tag's image ID. We map the ID in the frontend based on the image data returned

This commit is contained in:
Joseph Schorr 2014-07-17 15:16:22 -04:00
parent 126371f8a1
commit a45054bf2e
3 changed files with 52 additions and 54 deletions

View file

@ -466,31 +466,6 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi
addedDisplayed - removedDisplayed - changedDisplayed;
};
$scope.setImage = function(imageId, opt_updateURL) {
var image = null;
for (var i = 0; i < $scope.images.length; ++i) {
var currentImage = $scope.images[i];
if (currentImage.id == imageId || currentImage.id.substr(0, 12) == imageId) {
image = currentImage;
break;
}
}
if (!image) { return; }
$scope.currentTag = null;
$scope.currentImage = image;
$scope.loadImageChanges(image);
if ($scope.tree) {
$scope.tree.setImage(image.id);
}
if (opt_updateURL) {
$location.search('tag', null);
$location.search('image', imageId.substr(0, 12));
}
};
$scope.showAddTag = function(image) {
$scope.toTagImage = image;
$('#addTagModal').modal('show');
@ -513,6 +488,10 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi
$('#confirmdeleteTagModal').modal('show');
};
$scope.findImageForTag = function(tag) {
return tag && $scope.imageByDBID && $scope.imageByDBID[tag.dbid];
};
$scope.createOrMoveTag = function(image, tagName, opt_invalid) {
if (opt_invalid) { return; }
@ -592,13 +571,38 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi
return size;
};
$scope.setImage = function(imageId, opt_updateURL) {
var image = null;
for (var i = 0; i < $scope.images.length; ++i) {
var currentImage = $scope.images[i];
if (currentImage.id == imageId || currentImage.id.substr(0, 12) == imageId) {
image = currentImage;
break;
}
}
if (!image) { return; }
$scope.currentTag = null;
$scope.currentImage = image;
$scope.loadImageChanges(image);
if ($scope.tree) {
$scope.tree.setImage(image.id);
}
if (opt_updateURL) {
$location.search('tag', null);
$location.search('image', imageId.substr(0, 12));
}
};
$scope.setTag = function(tagName, opt_updateURL) {
var repo = $scope.repo;
if (!repo) { return; }
var proposedTag = repo.tags[tagName];
if (!proposedTag) {
// We must find a good default
// We must find a good default.
for (tagName in repo.tags) {
if (!proposedTag || tagName == 'latest') {
proposedTag = repo.tags[tagName];
@ -608,8 +612,8 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi
if (proposedTag) {
$scope.currentTag = proposedTag;
$scope.currentImage = proposedTag.image;
$scope.loadImageChanges($scope.currentImage);
$scope.currentImage = null;
if ($scope.tree) {
$scope.tree.setTag(proposedTag.name);
}
@ -686,9 +690,14 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi
var forAllTagImages = function(tag, callback) {
if (!tag || !$scope.imageByDBID) { return; }
callback(tag.image);
var tag_image = $scope.imageByDBID[tag.dbid];
if (!tag_image) { return; }
var ancestors = tag.image.ancestors.split('/');
// Callback the tag's image itself.
callback(tag_image);
// Callback any parent images.
var ancestors = tag_image.ancestors.split('/');
for (var i = 0; i < ancestors.length; ++i) {
var image = $scope.imageByDBID[ancestors[i]];
if (image) {