2018-06-15 23:03:24 +08:00
|
|
|
import debounce from "discourse/lib/debounce";
|
|
|
|
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";
|
2019-04-26 18:16:21 +08:00
|
|
|
import computed from "ember-addons/ember-computed-decorators";
|
2015-08-08 03:08:27 +08:00
|
|
|
|
2018-12-19 17:24:57 +08:00
|
|
|
export default Ember.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-04-26 18:16:21 +08:00
|
|
|
@computed("query")
|
|
|
|
title(query) {
|
|
|
|
return I18n.t("admin.users.titles." + query);
|
|
|
|
},
|
2014-11-27 02:05:49 +08:00
|
|
|
|
2015-08-11 05:11:27 +08:00
|
|
|
_filterUsers: debounce(function() {
|
2019-07-01 17:00:06 +08:00
|
|
|
this.resetFilters();
|
2018-06-15 23:03:24 +08:00
|
|
|
}, 250).observes("listFilter"),
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|