2023-03-15 05:42:12 -04:00
|
|
|
import { action } from "@ember/object";
|
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
|
|
|
import { observes } from "@ember-decorators/object";
|
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";
|
2019-10-23 13:06:54 -04:00
|
|
|
import Controller from "@ember/controller";
|
2020-05-13 16:23:41 -04:00
|
|
|
import I18n from "I18n";
|
2020-03-11 10:28:16 -04:00
|
|
|
import { INPUT_DELAY } from "discourse-common/config/environment";
|
2020-12-18 08:18:52 -05:00
|
|
|
import discourseDebounce from "discourse-common/lib/debounce";
|
2015-08-07 15:08:27 -04:00
|
|
|
import { i18n } from "discourse/lib/computed";
|
|
|
|
|
2023-03-15 05:42:12 -04:00
|
|
|
export default class AdminUsersListShowController extends Controller.extend(
|
|
|
|
CanCheckEmails
|
|
|
|
) {
|
|
|
|
model = null;
|
|
|
|
query = null;
|
|
|
|
order = null;
|
|
|
|
asc = null;
|
|
|
|
showEmails = false;
|
|
|
|
refreshing = false;
|
|
|
|
listFilter = null;
|
|
|
|
selectAll = false;
|
2014-11-26 13:05:49 -05:00
|
|
|
|
2023-03-15 05:42:12 -04:00
|
|
|
@i18n("search_hint") searchHint;
|
2019-07-01 05:00:06 -04:00
|
|
|
|
2023-03-15 05:42:12 -04:00
|
|
|
_page = 1;
|
|
|
|
_results = [];
|
|
|
|
_canLoadMore = true;
|
2019-07-01 05:00:06 -04:00
|
|
|
|
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);
|
2023-03-15 05:42:12 -04:00
|
|
|
}
|
2014-11-26 13:05:49 -05:00
|
|
|
|
2023-03-02 15:10:19 -05:00
|
|
|
@discourseComputed("showEmails")
|
|
|
|
columnCount(showEmails) {
|
|
|
|
let colCount = 7; // note that the first column is hardcoded in the template
|
|
|
|
|
|
|
|
if (showEmails) {
|
|
|
|
colCount += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.siteSettings.must_approve_users) {
|
|
|
|
colCount += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return colCount;
|
2023-03-15 05:42:12 -04:00
|
|
|
}
|
2023-03-02 15:10:19 -05:00
|
|
|
|
2020-01-16 12:56:53 -05:00
|
|
|
@observes("listFilter")
|
2020-12-18 08:18:52 -05:00
|
|
|
_filterUsers() {
|
|
|
|
discourseDebounce(this, this.resetFilters, INPUT_DELAY);
|
2023-03-15 05:42:12 -04:00
|
|
|
}
|
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();
|
2023-03-15 05:42:12 -04:00
|
|
|
}
|
2019-07-01 05:00:06 -04:00
|
|
|
|
2019-02-26 04:43:24 -05:00
|
|
|
_refreshUsers() {
|
2019-07-01 05:00:06 -04:00
|
|
|
if (!this._canLoadMore) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-26 10:54:52 -04:00
|
|
|
const page = this._page;
|
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,
|
2020-05-14 22:10:59 -04:00
|
|
|
asc: this.asc,
|
2022-07-26 10:54:52 -04:00
|
|
|
page,
|
2017-02-20 08:42:33 -05:00
|
|
|
})
|
2019-07-01 05:00:06 -04:00
|
|
|
.then((result) => {
|
2022-09-26 09:37:56 -04:00
|
|
|
this._results[page] = result;
|
|
|
|
this.set("model", this._results.flat());
|
|
|
|
|
|
|
|
if (result.length === 0) {
|
2019-07-01 05:00:06 -04:00
|
|
|
this._canLoadMore = false;
|
|
|
|
}
|
|
|
|
})
|
2022-03-16 09:47:48 -04:00
|
|
|
.finally(() => {
|
|
|
|
this.set("refreshing", false);
|
|
|
|
});
|
2023-03-15 05:42:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
loadMore() {
|
|
|
|
this._page += 1;
|
|
|
|
this._refreshUsers();
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
toggleEmailVisibility() {
|
|
|
|
this.toggleProperty("showEmails");
|
|
|
|
this.resetFilters();
|
|
|
|
}
|
|
|
|
}
|