@@ -29,10 +29,24 class MessagesController < ApplicationController | |||
|
29 | 29 | helper :attachments |
|
30 | 30 | include AttachmentsHelper |
|
31 | 31 | |
|
32 | REPLIES_PER_PAGE = 25 unless const_defined?(:REPLIES_PER_PAGE) | |
|
33 | ||
|
32 | 34 | # Show a topic and its replies |
|
33 | 35 | def show |
|
34 | @replies = @topic.children.find(:all, :include => [:author, :attachments, {:board => :project}]) | |
|
35 | @replies.reverse! if User.current.wants_comments_in_reverse_order? | |
|
36 | page = params[:page] | |
|
37 | # Find the page of the requested reply | |
|
38 | if params[:r] && page.nil? | |
|
39 | offset = @topic.children.count(:conditions => ["#{Message.table_name}.id < ?", params[:r].to_i]) | |
|
40 | page = 1 + offset / REPLIES_PER_PAGE | |
|
41 | end | |
|
42 | ||
|
43 | @reply_count = @topic.children.count | |
|
44 | @reply_pages = Paginator.new self, @reply_count, REPLIES_PER_PAGE, page | |
|
45 | @replies = @topic.children.find(:all, :include => [:author, :attachments, {:board => :project}], | |
|
46 | :order => "#{Message.table_name}.created_on ASC", | |
|
47 | :limit => @reply_pages.items_per_page, | |
|
48 | :offset => @reply_pages.current.offset) | |
|
49 | ||
|
36 | 50 | @reply = Message.new(:subject => "RE: #{@message.subject}") |
|
37 | 51 | render :action => "show", :layout => false if request.xhr? |
|
38 | 52 | end |
@@ -63,7 +77,7 class MessagesController < ApplicationController | |||
|
63 | 77 | call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply}) |
|
64 | 78 | attach_files(@reply, params[:attachments]) |
|
65 | 79 | end |
|
66 | redirect_to :action => 'show', :id => @topic | |
|
80 | redirect_to :action => 'show', :id => @topic, :r => @reply | |
|
67 | 81 | end |
|
68 | 82 | |
|
69 | 83 | # Edit a message |
@@ -77,7 +91,7 class MessagesController < ApplicationController | |||
|
77 | 91 | attach_files(@message, params[:attachments]) |
|
78 | 92 | flash[:notice] = l(:notice_successful_update) |
|
79 | 93 | @message.reload |
|
80 | redirect_to :action => 'show', :board_id => @message.board, :id => @message.root | |
|
94 | redirect_to :action => 'show', :board_id => @message.board, :id => @message.root, :r => (@message.parent_id && @message.id) | |
|
81 | 95 | end |
|
82 | 96 | end |
|
83 | 97 | |
@@ -87,7 +101,7 class MessagesController < ApplicationController | |||
|
87 | 101 | @message.destroy |
|
88 | 102 | redirect_to @message.parent.nil? ? |
|
89 | 103 | { :controller => 'boards', :action => 'show', :project_id => @project, :id => @board } : |
|
90 | { :action => 'show', :id => @message.parent } | |
|
104 | { :action => 'show', :id => @message.parent, :r => @message } | |
|
91 | 105 | end |
|
92 | 106 | |
|
93 | 107 | def quote |
@@ -289,6 +289,7 module ApplicationHelper | |||
|
289 | 289 | |
|
290 | 290 | def pagination_links_full(paginator, count=nil, options={}) |
|
291 | 291 | page_param = options.delete(:page_param) || :page |
|
292 | per_page_links = options.delete(:per_page_links) | |
|
292 | 293 | url_param = params.dup |
|
293 | 294 | # don't reuse query params if filters are present |
|
294 | 295 | url_param.merge!(:fields => nil, :values => nil, :operators => nil) if url_param.delete(:set_filter) |
@@ -307,10 +308,10 module ApplicationHelper | |||
|
307 | 308 | end |
|
308 | 309 | |
|
309 | 310 | unless count.nil? |
|
310 | html << [ | |
|
311 | " (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})", | |
|
312 | per_page_links(paginator.items_per_page) | |
|
313 | ].compact.join(' | ') | |
|
311 | html << " (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})" | |
|
312 | if per_page_links != false && links = per_page_links(paginator.items_per_page) | |
|
313 | html << " | #{links}" | |
|
314 | end | |
|
314 | 315 | end |
|
315 | 316 | |
|
316 | 317 | html |
@@ -23,6 +23,7 module MessagesHelper | |||
|
23 | 23 | :action => 'show', |
|
24 | 24 | :board_id => message.board_id, |
|
25 | 25 | :id => message.root, |
|
26 | :r => (message.parent_id && message.id), | |
|
26 | 27 | :anchor => (message.parent_id ? "message-#{message.id}" : nil) |
|
27 | 28 | end |
|
28 | 29 | end |
@@ -30,7 +30,7 class Message < ActiveRecord::Base | |||
|
30 | 30 | :description => :content, |
|
31 | 31 | :type => Proc.new {|o| o.parent_id.nil? ? 'message' : 'reply'}, |
|
32 | 32 | :url => Proc.new {|o| {:controller => 'messages', :action => 'show', :board_id => o.board_id}.merge(o.parent_id.nil? ? {:id => o.id} : |
|
33 | {:id => o.parent_id, :anchor => "message-#{o.id}"})} | |
|
33 | {:id => o.parent_id, :r => o.id, :anchor => "message-#{o.id}"})} | |
|
34 | 34 | |
|
35 | 35 | acts_as_activity_provider :find_options => {:include => [{:board => :project}, :author]}, |
|
36 | 36 | :author_key => :author_id |
@@ -20,7 +20,7 | |||
|
20 | 20 | <br /> |
|
21 | 21 | |
|
22 | 22 | <% unless @replies.empty? %> |
|
23 | <h3 class="comments"><%= l(:label_reply_plural) %></h3> | |
|
23 | <h3 class="comments"><%= l(:label_reply_plural) %> (<%= @reply_count %>)</h3> | |
|
24 | 24 | <% @replies.each do |message| %> |
|
25 | 25 | <div class="message reply" id="<%= "message-#{message.id}" %>"> |
|
26 | 26 | <div class="contextual"> |
@@ -38,6 +38,7 | |||
|
38 | 38 | <%= link_to_attachments message, :author => false %> |
|
39 | 39 | </div> |
|
40 | 40 | <% end %> |
|
41 | <p class="pagination"><%= pagination_links_full @reply_pages, @reply_count, :per_page_links => false %></p> | |
|
41 | 42 | <% end %> |
|
42 | 43 | |
|
43 | 44 | <% if !@topic.locked? && authorize_for('messages', 'reply') %> |
@@ -47,6 +47,22 class MessagesControllerTest < ActionController::TestCase | |||
|
47 | 47 | assert_not_nil assigns(:topic) |
|
48 | 48 | end |
|
49 | 49 | |
|
50 | def test_show_with_pagination | |
|
51 | message = Message.find(1) | |
|
52 | assert_difference 'Message.count', 30 do | |
|
53 | 30.times do | |
|
54 | message.children << Message.new(:subject => 'Reply', :content => 'Reply body', :author_id => 2, :board_id => 1) | |
|
55 | end | |
|
56 | end | |
|
57 | get :show, :board_id => 1, :id => 1, :r => message.children.last(:order => 'id').id | |
|
58 | assert_response :success | |
|
59 | assert_template 'show' | |
|
60 | replies = assigns(:replies) | |
|
61 | assert_not_nil replies | |
|
62 | assert !replies.include?(message.children.first(:order => 'id')) | |
|
63 | assert replies.include?(message.children.last(:order => 'id')) | |
|
64 | end | |
|
65 | ||
|
50 | 66 | def test_show_with_reply_permission |
|
51 | 67 | @request.session[:user_id] = 2 |
|
52 | 68 | get :show, :board_id => 1, :id => 1 |
@@ -143,7 +159,8 class MessagesControllerTest < ActionController::TestCase | |||
|
143 | 159 | def test_reply |
|
144 | 160 | @request.session[:user_id] = 2 |
|
145 | 161 | post :reply, :board_id => 1, :id => 1, :reply => { :content => 'This is a test reply', :subject => 'Test reply' } |
|
146 | assert_redirected_to 'boards/1/topics/1' | |
|
162 | reply = Message.find(:first, :order => 'id DESC') | |
|
163 | assert_redirected_to "boards/1/topics/1?r=#{reply.id}" | |
|
147 | 164 | assert Message.find_by_subject('Test reply') |
|
148 | 165 | end |
|
149 | 166 |
General Comments 0
You need to be logged in to leave comments.
Login now