diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2015-06-13 10:56:44 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2015-06-13 10:56:44 +0000 |
commit | 98f2b30ac5871b684a6690be6449283926f3ef2a (patch) | |
tree | 017d0b458c1c70bd21ba2dea64d8d04186ec85fc /app/models/issue_query.rb | |
parent | 3077ed8d3a79fc613f31ecd47418fcec291cfd18 (diff) | |
download | redmine-98f2b30ac5871b684a6690be6449283926f3ef2a.tar.gz redmine-98f2b30ac5871b684a6690be6449283926f3ef2a.zip |
Adds issue filters on parent/subtasks (#6118).
git-svn-id: http://svn.redmine.org/redmine/trunk@14304 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/issue_query.rb')
-rw-r--r-- | app/models/issue_query.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/app/models/issue_query.rb b/app/models/issue_query.rb index b8cad3242..20ea59630 100644 --- a/app/models/issue_query.rb +++ b/app/models/issue_query.rb @@ -241,6 +241,8 @@ class IssueQuery < Query IssueRelation::TYPES.each do |relation_type, options| add_available_filter relation_type, :type => :relation, :label => options[:name] end + add_available_filter "parent_id", :type => :tree, :label => :field_parent_issue + add_available_filter "child_id", :type => :tree, :label => :label_subtask_plural Tracker.disabled_core_fields(trackers).each {|field| delete_available_filter field @@ -451,6 +453,47 @@ class IssueQuery < Query "#{Issue.table_name}.is_private #{op} (#{va})" end + def sql_for_parent_id_field(field, operator, value) + case operator + when "=" + "#{Issue.table_name}.parent_id = #{value.first.to_i}" + when "~" + root_id, lft, rgt = Issue.where(:id => value.first.to_i).pluck(:root_id, :lft, :rgt).first + if root_id && lft && rgt + "#{Issue.table_name}.root_id = #{root_id} AND #{Issue.table_name}.lft > #{lft} AND #{Issue.table_name}.rgt < #{rgt}" + else + "1=0" + end + when "!*" + "#{Issue.table_name}.parent_id IS NULL" + when "*" + "#{Issue.table_name}.parent_id IS NOT NULL" + end + end + + def sql_for_child_id_field(field, operator, value) + case operator + when "=" + parent_id = Issue.where(:id => value.first.to_i).pluck(:parent_id).first + if parent_id + "#{Issue.table_name}.id = #{parent_id}" + else + "1=0" + end + when "~" + root_id, lft, rgt = Issue.where(:id => value.first.to_i).pluck(:root_id, :lft, :rgt).first + if root_id && lft && rgt + "#{Issue.table_name}.root_id = #{root_id} AND #{Issue.table_name}.lft < #{lft} AND #{Issue.table_name}.rgt > #{rgt}" + else + "1=0" + end + when "!*" + "#{Issue.table_name}.rgt - #{Issue.table_name}.lft = 1" + when "*" + "#{Issue.table_name}.rgt - #{Issue.table_name}.lft > 1" + end + end + def sql_for_relations(field, operator, value, options={}) relation_options = IssueRelation::TYPES[field] return relation_options unless relation_options |