mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Make report filters reusable (#9444)
This commit also adds 'include subcategories' report filter
This commit is contained in:
@@ -7,7 +7,6 @@ import Component from "@ember/component";
|
||||
import ReportLoader from "discourse/lib/reports-loader";
|
||||
import { exportEntity } from "discourse/lib/export-csv";
|
||||
import { outputExportResult } from "discourse/lib/export-result";
|
||||
import { isNumeric } from "discourse/lib/utilities";
|
||||
import Report, { SCHEMA_VERSION } from "admin/models/report";
|
||||
import ENV from "discourse-common/config/environment";
|
||||
|
||||
@@ -167,10 +166,9 @@ export default Component.extend({
|
||||
ENV.environment === "test" ? "end" : endDate.replace(/-/g, ""),
|
||||
"[:prev_period]",
|
||||
this.get("reportOptions.table.limit"),
|
||||
// Convert all filter values to strings to ensure unique serialization
|
||||
customFilters
|
||||
? JSON.stringify(customFilters, (key, value) =>
|
||||
isNumeric(value) ? value.toString() : value
|
||||
)
|
||||
? JSON.stringify(customFilters, (k, v) => (k ? `${v}` : v))
|
||||
: null,
|
||||
SCHEMA_VERSION
|
||||
]
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { action } from "@ember/object";
|
||||
import FilterComponent from "admin/components/report-filters/filter";
|
||||
|
||||
export default FilterComponent.extend({
|
||||
checked: false,
|
||||
|
||||
didReceiveAttrs() {
|
||||
this._super(...arguments);
|
||||
this.set("checked", !!this.filter.default);
|
||||
},
|
||||
|
||||
@action
|
||||
onChange() {
|
||||
this.applyFilter(this.filter.id, !this.checked || undefined);
|
||||
}
|
||||
});
|
||||
@@ -1,16 +1,12 @@
|
||||
import { action } from "@ember/object";
|
||||
import { readOnly } from "@ember/object/computed";
|
||||
import FilterComponent from "admin/components/report-filters/filter";
|
||||
|
||||
export default FilterComponent.extend({
|
||||
classNames: ["category-filter"],
|
||||
|
||||
layoutName: "admin/templates/components/report-filters/category",
|
||||
|
||||
category: readOnly("filter.default"),
|
||||
|
||||
actions: {
|
||||
onChange(categoryId) {
|
||||
this.applyFilter(this.get("filter.id"), categoryId || undefined);
|
||||
}
|
||||
@action
|
||||
onChange(categoryId) {
|
||||
this.applyFilter(this.filter.id, categoryId || undefined);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
import FilterComponent from "admin/components/report-filters/filter";
|
||||
|
||||
export default FilterComponent.extend({
|
||||
classNames: ["file-extension-filter"],
|
||||
|
||||
layoutName: "admin/templates/components/report-filters/file-extension"
|
||||
});
|
||||
@@ -1,8 +1,9 @@
|
||||
import Component from "@ember/component";
|
||||
import { action } from "@ember/object";
|
||||
|
||||
export default Component.extend({
|
||||
actions: {
|
||||
onChange(value) {
|
||||
this.applyFilter(this.get("filter.id"), value);
|
||||
}
|
||||
@action
|
||||
onChange(value) {
|
||||
this.applyFilter(this.filter.id, value);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
import { computed } from "@ember/object";
|
||||
import FilterComponent from "admin/components/report-filters/filter";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
|
||||
export default FilterComponent.extend({
|
||||
classNames: ["group-filter"],
|
||||
|
||||
layoutName: "admin/templates/components/report-filters/group",
|
||||
|
||||
@discourseComputed()
|
||||
groupOptions() {
|
||||
@computed
|
||||
get groupOptions() {
|
||||
return (this.site.groups || []).map(group => {
|
||||
return { name: group["name"], value: group["id"] };
|
||||
});
|
||||
},
|
||||
|
||||
@discourseComputed("filter.default")
|
||||
groupId(filterDefault) {
|
||||
return filterDefault ? parseInt(filterDefault, 10) : null;
|
||||
@computed("filter.default")
|
||||
get groupId() {
|
||||
return this.filter.default ? parseInt(this.filter.default, 10) : null;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
import FilterComponent from "admin/components/report-filters/filter";
|
||||
|
||||
export default FilterComponent.extend();
|
||||
@@ -3,7 +3,7 @@ import { ajax } from "discourse/lib/ajax";
|
||||
|
||||
export default DiscourseRoute.extend({
|
||||
model() {
|
||||
return ajax("/admin/reports").then(json => json);
|
||||
return ajax("/admin/reports");
|
||||
},
|
||||
|
||||
setupController(controller, model) {
|
||||
|
||||
@@ -165,7 +165,8 @@
|
||||
|
||||
<div class="input">
|
||||
{{component
|
||||
(concat "report-filters/" filter.id)
|
||||
(concat "report-filters/" filter.type)
|
||||
model=model
|
||||
filter=filter
|
||||
applyFilter=(action "applyFilter")}}
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{{input
|
||||
type="checkbox"
|
||||
checked=checked
|
||||
click=(action "onChange")
|
||||
}}
|
||||
@@ -1,7 +1,5 @@
|
||||
{{search-advanced-category-chooser
|
||||
value=category
|
||||
onChange=(action "onChange")
|
||||
options=(hash
|
||||
filterable=true
|
||||
)
|
||||
options=(hash filterable=true)
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user