FEATURE: adds infite scroll on admin users list page (#7821)

This commit is contained in:
Joffrey JAFFEUX 2019-07-01 11:00:06 +02:00 committed by GitHub
parent 4f97f85178
commit 11ae5c78db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 7 deletions

View File

@ -15,32 +15,64 @@ export default Ember.Controller.extend(CanCheckEmails, {
selectAll: false, selectAll: false,
searchHint: i18n("search_hint"), searchHint: i18n("search_hint"),
init() {
this._super(...arguments);
this._page = 0;
this._results = [];
this._canLoadMore = true;
},
@computed("query") @computed("query")
title(query) { title(query) {
return I18n.t("admin.users.titles." + query); return I18n.t("admin.users.titles." + query);
}, },
_filterUsers: debounce(function() { _filterUsers: debounce(function() {
this._refreshUsers(); this.resetFilters();
}, 250).observes("listFilter"), }, 250).observes("listFilter"),
resetFilters() {
this._page = 0;
this._results = [];
this._canLoadMore = true;
this._refreshUsers();
},
_refreshUsers() { _refreshUsers() {
if (!this._canLoadMore) {
return;
}
this.set("refreshing", true); this.set("refreshing", true);
AdminUser.findAll(this.query, { AdminUser.findAll(this.query, {
filter: this.listFilter, filter: this.listFilter,
show_emails: this.showEmails, show_emails: this.showEmails,
order: this.order, order: this.order,
ascending: this.ascending ascending: this.ascending,
page: this._page
}) })
.then(result => this.set("model", result)) .then(result => {
if (!result || result.length === 0) {
this._canLoadMore = false;
}
this._results = this._results.concat(result);
this.set("model", this._results);
})
.finally(() => this.set("refreshing", false)); .finally(() => this.set("refreshing", false));
}, },
actions: { actions: {
loadMore() {
this._page += 1;
this._refreshUsers();
},
toggleEmailVisibility() { toggleEmailVisibility() {
this.toggleProperty("showEmails"); this.toggleProperty("showEmails");
this._refreshUsers(); this.resetFilters();
} }
} }
}); });

View File

@ -21,7 +21,7 @@ export default Discourse.Route.extend({
refreshing: false refreshing: false
}); });
controller._refreshUsers(); controller.resetFilters();
} }
} }
} }

View File

@ -13,7 +13,7 @@
</div> </div>
{{#conditional-loading-spinner condition=refreshing}} {{#load-more selector=".users-list tr" action=(action "loadMore")}}
{{#if model}} {{#if model}}
<table class='table users-list grid'> <table class='table users-list grid'>
<thead> <thead>
@ -90,8 +90,9 @@
{{/each}} {{/each}}
</tbody> </tbody>
</table> </table>
{{conditional-loading-spinner condition=refreshing}}
{{else}} {{else}}
<p>{{i18n 'search.no_results'}}</p> <p>{{i18n 'search.no_results'}}</p>
{{/if}} {{/if}}
{{/conditional-loading-spinner}} {{/load-more}}