Patch #26030 » reply_display_order_with_pre_page.patch
| app/controllers/messages_controller.rb (working copy) | ||
|---|---|---|
| 28 | 28 | 
    helper :attachments  | 
| 29 | 29 | 
    include AttachmentsHelper  | 
| 30 | 30 | |
| 31 | 
    REPLIES_PER_PAGE = 25 unless const_defined?(:REPLIES_PER_PAGE)  | 
|
| 32 | ||
| 33 | 31 | 
    # Show a topic and its replies  | 
| 34 | 32 | 
    def show  | 
| 35 | 33 | 
    page = params[:page]  | 
| 36 | 34 | 
    # Find the page of the requested reply  | 
| 35 | 
    replies_order = User.current.wants_comments_in_reverse_order? ? 'DESC' : 'ASC'  | 
|
| 36 | 
    @replies = @topic.children.  | 
|
| 37 | 
          includes(:author, :attachments, {:board => :project}).
   | 
|
| 38 | 
          reorder("#{Message.table_name}.created_on #{replies_order}, #{Message.table_name}.id #{replies_order}")
   | 
|
| 39 | ||
| 37 | 40 | 
    if params[:r] && page.nil?  | 
| 38 | 
          offset = @topic.children.where("#{Message.table_name}.id < ?", params[:r].to_i).count
   | 
|
| 39 | 
          page = 1 + offset / REPLIES_PER_PAGE
   | 
|
| 41 | 
          offset = @replies.pluck(:id).index(params[:r].to_i)
   | 
|
| 42 | 
          page = 1 + offset / per_page_option
   | 
|
| 40 | 43 | 
    end  | 
| 41 | 44 | |
| 42 | 
    @reply_count = @topic.children.count  | 
|
| 43 | 
    @reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page  | 
|
| 44 | 
    @replies = @topic.children.  | 
|
| 45 | 
          includes(:author, :attachments, {:board => :project}).
   | 
|
| 46 | 
          reorder("#{Message.table_name}.created_on ASC, #{Message.table_name}.id ASC").
   | 
|
| 45 | 
    @reply_count = @replies.count  | 
|
| 46 | 
    @reply_pages = Paginator.new @reply_count, per_page_option, page  | 
|
| 47 | 
    @replies = @replies.  | 
|
| 47 | 48 | 
    limit(@reply_pages.per_page).  | 
| 48 | 49 | 
    offset(@reply_pages.offset).  | 
| 49 | 50 | 
    to_a  | 
| app/views/messages/show.html.erb (working copy) | ||
|---|---|---|
| 74 | 74 | 
    <%= link_to_attachments message, :author => false, :thumbnails => true %>  | 
| 75 | 75 | 
    </div>  | 
| 76 | 76 | 
    <% end %>  | 
| 77 | 
    <span class="pagination"><%= pagination_links_full @reply_pages, @reply_count, :per_page_links => false %></span>
   | 
|
| 77 | 
    <span class="pagination"><%= pagination_links_full @reply_pages, @reply_count %></span>  | 
|
| 78 | 78 | 
    <% end %>  | 
| 79 | 79 | |
| 80 | 80 | 
    <% if !@topic.locked? && authorize_for('messages', 'reply') %>
   | 
| test/integration/messages_test.rb (working copy) | ||
|---|---|---|
| 1 | 
    require File.expand_path('../../test_helper', __FILE__)
   | 
|
| 2 | 
     | 
|
| 3 | 
    class MessagesTest < Redmine::IntegrationTest  | 
|
| 4 | 
    fixtures :projects, :users, :email_addresses, :user_preferences, :members,  | 
|
| 5 | 
    :member_roles, :roles, :boards, :messages, :enabled_modules  | 
|
| 6 | 
     | 
|
| 7 | 
    def setup  | 
|
| 8 | 
    message = Message.find(1)  | 
|
| 9 | 
    assert_difference 'Message.count', 60 do  | 
|
| 10 | 
    60.times do  | 
|
| 11 | 
    message.children << Message.new(  | 
|
| 12 | 
    :subject => 'Reply',  | 
|
| 13 | 
    :content => 'Reply body',  | 
|
| 14 | 
    :author_id => 2,  | 
|
| 15 | 
    :board_id => 1)  | 
|
| 16 | 
    end  | 
|
| 17 | 
    end  | 
|
| 18 | 
    @reply_ids = message.children.map(&:id).sort  | 
|
| 19 | 
    @per_page = (@reply_ids.count - 1).to_s  | 
|
| 20 | 
     | 
|
| 21 | 
        log_user('jsmith', 'jsmith')
   | 
|
| 22 | 
    end  | 
|
| 23 | 
     | 
|
| 24 | 
    def test_show_with_pagination_should_ascending_order  | 
|
| 25 | 
    with_settings :per_page_options => @per_page do  | 
|
| 26 | 
          post '/my/account', :pref => { :comments_sorting => 'asc' }
   | 
|
| 27 | 
    assert !User.current.wants_comments_in_reverse_order?  | 
|
| 28 | 
     | 
|
| 29 | 
    get '/boards/1/topics/1', :r => @reply_ids.last  | 
|
| 30 | 
    assert_select 'span.pagination > ul.pages > li.current > span', text: '2'  | 
|
| 31 | 
    end  | 
|
| 32 | 
    end  | 
|
| 33 | 
     | 
|
| 34 | 
    def test_show_with_pagination_should_descending_order  | 
|
| 35 | 
    with_settings :per_page_options => @per_page do  | 
|
| 36 | 
          post '/my/account', :pref => { :comments_sorting => 'desc' }
   | 
|
| 37 | 
    assert User.current.wants_comments_in_reverse_order?  | 
|
| 38 | 
     | 
|
| 39 | 
    get '/boards/1/topics/1', :r => @reply_ids.last  | 
|
| 40 | 
    assert_select 'span.pagination > ul.pages > li.current > span', text: '1'  | 
|
| 41 | 
    end  | 
|
| 42 | 
    end  | 
|
| 43 | 
     | 
|
| 44 | 
    end  | 
|