New setting added to specify how many objects should be displayed on most paginated lists.

Default is: 25, 50, 100 (users can choose one of these values).
If one value only is entered in this setting (eg. 25), the 'per page' links are not displayed (prior behaviour).

git-svn-id: http://redmine.rubyforge.org/svn/trunk@1026 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2007-12-29 11:36:30 +00:00
parent 7eec539222
commit 9a1b46fe42
44 changed files with 108 additions and 34 deletions

View File

@ -35,7 +35,7 @@ class AdminController < ApplicationController
@project_count = Project.count(:conditions => conditions)
@project_pages = Paginator.new self, @project_count,
25,
per_page_option,
params['page']
@projects = Project.find :all, :order => sort_clause,
:conditions => conditions,

View File

@ -158,6 +158,21 @@ class ApplicationController < ActionController::Base
attachments
end
# Returns the number of objects that should be displayed
# on the paginated list
def per_page_option
per_page = nil
if params[:per_page] && Setting.per_page_options_array.include?(params[:per_page].to_s.to_i)
per_page = params[:per_page].to_s.to_i
session[:per_page] = per_page
elsif session[:per_page]
per_page = session[:per_page]
else
per_page = Setting.per_page_options_array.first || 25
end
per_page
end
# qvalues http header parser
# code taken from webrick
def parse_qvalues(value)

View File

@ -40,7 +40,7 @@ class BoardsController < ApplicationController
sort_update
@topic_count = @board.topics.count
@topic_pages = Paginator.new self, @topic_count, 25, params['page']
@topic_pages = Paginator.new self, @topic_count, per_page_option, params['page']
@topics = @board.topics.find :all, :order => "#{Message.table_name}.sticky DESC, #{sort_clause}",
:include => [:author, {:last_reply => :author}],
:limit => @topic_pages.items_per_page,

View File

@ -45,7 +45,7 @@ class IssuesController < ApplicationController
sort_update
retrieve_query
if @query.valid?
limit = %w(pdf csv).include?(params[:format]) ? Setting.issues_export_limit.to_i : 25
limit = %w(pdf csv).include?(params[:format]) ? Setting.issues_export_limit.to_i : per_page_option
@issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
@issue_pages = Paginator.new self, @issue_count, limit, params['page']
@issues = Issue.find :all, :order => sort_clause,

View File

@ -75,7 +75,7 @@ class RepositoriesController < ApplicationController
def revisions
@changeset_count = @repository.changesets.count
@changeset_pages = Paginator.new self, @changeset_count,
25,
per_page_option,
params['page']
@changesets = @repository.changesets.find(:all,
:limit => @changeset_pages.items_per_page,

View File

@ -39,7 +39,7 @@ class UsersController < ApplicationController
@user_count = User.count(:conditions => conditions)
@user_pages = Paginator.new self, @user_count,
15,
per_page_option,
params['page']
@users = User.find :all,:order => sort_clause,
:conditions => conditions,

View File

@ -97,7 +97,7 @@ class WikiController < ApplicationController
@page = @wiki.find_page(params[:page])
@version_count = @page.content.versions.count
@version_pages = Paginator.new self, @version_count, 25, params['p']
@version_pages = Paginator.new self, @version_count, per_page_option, params['p']
# don't load text
@versions = @page.content.versions.find :all,
:select => "id, author_id, comments, updated_on, version",

View File

@ -103,26 +103,40 @@ module ApplicationHelper
l(:actionview_datehelper_select_month_names).split(',')[month-1]
end
def pagination_links_full(paginator, options={}, html_options={})
def pagination_links_full(paginator, count=nil, options={})
page_param = options.delete(:page_param) || :page
url_param = params.dup
html = ''
html << link_to_remote(('&#171; ' + l(:label_previous)),
{:update => "content", :url => options.merge(page_param => paginator.current.previous)},
{:href => url_for(:params => options.merge(page_param => paginator.current.previous))}) + ' ' if paginator.current.previous
{:update => "content", :url => url_param.merge(page_param => paginator.current.previous)},
{:href => url_for(:params => url_param.merge(page_param => paginator.current.previous))}) + ' ' if paginator.current.previous
html << (pagination_links_each(paginator, options) do |n|
link_to_remote(n.to_s,
{:url => {:params => options.merge(page_param => n)}, :update => 'content'},
{:href => url_for(:params => options.merge(page_param => n))})
{:url => {:params => url_param.merge(page_param => n)}, :update => 'content'},
{:href => url_for(:params => url_param.merge(page_param => n))})
end || '')
html << ' ' + link_to_remote((l(:label_next) + ' &#187;'),
{:update => "content", :url => options.merge(page_param => paginator.current.next)},
{:href => url_for(:params => options.merge(page_param => paginator.current.next))}) if paginator.current.next
{:update => "content", :url => url_param.merge(page_param => paginator.current.next)},
{:href => url_for(:params => url_param.merge(page_param => paginator.current.next))}) if paginator.current.next
unless count.nil?
html << [" (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})", per_page_links(paginator.items_per_page)].compact.join(' | ')
end
html
end
def per_page_links(selected=nil)
links = Setting.per_page_options_array.collect do |n|
n == selected ? n : link_to_remote(n, {:update => "content", :url => params.dup.merge(:per_page => n)},
{:href => url_for(params.dup.merge(:per_page => n))})
end
links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil
end
def set_html_title(text)
@html_header_title = text
end

