diff --git a/polygerrit-ui/app/elements/gr-diff-view.html b/polygerrit-ui/app/elements/gr-diff-view.html index 5175a1b31e..9d30c4a0ad 100644 --- a/polygerrit-ui/app/elements/gr-diff-view.html +++ b/polygerrit-ui/app/elements/gr-diff-view.html @@ -20,6 +20,7 @@ limitations under the License. + @@ -99,6 +100,8 @@ limitations under the License. [[_changeNum]]: [[_change.subject]] — + [[_path]] @@ -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; + }, }); })(); diff --git a/polygerrit-ui/app/test/gr-diff-view-test.html b/polygerrit-ui/app/test/gr-diff-view-test.html index 3bf2c3370f..17b6b6b462 100644 --- a/polygerrit-ui/app/test/gr-diff-view-test.html +++ b/polygerrit-ui/app/test/gr-diff-view-test.html @@ -36,6 +36,7 @@ limitations under the License.