gr-ajax cleanup (gr-related-changes-list)

Bug: Issue 3988
Change-Id: I087f5abfa33e28246ef8701b1cfb06575c15c1db
This commit is contained in:
Andrew Bonventre
2016-05-04 12:15:44 -04:00
parent 0c76ebbb1d
commit 20d55158f9
4 changed files with 93 additions and 94 deletions

View File

@@ -266,9 +266,8 @@ limitations under the License.
</div>
<div class="relatedChanges">
<gr-related-changes-list id="relatedChanges"
change="[[_change]]"
server-config="[[serverConfig]]"
patch-num="[[_patchNum]]"></gr-related-changes-list>
change="[[_change]]"
patch-num="[[_patchNum]]"></gr-related-changes-list>
</div>
</div>
</section>

View File

@@ -15,8 +15,7 @@ limitations under the License.
-->
<link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="../../../behaviors/rest-client-behavior.html">
<link rel="import" href="../../shared/gr-ajax/gr-ajax.html">
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">
<dom-module id="gr-related-changes-list">
<template>
@@ -68,25 +67,6 @@ limitations under the License.
display: none;
}
</style>
<gr-ajax id="relatedXHR"
url="[[_computeRelatedURL(change._number, patchNum)]]"
last-response="{{_relatedResponse}}"></gr-ajax>
<gr-ajax id="submittedTogetherXHR"
url="[[_computeSubmittedTogetherURL(change._number)]]"
last-response="{{_submittedTogether}}"></gr-ajax>
<gr-ajax id="conflictsXHR"
url="/changes/"
params="[[_computeConflictsQueryParams(change._number)]]"
last-response="{{_conflicts}}"></gr-ajax>
<gr-ajax id="cherryPicksXHR"
url="/changes/"
params="[[_computeCherryPicksQueryParams(change.project, change.change_id, change._number)]]"
last-response="{{_cherryPicks}}"></gr-ajax>
<gr-ajax id="sameTopicXHR"
url="/changes/"
params="[[_computeSameTopicQueryParams(change.topic)]]"
last-response="{{_sameTopic}}"></gr-ajax>
<div hidden$="[[!_loading]]">Loading...</div>
<section class="relatedChanges" hidden$="[[!_relatedResponse.changes.length]]" hidden>
<h4>Relation chain</h4>
@@ -138,6 +118,7 @@ limitations under the License.
</a>
</template>
</section>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
</template>
<script src="gr-related-changes-list.js"></script>
</dom-module>

View File

@@ -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 = [

View File

@@ -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'));