WIP: Add include_subcategories report filter
This commit is contained in:
parent
dafb1d7c7f
commit
f30f1a295f
|
@ -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);
|
||||
},
|
||||
},
|
||||
});
|
|
@ -0,0 +1 @@
|
|||
{{input type="checkbox" checked=value click=(action "onChange")}}
|
|
@ -34,6 +34,11 @@ en:
|
|||
solved: "are solved"
|
||||
|
||||
admin:
|
||||
dashboard:
|
||||
reports:
|
||||
filters:
|
||||
include_subcategories:
|
||||
label: "Include Subcategories"
|
||||
web_hooks:
|
||||
solved_event:
|
||||
name: "Solved Event"
|
||||
|
|
15
plugin.rb
15
plugin.rb
|
@ -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)
|
||||
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
|
||||
accepted_solutions = accepted_solutions.joins(:topic).where("topics.category_id IN (?)", Category.subcategory_ids(category_filter.to_i))
|
||||
end
|
||||
if include_subcategories_filter
|
||||
accepted_solutions = accepted_solutions
|
||||
.joins(:topic)
|
||||
.where("topics.category_id IN (?)", Category.subcategory_ids(category_filter.to_i))
|
||||
else
|
||||
if report.category_id
|
||||
accepted_solutions = accepted_solutions.joins(:topic).where("topics.category_id IN (?)", Category.subcategory_ids(report.category_id.to_i))
|
||||
accepted_solutions = accepted_solutions
|
||||
.joins(:topic)
|
||||
.where("topics.category_id = ?", category_filter)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue