From 2a43443d3d8025e3c3c3cd048140e27b2170c175 Mon Sep 17 00:00:00 2001 From: SYU88 Date: Tue, 14 Jun 2016 07:13:06 -0700 Subject: [PATCH 1/2] Add additional sha, parent, and message information to head info box Add comments and clean up formatting --- js/historyview.js | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/js/historyview.js b/js/historyview.js index e350b21..f356c07 100644 --- a/js/historyview.js +++ b/js/historyview.js @@ -558,6 +558,7 @@ define(['d3'], function() { this.renderCommits(); this._setCurrentBranch(this.currentBranch); + this._setCurrentCommit(); }, destroy: function() { @@ -976,7 +977,32 @@ define(['d3'], function() { this.currentBranch = null; } - display.text(text); + //need to clear out display otherwise tspans will keep appending + display.text(''); + display.append('tspan').attr('x','10').attr('dy', '1.2em').text(text); + }, + + _setCurrentCommit: function() { + var display = this.svg.select('text.current-branch-display'); + + //this will error out without checking first to see if commit exits, possible async issue? + if(this.getCommit('HEAD')) { + display.append('tspan') + .attr('x','10') + .attr('dy', '1.2em') + .text('Sha: ' + this.getCommit('HEAD').id); + + display.append('tspan') + .attr('x','10') + .attr('dy', '1.2em') + .text('Parent: ' + this.getCommit('HEAD').parent); + + display.append('tspan') + .attr('x','10') + .attr('dy', '1.2em') + .text('Message: ' + this.getCommit('HEAD').message); + } + }, addReflogEntry: function(ref, destination, reason) { @@ -1265,7 +1291,6 @@ define(['d3'], function() { checkout: function(ref) { var commit = this.getCommit(ref); - if (!commit) { throw new Error('Cannot find commit: ' + ref); } @@ -1279,6 +1304,7 @@ define(['d3'], function() { var isBranch = this.branches.indexOf(ref) !== -1 this._setCurrentBranch(isBranch ? ref : null); + this._setCurrentCommit(); this.moveTag('HEAD', commit.id); this.renderTags(); @@ -1479,6 +1505,7 @@ define(['d3'], function() { this.moveTag(origBranch, newHeadCommit.id) this.reset(origBranch) this._setCurrentBranch(origBranch) + this._setCurrentCommit() this.addReflogEntry( 'HEAD', targetCommit.id, 'rebase finished: returning to resf/heads/' + origBranch ) From 29ad777d3c2ba99f55e99ae35736ed47ce958fbf Mon Sep 17 00:00:00 2001 From: SYU88 Date: Tue, 14 Jun 2016 22:07:04 -0700 Subject: [PATCH 2/2] Refactor to edit text of tspans instead of re-appending them --- js/historyview.js | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/js/historyview.js b/js/historyview.js index f356c07..6f7cd67 100644 --- a/js/historyview.js +++ b/js/historyview.js @@ -514,7 +514,7 @@ define(['d3'], function() { * @param container {String} selector for the container to render the SVG into */ render: function(container) { - var svgContainer, svg; + var svgContainer, svg, display; svgContainer = container.append('div') .classed('svg-container', true) @@ -547,6 +547,22 @@ define(['d3'], function() { .classed('current-branch-display', true) .attr('x', 10) .attr('y', 45); + + display = svg.select('text.current-branch-display'); + + display.append('svg:tspan') + .attr('x','10') + .attr('dy', '1.2em'); + display.append('svg:tspan') + .attr('x','10') + .attr('dy', '1.2em'); + display.append('svg:tspan') + .attr('x','10') + .attr('dy', '1.2em'); + display.append('svg:tspan') + .attr('x','10') + .attr('dy', '1.2em'); + } this.svgContainer = svgContainer; @@ -966,7 +982,7 @@ define(['d3'], function() { }, _setCurrentBranch: function(branch) { - var display = this.svg.select('text.current-branch-display'), + var display = this.svg.select('text.current-branch-display > tspan'), text = 'HEAD: '; if (branch && branch.indexOf('/') === -1) { @@ -976,31 +992,18 @@ define(['d3'], function() { text += ' (detached head)'; this.currentBranch = null; } - - //need to clear out display otherwise tspans will keep appending - display.text(''); - display.append('tspan').attr('x','10').attr('dy', '1.2em').text(text); + + d3.select(display[0][0]).text(text); }, _setCurrentCommit: function() { - var display = this.svg.select('text.current-branch-display'); + var display = this.svg.selectAll('text.current-branch-display > tspan'); //this will error out without checking first to see if commit exits, possible async issue? if(this.getCommit('HEAD')) { - display.append('tspan') - .attr('x','10') - .attr('dy', '1.2em') - .text('Sha: ' + this.getCommit('HEAD').id); - - display.append('tspan') - .attr('x','10') - .attr('dy', '1.2em') - .text('Parent: ' + this.getCommit('HEAD').parent); - - display.append('tspan') - .attr('x','10') - .attr('dy', '1.2em') - .text('Message: ' + this.getCommit('HEAD').message); + d3.select(display[0][1]).text('Sha: ' + this.getCommit('HEAD').id); + d3.select(display[0][2]).text('Parent: ' + this.getCommit('HEAD').parent); + d3.select(display[0][3]).text('Message: ' + this.getCommit('HEAD').message); } }, @@ -1291,6 +1294,7 @@ define(['d3'], function() { checkout: function(ref) { var commit = this.getCommit(ref); + if (!commit) { throw new Error('Cannot find commit: ' + ref); }