2024-03-20 14:23:18 +11:00
|
|
|
import Component from "@glimmer/component";
|
|
|
|
import { tracked } from "@glimmer/tracking";
|
2025-01-14 13:22:08 +10:00
|
|
|
import { fn } from "@ember/helper";
|
|
|
|
import { on } from "@ember/modifier";
|
2024-03-20 14:23:18 +11:00
|
|
|
import { service } from "@ember/service";
|
|
|
|
import ConditionalLoadingSpinner from "discourse/components/conditional-loading-spinner";
|
2025-01-14 13:22:08 +10:00
|
|
|
import withEventValue from "discourse/helpers/with-event-value";
|
2024-03-20 14:23:18 +11:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2025-01-13 13:02:49 +00:00
|
|
|
import { bind } from "discourse/lib/decorators";
|
2024-11-19 20:45:18 +00:00
|
|
|
import { i18n } from "discourse-i18n";
|
2025-01-14 13:22:08 +10:00
|
|
|
import AdminSectionLandingItem from "admin/components/admin-section-landing-item";
|
|
|
|
import AdminSectionLandingWrapper from "admin/components/admin-section-landing-wrapper";
|
2024-03-20 14:23:18 +11:00
|
|
|
|
|
|
|
export default class AdminReports extends Component {
|
|
|
|
@service siteSettings;
|
|
|
|
@tracked reports = null;
|
|
|
|
@tracked filter = "";
|
2025-01-14 13:22:08 +10:00
|
|
|
@tracked isLoading = true;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super(...arguments);
|
|
|
|
this.loadReports();
|
|
|
|
}
|
2024-03-20 14:23:18 +11:00
|
|
|
|
|
|
|
@bind
|
|
|
|
loadReports() {
|
|
|
|
ajax("/admin/reports")
|
|
|
|
.then((json) => {
|
|
|
|
this.reports = json.reports;
|
|
|
|
})
|
|
|
|
.finally(() => (this.isLoading = false));
|
|
|
|
}
|
|
|
|
|
|
|
|
get filteredReports() {
|
|
|
|
if (!this.reports) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
let filteredReports = this.reports;
|
|
|
|
if (this.filter) {
|
|
|
|
const lowerCaseFilter = this.filter.toLowerCase();
|
|
|
|
filteredReports = filteredReports.filter((report) => {
|
|
|
|
return (
|
|
|
|
(report.title || "").toLowerCase().includes(lowerCaseFilter) ||
|
|
|
|
(report.description || "").toLowerCase().includes(lowerCaseFilter)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const hiddenReports = (this.siteSettings.dashboard_hidden_reports || "")
|
|
|
|
.split("|")
|
|
|
|
.filter(Boolean);
|
|
|
|
filteredReports = filteredReports.filter(
|
|
|
|
(report) => !hiddenReports.includes(report.type)
|
|
|
|
);
|
|
|
|
|
|
|
|
return filteredReports;
|
|
|
|
}
|
|
|
|
|
|
|
|
<template>
|
2025-01-14 13:22:08 +10:00
|
|
|
<ConditionalLoadingSpinner @condition={{this.isLoading}}>
|
|
|
|
<div class="d-admin-filter admin-reports-header">
|
|
|
|
<div class="admin-filter__input-container">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
class="admin-filter__input admin-reports-header__filter"
|
2024-03-20 14:23:18 +11:00
|
|
|
placeholder={{i18n "admin.filter_reports"}}
|
2025-01-14 13:22:08 +10:00
|
|
|
value={{this.filter}}
|
|
|
|
{{on "input" (withEventValue (fn (mut this.filter)))}}
|
2024-03-20 14:23:18 +11:00
|
|
|
/>
|
|
|
|
</div>
|
2025-01-14 13:22:08 +10:00
|
|
|
</div>
|
|
|
|
<AdminSectionLandingWrapper class="admin-reports-list">
|
|
|
|
{{#each this.filteredReports as |report|}}
|
|
|
|
<AdminSectionLandingItem
|
|
|
|
@titleLabelTranslated={{report.title}}
|
|
|
|
@descriptionLabelTranslated={{report.description}}
|
|
|
|
@titleRoute="adminReports.show"
|
|
|
|
@titleRouteModel={{report.type}}
|
|
|
|
/>
|
|
|
|
{{/each}}
|
|
|
|
</AdminSectionLandingWrapper>
|
|
|
|
</ConditionalLoadingSpinner>
|
2024-03-20 14:23:18 +11:00
|
|
|
</template>
|
|
|
|
}
|