Patch #44157 » add_query_parent_issue_column-2.patch
| app/models/issue_query.rb | ||
|---|---|---|
| 27 | 27 |
:default_order => 'desc', :caption => '#', :frozen => true), |
| 28 | 28 |
QueryColumn.new(:project, :sortable => "#{Project.table_name}.name", :groupable => true),
|
| 29 | 29 |
QueryColumn.new(:tracker, :sortable => "#{Tracker.table_name}.position", :groupable => true),
|
| 30 |
QueryColumn.new(:parent, |
|
| 30 |
QueryParentIssueColumn.new(:parent,
|
|
| 31 | 31 |
:sortable => ["#{Issue.table_name}.root_id", "#{Issue.table_name}.lft ASC"],
|
| 32 | 32 |
:default_order => 'desc', :caption => :field_parent_issue), |
| 33 | 33 |
QueryAssociationColumn.new(:parent, :subject, :caption => :field_parent_issue_subject), |
| app/models/query.rb | ||
|---|---|---|
| 213 | 213 |
end |
| 214 | 214 |
end |
| 215 | 215 | |
| 216 |
class QueryParentIssueColumn < QueryColumn |
|
| 217 |
def groupable? |
|
| 218 |
true |
|
| 219 |
end |
|
| 220 | ||
| 221 |
def group_by_statement |
|
| 222 |
"#{Issue.table_name}.parent_id"
|
|
| 223 |
end |
|
| 224 | ||
| 225 |
def group_value(object) |
|
| 226 |
object.parent |
|
| 227 |
end |
|
| 228 |
end |
|
| 229 | ||
| 216 | 230 |
class QueryFilter |
| 217 | 231 |
include Redmine::I18n |
| 218 | 232 | |
| ... | ... | |
| 942 | 956 |
column_sortable = column.sortable |
| 943 | 957 |
if column.is_a?(TimestampQueryColumn) |
| 944 | 958 |
column_sortable = Redmine::Database.timestamp_to_date(column.sortable, User.current.time_zone) |
| 959 |
elsif column.is_a?(QueryParentIssueColumn) |
|
| 960 |
column_sortable = "#{Issue.table_name}.parent_id"
|
|
| 945 | 961 |
end |
| 946 | 962 |
Array(column_sortable).map {|s| Arel.sql("#{s} #{order}")}
|
| 947 | 963 |
end |
| ... | ... | |
| 1117 | 1133 |
c = group_by_column |
| 1118 | 1134 |
if c.is_a?(QueryCustomFieldColumn) |
| 1119 | 1135 |
r = r.keys.to_h { |k| [c.custom_field.cast_value(k), r[k]] }
|
| 1136 |
elsif c.is_a?(QueryParentIssueColumn) |
|
| 1137 |
ids = r.keys.compact |
|
| 1138 |
issues_by_id = Issue.where(id: ids).index_by(&:id) |
|
| 1139 |
r = r.keys.to_h { |k| [k ? issues_by_id[k] : nil, r[k]] }
|
|
| 1120 | 1140 |
end |
| 1121 | 1141 |
end |
| 1122 | 1142 |
r |