gr-ajax cleanup (gr-change-list-view)
Bug: Issue 3988 Change-Id: I1f312eba0e561f0c04296f42e8f8da5779077402
This commit is contained in:
@@ -15,8 +15,7 @@ limitations under the License.
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
||||||
<link rel="import" href="../../../behaviors/rest-client-behavior.html">
|
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">
|
||||||
<link rel="import" href="../../shared/gr-ajax/gr-ajax.html">
|
|
||||||
<link rel="import" href="../gr-change-list/gr-change-list.html">
|
<link rel="import" href="../gr-change-list/gr-change-list.html">
|
||||||
|
|
||||||
<dom-module id="gr-change-list-view">
|
<dom-module id="gr-change-list-view">
|
||||||
@@ -26,15 +25,9 @@ limitations under the License.
|
|||||||
background-color: var(--view-background-color);
|
background-color: var(--view-background-color);
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
.loading,
|
|
||||||
.error {
|
|
||||||
padding: 1em var(--default-horizontal-margin);
|
|
||||||
}
|
|
||||||
.loading {
|
.loading {
|
||||||
color: #666;
|
color: #666;
|
||||||
}
|
padding: 1em var(--default-horizontal-margin);
|
||||||
.error {
|
|
||||||
color: #D32F2F;
|
|
||||||
}
|
}
|
||||||
gr-change-list {
|
gr-change-list {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@@ -56,30 +49,21 @@ limitations under the License.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<gr-ajax
|
<div class="loading" hidden$="[[!_loading]]">Loading...</div>
|
||||||
auto
|
<div hidden$="[[_loading]]">
|
||||||
url="/changes/"
|
|
||||||
params="[[_computeQueryParams(_query, _offset, changesPerPage)]]"
|
|
||||||
last-response="{{_changes}}"
|
|
||||||
last-error="{{_lastError}}"
|
|
||||||
loading="{{_loading}}"></gr-ajax>
|
|
||||||
<div class="loading" hidden$="[[!_loading]]" hidden>Loading...</div>
|
|
||||||
<div class="error" hidden$="[[_computeErrorHidden(_loading, _lastError)]]" hidden>
|
|
||||||
[[_lastError.request.xhr.responseText]]
|
|
||||||
</div>
|
|
||||||
<div hidden$="[[_computeListHidden(_loading, _lastError)]]" hidden>
|
|
||||||
<gr-change-list
|
<gr-change-list
|
||||||
changes="{{_changes}}"
|
changes="{{_changes}}"
|
||||||
selected-index="{{viewState.selectedChangeIndex}}"
|
selected-index="{{viewState.selectedChangeIndex}}"
|
||||||
show-star="[[loggedIn]]"></gr-change-list>
|
show-star="[[loggedIn]]"></gr-change-list>
|
||||||
<nav>
|
<nav>
|
||||||
<a href$="[[_computeNavLink(_query, _offset, -1, changesPerPage)]]"
|
<a href$="[[_computeNavLink(_query, _offset, -1, _changesPerPage)]]"
|
||||||
hidden$="[[_hidePrevArrow(_offset)]]">← Prev</a>
|
hidden$="[[_hidePrevArrow(_offset)]]">← Prev</a>
|
||||||
<a href$="[[_computeNavLink(_query, _offset, 1, changesPerPage)]]"
|
<a href$="[[_computeNavLink(_query, _offset, 1, _changesPerPage)]]"
|
||||||
hidden$="[[_hideNextArrow(_changes.length, changesPerPage)]]">
|
hidden$="[[_hideNextArrow(_changes.length, _changesPerPage)]]">
|
||||||
Next →</a>
|
Next →</a>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
|
||||||
</template>
|
</template>
|
||||||
<script src="gr-change-list-view.js"></script>
|
<script src="gr-change-list-view.js"></script>
|
||||||
</dom-module>
|
</dom-module>
|
||||||
|
@@ -49,7 +49,7 @@
|
|||||||
value: function() { return {}; },
|
value: function() { return {}; },
|
||||||
},
|
},
|
||||||
|
|
||||||
changesPerPage: Number,
|
_changesPerPage: Number,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Currently active query.
|
* Currently active query.
|
||||||
@@ -66,11 +66,6 @@
|
|||||||
*/
|
*/
|
||||||
_changes: Array,
|
_changes: Array,
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains error of last request (in case of change loading error).
|
|
||||||
*/
|
|
||||||
_lastError: Object,
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For showing a "loading..." string during ajax requests.
|
* For showing a "loading..." string during ajax requests.
|
||||||
*/
|
*/
|
||||||
@@ -80,10 +75,6 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
behaviors: [
|
|
||||||
Gerrit.RESTClientBehavior,
|
|
||||||
],
|
|
||||||
|
|
||||||
attached: function() {
|
attached: function() {
|
||||||
this.fire('title-change', {title: this._query});
|
this.fire('title-change', {title: this._query});
|
||||||
},
|
},
|
||||||
@@ -91,6 +82,7 @@
|
|||||||
_paramsChanged: function(value) {
|
_paramsChanged: function(value) {
|
||||||
if (value.view != this.tagName.toLowerCase()) { return; }
|
if (value.view != this.tagName.toLowerCase()) { return; }
|
||||||
|
|
||||||
|
this._loading = true;
|
||||||
this._query = value.query;
|
this._query = value.query;
|
||||||
this._offset = value.offset || 0;
|
this._offset = value.offset || 0;
|
||||||
if (this.viewState.query != this._query ||
|
if (this.viewState.query != this._query ||
|
||||||
@@ -101,22 +93,23 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.fire('title-change', {title: this._query});
|
this.fire('title-change', {title: this._query});
|
||||||
|
|
||||||
|
this._getPreferences().then(function(prefs) {
|
||||||
|
this._changesPerPage = prefs.changes_per_page;
|
||||||
|
return this._getChanges();
|
||||||
|
}.bind(this)).then(function(changes) {
|
||||||
|
this._changes = changes;
|
||||||
|
this._loading = false;
|
||||||
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
_computeQueryParams: function(query, offset, changesPerPage) {
|
_getChanges: function() {
|
||||||
var options = this.listChangesOptionsToHex(
|
return this.$.restAPI.getChanges(this._changesPerPage, this._query,
|
||||||
this.ListChangesOption.LABELS,
|
this._offset);
|
||||||
this.ListChangesOption.DETAILED_ACCOUNTS
|
},
|
||||||
);
|
|
||||||
var obj = {
|
_getPreferences: function() {
|
||||||
n: changesPerPage,
|
return this.$.restAPI.getPreferences();
|
||||||
O: options,
|
|
||||||
S: offset || 0,
|
|
||||||
};
|
|
||||||
if (query && query.length > 0) {
|
|
||||||
obj.q = query;
|
|
||||||
}
|
|
||||||
return obj;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_computeNavLink: function(query, offset, direction, changesPerPage) {
|
_computeNavLink: function(query, offset, direction, changesPerPage) {
|
||||||
|
@@ -121,29 +121,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
_getDiffPreferences: function() {
|
_getDiffPreferences: function() {
|
||||||
return this._getLoggedIn().then(function(loggedIn) {
|
return this.$.restAPI.getDiffPreferences();
|
||||||
if (!loggedIn) {
|
|
||||||
// These defaults should match the defaults in
|
|
||||||
// gerrit-extension-api/src/main/jcg/gerrit/extensions/client/DiffPreferencesInfo.java
|
|
||||||
// NOTE: There are some settings that don't apply to PolyGerrit
|
|
||||||
// (Render mode being at least one of them).
|
|
||||||
return Promise.resolve({
|
|
||||||
auto_hide_diff_table_header: true,
|
|
||||||
context: 10,
|
|
||||||
cursor_blink_rate: 0,
|
|
||||||
ignore_whitespace: 'IGNORE_NONE',
|
|
||||||
intraline_difference: true,
|
|
||||||
line_length: 100,
|
|
||||||
show_line_endings: true,
|
|
||||||
show_tabs: true,
|
|
||||||
show_whitespace_errors: true,
|
|
||||||
syntax_highlighting: true,
|
|
||||||
tab_size: 8,
|
|
||||||
theme: 'DEFAULT',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return this.$.restAPI.getDiffPreferences();
|
|
||||||
}.bind(this));
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_handleReviewedChange: function(e) {
|
_handleReviewedChange: function(e) {
|
||||||
|
@@ -89,7 +89,6 @@ limitations under the License.
|
|||||||
<gr-change-list-view
|
<gr-change-list-view
|
||||||
params="[[params]]"
|
params="[[params]]"
|
||||||
view-state="{{_viewState.changeListView}}"
|
view-state="{{_viewState.changeListView}}"
|
||||||
changes-per-page="[[_preferences.changes_per_page]]"
|
|
||||||
logged-in="[[_computeLoggedIn(_account)]]"></gr-change-list-view>
|
logged-in="[[_computeLoggedIn(_account)]]"></gr-change-list-view>
|
||||||
</template>
|
</template>
|
||||||
<template is="dom-if" if="[[_showDashboardView]]" restamp="true">
|
<template is="dom-if" if="[[_showDashboardView]]" restamp="true">
|
||||||
|
@@ -30,7 +30,6 @@
|
|||||||
},
|
},
|
||||||
_serverConfig: Object,
|
_serverConfig: Object,
|
||||||
_version: String,
|
_version: String,
|
||||||
_preferences: Object,
|
|
||||||
_showChangeListView: Boolean,
|
_showChangeListView: Boolean,
|
||||||
_showDashboardView: Boolean,
|
_showDashboardView: Boolean,
|
||||||
_showChangeView: Boolean,
|
_showChangeView: Boolean,
|
||||||
@@ -52,10 +51,6 @@
|
|||||||
Gerrit.KeyboardShortcutBehavior,
|
Gerrit.KeyboardShortcutBehavior,
|
||||||
],
|
],
|
||||||
|
|
||||||
get loggedIn() {
|
|
||||||
return !!(this._account && Object.keys(this._account).length > 0);
|
|
||||||
},
|
|
||||||
|
|
||||||
attached: function() {
|
attached: function() {
|
||||||
this.$.restAPI.getAccount().then(function(account) {
|
this.$.restAPI.getAccount().then(function(account) {
|
||||||
this._account = account;
|
this._account = account;
|
||||||
@@ -88,17 +83,9 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
_accountChanged: function(account) {
|
_accountChanged: function(account) {
|
||||||
if (this.loggedIn) {
|
// Preferences are cached when a user is logged in; warm them.
|
||||||
this.$.restAPI.getPreferences().then(function(preferences) {
|
this.$.restAPI.getPreferences();
|
||||||
this._preferences = preferences;
|
this.$.restAPI.getDiffPreferences();
|
||||||
}.bind(this));
|
|
||||||
// Diff preferences are cached; warm it before a diff is rendered.
|
|
||||||
this.$.restAPI.getDiffPreferences();
|
|
||||||
} else {
|
|
||||||
this._preferences = {
|
|
||||||
changes_per_page: 25,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_viewChanged: function(view) {
|
_viewChanged: function(view) {
|
||||||
@@ -117,7 +104,7 @@
|
|||||||
|
|
||||||
// Argument used for binding update only.
|
// Argument used for binding update only.
|
||||||
_computeLoggedIn: function(account) {
|
_computeLoggedIn: function(account) {
|
||||||
return this.loggedIn;
|
return !!(account && Object.keys(account).length > 0);
|
||||||
},
|
},
|
||||||
|
|
||||||
_handlePageError: function(e) {
|
_handlePageError: function(e) {
|
||||||
|
@@ -153,7 +153,29 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
getDiffPreferences: function() {
|
getDiffPreferences: function() {
|
||||||
return this._fetchSharedCacheURL('/accounts/self/preferences.diff');
|
return this.getLoggedIn().then(function(loggedIn) {
|
||||||
|
if (loggedIn) {
|
||||||
|
return this._fetchSharedCacheURL('/accounts/self/preferences.diff');
|
||||||
|
}
|
||||||
|
// These defaults should match the defaults in
|
||||||
|
// gerrit-extension-api/src/main/jcg/gerrit/extensions/client/DiffPreferencesInfo.java
|
||||||
|
// NOTE: There are some settings that don't apply to PolyGerrit
|
||||||
|
// (Render mode being at least one of them).
|
||||||
|
return Promise.resolve({
|
||||||
|
auto_hide_diff_table_header: true,
|
||||||
|
context: 10,
|
||||||
|
cursor_blink_rate: 0,
|
||||||
|
ignore_whitespace: 'IGNORE_NONE',
|
||||||
|
intraline_difference: true,
|
||||||
|
line_length: 100,
|
||||||
|
show_line_endings: true,
|
||||||
|
show_tabs: true,
|
||||||
|
show_whitespace_errors: true,
|
||||||
|
syntax_highlighting: true,
|
||||||
|
tab_size: 8,
|
||||||
|
theme: 'DEFAULT',
|
||||||
|
});
|
||||||
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
saveDiffPreferences: function(prefs, opt_errFn, opt_ctx) {
|
saveDiffPreferences: function(prefs, opt_errFn, opt_ctx) {
|
||||||
@@ -172,7 +194,15 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
getPreferences: function() {
|
getPreferences: function() {
|
||||||
return this._fetchSharedCacheURL('/accounts/self/preferences');
|
return this.getLoggedIn().then(function(loggedIn) {
|
||||||
|
if (loggedIn) {
|
||||||
|
return this._fetchSharedCacheURL('/accounts/self/preferences');
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve({
|
||||||
|
changes_per_page: 25,
|
||||||
|
});
|
||||||
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
_fetchSharedCacheURL: function(url) {
|
_fetchSharedCacheURL: function(url) {
|
||||||
@@ -197,6 +227,22 @@
|
|||||||
return this._sharedFetchPromises[url];
|
return this._sharedFetchPromises[url];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getChanges: function(changesPerPage, opt_query, opt_offset) {
|
||||||
|
var options = this._listChangesOptionsToHex(
|
||||||
|
ListChangesOption.LABELS,
|
||||||
|
ListChangesOption.DETAILED_ACCOUNTS
|
||||||
|
);
|
||||||
|
var params = {
|
||||||
|
n: changesPerPage,
|
||||||
|
O: options,
|
||||||
|
S: opt_offset || 0,
|
||||||
|
};
|
||||||
|
if (opt_query && opt_query.length > 0) {
|
||||||
|
params.q = opt_query;
|
||||||
|
}
|
||||||
|
return this.fetchJSON('/changes/', null, null, params);
|
||||||
|
},
|
||||||
|
|
||||||
getChangeActionURL: function(changeNum, opt_patchNum, endpoint) {
|
getChangeActionURL: function(changeNum, opt_patchNum, endpoint) {
|
||||||
return this._changeBaseURL(changeNum, opt_patchNum) + endpoint;
|
return this._changeBaseURL(changeNum, opt_patchNum) + endpoint;
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user