View File

@ -95,6 +95,11 @@ class Setting < ActiveRecord::Base
class_eval src, __FILE__, __LINE__
end
# Helper that returns an array based on per_page_options setting
def self.per_page_options_array
per_page_options.split(%r{[\s,]}).collect(&:to_i).select {|n| n > 0}.sort
end
# Checks if settings have changed since the values were read
# and clears the cache hash if it's the case
# Called once per request

View File

@ -45,7 +45,6 @@
</tbody>
</table>
<p><%= pagination_links_full @project_pages, :status => @status %>
[ <%= @project_pages.current.first_item %> - <%= @project_pages.current.last_item %> / <%= @project_count %> ]</p>
<p class="pagination"><%= pagination_links_full @project_pages, @project_count %></p>
<% set_html_title l(:label_project_plural) -%>

View File

@ -25,4 +25,4 @@
</tbody>
</table>
<%= pagination_links_full @auth_source_pages %>
<p class="pagination"><%= pagination_links_full @auth_source_pages %></p>

View File

@ -43,8 +43,7 @@
<% end %>
</tbody>
</table>
<p><%= pagination_links_full @topic_pages %>
[ <%= @topic_pages.current.first_item %> - <%= @topic_pages.current.last_item %> / <%= @topic_count %> ]</p>
<p class="pagination"><%= pagination_links_full @topic_pages, @topic_count %></p>
<% else %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>

View File

@ -32,6 +32,6 @@
</tbody>
</table>
<%= pagination_links_full @issue_status_pages %>
<p class="pagination"><%= pagination_links_full @issue_status_pages %></p>
<% set_html_title(l(:label_issue_status_plural)) -%>

View File

@ -48,8 +48,7 @@
<%= link_to 'CSV', {:format => 'csv'}, :class => 'icon icon-csv' %>,
<%= link_to 'PDF', {:format => 'pdf'}, :class => 'icon icon-pdf' %>
</div>
<p><%= pagination_links_full @issue_pages %>
[ <%= @issue_pages.current.first_item %> - <%= @issue_pages.current.last_item %> / <%= @issue_count %> ]</p>
<p class="pagination"><%= pagination_links_full @issue_pages, @issue_count %></p>
<% end %>
<% end %>
<% end %>

View File

@ -27,7 +27,7 @@
<%= textilizable(news.description) %>
<% end %>
<% end %>
<%= pagination_links_full @news_pages %>
<p class="pagination"><%= pagination_links_full @news_pages %></p>
<% content_for :header_tags do %>
<%= auto_discovery_link_tag(:atom, params.merge({:format => 'atom', :page => nil, :key => User.current.rss_key})) %>

View File

@ -56,8 +56,7 @@
<% end %>
</tbody>
</table>
<p><%= pagination_links_full @changes_pages, :rev => @changeset.revision %>
[ <%= @changes_pages.current.first_item %> - <%= @changes_pages.current.last_item %> / <%= @changes_count %> ]</p>
<p class="pagination"><%= pagination_links_full @changes_pages %></p>
<% content_for :header_tags do %>
<%= stylesheet_link_tag "scm" %>

View File

@ -9,8 +9,7 @@
<%= render :partial => 'revisions', :locals => {:project => @project, :path => '', :revisions => @changesets, :entry => nil }%>
<p><%= pagination_links_full @changeset_pages %>
[ <%= @changeset_pages.current.first_item %> - <%= @changeset_pages.current.last_item %> / <%= @changeset_count %> ]</p>
<p class="pagination"><%= pagination_links_full @changeset_pages,@changeset_count %></p>
<% content_for :header_tags do %>
<%= stylesheet_link_tag "scm" %>

View File

@ -29,7 +29,7 @@
</tbody>
</table>
<p><%= pagination_links_full @role_pages %></p>
<p class="pagination"><%= pagination_links_full @role_pages %></p>
<p><%= link_to l(:label_permissions_report), :action => 'report' %></p>

