Changesets can be listed by changeset number.
The Git repository is here.
Changeset 442
Implement per-page selection (25, 50, 100 items) for lists of posts
and posts within topics, as per Ticket #261. RSS feeds for posts within
topics have been increased from 25 to 50 items in passing as these are
quite lightweight to process.
- Comitted by: rool
- Date: Friday August 30 07:46:48 2013 (over 11 years ago)
Affected files:
- rool/rails/beast/trunk/app/controllers/posts_controller.rb (diff)
- rool/rails/beast/trunk/app/controllers/topics_controller.rb (diff)
- rool/rails/beast/trunk/app/views/posts/index.rhtml (diff)
- rool/rails/beast/trunk/app/views/topics/show.rhtml (diff)
rool/rails/beast/trunk/app/controllers/posts_controller.rb:
prev. | current | |
def search | ||
conditions = params[:q].blank? ? nil : Post.send(:sanitize_sql, ['LOWER(posts.body) LIKE ?', "%#{params[:q].downcase}%"]) | ||
31 | | |
31 | @post_pages, @posts = paginate(:posts, @@query_options.merge(:conditions => conditions).merge(per_page())) | |
@users = User.find(:all, :select => 'distinct *', :conditions => ['id in (?)', @posts.collect(&:user_id).uniq]).index_by(&:id) | ||
render_posts_or_xml :index | ||
end | ||
... | ... | |
@user = User.find params[:user_id] | ||
options = @@query_options.merge(:conditions => ['monitorships.user_id = ? and posts.user_id != ?', params[:user_id], @user.id]) | ||
options[:joins] += ' inner join monitorships on monitorships.topic_id = topics.id' | ||
40 | | |
40 | @post_pages, @posts = paginate(:posts, options.merge(per_page())) | |
render_posts_or_xml | ||
end | ||
... | ... | |
conditions = [] | ||
[:user_id, :forum_id].each { |attr| conditions << Post.send(:sanitize_sql, ["posts.#{attr} = ?", params[attr]]) if params[attr] } | ||
conditions = conditions.any? ? conditions.collect { |c| "(#{c})" }.join(' AND ') : nil | ||
125 | | |
125 | @post_pages, @posts = paginate(:posts, @@query_options.merge(:conditions => conditions).merge(per_page())) | |
@users = User.find(:all, :select => 'distinct *', :conditions => ['id in (?)', @posts.collect(&:user_id).uniq]).index_by(&:id) | ||
end | ||
... | ... | |
format.xml { render :xml => @posts.to_xml } | ||
end | ||
end | ||
144 | ||
145 | def per_page | |
146 | per_page = {} | |
147 | per_page[:per_page] = [params[:posts_per_page].to_i, 25].max if (params.has_key?(:posts_per_page)) | |
148 | ||
149 | return per_page | |
150 | end | |
end |
rool/rails/beast/trunk/app/controllers/topics_controller.rb:
prev. | current | |
(session[:topics] ||= {})[@topic.id] = Time.now.utc if logged_in? | ||
# authors of topics don't get counted towards total hits | ||
@topic.hit! unless logged_in? and @topic.user == current_user | ||
39 | | |
39 | per_page = [params[:posts_per_page].to_i, 25].max | |
40 | @post_pages, @posts = paginate(:posts, :per_page => per_page, :order => 'posts.created_at', :include => :user, :conditions => ['posts.topic_id = ?', params[:id]]) | |
@voices = @posts.map(&:user) ; @voices.uniq! | ||
@post = Post.new | ||
end | ||
... | ... | |
render :xml => @topic.to_xml | ||
end | ||
format.rss do | ||
47 | | |
48 | @posts = @topic.posts.find(:all, :order => 'created_at desc', :limit => 50) | |
render :action => 'show.rxml', :layout => false | ||
end | ||
end |
rool/rails/beast/trunk/app/views/posts/index.rhtml:
prev. | current | |
</p> | ||
<% if @post_pages.page_count > 1 -%> | ||
16 | <div style="float: right; white-space: nowrap"> | |
17 | <% form_tag( @posts, { :method => 'get' } ) do %> | |
18 | <%= hidden_field_tag( :q, params[ :q ] ) if params.has_key? :q %> | |
19 | <small> | |
20 | Posts per page: | |
21 | <%= | |
22 | select_tag( | |
23 | 'posts_per_page', | |
24 | options_for_select( | |
25 | [ '25', '50', '100' ], | |
26 | params[ :posts_per_page ] | |
27 | ), | |
28 | :id => nil | |
29 | ) | |
30 | %> | |
31 | </small> | |
32 | <%= submit_tag( 'Change', { :name => 'posts_per_page_change', :style => 'font-size: 9pt' } ) %> | |
33 | <% end %> | |
34 | </div> | |
<p class="pages">Pages: <strong><%= pagination_links @post_pages, :window_size => 10, :params => params %></strong></p> | ||
<% end -%> | ||
rool/rails/beast/trunk/app/views/topics/show.rhtml:
prev. | current | |
</p> | ||
<% if @post_pages.page_count > 1 -%> | ||
71 | <div style="float: right; white-space: nowrap"> | |
72 | <% form_tag( @posts, { :method => 'get' } ) do %> | |
73 | <%= hidden_field_tag( :q, params[ :q ] ) if params.has_key? :q %> | |
74 | <small> | |
75 | Posts per page: | |
76 | <%= | |
77 | select_tag( | |
78 | 'posts_per_page', | |
79 | options_for_select( | |
80 | [ '25', '50', '100' ], | |
81 | params[ :posts_per_page ] | |
82 | ), | |
83 | :id => nil | |
84 | ) | |
85 | %> | |
86 | </small> | |
87 | <%= submit_tag( 'Change', { :name => 'posts_per_page_change', :style => 'font-size: 9pt' } ) %> | |
88 | <% end %> | |
89 | </div> | |
<p class="pages">Pages: <strong><%= pagination_links @post_pages, :window_size => 10 %></strong></p> | ||
<% end -%> | ||