discourse/app/assets/javascripts/admin/controllers/admin-users-list-show.js

Failed to ignore revisions in .git-blame-ignore-revs.

83 lines
1.9 KiB
JavaScript
Raw Normal View History

import I18n from "I18n";
import discourseComputed, { observes } from "discourse-common/utils/decorators";
import Controller from "@ember/controller";
import discourseDebounce from "discourse/lib/debounce";
2018-06-15 11:03:24 -04:00
import { i18n } from "discourse/lib/computed";
import AdminUser from "admin/models/admin-user";
import CanCheckEmails from "discourse/mixins/can-check-emails";
import { INPUT_DELAY } from "discourse-common/config/environment";
2015-08-07 15:08:27 -04:00
export default Controller.extend(CanCheckEmails, {
model: null,
query: null,
order: null,
ascending: null,
showEmails: false,
refreshing: false,
listFilter: null,
selectAll: false,
2018-06-15 11:03:24 -04:00
searchHint: i18n("search_hint"),
init() {
this._super(...arguments);
2019-07-02 11:26:23 -04:00
this._page = 1;
this._results = [];
this._canLoadMore = true;
},
@discourseComputed("query")
title(query) {
return I18n.t("admin.users.titles." + query);
},
@observes("listFilter")
_filterUsers: discourseDebounce(function() {
this.resetFilters();
}, INPUT_DELAY),
resetFilters() {
2019-07-02 11:26:23 -04:00
this._page = 1;
this._results = [];
this._canLoadMore = true;
this._refreshUsers();
},
_refreshUsers() {
if (!this._canLoadMore) {
return;
}
2018-06-15 11:03:24 -04:00
this.set("refreshing", true);
AdminUser.findAll(this.query, {
filter: this.listFilter,
show_emails: this.showEmails,
order: this.order,
ascending: this.ascending,
page: this._page
2018-06-15 11:03:24 -04:00
})
.then(result => {
if (!result || result.length === 0) {
this._canLoadMore = false;
}
this._results = this._results.concat(result);
this.set("model", this._results);
})
.finally(() => this.set("refreshing", false));
},
actions: {
loadMore() {
this._page += 1;
this._refreshUsers();
},
toggleEmailVisibility() {
this.toggleProperty("showEmails");
this.resetFilters();
}
}
});