summaryrefslogtreecommitdiffstats
path: root/app
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
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')
-rw-r--r--app/helpers/queries_helper.rb10
-rw-r--r--app/models/time_entry_query.rb29
2 files changed, 34 insertions, 5 deletions
diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb
index 20dae6fd4..662e22ee8 100644
--- a/app/helpers/queries_helper.rb
+++ b/app/helpers/queries_helper.rb
@@ -26,15 +26,15 @@ module QueriesHelper
ungrouped = []
grouped = {label_string: [], label_date: [], label_time_tracking: [], label_attachment: []}
query.available_filters.map do |field, field_options|
- if field_options[:type] == :relation
+ if field =~ /^(.+)\./
+ # association filters
+ group = "field_#{$1}".to_sym
+ elsif field_options[:type] == :relation
group = :label_relations
elsif field_options[:type] == :tree
group = query.is_a?(IssueQuery) ? :label_relations : nil
elsif /^cf_\d+\./.match?(field)
group = (field_options[:through] || field_options[:field]).try(:name)
- elsif field =~ /^(.+)\./
- # association filters
- group = "field_#{$1}".to_sym
elsif %w(member_of_group assigned_to_role).include?(field)
group = :field_assigned_to
elsif field_options[:type] == :date_past || field_options[:type] == :date
@@ -256,7 +256,7 @@ module QueriesHelper
link_to value, issue_path(item)
when :subject
link_to value, issue_path(item)
- when :parent
+ when :parent, :'issue.parent'
value ? (value.visible? ? link_to_issue(value, :subject => false) : "##{value.id}") : ''
when :description
item.description? ? content_tag('div', textilizable(item, :description), :class => "wiki") : ''
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