2019-10-23 13:06:54 -04:00
|
|
|
import Controller from "@ember/controller";
|
2023-10-10 14:38:59 -04:00
|
|
|
import { action, get } from "@ember/object";
|
2020-03-11 10:28:16 -04:00
|
|
|
import { INPUT_DELAY } from "discourse-common/config/environment";
|
2020-12-18 08:18:52 -05:00
|
|
|
import discourseDebounce from "discourse-common/lib/debounce";
|
2023-10-10 14:38:59 -04:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2018-12-19 08:44:43 -05:00
|
|
|
|
2023-03-15 05:42:12 -04:00
|
|
|
export default class AdminDashboardReportsController extends Controller {
|
|
|
|
filter = null;
|
2018-12-19 08:44:43 -05:00
|
|
|
|
2020-04-30 11:31:04 -04:00
|
|
|
@discourseComputed(
|
|
|
|
"model.[]",
|
|
|
|
"filter",
|
|
|
|
"siteSettings.dashboard_hidden_reports"
|
|
|
|
)
|
2022-07-06 04:37:54 -04:00
|
|
|
filteredReports(reports, filter) {
|
2018-12-19 08:44:43 -05:00
|
|
|
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 (
|
2022-07-17 14:48:36 -04:00
|
|
|
(get(report, "title") || "").toLowerCase().includes(filter) ||
|
|
|
|
(get(report, "description") || "").toLowerCase().includes(filter)
|
2018-12-19 08:44:43 -05:00
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
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;
|
2023-03-15 05:42:12 -04:00
|
|
|
}
|
2018-12-19 08:44:43 -05:00
|
|
|
|
2023-03-15 05:42:12 -04:00
|
|
|
@action
|
|
|
|
filterReports(filter) {
|
|
|
|
discourseDebounce(this, this._performFiltering, filter, INPUT_DELAY);
|
|
|
|
}
|
2018-12-19 08:44:43 -05:00
|
|
|
|
|
|
|
_performFiltering(filter) {
|
|
|
|
this.set("filter", filter);
|
2023-03-15 05:42:12 -04:00
|
|
|
}
|
|
|
|
}
|