2023-03-15 09:42:12 +00:00
|
|
|
import { action } from "@ember/object";
|
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
|
|
|
import { observes } from "@ember-decorators/object";
|
2015-11-21 12:27:06 +11:00
|
|
|
import AdminUser from "admin/models/admin-user";
|
2018-12-19 10:24:57 +01: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 15:28:16 +01:00
|
|
|
import { INPUT_DELAY } from "discourse-common/config/environment";
|
2020-12-18 10:18:52 -03: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 09:42:12 +00: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 09:42:12 +00:00
|
|
|
@i18n("search_hint") searchHint;
|
2019-07-01 11:00:06 +02:00
|
|
|
|
2023-03-15 09:42:12 +00:00
|
|
|
_page = 1;
|
|
|
|
_results = [];
|
|
|
|
_canLoadMore = true;
|
2019-07-01 11:00:06 +02:00
|
|
|
|
2019-11-07 15:38:28 -06:00
|
|
|
@discourseComputed("query")
|
2019-04-26 12:16:21 +02:00
|
|
|
title(query) {
|
|
|
|
return I18n.t("admin.users.titles." + query);
|
2023-03-15 09:42:12 +00: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 09:42:12 +00:00
|
|
|
}
|
2023-03-02 15:10:19 -05:00
|
|
|
|
2020-01-16 18:56:53 +01:00
|
|
|
@observes("listFilter")
|
2020-12-18 10:18:52 -03:00
|
|
|
_filterUsers() {
|
|
|
|
discourseDebounce(this, this.resetFilters, INPUT_DELAY);
|
2023-03-15 09:42:12 +00:00
|
|
|
}
|
2017-02-20 14:42:33 +01:00
|
|
|
|
2019-07-01 11:00:06 +02:00
|
|
|
resetFilters() {
|
2019-07-02 17:26:23 +02:00
|
|
|
this._page = 1;
|
2019-07-01 11:00:06 +02:00
|
|
|
this._results = [];
|
|
|
|
this._canLoadMore = true;
|
|
|
|
this._refreshUsers();
|
2023-03-15 09:42:12 +00:00
|
|
|
}
|
2019-07-01 11:00:06 +02:00
|
|
|
|
2019-02-26 10:43:24 +01:00
|
|
|
_refreshUsers() {
|
2019-07-01 11:00:06 +02:00
|
|
|
if (!this._canLoadMore) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-26 17:54:52 +03:00
|
|
|
const page = this._page;
|
2014-11-26 13:05:49 -05:00
|
|
|
this.set("refreshing", true);
|
|
|
|
|
2019-05-27 10:15:39 +02:00
|
|
|
AdminUser.findAll(this.query, {
|
|
|
|
filter: this.listFilter,
|
|
|
|
show_emails: this.showEmails,
|
|
|
|
order: this.order,
|
2020-05-14 20:10:59 -06:00
|
|
|
asc: this.asc,
|
2022-07-26 17:54:52 +03:00
|
|
|
page,
|
2017-02-20 14:42:33 +01:00
|
|
|
})
|
2019-07-01 11:00:06 +02:00
|
|
|
.then((result) => {
|
2022-09-26 16:37:56 +03:00
|
|
|
this._results[page] = result;
|
|
|
|
this.set("model", this._results.flat());
|
|
|
|
|
|
|
|
if (result.length === 0) {
|
2019-07-01 11:00:06 +02:00
|
|
|
this._canLoadMore = false;
|
|
|
|
}
|
|
|
|
})
|
2022-03-16 08:47:48 -05:00
|
|
|
.finally(() => {
|
|
|
|
this.set("refreshing", false);
|
|
|
|
});
|
2023-03-15 09:42:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
loadMore() {
|
|
|
|
this._page += 1;
|
|
|
|
this._refreshUsers();
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
toggleEmailVisibility() {
|
|
|
|
this.toggleProperty("showEmails");
|
|
|
|
this.resetFilters();
|
|
|
|
}
|
|
|
|
}
|