View File

@ -27,6 +27,9 @@
<p><label><%= l(:setting_attachment_max_size) %></label>
<%= text_field_tag 'settings[attachment_max_size]', Setting.attachment_max_size, :size => 6 %> KB</p>
<p><label><%= l(:setting_per_page_options) %></label>
<%= text_field_tag 'settings[per_page_options]', Setting.per_page_options_array.join(', '), :size => 20 %><br /><em><%= l(:text_comma_separated) %></em></p>
<p><label><%= l(:setting_issues_export_limit) %></label>
<%= text_field_tag 'settings[issues_export_limit]', Setting.issues_export_limit, :size => 6 %></p>

View File

@ -30,6 +30,6 @@
</tbody>
</table>
<%= pagination_links_full @tracker_pages %>
<p class="pagination"><%= pagination_links_full @tracker_pages %></p>
<% set_html_title(l(:label_tracker_plural)) -%>

View File

@ -55,8 +55,6 @@
</tbody>
</table>
<p><%= pagination_links_full @user_pages, :status => @status %>
[ <%= @user_pages.current.first_item %> - <%= @user_pages.current.last_item %> / <%= @user_count %> ]
</p>
<p class="pagination"><%= pagination_links_full @user_pages, @user_count %></p>
<% set_html_title(l(:label_user_plural)) -%>

View File

@ -31,6 +31,5 @@
</tbody>
</table>
<%= submit_tag l(:label_view_diff), :class => 'small' %>
<%= pagination_links_full @version_pages, :page_param => :p %>
[ <%= @version_pages.current.first_item %> - <%= @version_pages.current.last_item %> / <%= @version_count %> ]
<span class="pagination"><%= pagination_links_full @version_pages, @version_count, :page_param => :p %></span>
<% end %>

View File

@ -37,6 +37,8 @@ attachment_max_size:
issues_export_limit:
format: int
default: 500
per_page_options:
default: '25,50,100'
mail_from:
default: redmine@somenet.foo
bcc_recipients:

View File

@ -550,3 +550,5 @@ setting_bcc_recipients: Blind carbon copy recipients (bcc)
button_annotate: Annotate
label_issues_by: Issues by %s
field_searchable: Searchable
label_display_per_page: 'Per page: %s'
setting_per_page_options: Objects per page options

View File

@ -550,3 +550,5 @@ setting_bcc_recipients: Blind carbon copy recipients (bcc)
button_annotate: Annotate
label_issues_by: Issues by %s
field_searchable: Searchable
label_display_per_page: 'Per page: %s'
setting_per_page_options: Objects per page options

View File

@ -550,3 +550,5 @@ setting_bcc_recipients: Blind carbon copy recipients (bcc)
button_annotate: Annotate
label_issues_by: Issues by %s
field_searchable: Searchable
label_display_per_page: 'Per page: %s'
setting_per_page_options: Objects per page options

View File

@ -198,6 +198,7 @@ setting_issue_list_default_columns: Default columns displayed on the issue list
setting_repositories_encodings: Repositories encodings
setting_emails_footer: Emails footer
setting_protocol: Protocol
setting_per_page_options: Objects per page options
label_user: User
label_user_plural: Users
@ -456,6 +457,7 @@ label_user_mail_no_self_notified: "I don't want to be notified of changes that I
label_registration_activation_by_email: account activation by email
label_registration_manual_activation: manual account activation
label_registration_automatic_activation: automatic account activation
label_display_per_page: 'Per page: %s'
button_login: Login
button_submit: Submit

View File

@ -553,3 +553,5 @@ setting_bcc_recipients: Blind carbon copy recipients (bcc)
button_annotate: Annotate
label_issues_by: Issues by %s
field_searchable: Searchable
label_display_per_page: 'Per page: %s'
setting_per_page_options: Objects per page options

View File

@ -198,6 +198,7 @@ setting_issue_list_default_columns: Colonnes affichées par défaut sur la liste
setting_repositories_encodings: Encodages des dépôts
setting_emails_footer: Pied-de-page des emails
setting_protocol: Protocole
setting_per_page_options: Options d'objets affichés par page
label_user: Utilisateur
label_user_plural: Utilisateurs
@ -456,6 +457,7 @@ label_user_mail_no_self_notified: "Je ne veux pas être notifié des changements
label_registration_activation_by_email: activation du compte par email
label_registration_manual_activation: activation manuelle du compte
label_registration_automatic_activation: activation automatique du compte
label_display_per_page: 'Par page: %s'
button_login: Connexion
button_submit: Soumettre

