Merge branch 'tagyourit'

This commit is contained in:
Joseph Schorr 2014-04-17 14:20:28 -04:00
commit d8efb399b0
12 changed files with 641 additions and 172 deletions

View file

@ -425,6 +425,8 @@ quayApp = angular.module('quay', quayDependencies, function($provide, cfpLoading
'role': 'th-large',
'original_role': 'th-large',
'application_name': 'cloud',
'image': 'archive',
'original_image': 'archive',
'client_id': 'chain'
};
@ -436,6 +438,9 @@ quayApp = angular.module('quay', quayDependencies, function($provide, cfpLoading
for (var key in metadata) {
if (metadata.hasOwnProperty(key)) {
var value = metadata[key] != null ? metadata[key].toString() : '(Unknown)';
if (key.indexOf('image') >= 0) {
value = value.substr(0, 12);
}
var markedDown = getMarkedDown(value);
markedDown = markedDown.substr('<p>'.length, markedDown.length - '<p></p>'.length);
@ -2133,6 +2138,8 @@ quayApp.directive('logsView', function () {
}
},
'delete_tag': 'Tag {tag} deleted in repository {repo} by user {username}',
'create_tag': 'Tag {tag} created in repository {repo} on image {image} by user {username}',
'move_tag': 'Tag {tag} moved from image {original_image} to image {image} in repository {repo} by user {username}',
'change_repo_visibility': 'Change visibility for repository {repo} to {visibility}',
'add_repo_accesstoken': 'Create access token {token} in repository {repo}',
'delete_repo_accesstoken': 'Delete access token {token} in repository {repo}',
@ -2212,6 +2219,8 @@ quayApp.directive('logsView', function () {
'set_repo_description': 'Change repository description',
'build_dockerfile': 'Build image from Dockerfile',
'delete_tag': 'Delete Tag',
'create_tag': 'Create Tag',
'move_tag': 'Move Tag',
'org_create_team': 'Create team',
'org_delete_team': 'Delete team',
'org_add_team_member': 'Add team member',
@ -4522,6 +4531,121 @@ quayApp.directive('dockerfileBuildForm', function () {
});
quayApp.directive('tagSpecificImagesView', function () {
var directiveDefinitionObject = {
priority: 0,
templateUrl: '/static/directives/tag-specific-images-view.html',
replace: false,
transclude: true,
restrict: 'C',
scope: {
'repository': '=repository',
'tag': '=tag',
'images': '=images'
},
controller: function($scope, $element) {
$scope.getFirstTextLine = getFirstTextLine;
$scope.hasImages = false;
$scope.tagSpecificImages = [];
$scope.getImageListingClasses = function(image) {
var classes = '';
if (image.ancestors.length > 1) {
classes += 'child ';
}
var currentTag = $scope.repository.tags[$scope.tag];
if (image.dbid == currentTag.image.dbid) {
classes += 'tag-image ';
}
return classes;
};
var forAllTagImages = function(tag, callback) {
if (!tag) { return; }
callback(tag.image);
if (!$scope.imageByDBID) {
$scope.imageByDBID = [];
for (var i = 0; i < $scope.images.length; ++i) {
var currentImage = $scope.images[i];
$scope.imageByDBID[currentImage.dbid] = currentImage;
}
}
var ancestors = tag.image.ancestors.split('/');
for (var i = 0; i < ancestors.length; ++i) {
var image = $scope.imageByDBID[ancestors[i]];
if (image) {
callback(image);
}
}
};
var refresh = function() {
if (!$scope.repository || !$scope.tag || !$scope.images) {
$scope.tagSpecificImages = [];
return;
}
var tag = $scope.repository.tags[$scope.tag];
if (!tag) {
$scope.tagSpecificImages = [];
return;
}
var getIdsForTag = function(currentTag) {
var ids = {};
forAllTagImages(currentTag, function(image) {
ids[image.dbid] = true;
});
return ids;
};
// Remove any IDs that match other tags.
var toDelete = getIdsForTag(tag);
for (var currentTagName in $scope.repository.tags) {
var currentTag = $scope.repository.tags[currentTagName];
if (currentTag != tag) {
for (var dbid in getIdsForTag(currentTag)) {
delete toDelete[dbid];
}
}
}
// Return the matching list of images.
var images = [];
for (var i = 0; i < $scope.images.length; ++i) {
var image = $scope.images[i];
if (toDelete[image.dbid]) {
images.push(image);
}
}
images.sort(function(a, b) {
var result = new Date(b.created) - new Date(a.created);
if (result != 0) {
return result;
}
return b.dbid - a.dbid;
});
$scope.tagSpecificImages = images;
};
$scope.$watch('repository', refresh);
$scope.$watch('tag', refresh);
$scope.$watch('images', refresh);
}
};
return directiveDefinitionObject;
});
// Note: ngBlur is not yet in Angular stable, so we add it manaully here.
quayApp.directive('ngBlur', function() {
return function( scope, elem, attrs ) {

View file

@ -398,9 +398,9 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi
$scope.getMoreCount = function(changes) {
if (!changes) { return 0; }
var addedDisplayed = Math.min(5, changes.added.length);
var removedDisplayed = Math.min(5, changes.removed.length);
var changedDisplayed = Math.min(5, changes.changed.length);
var addedDisplayed = Math.min(2, changes.added.length);
var removedDisplayed = Math.min(2, changes.removed.length);
var changedDisplayed = Math.min(2, changes.changed.length);
return (changes.added.length + changes.removed.length + changes.changed.length) -
addedDisplayed - removedDisplayed - changedDisplayed;
@ -429,57 +429,21 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi
$location.search('tag', null);
$location.search('image', imageId.substr(0, 12));
}
};
$scope.showAddTag = function(image) {
$scope.toTagImage = image;
$('#addTagModal').modal('show');
};
$scope.tagSpecificImages = function(tagName) {
if (!tagName) { return []; }
$scope.isOwnedTag = function(image, tagName) {
if (!image || !tagName) { return false; }
return image.tags.indexOf(tagName) >= 0;
};
var tag = $scope.repo.tags[tagName];
if (!tag) { return []; }
if ($scope.specificImages && $scope.specificImages[tagName]) {
return $scope.specificImages[tagName];
}
var getIdsForTag = function(currentTag) {
var ids = {};
forAllTagImages(currentTag, function(image) {
ids[image.dbid] = true;
});
return ids;
};
// Remove any IDs that match other tags.
var toDelete = getIdsForTag(tag);
for (var currentTagName in $scope.repo.tags) {
var currentTag = $scope.repo.tags[currentTagName];
if (currentTag != tag) {
for (var dbid in getIdsForTag(currentTag)) {
delete toDelete[dbid];
}
}
}
// Return the matching list of images.
var images = [];
for (var i = 0; i < $scope.images.length; ++i) {
var image = $scope.images[i];
if (toDelete[image.dbid]) {
images.push(image);
}
}
images.sort(function(a, b) {
var result = new Date(b.created) - new Date(a.created);
if (result != 0) {
return result;
}
return b.dbid - a.dbid;
});
$scope.specificImages[tagName] = images;
return images;
$scope.isAnotherImageTag = function(image, tagName) {
if (!image || !tagName) { return false; }
return image.tags.indexOf(tagName) < 0 && $scope.repo.tags[tagName];
};
$scope.askDeleteTag = function(tagName) {
@ -489,6 +453,39 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi
$('#confirmdeleteTagModal').modal('show');
};
$scope.createOrMoveTag = function(image, tagName, opt_invalid) {
if (opt_invalid) { return; }
$scope.creatingTag = true;
var params = {
'repository': $scope.repo.namespace + '/' + $scope.repo.name,
'tag': tagName
};
var data = {
'image': image.id
};
ApiService.changeTagImage(data, params).then(function(resp) {
$scope.creatingTag = false;
loadViewInfo();
$('#addTagModal').modal('hide');
}, function(resp) {
$('#addTagModal').modal('hide');
bootbox.dialog({
"message": resp.data ? resp.data : 'Could not create or move tag',
"title": "Cannot create or move tag",
"buttons": {
"close": {
"label": "Close",
"className": "btn-primary"
}
}
});
});
};
$scope.deleteTag = function(tagName) {
if (!$scope.repo.can_admin) { return; }
$('#confirmdeleteTagModal').modal('hide');
@ -569,20 +566,6 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi
$scope.getFirstTextLine = getFirstTextLine;
$scope.getImageListingClasses = function(image, tagName) {
var classes = '';
if (image.ancestors.length > 1) {
classes += 'child ';
}
var currentTag = $scope.repo.tags[tagName];
if (image.dbid == currentTag.image.dbid) {
classes += 'tag-image ';
}
return classes;
};
$scope.getTagCount = function(repo) {
if (!repo) { return 0; }
var count = 0;

View file

@ -115,12 +115,20 @@ ImageHistoryTree.prototype.setupOverscroll_ = function() {
$(that).trigger({
'type': 'hideTagMenu'
});
$(that).trigger({
'type': 'hideImageMenu'
});
});
overscroll.on('scroll', function() {
$(that).trigger({
'type': 'hideTagMenu'
});
$(that).trigger({
'type': 'hideImageMenu'
});
});
};
@ -664,7 +672,19 @@ ImageHistoryTree.prototype.update_ = function(source) {
if (d.collapsed) { that.expandCollapsed_(d); }
})
.on('mouseover', tip.show)
.on('mouseout', tip.hide);
.on('mouseout', tip.hide)
.on("contextmenu", function(d, e) {
d3.event.preventDefault();
if (d.image) {
$(that).trigger({
'type': 'showImageMenu',
'image': d.image.id,
'clientX': d3.event.clientX,
'clientY': d3.event.clientY
});
}
});
nodeEnter.selectAll("tags")
.append("svg:text")
@ -732,15 +752,16 @@ ImageHistoryTree.prototype.update_ = function(source) {
return '';
}
var html = '';
var html = '<div style="width: ' + DEPTH_HEIGHT + 'px">';
for (var i = 0; i < d.tags.length; ++i) {
var tag = d.tags[i];
var kind = 'default';
if (tag == currentTag) {
kind = 'success';
}
html += '<span class="label label-' + kind + ' tag" data-tag="' + tag + '" title="' + tag + '">' + tag + '</span>';
html += '<span class="label label-' + kind + ' tag" data-tag="' + tag + '" title="' + tag + '" style="max-width: ' + DEPTH_HEIGHT + 'px">' + tag + '</span>';
}
html += '</div>';
return html;
});