summaryrefslogtreecommitdiffstats
path: root/lib/redmine/pagination.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-12-17 20:17:52 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-12-17 20:17:52 +0000
commit56669f9b13d1bb14fd1385255db8b9681406f0ac (patch)
tree7f2caa5b49b9b56ff7c1faa1c450570f6192b597 /lib/redmine/pagination.rb
parentab3330a945e410de568e8a824203a9c025d2d8b0 (diff)
downloadredmine-56669f9b13d1bb14fd1385255db8b9681406f0ac.tar.gz
redmine-56669f9b13d1bb14fd1385255db8b9681406f0ac.zip
Split #per_page_links helper and moved test to specific test case.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11031 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine/pagination.rb')
-rw-r--r--lib/redmine/pagination.rb30
1 files changed, 19 insertions, 11 deletions
diff --git a/lib/redmine/pagination.rb b/lib/redmine/pagination.rb
index 889e0f5cb..97d04dcf9 100644
--- a/lib/redmine/pagination.rb
+++ b/lib/redmine/pagination.rb
@@ -208,22 +208,30 @@ module Redmine
# Renders the "Per page" links.
def per_page_links(selected=nil, item_count=nil, &block)
- values = Setting.per_page_options_array
- if item_count && values.any?
- if item_count > values.first
- max = values.detect {|value| value >= item_count} || item_count
+ values = per_page_options(selected, item_count)
+ if values.any?
+ links = values.collect do |n|
+ n == selected ? n : yield(n, :per_page => n)
+ end
+ l(:label_display_per_page, links.join(', '))
+ end
+ end
+
+ def per_page_options(selected=nil, item_count=nil)
+ options = Setting.per_page_options_array
+ if item_count && options.any?
+ if item_count > options.first
+ max = options.detect {|value| value >= item_count} || item_count
else
max = item_count
end
- values = values.select {|value| value <= max || value == selected}
+ options = options.select {|value| value <= max || value == selected}
end
- if values.empty? || (values.size == 1 && values.first == selected)
- return nil
- end
- links = values.collect do |n|
- n == selected ? n : yield(n, :per_page => n)
+ if options.empty? || (options.size == 1 && options.first == selected)
+ []
+ else
+ options
end
- l(:label_display_per_page, links.join(', '))
end
end
end