@@ -399,7 +399,7 module ApplicationHelper | |||||
399 |
|
399 | |||
400 | unless count.nil? |
|
400 | unless count.nil? | |
401 | html << " (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})" |
|
401 | html << " (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})" | |
402 | if per_page_links != false && links = per_page_links(paginator.items_per_page) |
|
402 | if per_page_links != false && links = per_page_links(paginator.items_per_page, count) | |
403 | html << " | #{links}" |
|
403 | html << " | #{links}" | |
404 | end |
|
404 | end | |
405 | end |
|
405 | end | |
@@ -407,11 +407,23 module ApplicationHelper | |||||
407 | html.html_safe |
|
407 | html.html_safe | |
408 | end |
|
408 | end | |
409 |
|
409 | |||
410 | def per_page_links(selected=nil) |
|
410 | def per_page_links(selected=nil, item_count=nil) | |
411 |
|
|
411 | values = Setting.per_page_options_array | |
|
412 | if item_count && values.any? | |||
|
413 | if item_count > values.first | |||
|
414 | max = values.detect {|value| value >= item_count} || item_count | |||
|
415 | else | |||
|
416 | max = item_count | |||
|
417 | end | |||
|
418 | values = values.select {|value| value <= max || value == selected} | |||
|
419 | end | |||
|
420 | if values.empty? || (values.size == 1 && values.first == selected) | |||
|
421 | return nil | |||
|
422 | end | |||
|
423 | links = values.collect do |n| | |||
412 | n == selected ? n : link_to_content_update(n, params.merge(:per_page => n)) |
|
424 | n == selected ? n : link_to_content_update(n, params.merge(:per_page => n)) | |
413 | end |
|
425 | end | |
414 |
|
|
426 | l(:label_display_per_page, links.join(', ')) | |
415 | end |
|
427 | end | |
416 |
|
428 | |||
417 | def reorder_links(name, url, method = :post) |
|
429 | def reorder_links(name, url, method = :post) |
@@ -1088,4 +1088,19 RAW | |||||
1088 | def test_javascript_include_tag_for_plugin_should_pick_the_plugin_javascript |
|
1088 | def test_javascript_include_tag_for_plugin_should_pick_the_plugin_javascript | |
1089 | assert_match 'src="/plugin_assets/foo/javascripts/scripts.js"', javascript_include_tag("scripts", :plugin => :foo) |
|
1089 | assert_match 'src="/plugin_assets/foo/javascripts/scripts.js"', javascript_include_tag("scripts", :plugin => :foo) | |
1090 | end |
|
1090 | end | |
|
1091 | ||||
|
1092 | def test_per_page_links_should_show_usefull_values | |||
|
1093 | set_language_if_valid 'en' | |||
|
1094 | stubs(:link_to).returns("[link]") | |||
|
1095 | ||||
|
1096 | with_settings :per_page_options => '10, 25, 50, 100' do | |||
|
1097 | assert_nil per_page_links(10, 3) | |||
|
1098 | assert_nil per_page_links(25, 3) | |||
|
1099 | assert_equal "Per page: 10, [link]", per_page_links(10, 22) | |||
|
1100 | assert_equal "Per page: [link], 25", per_page_links(25, 22) | |||
|
1101 | assert_equal "Per page: [link], [link], 50", per_page_links(50, 22) | |||
|
1102 | assert_equal "Per page: [link], 25, [link]", per_page_links(25, 26) | |||
|
1103 | assert_equal "Per page: [link], 25, [link], [link]", per_page_links(25, 120) | |||
|
1104 | end | |||
|
1105 | end | |||
1091 | end |
|
1106 | end |
General Comments 0
You need to be logged in to leave comments.
Login now