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