Merge "Add total change counts to file list in change view"
This commit is contained in:
@@ -89,7 +89,8 @@ limitations under the License.
|
|||||||
.invisible {
|
.invisible {
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
}
|
}
|
||||||
.row:not(.header) .stats {
|
.row:not(.header) .stats,
|
||||||
|
.total-stats {
|
||||||
font-family: var(--monospace-font-family);
|
font-family: var(--monospace-font-family);
|
||||||
}
|
}
|
||||||
.added {
|
.added {
|
||||||
@@ -108,6 +109,11 @@ limitations under the License.
|
|||||||
.fileListButton {
|
.fileListButton {
|
||||||
margin: .5em;
|
margin: .5em;
|
||||||
}
|
}
|
||||||
|
.totalChanges {
|
||||||
|
justify-content: flex-end;
|
||||||
|
padding-right: 2.6em;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
input.show-hide {
|
input.show-hide {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
@@ -221,6 +227,12 @@ limitations under the License.
|
|||||||
project-config="[[projectConfig]]"
|
project-config="[[projectConfig]]"
|
||||||
view-mode="[[_diffMode]]"></gr-diff>
|
view-mode="[[_diffMode]]"></gr-diff>
|
||||||
</template>
|
</template>
|
||||||
|
<div class="row totalChanges">
|
||||||
|
<div class="total-stats" hidden$="[[_hideChangeTotals]]">
|
||||||
|
<span class="added">+[[_patchChange.inserted]]</span>
|
||||||
|
<span class="removed">-[[_patchChange.deleted]]</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<gr-button
|
<gr-button
|
||||||
class="fileListButton"
|
class="fileListButton"
|
||||||
id="incrementButton"
|
id="incrementButton"
|
||||||
|
@@ -66,11 +66,19 @@
|
|||||||
type: Number,
|
type: Number,
|
||||||
value: 75,
|
value: 75,
|
||||||
},
|
},
|
||||||
|
_patchChange: {
|
||||||
|
type: Object,
|
||||||
|
computed: '_calculatePatchChange(_files)',
|
||||||
|
},
|
||||||
_fileListIncrement: {
|
_fileListIncrement: {
|
||||||
type: Number,
|
type: Number,
|
||||||
readOnly: true,
|
readOnly: true,
|
||||||
value: 75,
|
value: 75,
|
||||||
},
|
},
|
||||||
|
_hideChangeTotals: {
|
||||||
|
type: Boolean,
|
||||||
|
computed: '_shouldHideChangeTotals(_patchChange)',
|
||||||
|
},
|
||||||
_shownFiles: {
|
_shownFiles: {
|
||||||
type: Array,
|
type: Array,
|
||||||
computed: '_computeFilesShown(_numFilesShown, _files.*)',
|
computed: '_computeFilesShown(_numFilesShown, _files.*)',
|
||||||
@@ -130,6 +138,22 @@
|
|||||||
return Polymer.dom(this.root).querySelectorAll('gr-diff');
|
return Polymer.dom(this.root).querySelectorAll('gr-diff');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_calculatePatchChange: function(files) {
|
||||||
|
var filesNoCommitMsg = files.filter(function(files) {
|
||||||
|
return files.__path !== '/COMMIT_MSG';
|
||||||
|
});
|
||||||
|
|
||||||
|
return filesNoCommitMsg.reduce(function(acc, obj) {
|
||||||
|
var inserted = obj.lines_inserted ? obj.lines_inserted : 0;
|
||||||
|
var deleted = obj.lines_deleted ? obj.lines_deleted : 0;
|
||||||
|
|
||||||
|
return {
|
||||||
|
inserted: acc.inserted + inserted,
|
||||||
|
deleted: acc.deleted + deleted,
|
||||||
|
};
|
||||||
|
}, {inserted: 0, deleted: 0});
|
||||||
|
},
|
||||||
|
|
||||||
_getDiffPreferences: function() {
|
_getDiffPreferences: function() {
|
||||||
return this.$.restAPI.getDiffPreferences();
|
return this.$.restAPI.getDiffPreferences();
|
||||||
},
|
},
|
||||||
@@ -423,6 +447,10 @@
|
|||||||
window.scrollTo(0, top - document.body.clientHeight / 2);
|
window.scrollTo(0, top - document.body.clientHeight / 2);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_shouldHideChangeTotals: function(_patchChange) {
|
||||||
|
return (_patchChange.inserted === 0 && _patchChange.deleted === 0);
|
||||||
|
},
|
||||||
|
|
||||||
_computeFileSelected: function(index, selectedIndex) {
|
_computeFileSelected: function(index, selectedIndex) {
|
||||||
return index === selectedIndex;
|
return index === selectedIndex;
|
||||||
},
|
},
|
||||||
|
@@ -97,6 +97,37 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('calculate totals for patch number', function() {
|
||||||
|
element._files = [
|
||||||
|
{__path: '/COMMIT_MSG', lines_inserted: 9},
|
||||||
|
{__path: 'file_added_in_rev2.txt', lines_inserted: 1, lines_deleted: 1},
|
||||||
|
{__path: 'myfile.txt', lines_inserted: 1, lines_deleted: 1},
|
||||||
|
];
|
||||||
|
assert.deepEqual(element._patchChange, {inserted: 2, deleted: 2});
|
||||||
|
|
||||||
|
// Test with a commit message that isn't the first file.
|
||||||
|
element._files = [
|
||||||
|
{__path: 'file_added_in_rev2.txt', lines_inserted: 1, lines_deleted: 1},
|
||||||
|
{__path: '/COMMIT_MSG', lines_inserted: 9},
|
||||||
|
{__path: 'myfile.txt', lines_inserted: 1, lines_deleted: 1},
|
||||||
|
];
|
||||||
|
assert.deepEqual(element._patchChange, {inserted: 2, deleted: 2});
|
||||||
|
|
||||||
|
// Test with no commit message.
|
||||||
|
element._files = [
|
||||||
|
{__path: 'file_added_in_rev2.txt', lines_inserted: 1, lines_deleted: 1},
|
||||||
|
{__path: 'myfile.txt', lines_inserted: 1, lines_deleted: 1},
|
||||||
|
];
|
||||||
|
assert.deepEqual(element._patchChange, {inserted: 2, deleted: 2});
|
||||||
|
|
||||||
|
// Test with files missing either lines_inserted or lines_deleted.
|
||||||
|
element._files = [
|
||||||
|
{__path: 'file_added_in_rev2.txt', lines_inserted: 1},
|
||||||
|
{__path: 'myfile.txt', lines_deleted: 1},
|
||||||
|
];
|
||||||
|
assert.deepEqual(element._patchChange, {inserted: 1, deleted: 1});
|
||||||
|
});
|
||||||
|
|
||||||
suite('keyboard shortcuts', function() {
|
suite('keyboard shortcuts', function() {
|
||||||
setup(function() {
|
setup(function() {
|
||||||
element._files = [
|
element._files = [
|
||||||
@@ -128,7 +159,7 @@ limitations under the License.
|
|||||||
flushAsynchronousOperations();
|
flushAsynchronousOperations();
|
||||||
var elementItems = Polymer.dom(element.root).querySelectorAll(
|
var elementItems = Polymer.dom(element.root).querySelectorAll(
|
||||||
'.row:not(.header)');
|
'.row:not(.header)');
|
||||||
assert.equal(elementItems.length, 3);
|
assert.equal(elementItems.length, 4);
|
||||||
assert.isTrue(elementItems[0].hasAttribute('selected'));
|
assert.isTrue(elementItems[0].hasAttribute('selected'));
|
||||||
assert.isFalse(elementItems[1].hasAttribute('selected'));
|
assert.isFalse(elementItems[1].hasAttribute('selected'));
|
||||||
assert.isFalse(elementItems[2].hasAttribute('selected'));
|
assert.isFalse(elementItems[2].hasAttribute('selected'));
|
||||||
|
Reference in New Issue
Block a user