WIP: Add include_subcategories report filter

This commit is contained in:
Dan Ungureanu 2020-04-09 18:12:39 +03:00
parent dafb1d7c7f
commit f30f1a295f
No known key found for this signature in database
GPG Key ID: 0AA2A00D6ACC8B84
5 changed files with 32 additions and 10 deletions

View File

@ -0,0 +1,11 @@
import FilterComponent from "admin/components/report-filters/filter";
export default FilterComponent.extend({
value: null,
actions: {
onChange(value) {
this.applyFilter(this.get("filter.id"), !!value);
},
},
});

View File

@ -0,0 +1 @@
{{input type="checkbox" checked=value click=(action "onChange")}}

View File

@ -34,6 +34,11 @@ en:
solved: "are solved"
admin:
dashboard:
reports:
filters:
include_subcategories:
label: "Include Subcategories"
web_hooks:
solved_event:
name: "Solved Event"

View File

@ -16,7 +16,7 @@ en:
no_solutions:
self: "You have no accepted solutions yet."
others: "No accepted solutions."
badges:
helpdesk:
name: "Helpdesk"

View File

@ -313,15 +313,20 @@ SQL
accepted_solutions = TopicCustomField.where(name: "accepted_answer_post_id")
if report.respond_to?(:add_filter)
category_filter = report.filters.dig(:category)
report.add_filter('category', default: category_filter)
if category_filter
accepted_solutions = accepted_solutions.joins(:topic).where("topics.category_id IN (?)", Category.subcategory_ids(category_filter.to_i))
end
else
if report.category_id
accepted_solutions = accepted_solutions.joins(:topic).where("topics.category_id IN (?)", Category.subcategory_ids(report.category_id.to_i))
category_filter = report.filters.dig(:category)
include_subcategories_filter = ActiveModel::Type::Boolean.new.cast(report.filters.dig(:include_subcategories))
report.add_filter('category', default: category_filter)
report.add_filter('include_subcategories')
if category_filter
if include_subcategories_filter
accepted_solutions = accepted_solutions
.joins(:topic)
.where("topics.category_id IN (?)", Category.subcategory_ids(category_filter.to_i))
else
accepted_solutions = accepted_solutions
.joins(:topic)
.where("topics.category_id = ?", category_filter)
end
end