diff --git a/config/locales/en.yml b/config/locales/en.yml index 8c48283..3107b52 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -72,4 +72,6 @@ en: label_all_relations: "All related to" + label_descendant_of: "Descendant of" + field_root: "Root" diff --git a/lib/redmine_more_filters/patches/issue_query_patch.rb b/lib/redmine_more_filters/patches/issue_query_patch.rb index 7b261b2..5d631a9 100644 --- a/lib/redmine_more_filters/patches/issue_query_patch.rb +++ b/lib/redmine_more_filters/patches/issue_query_patch.rb @@ -72,6 +72,12 @@ def initialize_available_filters_with_more_filters :type => :integer, :label => :label_all_relations + + add_available_filter("descendant_of", + :type => :integer, + :label => :label_descendant_of + ) + add_available_filter("created_on_by_clock_time", :type => :time_past ) @@ -210,6 +216,11 @@ def sql_for_all_relations_field(field, operator, value, options={}) end "(#{sql})" end + + def sql_for_descendant_of_field(field, operator, value) + sql = "#{Issue.table_name}.id IN ( SELECT DISTINCT i.id FROM #{Issue.table_name} i INNER JOIN #{Issue.table_name} j ON i.root_id = j.root_id AND i.lft > j.lft AND i.rgt < j.rgt WHERE #{sql_for_field("id", "=", value, "j", "id")} )" + "(#{sql})" + end end #module end #module diff --git a/lib/redmine_more_filters/patches/queries_helper_patch.rb b/lib/redmine_more_filters/patches/queries_helper_patch.rb index fe2248a..8536a58 100644 --- a/lib/redmine_more_filters/patches/queries_helper_patch.rb +++ b/lib/redmine_more_filters/patches/queries_helper_patch.rb @@ -64,7 +64,7 @@ def filters_options_for_select_with_more_filters(query) group = :label_relations elsif field_options[:type] == :tree group = query.is_a?(IssueQuery) ? :label_relations : nil - elsif field =~ /root_id|all_relations/ + elsif field =~ /root_id|all_relations|descendant_of/ group = :label_relations elsif field =~ /^cf_\d+\./ group = (field_options[:through] || field_options[:field]).try(:name)