2019-10-23 13:06:54 -04:00
|
|
|
import Controller from "@ember/controller";
|
2020-03-11 10:28:16 -04:00
|
|
|
import { INPUT_DELAY } from "discourse-common/config/environment";
|
2019-11-07 16:38:28 -05:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2020-12-18 08:18:52 -05:00
|
|
|
import discourseDebounce from "discourse-common/lib/debounce";
|
2021-06-29 13:54:18 -04:00
|
|
|
import { get } from "@ember/object";
|
2018-12-19 08:44:43 -05:00
|
|
|
|
2019-10-23 13:06:54 -04:00
|
|
|
export default Controller.extend({
|
2018-12-19 08:44:43 -05:00
|
|
|
filter: null,
|
|
|
|
|
2020-04-30 11:31:04 -04:00
|
|
|
@discourseComputed(
|
|
|
|
"model.[]",
|
|
|
|
"filter",
|
|
|
|
"siteSettings.dashboard_hidden_reports"
|
|
|
|
)
|
2018-12-19 08:44:43 -05:00
|
|
|
filterReports(reports, filter) {
|
|
|
|
if (filter) {
|
|
|
|
filter = filter.toLowerCase();
|
2020-04-30 11:31:04 -04:00
|
|
|
reports = reports.filter((report) => {
|
2018-12-19 08:44:43 -05:00
|
|
|
return (
|
|
|
|
(get(report, "title") || "").toLowerCase().indexOf(filter) > -1 ||
|
|
|
|
(get(report, "description") || "").toLowerCase().indexOf(filter) > -1
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2020-04-30 11:31:04 -04:00
|
|
|
|
|
|
|
const hiddenReports = (this.siteSettings.dashboard_hidden_reports || "")
|
|
|
|
.split("|")
|
|
|
|
.filter(Boolean);
|
|
|
|
reports = reports.filter((report) => !hiddenReports.includes(report.type));
|
|
|
|
|
2018-12-19 08:44:43 -05:00
|
|
|
return reports;
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
filterReports(filter) {
|
2020-12-18 08:18:52 -05:00
|
|
|
discourseDebounce(this, this._performFiltering, filter, INPUT_DELAY);
|
2018-12-19 08:44:43 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
_performFiltering(filter) {
|
|
|
|
this.set("filter", filter);
|
|
|
|
},
|
|
|
|
});
|