Have the image tree allow a state with no selected image nor so selected tag.

This commit is contained in:
Joseph Schorr 2013-10-16 22:33:35 -04:00
parent f1746417b1
commit 50929102b5
2 changed files with 35 additions and 25 deletions

View file

@ -302,7 +302,7 @@ function RepoCtrl($scope, Restangular, $routeParams, $rootScope) {
var imageFetch = Restangular.one('repository/' + namespace + '/' + name + '/image'); var imageFetch = Restangular.one('repository/' + namespace + '/' + name + '/image');
imageFetch.get().then(function(resp) { imageFetch.get().then(function(resp) {
$scope.imageHistory = resp.images; $scope.imageHistory = resp.images;
$scope.tree = new ImageHistoryTree(namespace, name, resp.images, $scope.currentTag, $scope.tree = new ImageHistoryTree(namespace, name, resp.images,
$scope.getCommentFirstLine, $scope.getTimeSince); $scope.getCommentFirstLine, $scope.getTimeSince);
$scope.tree.draw('image-history-container'); $scope.tree.draw('image-history-container');

View file

@ -4,7 +4,7 @@ var DEPTH_WIDTH = 132;
/** /**
* Based off of http://mbostock.github.io/d3/talk/20111018/tree.html by Mike Bostock (@mbostock) * Based off of http://mbostock.github.io/d3/talk/20111018/tree.html by Mike Bostock (@mbostock)
*/ */
function ImageHistoryTree(namespace, name, images, current, formatComment, formatTime) { function ImageHistoryTree(namespace, name, images, formatComment, formatTime) {
/** /**
* The namespace of the repo. * The namespace of the repo.
*/ */
@ -20,21 +20,6 @@ function ImageHistoryTree(namespace, name, images, current, formatComment, forma
*/ */
this.images_ = images; this.images_ = images;
/**
* The current tag.
*/
this.currentTag_ = current.name;
/**
* The current image.
*/
this.currentImage_ = current.image;
/**
* Counter for creating unique IDs.
*/
this.idCounter_ = 0;
/** /**
* Method to invoke to format a comment for an image. * Method to invoke to format a comment for an image.
*/ */
@ -44,6 +29,21 @@ function ImageHistoryTree(namespace, name, images, current, formatComment, forma
* Method to invoke to format the time for an image. * Method to invoke to format the time for an image.
*/ */
this.formatTime_ = formatTime; this.formatTime_ = formatTime;
/**
* The current tag (if any).
*/
this.currentTag_ = null;
/**
* The current image (if any).
*/
this.currentImage_ = null;
/**
* Counter for creating unique IDs.
*/
this.idCounter_ = 0;
} }
@ -361,21 +361,27 @@ ImageHistoryTree.prototype.markPath_ = function(startingNode, isHighlighted) {
* Sets the current tag displayed in the tree. * Sets the current tag displayed in the tree.
*/ */
ImageHistoryTree.prototype.setTag_ = function(tagName) { ImageHistoryTree.prototype.setTag_ = function(tagName) {
// Save the current tag.
this.currentTag_ = tagName; this.currentTag_ = tagName;
// Update the state of each existing node to no longer be highlighted.
var imageByDBID = this.imageByDBID_; var imageByDBID = this.imageByDBID_;
// Update the state of each existing node to no longer be highlighted.
if (this.currentImage_) {
var currentNode = imageByDBID[this.currentImage_.dbid]; var currentNode = imageByDBID[this.currentImage_.dbid];
this.markPath_(currentNode, false); this.markPath_(currentNode, false);
}
// Find the new current image. // Find the new current image (if any).
this.currentImage_ = this.findImage_(function(image) { this.currentImage_ = this.findImage_(function(image) {
return image.tags.indexOf(tagName) >= 0; return image.tags.indexOf(tagName || '(no tag specified)') >= 0;
}); });
// Update the state of the new node path. // Update the state of the new node path.
currentNode = imageByDBID[this.currentImage_.dbid]; if (this.currentImage_) {
var currentNode = imageByDBID[this.currentImage_.dbid];
this.markPath_(currentNode, true); this.markPath_(currentNode, true);
}
// Ensure that the children are in the correct order. // Ensure that the children are in the correct order.
for (var i = 0; i < this.images_.length; ++i) { for (var i = 0; i < this.images_.length; ++i) {
@ -432,6 +438,7 @@ ImageHistoryTree.prototype.update_ = function(source) {
var diagonal = this.diagonal_; var diagonal = this.diagonal_;
var tip = this.tip_; var tip = this.tip_;
var currentTag = this.currentTag_; var currentTag = this.currentTag_;
var currentImage = this.currentImage_;
var repoNamespace = this.repoNamespace_; var repoNamespace = this.repoNamespace_;
var repoName = this.repoName_; var repoName = this.repoName_;
var maxHeight = this.maxHeight_; var maxHeight = this.maxHeight_;
@ -520,7 +527,10 @@ ImageHistoryTree.prototype.update_ = function(source) {
if (d.collapsed) { if (d.collapsed) {
return 'collapsed'; return 'collapsed';
} }
return d.image.id == that.currentImage_.id ? 'current' : ''; if (!currentImage) {
return '';
}
return d.image.id == currentImage.id ? 'current' : '';
}); });
// Ensure that the node is visible. // Ensure that the node is visible.