summaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2023-04-11 09:11:40 +0000
committerGo MAEDA <maeda@farend.jp>2023-04-11 09:11:40 +0000
commit9546dfa5e3aac247db62ea3a0d8e09672ed8196b (patch)
treee6a8d55193cc05f4470836502ea13fd6abe7fef5 /app/models
parent87f3352d3a64e2b6a89aa7036852627eb3953e6f (diff)
downloadredmine-9546dfa5e3aac247db62ea3a0d8e09672ed8196b.tar.gz
redmine-9546dfa5e3aac247db62ea3a0d8e09672ed8196b.zip
Add Parent task filter and column to Spent time (#37623).
Patch by Mizuki ISHIKAWA. git-svn-id: https://svn.redmine.org/redmine/trunk@22177 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models')
-rw-r--r--app/models/time_entry_query.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/app/models/time_entry_query.rb b/app/models/time_entry_query.rb
index fab5a3448..b586350ca 100644
--- a/app/models/time_entry_query.rb
+++ b/app/models/time_entry_query.rb
@@ -31,6 +31,7 @@ class TimeEntryQuery < Query
QueryColumn.new(:activity, :sortable => "#{TimeEntryActivity.table_name}.position", :groupable => true),
QueryColumn.new(:issue, :sortable => "#{Issue.table_name}.id", :groupable => true),
QueryAssociationColumn.new(:issue, :tracker, :caption => :field_tracker, :sortable => "#{Tracker.table_name}.position"),
+ QueryAssociationColumn.new(:issue, :parent, :caption => :field_parent_issue, :sortable => ["#{Issue.table_name}.root_id", "#{Issue.table_name}.lft ASC"], :default_order => 'desc'),
QueryAssociationColumn.new(:issue, :status, :caption => :field_status, :sortable => "#{IssueStatus.table_name}.position"),
QueryAssociationColumn.new(:issue, :category, :caption => :field_category, :sortable => "#{IssueCategory.table_name}.name"),
QueryAssociationColumn.new(:issue, :fixed_version, :caption => :field_fixed_version, :sortable => Version.fields_for_order_statement),
@@ -62,6 +63,10 @@ class TimeEntryQuery < Query
:name => l("label_attribute_of_issue", :name => l(:field_tracker)),
:values => lambda {trackers.map {|t| [t.name, t.id.to_s]}})
add_available_filter(
+ "issue.parent_id",
+ :type => :tree,
+ :name => l("label_attribute_of_issue", :name => l(:field_parent_issue)))
+ add_available_filter(
"issue.status_id",
:type => :list,
:name => l("label_attribute_of_issue", :name => l(:field_status)),
@@ -205,6 +210,30 @@ class TimeEntryQuery < Query
end
end
+ def sql_for_issue_parent_id_field(field, operator, value)
+ case operator
+ when "="
+ # accepts a comma separated list of ids
+ parent_ids = value.first.to_s.scan(/\d+/).map(&:to_i).uniq
+ issue_ids = Issue.where(:parent_id => parent_ids).pluck(:id)
+ if issue_ids.present?
+ "#{TimeEntry.table_name}.issue_id IN (#{issue_ids.join(',')})"
+ else
+ "1=0"
+ end
+ when "~"
+ root_id, lft, rgt = Issue.where(:id => value.first.to_i).pick(:root_id, :lft, :rgt)
+ issue_ids = Issue.where("#{Issue.table_name}.root_id = ? AND #{Issue.table_name}.lft > ? AND #{Issue.table_name}.rgt < ?", root_id, lft, rgt).pluck(:id) if root_id && lft && rgt
+ if issue_ids.present?
+ "#{TimeEntry.table_name}.issue_id IN (#{issue_ids.join(',')})"
+ else
+ "1=0"
+ end
+ else
+ sql_for_field("parent_id", operator, value, Issue.table_name, "parent_id")
+ end
+ end
+
def sql_for_activity_id_field(field, operator, value)
ids = value.map(&:to_i).join(',')
table_name = Enumeration.table_name