2018-03-26 10:04:27 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright (C) 2016 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the 'License');
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an 'AS IS' BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2016-03-13 21:23:11 -04:00
|
|
|
(function(window, GrDiffBuilder) {
|
|
|
|
'use strict';
|
|
|
|
|
2016-06-27 09:36:36 -07:00
|
|
|
// Prevent redefinition.
|
|
|
|
if (window.GrDiffBuilderSideBySide) { return; }
|
|
|
|
|
2017-07-31 14:33:16 -07:00
|
|
|
function GrDiffBuilderSideBySide(
|
|
|
|
diff, comments, prefs, projectName, outputEl, layers) {
|
|
|
|
GrDiffBuilder.call(
|
|
|
|
this, diff, comments, prefs, projectName, outputEl, layers);
|
2016-03-13 21:23:11 -04:00
|
|
|
}
|
|
|
|
GrDiffBuilderSideBySide.prototype = Object.create(GrDiffBuilder.prototype);
|
|
|
|
GrDiffBuilderSideBySide.prototype.constructor = GrDiffBuilderSideBySide;
|
|
|
|
|
2016-06-09 16:08:04 -07:00
|
|
|
GrDiffBuilderSideBySide.prototype.buildSectionElement = function(group) {
|
2017-05-16 13:45:17 -07:00
|
|
|
const sectionEl = this._createElement('tbody', 'section');
|
2016-03-15 18:58:46 -04:00
|
|
|
sectionEl.classList.add(group.type);
|
2016-12-21 12:55:21 -08:00
|
|
|
if (this._isTotal(group)) {
|
|
|
|
sectionEl.classList.add('total');
|
|
|
|
}
|
2017-05-05 17:48:31 +02:00
|
|
|
if (group.dueToRebase) {
|
|
|
|
sectionEl.classList.add('dueToRebase');
|
|
|
|
}
|
2017-05-16 13:45:17 -07:00
|
|
|
const pairs = group.getSideBySidePairs();
|
|
|
|
for (let i = 0; i < pairs.length; i++) {
|
2016-03-16 18:23:56 -04:00
|
|
|
sectionEl.appendChild(this._createRow(sectionEl, pairs[i].left,
|
|
|
|
pairs[i].right));
|
2016-03-13 21:23:11 -04:00
|
|
|
}
|
2016-05-23 15:31:21 -07:00
|
|
|
return sectionEl;
|
2016-04-29 22:25:51 +02:00
|
|
|
};
|
2016-03-13 21:23:11 -04:00
|
|
|
|
2016-10-31 14:35:35 -07:00
|
|
|
GrDiffBuilderSideBySide.prototype.addColumns = function(outputEl, fontSize) {
|
2017-05-16 13:45:17 -07:00
|
|
|
const width = fontSize * 4;
|
|
|
|
const colgroup = document.createElement('colgroup');
|
2016-10-31 14:35:35 -07:00
|
|
|
|
2017-09-14 09:45:50 -07:00
|
|
|
// Add the blame column.
|
|
|
|
let col = this._createElement('col', 'blame');
|
|
|
|
colgroup.appendChild(col);
|
|
|
|
|
2016-10-31 14:35:35 -07:00
|
|
|
// Add left-side line number.
|
2017-09-14 09:45:50 -07:00
|
|
|
col = document.createElement('col');
|
2016-10-31 14:35:35 -07:00
|
|
|
col.setAttribute('width', width);
|
|
|
|
colgroup.appendChild(col);
|
|
|
|
|
|
|
|
// Add left-side content.
|
|
|
|
colgroup.appendChild(document.createElement('col'));
|
|
|
|
|
|
|
|
// Add right-side line number.
|
|
|
|
col = document.createElement('col');
|
|
|
|
col.setAttribute('width', width);
|
|
|
|
colgroup.appendChild(col);
|
|
|
|
|
|
|
|
// Add right-side content.
|
|
|
|
colgroup.appendChild(document.createElement('col'));
|
|
|
|
|
|
|
|
outputEl.appendChild(colgroup);
|
|
|
|
};
|
|
|
|
|
2016-03-16 18:23:56 -04:00
|
|
|
GrDiffBuilderSideBySide.prototype._createRow = function(section, leftLine,
|
|
|
|
rightLine) {
|
2017-05-16 13:45:17 -07:00
|
|
|
const row = this._createElement('tr');
|
2016-05-16 14:40:51 -07:00
|
|
|
row.classList.add('diff-row', 'side-by-side');
|
|
|
|
row.setAttribute('left-type', leftLine.type);
|
|
|
|
row.setAttribute('right-type', rightLine.type);
|
2017-06-06 16:59:22 -07:00
|
|
|
row.tabIndex = -1;
|
2016-05-16 14:40:51 -07:00
|
|
|
|
2017-09-14 09:45:50 -07:00
|
|
|
row.appendChild(this._createBlameCell(leftLine));
|
|
|
|
|
2016-03-20 14:14:20 -04:00
|
|
|
this._appendPair(section, row, leftLine, leftLine.beforeNumber,
|
|
|
|
GrDiffBuilder.Side.LEFT);
|
|
|
|
this._appendPair(section, row, rightLine, rightLine.afterNumber,
|
|
|
|
GrDiffBuilder.Side.RIGHT);
|
2016-03-13 21:23:11 -04:00
|
|
|
return row;
|
|
|
|
};
|
|
|
|
|
2016-03-20 14:14:20 -04:00
|
|
|
GrDiffBuilderSideBySide.prototype._appendPair = function(section, row, line,
|
2016-03-18 14:45:58 -04:00
|
|
|
lineNumber, side) {
|
2017-05-16 13:45:17 -07:00
|
|
|
const lineEl = this._createLineEl(line, lineNumber, line.type, side);
|
2016-05-23 15:31:21 -07:00
|
|
|
lineEl.classList.add(side);
|
|
|
|
row.appendChild(lineEl);
|
2017-05-16 13:45:17 -07:00
|
|
|
const action = this._createContextControl(section, line);
|
2016-03-15 18:58:46 -04:00
|
|
|
if (action) {
|
|
|
|
row.appendChild(action);
|
|
|
|
} else {
|
2017-05-16 13:45:17 -07:00
|
|
|
const textEl = this._createTextEl(line, side);
|
|
|
|
const threadGroupEl = this._commentThreadGroupForLine(line, side);
|
2017-01-27 15:33:08 -08:00
|
|
|
if (threadGroupEl) {
|
|
|
|
textEl.appendChild(threadGroupEl);
|
2016-03-20 14:14:20 -04:00
|
|
|
}
|
|
|
|
row.appendChild(textEl);
|
2016-03-15 18:58:46 -04:00
|
|
|
}
|
2016-03-13 21:23:11 -04:00
|
|
|
};
|
|
|
|
|
2016-07-21 22:19:25 -07:00
|
|
|
GrDiffBuilderSideBySide.prototype._getNextContentOnSide = function(
|
|
|
|
content, side) {
|
2017-05-16 13:45:17 -07:00
|
|
|
let tr = content.parentElement.parentElement;
|
2016-07-21 22:19:25 -07:00
|
|
|
while (tr = tr.nextSibling) {
|
|
|
|
content = tr.querySelector(
|
|
|
|
'td.content .contentText[data-side="' + side + '"]');
|
|
|
|
if (content) { return content; }
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
2016-03-13 21:23:11 -04:00
|
|
|
window.GrDiffBuilderSideBySide = GrDiffBuilderSideBySide;
|
|
|
|
})(window, GrDiffBuilder);
|