mirror of
https://github.com/discourse/discourse.git
synced 2024-12-05 09:04:01 +08:00
1a2b9435b0
* DEV: Standardize table sorting verbiage This commit creates a common component that tables can use to make their headers sortable. This commit also standardizes on using `desc` as the default and passing in the `asc=true` flag to adjust the sorting direction. * Add deprecation warnings Adds deprecation warnings if using previous params and maintains backwards compatibility. Set the default sort value for group members to be asc. * switch group requests to use common table-header-toggle * update fixture
83 lines
1.9 KiB
JavaScript
83 lines
1.9 KiB
JavaScript
import I18n from "I18n";
|
|
import discourseComputed, { observes } from "discourse-common/utils/decorators";
|
|
import Controller from "@ember/controller";
|
|
import discourseDebounce from "discourse/lib/debounce";
|
|
import { i18n } from "discourse/lib/computed";
|
|
import AdminUser from "admin/models/admin-user";
|
|
import CanCheckEmails from "discourse/mixins/can-check-emails";
|
|
import { INPUT_DELAY } from "discourse-common/config/environment";
|
|
|
|
export default Controller.extend(CanCheckEmails, {
|
|
model: null,
|
|
query: null,
|
|
order: null,
|
|
asc: null,
|
|
showEmails: false,
|
|
refreshing: false,
|
|
listFilter: null,
|
|
selectAll: false,
|
|
searchHint: i18n("search_hint"),
|
|
|
|
init() {
|
|
this._super(...arguments);
|
|
|
|
this._page = 1;
|
|
this._results = [];
|
|
this._canLoadMore = true;
|
|
},
|
|
|
|
@discourseComputed("query")
|
|
title(query) {
|
|
return I18n.t("admin.users.titles." + query);
|
|
},
|
|
|
|
@observes("listFilter")
|
|
_filterUsers: discourseDebounce(function() {
|
|
this.resetFilters();
|
|
}, INPUT_DELAY),
|
|
|
|
resetFilters() {
|
|
this._page = 1;
|
|
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,
|
|
asc: this.asc,
|
|
page: this._page
|
|
})
|
|
.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));
|
|
},
|
|
|
|
actions: {
|
|
loadMore() {
|
|
this._page += 1;
|
|
this._refreshUsers();
|
|
},
|
|
|
|
toggleEmailVisibility() {
|
|
this.toggleProperty("showEmails");
|
|
this.resetFilters();
|
|
}
|
|
}
|
|
});
|