2016-03-13 21:23:11 -04:00
|
|
|
// 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.
|
|
|
|
(function(window, GrDiffBuilder) {
|
|
|
|
'use strict';
|
|
|
|
|
2016-03-20 14:14:20 -04:00
|
|
|
function GrDiffBuilderSideBySide(diff, comments, prefs, outputEl) {
|
|
|
|
GrDiffBuilder.call(this, diff, comments, prefs, outputEl);
|
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) {
|
2016-03-13 21:23:11 -04:00
|
|
|
var sectionEl = this._createElement('tbody', 'section');
|
2016-03-15 18:58:46 -04:00
|
|
|
sectionEl.classList.add(group.type);
|
2016-03-13 21:23:11 -04:00
|
|
|
var pairs = group.getSideBySidePairs();
|
2016-03-15 18:58:46 -04:00
|
|
|
for (var 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-03-16 18:23:56 -04:00
|
|
|
GrDiffBuilderSideBySide.prototype._createRow = function(section, leftLine,
|
|
|
|
rightLine) {
|
2016-03-13 21:23:11 -04:00
|
|
|
var 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);
|
|
|
|
|
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) {
|
2016-05-23 15:31:21 -07:00
|
|
|
var lineEl = this._createLineEl(line, lineNumber, line.type, side);
|
|
|
|
lineEl.classList.add(side);
|
|
|
|
row.appendChild(lineEl);
|
2016-03-16 18:23:56 -04:00
|
|
|
var action = this._createContextControl(section, line);
|
2016-03-15 18:58:46 -04:00
|
|
|
if (action) {
|
|
|
|
row.appendChild(action);
|
|
|
|
} else {
|
2016-03-20 14:14:20 -04:00
|
|
|
var textEl = this._createTextEl(line);
|
2016-03-22 19:14:12 -04:00
|
|
|
var threadEl = this._commentThreadForLine(line, side);
|
2016-03-20 14:14:20 -04:00
|
|
|
if (threadEl) {
|
|
|
|
textEl.appendChild(threadEl);
|
|
|
|
}
|
|
|
|
row.appendChild(textEl);
|
2016-03-15 18:58:46 -04:00
|
|
|
}
|
2016-03-13 21:23:11 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
window.GrDiffBuilderSideBySide = GrDiffBuilderSideBySide;
|
|
|
|
})(window, GrDiffBuilder);
|