From 20d55158f96a58e932e38bd1dff6cc6cc8c64ff8 Mon Sep 17 00:00:00 2001 From: Andrew Bonventre Date: Wed, 4 May 2016 12:15:44 -0400 Subject: [PATCH] gr-ajax cleanup (gr-related-changes-list) Bug: Issue 3988 Change-Id: I087f5abfa33e28246ef8701b1cfb06575c15c1db --- .../change/gr-change-view/gr-change-view.html | 5 +- .../gr-related-changes-list.html | 23 +--- .../gr-related-changes-list.js | 105 ++++++------------ .../gr-rest-api-interface.js | 54 +++++++++ 4 files changed, 93 insertions(+), 94 deletions(-) diff --git a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html index 30e89bf04d..7ab23a18e2 100644 --- a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html +++ b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html @@ -266,9 +266,8 @@ limitations under the License.
+ change="[[_change]]" + patch-num="[[_patchNum]]">
diff --git a/polygerrit-ui/app/elements/change/gr-related-changes-list/gr-related-changes-list.html b/polygerrit-ui/app/elements/change/gr-related-changes-list/gr-related-changes-list.html index 2b13dd6eef..213b0049cf 100644 --- a/polygerrit-ui/app/elements/change/gr-related-changes-list/gr-related-changes-list.html +++ b/polygerrit-ui/app/elements/change/gr-related-changes-list/gr-related-changes-list.html @@ -15,8 +15,7 @@ limitations under the License. --> - - + + diff --git a/polygerrit-ui/app/elements/change/gr-related-changes-list/gr-related-changes-list.js b/polygerrit-ui/app/elements/change/gr-related-changes-list/gr-related-changes-list.js index 9f433dca78..73a57d433d 100644 --- a/polygerrit-ui/app/elements/change/gr-related-changes-list/gr-related-changes-list.js +++ b/polygerrit-ui/app/elements/change/gr-related-changes-list/gr-related-changes-list.js @@ -20,10 +20,6 @@ properties: { change: Object, patchNum: String, - serverConfig: { - type: Object, - observer: '_serverConfigChanged', - }, hidden: { type: Boolean, value: false, @@ -31,15 +27,6 @@ }, _loading: Boolean, - _resolveServerConfigReady: Function, - _serverConfigReady: { - type: Object, - value: function() { - return new Promise(function(resolve) { - this._resolveServerConfigReady = resolve; - }.bind(this)); - } - }, _connectedRevisions: { type: Array, computed: '_computeConnectedRevisions(change, patchNum, ' + @@ -52,10 +39,6 @@ _sameTopic: Array, }, - behaviors: [ - Gerrit.RESTClientBehavior, - ], - observers: [ '_resultsChanged(_relatedResponse.changes, _submittedTogether, ' + '_conflicts, _cherryPicks, _sameTopic)', @@ -67,72 +50,58 @@ } this._loading = true; var promises = [ - this.$.relatedXHR.generateRequest().completes, - this.$.submittedTogetherXHR.generateRequest().completes, - this.$.conflictsXHR.generateRequest().completes, - this.$.cherryPicksXHR.generateRequest().completes, + this._getRelatedChanges().then(function(response) { + this._relatedResponse = response; + }.bind(this)), + this._getSubmittedTogether().then(function(response) { + this._submittedTogether = response; + }.bind(this)), + this._getConflicts().then(function(response) { + this._conflicts = response; + }.bind(this)), + this._getCherryPicks().then(function(response) { + this._cherryPicks = response; + }.bind(this)), ]; - return this._serverConfigReady.then(function() { - if (this.change.topic && - !this.serverConfig.change.submit_whole_topic) { - return this.$.sameTopicXHR.generateRequest().completes; + return this._getServerConfig().then(function(config) { + if (this.change.topic && !config.change.submit_whole_topic) { + return this._getChangesWithSameTopic().then(function(response) { + this._sameTopic = response; + }.bind(this)); } else { - this._sameTopic = []; + this._sameTopic = []; } - return Promise.resolve(); + return this._sameTopic; }.bind(this)).then(Promise.all(promises)).then(function() { this._loading = false; }.bind(this)); }, - _computeRelatedURL: function(changeNum, patchNum) { - return this.changeBaseURL(changeNum, patchNum) + '/related'; + _getRelatedChanges: function() { + return this.$.restAPI.getRelatedChanges(this.change._number, + this.patchNum); }, - _computeSubmittedTogetherURL: function(changeNum) { - return this.changeBaseURL(changeNum) + '/submitted_together'; + _getSubmittedTogether: function() { + return this.$.restAPI.getChangesSubmittedTogether(this.change._number); }, - _computeConflictsQueryParams: function(changeNum) { - var options = this.listChangesOptionsToHex( - this.ListChangesOption.CURRENT_REVISION, - this.ListChangesOption.CURRENT_COMMIT - ); - return { - O: options, - q: 'status:open is:mergeable conflicts:' + changeNum, - }; + _getServerConfig: function() { + return this.$.restAPI.getConfig(); }, - _computeCherryPicksQueryParams: function(project, changeID, changeNum) { - var options = this.listChangesOptionsToHex( - this.ListChangesOption.CURRENT_REVISION, - this.ListChangesOption.CURRENT_COMMIT - ); - var query = [ - 'project:' + project, - 'change:' + changeID, - '-change:' + changeNum, - '-is:abandoned', - ].join(' '); - return { - O: options, - q: query - }; + _getConflicts: function() { + return this.$.restAPI.getChangeConflicts(this.change._number); }, - _computeSameTopicQueryParams: function(topic) { - var options = this.listChangesOptionsToHex( - this.ListChangesOption.LABELS, - this.ListChangesOption.CURRENT_REVISION, - this.ListChangesOption.CURRENT_COMMIT, - this.ListChangesOption.DETAILED_LABELS - ); - return { - O: options, - q: 'status:open topic:' + topic, - }; + _getCherryPicks: function() { + return this.$.restAPI.getChangeCherryPicks(this.change.project, + this.change.change_id, this.change._number); + }, + + _getChangesWithSameTopic: function() { + return this.$.restAPI.getChangesWithSameTopic(this.change.topic); }, _computeChangeURL: function(changeNum, patchNum) { @@ -182,10 +151,6 @@ return ''; }, - _serverConfigChanged: function(config) { - this._resolveServerConfigReady(config); - }, - _resultsChanged: function(related, submittedTogether, conflicts, cherryPicks, sameTopic) { var results = [ diff --git a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js index 1947654a70..82e045e33a 100644 --- a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js +++ b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js @@ -407,6 +407,60 @@ return this.send(method, url, body); }, + getRelatedChanges: function(changeNum, patchNum) { + return this.fetchJSON( + this.getChangeActionURL(changeNum, patchNum, '/related')); + }, + + getChangesSubmittedTogether: function(changeNum) { + return this.fetchJSON( + this.getChangeActionURL(changeNum, null, '/submitted_together')); + }, + + getChangeConflicts: function(changeNum) { + var options = this._listChangesOptionsToHex( + ListChangesOption.CURRENT_REVISION, + ListChangesOption.CURRENT_COMMIT + ); + var params = { + O: options, + q: 'status:open is:mergeable conflicts:' + changeNum, + }; + return this.fetchJSON('/changes/', null, null, params); + }, + + getChangeCherryPicks: function(project, changeID, changeNum) { + var options = this._listChangesOptionsToHex( + ListChangesOption.CURRENT_REVISION, + ListChangesOption.CURRENT_COMMIT + ); + var query = [ + 'project:' + project, + 'change:' + changeID, + '-change:' + changeNum, + '-is:abandoned', + ].join(' '); + var params = { + O: options, + q: query + }; + return this.fetchJSON('/changes/', null, null, params); + }, + + getChangesWithSameTopic: function(topic) { + var options = this._listChangesOptionsToHex( + ListChangesOption.LABELS, + ListChangesOption.CURRENT_REVISION, + ListChangesOption.CURRENT_COMMIT, + ListChangesOption.DETAILED_LABELS + ); + var params = { + O: options, + q: 'status:open topic:' + topic, + }; + return this.fetchJSON('/changes/', null, null, params); + }, + getReviewedFiles: function(changeNum, patchNum) { return this.fetchJSON( this.getChangeActionURL(changeNum, patchNum, '/files?reviewed'));