mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 11:34:24 +03:00
a8ca517c54
closes #3222 - implementing server-side pagination for /users API - passing /users?limit=none will return all users - passing /users?status=invited will filter base on user status - creating 3 mixins (route, controller and view) to keep pagination logic DRY - updating route, controller and view for Posts to use new mixing - implementing infinite scrolling for Users Management screen (using new mixins) - Users Management screen displays all invited users, but paginates active users
77 lines
2.3 KiB
JavaScript
77 lines
2.3 KiB
JavaScript
import { getRequestErrorMessage } from 'ghost/utils/ajax';
|
|
|
|
var PaginationControllerMixin = Ember.Mixin.create({
|
|
|
|
// set from PaginationRouteMixin
|
|
paginationSettings: null,
|
|
|
|
// holds the next page to load during infinite scroll
|
|
nextPage: null,
|
|
|
|
// indicates whether we're currently loading the next page
|
|
isLoading: null,
|
|
|
|
/**
|
|
*
|
|
* @param options: {
|
|
* modelType: <String> name of the model that will be paginated
|
|
* }
|
|
*/
|
|
init: function (options) {
|
|
this._super();
|
|
|
|
var metadata = this.store.metadataFor(options.modelType);
|
|
this.set('nextPage', metadata.pagination.next);
|
|
},
|
|
|
|
|
|
/**
|
|
* Takes an ajax response, concatenates any error messages, then generates an error notification.
|
|
* @param {jqXHR} response The jQuery ajax reponse object.
|
|
* @return
|
|
*/
|
|
reportLoadError: function (response) {
|
|
var message = 'A problem was encountered while loading more records';
|
|
|
|
if (response) {
|
|
// Get message from response
|
|
message += ': ' + getRequestErrorMessage(response, true);
|
|
} else {
|
|
message += '.';
|
|
}
|
|
|
|
this.notifications.showError(message);
|
|
},
|
|
|
|
actions: {
|
|
/**
|
|
* Loads the next paginated page of posts into the ember-data store. Will cause the posts list UI to update.
|
|
* @return
|
|
*/
|
|
loadNextPage: function () {
|
|
|
|
var self = this,
|
|
store = this.get('store'),
|
|
recordType = this.get('model').get('type'),
|
|
nextPage = this.get('nextPage'),
|
|
paginationSettings = this.get('paginationSettings');
|
|
|
|
if (nextPage) {
|
|
this.set('isLoading', true);
|
|
this.set('paginationSettings.page', nextPage);
|
|
store.find(recordType, paginationSettings).then(function () {
|
|
var metadata = store.metadataFor(recordType);
|
|
|
|
self.set('nextPage', metadata.pagination.next);
|
|
self.set('isLoading', false);
|
|
}, function (response) {
|
|
self.reportLoadError(response);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
export default PaginationControllerMixin;
|