Skip to content

Commit

Permalink
Makes author column sortable and groupable on the issue list (#1567).
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7843 e93f8b46-1217-0410-a6f0-8f06a7374b81
  • Loading branch information
jplang committed Nov 19, 2011
1 parent bf18ee1 commit 8ec1231
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/models/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class StatementInvalid < ::ActiveRecord::StatementInvalid
QueryColumn.new(:status, :sortable => "#{IssueStatus.table_name}.position", :groupable => true),
QueryColumn.new(:priority, :sortable => "#{IssuePriority.table_name}.position", :default_order => 'desc', :groupable => true),
QueryColumn.new(:subject, :sortable => "#{Issue.table_name}.subject"),
QueryColumn.new(:author),
QueryColumn.new(:author, :sortable => ["authors.lastname", "authors.firstname", "authors.id"], :groupable => true),
QueryColumn.new(:assigned_to, :sortable => ["#{User.table_name}.lastname", "#{User.table_name}.firstname", "#{User.table_name}.id"], :groupable => true),
QueryColumn.new(:updated_on, :sortable => "#{Issue.table_name}.updated_on", :default_order => 'desc'),
QueryColumn.new(:category, :sortable => "#{IssueCategory.table_name}.name", :groupable => true),
Expand Down Expand Up @@ -554,10 +554,13 @@ def issue_count_by_group
def issues(options={})
order_option = [group_by_sort_order, options[:order]].reject {|s| s.blank?}.join(',')
order_option = nil if order_option.blank?

joins = (order_option && order_option.include?('authors')) ? "LEFT OUTER JOIN users authors ON authors.id = #{Issue.table_name}.author_id" : nil

Issue.visible.find :all, :include => ([:status, :project] + (options[:include] || [])).uniq,
:conditions => Query.merge_conditions(statement, options[:conditions]),
:order => order_option,
:joins => joins,
:limit => options[:limit],
:offset => options[:offset]
rescue ::ActiveRecord::StatementInvalid => e
Expand Down
10 changes: 10 additions & 0 deletions test/functional/issues_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,16 @@ def test_index_sort
assert !issues.empty?
assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
end

def test_index_sort_by_author
get :index, :sort => 'author'
assert_response :success
end

def test_index_group_by_author
get :index, :group_by => 'author', :sort => 'priority'
assert_response :success
end

def test_index_with_columns
columns = ['tracker', 'subject', 'assigned_to']
Expand Down

0 comments on commit 8ec1231

Please sign in to comment.