This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/app/controllers/groups-index.js
Robin Ward eab560fe2a
DEV: import I18n instead of global usage (#9768)
Co-authored-by: Mark VanLandingham <markvanlan@gmail.com>
Co-authored-by: Robin Ward <robin.ward@gmail.com>

Co-authored-by: Mark VanLandingham <markvanlan@gmail.com>
2020-05-13 16:23:41 -04:00

65 lines
1.4 KiB
JavaScript

import I18n from "I18n";
import Controller, { inject as controller } from "@ember/controller";
import { debounce } from "@ember/runloop";
import { action } from "@ember/object";
import discourseComputed from "discourse-common/utils/decorators";
import { INPUT_DELAY } from "discourse-common/config/environment";
export default Controller.extend({
application: controller(),
queryParams: ["order", "asc", "filter", "type"],
order: null,
asc: null,
filter: "",
type: null,
groups: null,
isLoading: false,
@discourseComputed("groups.extras.type_filters")
types(typeFilters) {
const types = [];
if (typeFilters) {
typeFilters.forEach(type =>
types.push({ id: type, name: I18n.t(`groups.index.${type}_groups`) })
);
}
return types;
},
loadGroups(params) {
this.set("isLoading", true);
this.store
.findAll("group", params)
.then(groups => {
this.set("groups", groups);
if (groups.canLoadMore) {
this.set("application.showFooter", !groups.canLoadMore);
}
})
.finally(() => this.set("isLoading", false));
},
@action
onFilterChanged(filter) {
debounce(this, this._debouncedFilter, filter, INPUT_DELAY);
},
@action
loadMore() {
this.groups && this.groups.loadMore();
},
@action
new() {
this.transitionToRoute("groups.new");
},
_debouncedFilter(filter) {
this.set("filter", filter);
}
});