Properly handle empty repos

This commit is contained in:
Joseph Schorr 2013-10-16 22:42:35 -04:00
parent 50929102b5
commit 0c3c1b9e0e

View file

@ -101,6 +101,10 @@ ImageHistoryTree.prototype.draw = function(container) {
return html; return html;
} }
if (!d.image) {
return '(This repository is empty)';
}
if (d.image.comment) { if (d.image.comment) {
html += '<span class="comment">' + formatComment(d.image.comment) + '</span>'; html += '<span class="comment">' + formatComment(d.image.comment) + '</span>';
} }
@ -198,7 +202,7 @@ ImageHistoryTree.prototype.buildRoot_ = function() {
// "name": "...", // "name": "...",
// "children": [...] // "children": [...]
// } // }
var formatted = {}; var formatted = {"name": "No images found"};
// Build a node for each image. // Build a node for each image.
var imageByDBID = {}; var imageByDBID = {};
@ -266,9 +270,11 @@ ImageHistoryTree.prototype.buildRoot_ = function() {
*/ */
ImageHistoryTree.prototype.determineMaximumHeight_ = function(node) { ImageHistoryTree.prototype.determineMaximumHeight_ = function(node) {
var maxHeight = 0; var maxHeight = 0;
if (node.children) {
for (var i = 0; i < node.children.length; ++i) { for (var i = 0; i < node.children.length; ++i) {
maxHeight = Math.max(this.determineMaximumHeight_(node.children[i]), maxHeight); maxHeight = Math.max(this.determineMaximumHeight_(node.children[i]), maxHeight);
} }
}
return maxHeight + 1; return maxHeight + 1;
}; };
@ -476,7 +482,7 @@ ImageHistoryTree.prototype.update_ = function(source) {
.attr("dy", ".35em") .attr("dy", ".35em")
.attr("text-anchor", function(d) { return d.children || d._children ? "end" : "start"; }) .attr("text-anchor", function(d) { return d.children || d._children ? "end" : "start"; })
.text(function(d) { return d.name; }) .text(function(d) { return d.name; })
.on("click", function(d) { that.changeImage_(d.image.id); }) .on("click", function(d) { if (d.image) { that.changeImage_(d.image.id); } })
.on('mouseover', tip.show) .on('mouseover', tip.show)
.on('mouseout', tip.hide); .on('mouseout', tip.hide);