Add file review status to diff view
When diff is opened, it is automatically marked as reviewed. Change-Id: I13e4c28f2ccc38dd2e9fb41793cedae4ffdd5ba7 Feature: Issue 3880
This commit is contained in:
@@ -20,6 +20,7 @@ limitations under the License.
|
||||
<link rel="import" href="../behaviors/rest-client-behavior.html">
|
||||
<link rel="import" href="gr-ajax.html">
|
||||
<link rel="import" href="gr-diff.html">
|
||||
<link rel="import" href="gr-request.html">
|
||||
|
||||
<dom-module id="gr-diff-view">
|
||||
<template>
|
||||
@@ -99,6 +100,8 @@ limitations under the License.
|
||||
<h3>
|
||||
<a href$="[[_computeChangePath(_changeNum)]]">[[_changeNum]]</a><span>:</span>
|
||||
<span>[[_change.subject]]</span> —
|
||||
<input id="reviewed" type="checkbox" on-change="_handleReviewedChange"
|
||||
hidden$="[[!_loggedIn]]" hidden>
|
||||
<div class="jumpToFileContainer">
|
||||
<button class="dropdown-trigger" id="trigger" on-tap="_showDropdownTapHandler">
|
||||
<span>[[_path]]</span>
|
||||
@@ -177,6 +180,7 @@ limitations under the License.
|
||||
type: Boolean,
|
||||
value: false,
|
||||
},
|
||||
_xhrPromise: Object, // Used for testing.
|
||||
},
|
||||
|
||||
behaviors: [
|
||||
@@ -187,6 +191,9 @@ limitations under the License.
|
||||
ready: function() {
|
||||
app.accountReady.then(function() {
|
||||
this._loggedIn = app.loggedIn;
|
||||
if (this._loggedIn) {
|
||||
this._setReviewed(true);
|
||||
}
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
@@ -201,6 +208,23 @@ limitations under the License.
|
||||
window.removeEventListener('resize', this._boundWindowResizeHandler);
|
||||
},
|
||||
|
||||
_handleReviewedChange: function(e) {
|
||||
this._setReviewed(Polymer.dom(e).rootTarget.checked);
|
||||
},
|
||||
|
||||
_setReviewed: function(reviewed) {
|
||||
this.$.reviewed.checked = reviewed;
|
||||
var method = reviewed ? 'PUT' : 'DELETE';
|
||||
var url = this.changeBaseURL(this._changeNum,
|
||||
this._patchRange.patchNum) + '/files/' +
|
||||
encodeURIComponent(this._path) + '/reviewed';
|
||||
this._send(method, url).catch(function(err) {
|
||||
alert('Couldn’t change file review status. Check the console ' +
|
||||
'and contact the PolyGerrit team for assistance.');
|
||||
throw err;
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
_handleKey: function(e) {
|
||||
if (this.shouldSupressKeyboardShortcut(e)) { return; }
|
||||
|
||||
@@ -277,6 +301,10 @@ limitations under the License.
|
||||
|
||||
this.set('changeViewState.selectedFileIndex',
|
||||
this._fileList.indexOf(path));
|
||||
|
||||
if (this._loggedIn) {
|
||||
this._setReviewed(true);
|
||||
}
|
||||
},
|
||||
|
||||
_computeDiffURL: function(changeNum, patchRange, path) {
|
||||
@@ -344,6 +372,15 @@ limitations under the License.
|
||||
_showDropdownTapHandler: function(e) {
|
||||
this.$.dropdown.open();
|
||||
},
|
||||
|
||||
_send: function(method, url) {
|
||||
var xhr = document.createElement('gr-request');
|
||||
this._xhrPromise = xhr.send({
|
||||
method: method,
|
||||
url: url,
|
||||
});
|
||||
return this._xhrPromise;
|
||||
},
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
|
@@ -36,6 +36,7 @@ limitations under the License.
|
||||
<script>
|
||||
suite('gr-diff-view tests', function() {
|
||||
var element;
|
||||
var server;
|
||||
|
||||
setup(function() {
|
||||
element = fixture('basic');
|
||||
@@ -43,6 +44,31 @@ limitations under the License.
|
||||
element.$.filesXHR.auto = false;
|
||||
element.$.configXHR.auto = false;
|
||||
element.$.diff.auto = false;
|
||||
|
||||
server = sinon.fakeServer.create();
|
||||
server.respondWith(
|
||||
'PUT',
|
||||
'/changes/42/revisions/2/files/%2FCOMMIT_MSG/reviewed',
|
||||
[
|
||||
201,
|
||||
{'Content-Type': 'application/json'},
|
||||
')]}\'\n' +
|
||||
'""',
|
||||
]
|
||||
);
|
||||
server.respondWith(
|
||||
'DELETE',
|
||||
'/changes/42/revisions/2/files/%2FCOMMIT_MSG/reviewed',
|
||||
[
|
||||
204,
|
||||
{'Content-Type': 'application/json'},
|
||||
'',
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
server.restore();
|
||||
});
|
||||
|
||||
test('keyboard shortcuts', function() {
|
||||
@@ -182,5 +208,46 @@ limitations under the License.
|
||||
assert.equal(linkEls[1].getAttribute('href'), '/c/42/5..10/glados.txt');
|
||||
assert.equal(linkEls[2].getAttribute('href'), '/c/42/5..10/wheatley.md');
|
||||
});
|
||||
|
||||
test('file review status', function(done) {
|
||||
element._loggedIn = true;
|
||||
element._changeNum = '42';
|
||||
element._patchRange = {
|
||||
basePatchNum: '1',
|
||||
patchNum: '2',
|
||||
};
|
||||
element._fileList = ['/COMMIT_MSG'];
|
||||
element._path = '/COMMIT_MSG';
|
||||
|
||||
server.respond();
|
||||
|
||||
element.async(function() {
|
||||
var commitMsg = Polymer.dom(element.root).querySelector(
|
||||
'input[type="checkbox"]');
|
||||
|
||||
assert.isTrue(commitMsg.checked);
|
||||
|
||||
MockInteractions.tap(commitMsg);
|
||||
server.respond();
|
||||
element._xhrPromise.then(function(req) {
|
||||
assert.isFalse(commitMsg.checked);
|
||||
assert.equal(req.status, 204);
|
||||
assert.equal(req.url,
|
||||
'/changes/42/revisions/2/files/%2FCOMMIT_MSG/reviewed');
|
||||
|
||||
MockInteractions.tap(commitMsg);
|
||||
server.respond();
|
||||
}).then(function() {
|
||||
element._xhrPromise.then(function(req) {
|
||||
assert.isTrue(commitMsg.checked);
|
||||
assert.equal(req.status, 201);
|
||||
assert.equal(req.url,
|
||||
'/changes/42/revisions/2/files/%2FCOMMIT_MSG/reviewed');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
}, 1);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
Reference in New Issue
Block a user