Make sure that we only save the tree reference if we have actually rendered it.

This commit is contained in:
Joseph Schorr 2014-05-01 16:11:50 -04:00
parent c2ed1a9e52
commit 8da4104e7b
2 changed files with 30 additions and 22 deletions

View file

@ -731,33 +731,34 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi
}
// Create the new tree.
$scope.tree = new ImageHistoryTree(namespace, name, resp.images,
var tree = new ImageHistoryTree(namespace, name, resp.images,
getFirstTextLine, $scope.getTimeSince, ImageMetadataService.getEscapedFormattedCommand);
$scope.tree.draw('image-history-container');
$scope.tree = tree.draw('image-history-container');
if ($scope.tree) {
// If we already have a tag, use it
if ($scope.currentTag) {
$scope.tree.setTag($scope.currentTag.name);
}
// If we already have a tag, use it
if ($scope.currentTag) {
$scope.tree.setTag($scope.currentTag.name);
// Listen for changes to the selected tag and image in the tree.
$($scope.tree).bind('tagChanged', function(e) {
$scope.$apply(function() { $scope.setTag(e.tag, true); });
});
$($scope.tree).bind('imageChanged', function(e) {
$scope.$apply(function() { $scope.setImage(e.image.id, true); });
});
$($scope.tree).bind('showTagMenu', function(e) {
$scope.$apply(function() { $scope.showTagMenu(e.tag, e.clientX, e.clientY); });
});
$($scope.tree).bind('hideTagMenu', function(e) {
$scope.$apply(function() { $scope.hideTagMenu(); });
});
}
// Listen for changes to the selected tag and image in the tree.
$($scope.tree).bind('tagChanged', function(e) {
$scope.$apply(function() { $scope.setTag(e.tag, true); });
});
$($scope.tree).bind('imageChanged', function(e) {
$scope.$apply(function() { $scope.setImage(e.image.id, true); });
});
$($scope.tree).bind('showTagMenu', function(e) {
$scope.$apply(function() { $scope.showTagMenu(e.tag, e.clientX, e.clientY); });
});
$($scope.tree).bind('hideTagMenu', function(e) {
$scope.$apply(function() { $scope.hideTagMenu(); });
});
if ($routeParams.image) {
$scope.setImage($routeParams.image);
}

View file

@ -196,6 +196,11 @@ ImageHistoryTree.prototype.draw = function(container) {
var rootSvg = d3.select("#" + container).append("svg:svg")
.attr("class", "image-tree");
if (!rootSvg) {
this.container_ = null;
return;
}
var vis = rootSvg.append("svg:g");
if (!vis) {
this.container_ = null;
@ -266,6 +271,8 @@ ImageHistoryTree.prototype.draw = function(container) {
this.setTag_(this.currentTag_);
this.setupOverscroll_();
return this;
};