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:
Urs Wolfer
2016-02-10 21:59:20 +01:00
parent 437e46ea7d
commit 51a7070de5
2 changed files with 104 additions and 0 deletions

View File

@@ -20,6 +20,7 @@ limitations under the License.
<link rel="import" href="../behaviors/rest-client-behavior.html"> <link rel="import" href="../behaviors/rest-client-behavior.html">
<link rel="import" href="gr-ajax.html"> <link rel="import" href="gr-ajax.html">
<link rel="import" href="gr-diff.html"> <link rel="import" href="gr-diff.html">
<link rel="import" href="gr-request.html">
<dom-module id="gr-diff-view"> <dom-module id="gr-diff-view">
<template> <template>
@@ -99,6 +100,8 @@ limitations under the License.
<h3> <h3>
<a href$="[[_computeChangePath(_changeNum)]]">[[_changeNum]]</a><span>:</span> <a href$="[[_computeChangePath(_changeNum)]]">[[_changeNum]]</a><span>:</span>
<span>[[_change.subject]]</span> <span>[[_change.subject]]</span>
<input id="reviewed" type="checkbox" on-change="_handleReviewedChange"
hidden$="[[!_loggedIn]]" hidden>
<div class="jumpToFileContainer"> <div class="jumpToFileContainer">
<button class="dropdown-trigger" id="trigger" on-tap="_showDropdownTapHandler"> <button class="dropdown-trigger" id="trigger" on-tap="_showDropdownTapHandler">
<span>[[_path]]</span> <span>[[_path]]</span>
@@ -177,6 +180,7 @@ limitations under the License.
type: Boolean, type: Boolean,
value: false, value: false,
}, },
_xhrPromise: Object, // Used for testing.
}, },
behaviors: [ behaviors: [
@@ -187,6 +191,9 @@ limitations under the License.
ready: function() { ready: function() {
app.accountReady.then(function() { app.accountReady.then(function() {
this._loggedIn = app.loggedIn; this._loggedIn = app.loggedIn;
if (this._loggedIn) {
this._setReviewed(true);
}
}.bind(this)); }.bind(this));
}, },
@@ -201,6 +208,23 @@ limitations under the License.
window.removeEventListener('resize', this._boundWindowResizeHandler); 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('Couldnt change file review status. Check the console ' +
'and contact the PolyGerrit team for assistance.');
throw err;
}.bind(this));
},
_handleKey: function(e) { _handleKey: function(e) {
if (this.shouldSupressKeyboardShortcut(e)) { return; } if (this.shouldSupressKeyboardShortcut(e)) { return; }
@@ -277,6 +301,10 @@ limitations under the License.
this.set('changeViewState.selectedFileIndex', this.set('changeViewState.selectedFileIndex',
this._fileList.indexOf(path)); this._fileList.indexOf(path));
if (this._loggedIn) {
this._setReviewed(true);
}
}, },
_computeDiffURL: function(changeNum, patchRange, path) { _computeDiffURL: function(changeNum, patchRange, path) {
@@ -344,6 +372,15 @@ limitations under the License.
_showDropdownTapHandler: function(e) { _showDropdownTapHandler: function(e) {
this.$.dropdown.open(); 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> </script>

View File

@@ -36,6 +36,7 @@ limitations under the License.
<script> <script>
suite('gr-diff-view tests', function() { suite('gr-diff-view tests', function() {
var element; var element;
var server;
setup(function() { setup(function() {
element = fixture('basic'); element = fixture('basic');
@@ -43,6 +44,31 @@ limitations under the License.
element.$.filesXHR.auto = false; element.$.filesXHR.auto = false;
element.$.configXHR.auto = false; element.$.configXHR.auto = false;
element.$.diff.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() { 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[1].getAttribute('href'), '/c/42/5..10/glados.txt');
assert.equal(linkEls[2].getAttribute('href'), '/c/42/5..10/wheatley.md'); 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> </script>