discourse/app/assets/javascripts/admin/addon/controllers/admin-dashboard-reports.js
Roman Rizzi 142e0ae062
Revert "Revert "DEV: Wrap Ember.run.debounce. (#11352)"" (#11509)
* Revert "Revert "DEV: Wrap `Ember.run.debounce`. (#11352)" (#11465)"

This reverts commit aa0d4ea764.

* Correctly debounce onScroll function
2020-12-18 10:18:52 -03:00

45 lines
1.2 KiB
JavaScript

import Controller from "@ember/controller";
import { INPUT_DELAY } from "discourse-common/config/environment";
import discourseComputed from "discourse-common/utils/decorators";
import discourseDebounce from "discourse-common/lib/debounce";
const { get } = Ember;
export default Controller.extend({
filter: null,
@discourseComputed(
"model.[]",
"filter",
"siteSettings.dashboard_hidden_reports"
)
filterReports(reports, filter) {
if (filter) {
filter = filter.toLowerCase();
reports = reports.filter((report) => {
return (
(get(report, "title") || "").toLowerCase().indexOf(filter) > -1 ||
(get(report, "description") || "").toLowerCase().indexOf(filter) > -1
);
});
}
const hiddenReports = (this.siteSettings.dashboard_hidden_reports || "")
.split("|")
.filter(Boolean);
reports = reports.filter((report) => !hiddenReports.includes(report.type));
return reports;
},
actions: {
filterReports(filter) {
discourseDebounce(this, this._performFiltering, filter, INPUT_DELAY);
},
},
_performFiltering(filter) {
this.set("filter", filter);
},
});