Patch #26030 » reply_order.patch
| app/controllers/messages_controller.rb (working copy) | ||
|---|---|---|
|
def show
|
||
|
page = params[:page]
|
||
|
# Find the page of the requested reply
|
||
|
replies_order = User.current.wants_comments_in_reverse_order? ? 'DESC' : 'ASC'
|
||
|
@replies = @topic.children.
|
||
|
includes(:author, :attachments, {:board => :project}).
|
||
|
reorder("#{Message.table_name}.created_on #{replies_order}, #{Message.table_name}.id #{replies_order}")
|
||
|
if params[:r] && page.nil?
|
||
|
offset = @topic.children.where("#{Message.table_name}.id < ?", params[:r].to_i).count
|
||
|
offset = @replies.pluck(:id).index(params[:r].to_i)
|
||
|
page = 1 + offset / REPLIES_PER_PAGE
|
||
|
end
|
||
|
@reply_count = @topic.children.count
|
||
|
@reply_count = @replies.count
|
||
|
@reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page
|
||
|
@replies = @topic.children.
|
||
|
includes(:author, :attachments, {:board => :project}).
|
||
|
reorder("#{Message.table_name}.created_on ASC, #{Message.table_name}.id ASC").
|
||
|
@replies = @replies.
|
||
|
limit(@reply_pages.per_page).
|
||
|
offset(@reply_pages.offset).
|
||
|
to_a
|
||
| test/integration/messages_test.rb (working copy) | ||
|---|---|---|
|
require File.expand_path('../../test_helper', __FILE__)
|
||
|
|
||
|
class MessagesTest < Redmine::IntegrationTest
|
||
|
fixtures :projects, :users, :email_addresses, :user_preferences, :members,
|
||
|
:member_roles, :roles, :boards, :messages, :enabled_modules
|
||
|
|
||
|
def setup
|
||
|
message = Message.find(1)
|
||
|
assert_difference 'Message.count', 60 do
|
||
|
60.times do
|
||
|
message.children << Message.new(
|
||
|
:subject => 'Reply',
|
||
|
:content => 'Reply body',
|
||
|
:author_id => 2,
|
||
|
:board_id => 1)
|
||
|
end
|
||
|
end
|
||
|
@reply_ids = message.children.map(&:id).sort
|
||
|
|
||
|
log_user('jsmith', 'jsmith')
|
||
|
end
|
||
|
|
||
|
def test_show_with_pagination_should_ascending_order
|
||
|
post '/my/account', :pref => { :comments_sorting => 'asc' }
|
||
|
get '/boards/1/topics/1', :r => @reply_ids.last
|
||
|
|
||
|
assert !User.current.wants_comments_in_reverse_order?
|
||
|
assert_select 'span.pagination > ul.pages > li.current > span', text: '3'
|
||
|
end
|
||
|
|
||
|
def test_show_with_pagination_should_descending_order
|
||
|
post '/my/account', :pref => { :comments_sorting => 'desc' }
|
||
|
get '/boards/1/topics/1', :r => @reply_ids.last
|
||
|
|
||
|
assert User.current.wants_comments_in_reverse_order?
|
||
|
assert_select 'span.pagination > ul.pages > li.current > span', text: '1'
|
||
|
end
|
||
|
|
||
|
end
|
||