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