2020-05-14 04:23:41 +08:00
|
|
|
import I18n from "I18n";
|
2020-01-17 01:56:53 +08:00
|
|
|
import discourseComputed, { observes } from "discourse-common/utils/decorators";
|
2019-10-24 01:06:54 +08:00
|
|
|
import Controller from "@ember/controller";
|
2019-11-12 02:34:01 +08:00
|
|
|
import discourseDebounce from "discourse/lib/debounce";
|
2018-06-15 23:03:24 +08:00
|
|
|
import { i18n } from "discourse/lib/computed";
|
|
|
|
import AdminUser from "admin/models/admin-user";
|
2018-12-19 17:24:57 +08:00
|
|
|
import CanCheckEmails from "discourse/mixins/can-check-emails";
|
2020-03-11 22:28:16 +08:00
|
|
|
import { INPUT_DELAY } from "discourse-common/config/environment";
|
2015-08-08 03:08:27 +08:00
|
|
|
|
2019-10-24 01:06:54 +08:00
|
|
|
export default Controller.extend(CanCheckEmails, {
|
2019-02-26 17:43:24 +08:00
|
|
|
model: null,
|
2014-11-27 02:05:49 +08:00
|
|
|
query: null,
|
2017-04-05 16:27:34 +08:00
|
|
|
order: null,
|
2017-02-20 21:42:33 +08:00
|
|
|
ascending: null,
|
2014-11-27 02:05:49 +08:00
|
|
|
showEmails: false,
|
|
|
|
refreshing: false,
|
|
|
|
listFilter: null,
|
|
|
|
selectAll: false,
|
2018-06-15 23:03:24 +08:00
|
|
|
searchHint: i18n("search_hint"),
|
2014-11-27 02:05:49 +08:00
|
|
|
|
2019-07-01 17:00:06 +08:00
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
|
2019-07-02 23:26:23 +08:00
|
|
|
this._page = 1;
|
2019-07-01 17:00:06 +08:00
|
|
|
this._results = [];
|
|
|
|
this._canLoadMore = true;
|
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("query")
|
2019-04-26 18:16:21 +08:00
|
|
|
title(query) {
|
|
|
|
return I18n.t("admin.users.titles." + query);
|
|
|
|
},
|
2014-11-27 02:05:49 +08:00
|
|
|
|
2020-01-17 01:56:53 +08:00
|
|
|
@observes("listFilter")
|
2019-11-12 02:34:01 +08:00
|
|
|
_filterUsers: discourseDebounce(function() {
|
2019-07-01 17:00:06 +08:00
|
|
|
this.resetFilters();
|
2020-03-11 22:28:16 +08:00
|
|
|
}, INPUT_DELAY),
|
2017-02-20 21:42:33 +08:00
|
|
|
|
2019-07-01 17:00:06 +08:00
|
|
|
resetFilters() {
|
2019-07-02 23:26:23 +08:00
|
|
|
this._page = 1;
|
2019-07-01 17:00:06 +08:00
|
|
|
this._results = [];
|
|
|
|
this._canLoadMore = true;
|
|
|
|
this._refreshUsers();
|
|
|
|
},
|
|
|
|
|
2019-02-26 17:43:24 +08:00
|
|
|
_refreshUsers() {
|
2019-07-01 17:00:06 +08:00
|
|
|
if (!this._canLoadMore) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("refreshing", true);
|
2014-11-27 02:05:49 +08:00
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
AdminUser.findAll(this.query, {
|
|
|
|
filter: this.listFilter,
|
|
|
|
show_emails: this.showEmails,
|
|
|
|
order: this.order,
|
2019-07-01 17:00:06 +08:00
|
|
|
ascending: this.ascending,
|
|
|
|
page: this._page
|
2018-06-15 23:03:24 +08:00
|
|
|
})
|
2019-07-01 17:00:06 +08:00
|
|
|
.then(result => {
|
|
|
|
if (!result || result.length === 0) {
|
|
|
|
this._canLoadMore = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._results = this._results.concat(result);
|
|
|
|
this.set("model", this._results);
|
|
|
|
})
|
2019-02-26 17:43:24 +08:00
|
|
|
.finally(() => this.set("refreshing", false));
|
2014-11-27 02:05:49 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
2019-07-01 17:00:06 +08:00
|
|
|
loadMore() {
|
|
|
|
this._page += 1;
|
|
|
|
this._refreshUsers();
|
|
|
|
},
|
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
toggleEmailVisibility() {
|
2019-03-21 17:16:58 +08:00
|
|
|
this.toggleProperty("showEmails");
|
2019-07-01 17:00:06 +08:00
|
|
|
this.resetFilters();
|
2014-11-27 02:05:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|