126 lines
3.8 KiB
HTML
126 lines
3.8 KiB
HTML
![]() |
<!--
|
||
|
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.
|
||
|
-->
|
||
|
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
||
|
|
||
|
<dom-module id="gr-diff-builder">
|
||
|
<template>
|
||
|
<div class="contentWrapper">
|
||
|
<content></content>
|
||
|
</div>
|
||
|
</template>
|
||
|
<script src="../gr-diff/gr-diff-line.js"></script>
|
||
|
<script src="../gr-diff/gr-diff-group.js"></script>
|
||
|
<script src="gr-diff-builder.js"></script>
|
||
|
<script src="gr-diff-builder-side-by-side.js"></script>
|
||
|
<script src="gr-diff-builder-unified.js"></script>
|
||
|
<script src="gr-diff-builder-image.js"></script>
|
||
|
<script>
|
||
|
(function() {
|
||
|
'use strict';
|
||
|
|
||
|
var DiffViewMode = {
|
||
|
SIDE_BY_SIDE: 'SIDE_BY_SIDE',
|
||
|
UNIFIED: 'UNIFIED_DIFF',
|
||
|
};
|
||
|
|
||
|
Polymer({
|
||
|
is: 'gr-diff-builder',
|
||
|
|
||
|
/**
|
||
|
* Fired when the diff is rendered.
|
||
|
*
|
||
|
* @event render
|
||
|
*/
|
||
|
|
||
|
properties: {
|
||
|
viewMode: String,
|
||
|
isImageDiff: Boolean,
|
||
|
baseImage: Object,
|
||
|
revisionImage: Object,
|
||
|
_builder: Object,
|
||
|
},
|
||
|
|
||
|
get diffElement() {
|
||
|
return this.queryEffectiveChildren('#diffTable');
|
||
|
},
|
||
|
|
||
|
render: function(diff, comments, prefs) {
|
||
|
this._builder = this._getDiffBuilder(diff, comments, prefs);
|
||
|
this._renderDiff();
|
||
|
},
|
||
|
|
||
|
createCommentThread: function(changeNum, patchNum, path, side,
|
||
|
projectConfig) {
|
||
|
return this._builder.createCommentThread(changeNum, patchNum, path,
|
||
|
side, projectConfig);
|
||
|
},
|
||
|
|
||
|
emitGroup: function(group, sectionEl) {
|
||
|
this._builder.emitGroup(group, sectionEl);
|
||
|
},
|
||
|
|
||
|
emitDiff: function() {
|
||
|
this._builder.emitDiff();
|
||
|
},
|
||
|
|
||
|
showContext: function(newGroups, sectionEl) {
|
||
|
var groups = this._builder._groups;
|
||
|
// TODO(viktard): Polyfill findIndex for IE10.
|
||
|
var contextIndex = groups.findIndex(function(group) {
|
||
|
return group.element == sectionEl;
|
||
|
});
|
||
|
groups.splice.apply(groups, [contextIndex, 1].concat(newGroups));
|
||
|
|
||
|
newGroups.forEach(function(newGroup) {
|
||
|
this._builder.emitGroup(newGroup, sectionEl);
|
||
|
}.bind(this));
|
||
|
sectionEl.parentNode.removeChild(sectionEl);
|
||
|
|
||
|
this.async(function() {
|
||
|
this.fire('render');
|
||
|
}.bind(this), 1);
|
||
|
},
|
||
|
|
||
|
_getDiffBuilder: function(diff, comments, prefs) {
|
||
|
if (this.isImageDiff) {
|
||
|
return new GrDiffBuilderImage(diff, comments, prefs,
|
||
|
this.diffElement, this.baseImage, this.revisionImage);
|
||
|
} else if (this.viewMode === DiffViewMode.SIDE_BY_SIDE) {
|
||
|
return new GrDiffBuilderSideBySide(
|
||
|
diff, comments, prefs, this.diffElement);
|
||
|
} else if (this.viewMode === DiffViewMode.UNIFIED) {
|
||
|
return new GrDiffBuilderUnified(
|
||
|
diff, comments, prefs, this.diffElement);
|
||
|
}
|
||
|
throw Error('Unsupported diff view mode: ' + this.viewMode);
|
||
|
},
|
||
|
|
||
|
_renderDiff: function() {
|
||
|
this._clearDiffContent();
|
||
|
this.emitDiff();
|
||
|
this.async(function() {
|
||
|
this.fire('render');
|
||
|
}, 1);
|
||
|
},
|
||
|
|
||
|
_clearDiffContent: function() {
|
||
|
this.diffElement.innerHTML = null;
|
||
|
},
|
||
|
});
|
||
|
})();
|
||
|
</script>
|
||
|
</dom-module>
|