Patch #26030 » reply_display_order_with_pre_page_4.patch
| app/controllers/messages_controller.rb (working copy) | ||
|---|---|---|
| 36 | 36 |
def show |
| 37 | 37 |
page = params[:page] |
| 38 | 38 |
# Find the page of the requested reply |
| 39 |
replies_order = User.current.wants_comments_in_reverse_order? ? 'DESC' : 'ASC' |
|
| 40 |
@replies = @topic.children |
|
| 41 |
@reply_count = @replies.count |
|
| 42 | ||
| 39 | 43 |
if params[:r] && page.nil? |
| 40 |
offset = @topic.children.where("#{Message.table_name}.id < ?", params[:r].to_i).count
|
|
| 41 |
page = 1 + offset / REPLIES_PER_PAGE |
|
| 44 |
if message_r = Message.find_by_id(params[:r].to_i) |
|
| 45 |
offset = @replies.where("#{Message.table_name}.created_on < :created_on OR (#{Message.table_name}.created_on = :created_on AND #{Message.table_name}.id < :id)", :created_on => message_r.created_on, :id => message_r.id).count
|
|
| 46 |
offset = @reply_count - offset - 1 if replies_order == 'DESC' |
|
| 47 |
page = 1 + offset / per_page_option |
|
| 48 |
else |
|
| 49 |
render_404 |
|
| 50 |
return |
|
| 51 |
end |
|
| 42 | 52 |
end |
| 43 | 53 | |
| 44 |
@reply_count = @topic.children.count |
|
| 45 |
@reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page |
|
| 46 |
@replies = @topic.children. |
|
| 54 |
@reply_pages = Paginator.new @reply_count, per_page_option, page |
|
| 55 |
@replies = @replies. |
|
| 47 | 56 |
includes(:author, :attachments, {:board => :project}).
|
| 48 |
reorder("#{Message.table_name}.created_on ASC, #{Message.table_name}.id ASC").
|
|
| 57 |
reorder("#{Message.table_name}.created_on #{replies_order}, #{Message.table_name}.id #{replies_order}").
|
|
| 49 | 58 |
limit(@reply_pages.per_page). |
| 50 | 59 |
offset(@reply_pages.offset). |
| 51 | 60 |
to_a |
| ... | ... | |
| 109 | 118 |
@message.destroy |
| 110 | 119 |
flash[:notice] = l(:notice_successful_delete) |
| 111 | 120 |
if @message.parent |
| 112 |
redirect_to board_message_path(@board, @message.parent, :r => r)
|
|
| 121 |
redirect_to board_message_path(@board, @message.parent) |
|
| 113 | 122 |
else |
| 114 | 123 |
redirect_to project_board_path(@project, @board) |
| 115 | 124 |
end |
| app/views/messages/_reply_form.html.erb (working copy) | ||
|---|---|---|
| 1 |
<% has_form ||= false %> |
|
| 2 |
<% if !@topic.locked? && authorize_for('messages', 'reply') %>
|
|
| 3 |
<% if has_form %> |
|
| 4 |
<p><%= toggle_link l(:button_reply), "reply", :focus => 'message_content' %></p> |
|
| 5 |
<div id="reply" style="display:none;"> |
|
| 6 |
<%= form_for @reply, :as => :reply, :url => {:action => 'reply', :id => @topic}, :html => {:multipart => true, :id => 'message-form'} do |f| %>
|
|
| 7 |
<%= render :partial => 'form', :locals => {:f => f, :replying => true} %>
|
|
| 8 |
<%= submit_tag l(:button_submit) %> |
|
| 9 |
<% end %> |
|
| 10 |
</div> |
|
| 11 |
<% else %> |
|
| 12 |
<p><%= toggle_link l(:button_reply), "reply", :focus => 'message_content', :scroll => 'message_content' %></p> |
|
| 13 |
<% end %> |
|
| 14 |
<% end %> |
|
| app/views/messages/show.html.erb (working copy) | ||
|---|---|---|
| 36 | 36 |
<% unless @replies.empty? %> |
| 37 | 37 |
<div id="replies"> |
| 38 | 38 |
<h3 class="comments icon icon-comments"><%= l(:label_reply_plural) %> (<%= @reply_count %>)</h3> |
| 39 |
<% if !@topic.locked? && authorize_for('messages', 'reply') && @replies.size >= 3 %>
|
|
| 40 |
<p><%= toggle_link l(:button_reply), "reply", :focus => 'message_content', :scroll => "message_content" %></p> |
|
| 41 |
<% end %> |
|
| 39 |
<%= render :partial => 'reply_form', :locals => {:has_form => User.current.wants_comments_in_reverse_order? } %>
|
|
| 42 | 40 |
<% @replies.each do |message| %> |
| 43 | 41 |
<div class="message reply" id="<%= "message-#{message.id}" %>">
|
| 44 | 42 |
<div class="contextual"> |
| ... | ... | |
| 76 | 74 |
</div> |
| 77 | 75 |
<% end %> |
| 78 | 76 |
</div> |
| 79 |
<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> |
|
| 80 | 78 |
<% end %> |
| 81 | 79 | |
| 82 |
<% if !@topic.locked? && authorize_for('messages', 'reply') %>
|
|
| 83 |
<p><%= toggle_link l(:button_reply), "reply", :focus => 'message_content' %></p> |
|
| 84 |
<div id="reply" style="display:none;"> |
|
| 85 |
<%= form_for @reply, :as => :reply, :url => {:action => 'reply', :id => @topic}, :html => {:multipart => true, :id => 'message-form'} do |f| %>
|
|
| 86 |
<%= render :partial => 'form', :locals => {:f => f, :replying => true} %>
|
|
| 87 |
<%= submit_tag l(:button_submit) %> |
|
| 88 |
<% end %> |
|
| 89 |
</div> |
|
| 90 |
<% end %> |
|
| 80 |
<%= render :partial => 'reply_form', :locals => {:has_form => @replies.empty? || !User.current.wants_comments_in_reverse_order? } %>
|
|
| 91 | 81 | |
| 92 | 82 |
<% html_title @topic.subject %> |
| test/functional/messages_controller_test.rb (working copy) | ||
|---|---|---|
| 253 | 253 |
:id => 2 |
| 254 | 254 |
} |
| 255 | 255 |
end |
| 256 |
assert_redirected_to '/boards/1/topics/1?r=2'
|
|
| 256 |
assert_redirected_to '/boards/1/topics/1' |
|
| 257 | 257 |
assert_equal I18n.t(:notice_successful_delete), flash[:notice] |
| 258 | 258 |
assert_nil Message.find_by_id(2) |
| 259 | 259 |
end |
| test/integration/messages_test.rb (working copy) | ||
|---|---|---|
| 1 |
# frozen_string_literal: true |
|
| 2 | ||
| 3 |
# Redmine - project management software |
|
| 4 |
# Copyright (C) 2006-2020 Jean-Philippe Lang |
|
| 5 |
# |
|
| 6 |
# This program is free software; you can redistribute it and/or |
|
| 7 |
# modify it under the terms of the GNU General Public License |
|
| 8 |
# as published by the Free Software Foundation; either version 2 |
|
| 9 |
# of the License, or (at your option) any later version. |
|
| 10 |
# |
|
| 11 |
# This program is distributed in the hope that it will be useful, |
|
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 14 |
# GNU General Public License for more details. |
|
| 15 |
# |
|
| 16 |
# You should have received a copy of the GNU General Public License |
|
| 17 |
# along with this program; if not, write to the Free Software |
|
| 18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 19 | ||
| 20 |
require File.expand_path('../../test_helper', __FILE__)
|
|
| 21 | ||
| 22 |
class MessagesTest < Redmine::IntegrationTest |
|
| 23 |
fixtures :projects, :users, :email_addresses, :user_preferences, :members, |
|
| 24 |
:member_roles, :roles, :boards, :messages, :enabled_modules |
|
| 25 | ||
| 26 |
def setup |
|
| 27 |
message = Message.find(1) |
|
| 28 |
assert_difference 'Message.count', 60 do |
|
| 29 |
60.times do |
|
| 30 |
message.children << Message.new( |
|
| 31 |
:subject => 'Reply', |
|
| 32 |
:content => 'Reply body', |
|
| 33 |
:author_id => 2, |
|
| 34 |
:board_id => 1) |
|
| 35 |
end |
|
| 36 |
end |
|
| 37 |
@reply_ids = message.children.map(&:id).sort |
|
| 38 |
@per_page = (@reply_ids.count - 1).to_s |
|
| 39 | ||
| 40 |
log_user('jsmith', 'jsmith')
|
|
| 41 |
end |
|
| 42 | ||
| 43 |
def test_show_with_pagination_should_ascending_order |
|
| 44 |
with_settings :per_page_options => @per_page do |
|
| 45 |
put '/my/account', :params => { :pref => { :comments_sorting => 'asc' }}
|
|
| 46 | ||
| 47 |
get '/boards/1/topics/1', :params => { :r => @reply_ids.last }
|
|
| 48 |
assert_select 'span.pagination > ul.pages > li.current > span', text: '2' |
|
| 49 |
end |
|
| 50 |
end |
|
| 51 | ||
| 52 |
def test_show_with_pagination_should_descending_order |
|
| 53 |
with_settings :per_page_options => @per_page do |
|
| 54 |
put '/my/account', :params => { :pref => { :comments_sorting => 'desc' }}
|
|
| 55 | ||
| 56 |
get '/boards/1/topics/1', :params => { :r => @reply_ids.last }
|
|
| 57 |
assert_select 'span.pagination > ul.pages > li.current > span', text: '1' |
|
| 58 |
end |
|
| 59 |
end |
|
| 60 |
end |
|
- « Previous
- 1
- …
- 3
- 4
- 5
- Next »