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

View File

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

View File

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