Remove getDashboardChanges from gr-rest-api-interface

Until this point, the schema/queries that comprised a user's dashboard
were hardcoded into the rest-api. This change removes them from that
file and adds them back to the dashboard-view as properties.

This work is being done as part of addressing Issue 5555, with the goal
of being generic enough to be reused when custom dashboards in PG are
implemented.

Feature: Issue 5555
Change-Id: I25a588b968cb17e088273d9f98ec93327fd7c6c3
This commit is contained in:
Kasper Nilsson
2017-05-30 12:49:01 -07:00
parent 73a04170a0
commit 8be6f1ac95
4 changed files with 38 additions and 28 deletions

View File

@@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
<link rel="import" href="../../../behaviors/rest-client-behavior/rest-client-behavior.html">
<link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">

View File

@@ -14,6 +14,13 @@
(function() {
'use strict';
const QUERIES = [
'is:open owner:self',
'is:open ((reviewer:self -owner:self -is:ignored) OR assignee:self)',
'is:closed (owner:self OR reviewer:self OR assignee:self) -age:4w ' +
'limit:10',
];
Polymer({
is: 'gr-dashboard-view',
@@ -53,6 +60,22 @@
},
},
behaviors: [
Gerrit.RESTClientBehavior,
],
get options() {
return this.listChangesOptionsToHex(
this.ListChangesOption.LABELS,
this.ListChangesOption.DETAILED_ACCOUNTS,
this.ListChangesOption.REVIEWED
);
},
get queries() {
return QUERIES;
},
attached() {
this.fire('title-change', {title: 'My Reviews'});
},
@@ -62,7 +85,7 @@
*/
_paramsChanged() {
this._loading = true;
this._getDashboardChanges().then(results => {
this._getChanges().then(results => {
this._results = results;
this._loading = false;
}).catch(err => {
@@ -71,8 +94,8 @@
});
},
_getDashboardChanges() {
return this.$.restAPI.getDashboardChanges();
_getChanges() {
return this.$.restAPI.getChanges(null, this.queries, null, this.options);
},
});
})();

View File

@@ -34,16 +34,20 @@ limitations under the License.
<script>
suite('gr-dashboard-view tests', () => {
let element;
let sandbox;
setup(() => {
element = fixture('basic');
sandbox = sinon.sandbox.create();
});
teardown(() => {
sandbox.restore();
});
test('content is refreshed with same dropdown selected twice', () => {
const getChangesStub = sinon.stub(element, '_getDashboardChanges',
() => {
return Promise.resolve();
});
const getChangesStub = sandbox.stub(element, '_getChanges',
() => Promise.resolve());
element.params = {view: 'gr-dashboard-view'};

View File

@@ -368,8 +368,8 @@
return window.innerWidth < MAX_UNIFIED_DEFAULT_WINDOW_WIDTH_PX;
},
getChanges(changesPerPage, opt_query, opt_offset) {
const options = this.listChangesOptionsToHex(
getChanges(opt_changesPerPage, opt_query, opt_offset, opt_options) {
const options = opt_options || this.listChangesOptionsToHex(
this.ListChangesOption.LABELS,
this.ListChangesOption.DETAILED_ACCOUNTS
);
@@ -378,34 +378,16 @@
opt_offset = 0;
}
const params = {
n: changesPerPage,
O: options,
S: opt_offset || 0,
};
if (opt_changesPerPage) { params.n = opt_changesPerPage; }
if (opt_query && opt_query.length > 0) {
params.q = opt_query;
}
return this.fetchJSON('/changes/', null, null, params);
},
getDashboardChanges() {
const options = this.listChangesOptionsToHex(
this.ListChangesOption.LABELS,
this.ListChangesOption.DETAILED_ACCOUNTS,
this.ListChangesOption.REVIEWED
);
const params = {
O: options,
q: [
'is:open owner:self',
'is:open ((reviewer:self -owner:self -is:ignored) OR assignee:self)',
'is:closed (owner:self OR reviewer:self OR assignee:self) -age:4w ' +
'limit:10',
],
};
return this.fetchJSON('/changes/', null, null, params);
},
getChangeActionURL(changeNum, opt_patchNum, endpoint) {
return this.changeBaseURL(changeNum, opt_patchNum) + endpoint;
},