mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 06:30:15 +08:00
8b426431a4
We want to wrap the `Ember.run.debounce` function and internally call `Ember.run` instead when running tests. This commit changes discourseDebounce to work the same way as `Ember.run.debounce`. Now that `discourseDebounce` works exactly like `Ember.run.debounce`, let's replace it and only use `DiscourseDebounce` from now on. Move debounce to discourse-common to be able to reuse it in different bundles Keep old debounce file for backwards-compatibility
45 lines
1.2 KiB
JavaScript
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);
|
|
},
|
|
});
|