View File

@ -550,3 +550,5 @@ setting_bcc_recipients: Blind carbon copy recipients (bcc)
button_annotate: Annotate
label_issues_by: Issues by %s
field_searchable: Searchable
label_display_per_page: 'Per page: %s'
setting_per_page_options: Objects per page options

View File

@ -550,3 +550,5 @@ setting_bcc_recipients: Blind carbon copy recipients (bcc)
button_annotate: Annotate
label_issues_by: Issues by %s
field_searchable: Searchable
label_display_per_page: 'Per page: %s'
setting_per_page_options: Objects per page options

View File

@ -551,3 +551,5 @@ setting_bcc_recipients: ブラインドカーボンコピーで受信(bcc)
button_annotate: 注釈
label_issues_by: %s別の問題
field_searchable: Searchable
label_display_per_page: 'Per page: %s'
setting_per_page_options: Objects per page options

View File

@ -550,3 +550,5 @@ setting_bcc_recipients: Blind carbon copy recipients (bcc)
button_annotate: Annotate
label_issues_by: Issues by %s
field_searchable: Searchable
label_display_per_page: 'Per page: %s'
setting_per_page_options: Objects per page options

View File

@ -551,3 +551,5 @@ setting_bcc_recipients: Blind carbon copy recipients (bcc)
button_annotate: Annotate
label_issues_by: Issues by %s
field_searchable: Searchable
label_display_per_page: 'Per page: %s'
setting_per_page_options: Objects per page options

View File

@ -550,3 +550,5 @@ setting_bcc_recipients: Odbiorcy kopii tajnej (kt/bcc)
button_annotate: Adnotuj
label_issues_by: Zagadnienia wprowadzone przez %s
field_searchable: Searchable
label_display_per_page: 'Per page: %s'
setting_per_page_options: Objects per page options

View File

@ -550,3 +550,5 @@ setting_bcc_recipients: Blind carbon copy recipients (bcc)
button_annotate: Annotate
label_issues_by: Issues by %s
field_searchable: Searchable
label_display_per_page: 'Per page: %s'
setting_per_page_options: Objects per page options

View File

@ -550,3 +550,5 @@ setting_bcc_recipients: Blind carbon copy recipients (bcc)
button_annotate: Annotate
label_issues_by: Issues by %s
field_searchable: Searchable
label_display_per_page: 'Per page: %s'
setting_per_page_options: Objects per page options

View File

@ -550,3 +550,5 @@ setting_bcc_recipients: Blind carbon copy recipients (bcc)
button_annotate: Annotate
label_issues_by: Issues by %s
field_searchable: Searchable
label_display_per_page: 'Per page: %s'
setting_per_page_options: Objects per page options

View File

@ -550,3 +550,5 @@ setting_bcc_recipients: Blind carbon copy recipients (bcc)
button_annotate: Annotate
label_issues_by: Issues by %s
field_searchable: Searchable
label_display_per_page: 'Per page: %s'
setting_per_page_options: Objects per page options

View File

@ -551,3 +551,5 @@ setting_bcc_recipients: Blind carbon copy recipients (bcc)
button_annotate: Annotate
label_issues_by: Issues by %s
field_searchable: Searchable
label_display_per_page: 'Per page: %s'
setting_per_page_options: Objects per page options

View File

@ -551,3 +551,5 @@ setting_bcc_recipients: Blind carbon copy recipients (bcc)
button_annotate: Annotate
label_issues_by: Issues by %s
field_searchable: Searchable
label_display_per_page: 'Per page: %s'
setting_per_page_options: Objects per page options

View File

@ -550,3 +550,5 @@ enumeration_issue_priorities: 項目重要性
enumeration_doc_categories: 文件分類
enumeration_activities: 活動 (time tracking)
field_searchable: Searchable
label_display_per_page: 'Per page: %s'
setting_per_page_options: Objects per page options

View File

@ -553,3 +553,5 @@ setting_bcc_recipients: Blind carbon copy recipients (bcc)
button_annotate: Annotate
label_issues_by: Issues by %s
field_searchable: Searchable
label_display_per_page: 'Per page: %s'
setting_per_page_options: Objects per page options

View File

@ -126,6 +126,9 @@ div.issue {background:#ffffdd; padding:6px; margin-bottom:6px;border: 1px solid
.autoscroll {overflow-x: auto; padding:1px; width:100%; margin-bottom: 1.2em;}
#user_firstname, #user_lastname, #user_mail, #my_account_form select { width: 90%; }
.pagination {font-size: 90%}
p.pagination {margin-top:8px;}
/***** Tabular forms ******/
.tabular p{
margin: 0;