11# -*- encoding : utf-8 -*-
22module Blacklight ::CatalogHelperBehavior
33
4+ extend Deprecation
5+ self . deprecation_horizon = 'Blacklight 5.x'
6+
47 # Pass in an RSolr::Response (or duck-typed similar) object,
58 # it translates to a Kaminari-paginatable
69 # object, with the keys Kaminari views expect.
@@ -25,11 +28,7 @@ def format_num(num); number_with_delimiter(num) end
2528 #
2629 # Pass in an RSolr::Response. Displays the "showing X through Y of N" message.
2730 def render_pagination_info ( response , options = { } )
28- # TODO: i18n the entry_name
29- entry_name = options [ :entry_name ]
30- entry_name ||= response . docs . first . class . name . underscore . sub ( '_' , ' ' ) unless response . docs . empty?
31- entry_name ||= t ( 'blacklight.entry_name.default' )
32-
31+ entry_name = options [ :entry_name ] || t ( 'blacklight.entry_name.default' )
3332
3433 end_num = if render_grouped_response?
3534 format_num ( response . start + response . groups . length )
@@ -43,14 +42,56 @@ def render_pagination_info(response, options = {})
4342 else ; t ( 'blacklight.search.pagination_info.pages' , :entry_name => entry_name . pluralize , :current_page => response . current_page , :num_pages => response . total_pages , :start_num => format_num ( response . start + 1 ) , :end_num => end_num , :total_num => response . total_count , :count => response . total_pages ) . html_safe
4443 end
4544 end
45+ deprecation_deprecate :render_pagination_info
46+
47+ # Override the Kaminari page_entries_info helper with our own, blacklight-aware
48+ # implementation
49+ #
50+ # Pass in an RSolr::Response. Displays the "showing X through Y of N" message.
51+
52+ def page_entries_info ( collection , options = { } )
53+ entry_name = if options [ :entry_name ]
54+ options [ :entry_name ]
55+ elsif collection . respond_to? :model # DataMapper
56+ collection . model . model_name . humanize . downcase
57+ elsif collection . respond_to? :model_name and !collection . model_name . nil? # AR, Blacklight::PaginationMethods
58+ collection . model_name . humanize . downcase
59+ elsif collection . is_a? ( ::Kaminari ::PaginatableArray )
60+ 'entry'
61+ else
62+ t ( 'blacklight.entry_name.default' )
63+ end
64+
65+ entry_name = entry_name . pluralize unless collection . total_count == 1
66+
67+ # grouped response objects need special handling
68+ end_num = if collection . respond_to? :groups and render_grouped_response? collection
69+ collection . groups . length
70+ else
71+ collection . limit_value
72+ end
73+
74+ end_num = if collection . offset_value + end_num <= collection . total_count
75+ format_num ( collection . offset_value + end_num )
76+ else
77+ format_num ( collection . total_count )
78+ end
79+
80+ case collection . total_count
81+ when 0 ; t ( 'blacklight.search.pagination_info.no_items_found' , :entry_name => entry_name ) . html_safe
82+ when 1 ; t ( 'blacklight.search.pagination_info.single_item_found' , :entry_name => entry_name ) . html_safe
83+ else ; t ( 'blacklight.search.pagination_info.pages' , :entry_name => entry_name , :current_page => collection . current_page , :num_pages => collection . total_pages , :start_num => format_num ( collection . offset_value + 1 ) , :end_num => end_num , :total_num => collection . total_count , :count => collection . total_pages ) . html_safe
84+ end
85+ end
86+
4687
4788 def document_counter_with_offset idx
4889 unless render_grouped_response?
4990 idx + 1 + @response . params [ :start ] . to_i
5091 end
5192 end
5293
53- # Like #render_pagination_info above, but for an individual
94+ # Like #page_entries_info above, but for an individual
5495 # item show page. Displays "showing X of Y items" message. Actually takes
5596 # data from session though (not a great design).
5697 # Code should call this method rather than interrogating session directly,
0 commit comments