2019-10-24 01:06:54 +08:00
|
|
|
import Controller from "@ember/controller";
|
2023-10-11 02:38:59 +08:00
|
|
|
import { action, get } from "@ember/object";
|
2020-03-11 22:28:16 +08:00
|
|
|
import { INPUT_DELAY } from "discourse-common/config/environment";
|
2020-12-18 21:18:52 +08:00
|
|
|
import discourseDebounce from "discourse-common/lib/debounce";
|
2023-10-11 02:38:59 +08:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2018-12-19 21:44:43 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
export default class AdminDashboardReportsController extends Controller {
|
|
|
|
filter = null;
|
2018-12-19 21:44:43 +08:00
|
|
|
|
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;
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
2018-12-19 21:44:43 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
@action
|
|
|
|
filterReports(filter) {
|
|
|
|
discourseDebounce(this, this._performFiltering, filter, INPUT_DELAY);
|
|
|
|
}
|
2018-12-19 21:44:43 +08:00
|
|
|
|
|
|
|
_performFiltering(filter) {
|
|
|
|
this.set("filter", filter);
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
|
|
|
}
|