module CatalogHelper def paginate_rsolr_response(response, options = {}, &block) per_page = response.rows per_page = 1 if per_page < 1 current_page = (response.start / per_page).ceil + 1 num_pages = (response.total / per_page.to_f).ceil paginate Struct.new(:current_page, :num_pages, :limit_value).new(current_page, num_pages, per_page), options, &block end # # shortcut for built-in Rails helper, "number_with_delimiter" # def format_num(num); number_with_delimiter(num) end # # Displays the "showing X through Y of N" message. def render_pagination_info(response, options = {}) start = response.start + 1 per_page = response.rows current_page = (response.start / per_page).ceil + 1 num_pages = (response.total / per_page.to_f).ceil total_hits = response.total start_num = format_num(start) end_num = format_num(start + response.docs.length - 1) total_num = format_num(total_hits) entry_name = options[:entry_name] || (response.empty?? 'entry' : response.docs.first.class.name.underscore.sub('_', ' ')) if num_pages < 2 case response.docs.length when 0; "No #{h(entry_name.pluralize)} found".html_safe when 1; "Displaying 1 #{h(entry_name)}".html_safe else; "Displaying all #{total_num} #{entry_name.pluralize}".html_safe end else "Displaying #{h(entry_name.pluralize)} #{start_num} - #{end_num} of #{total_num}".html_safe end end # Like the mysteriously named #page_entry_info above, but for an individual # item show page. Displays "showing X of Y items" message. # Code should call this method rather than interrogating session directly, # because implementation of where this data is stored/retrieved may change. def item_page_entry_info "Showing item #{session[:search][:counter].to_i} of #{format_num(session[:search][:total])} from your search.".html_safe end # Look up search field user-displayable label # based on params[:qt] and configuration. def search_field_label(params) h( Blacklight.label_for_search_field(params[:search_field]) ) end # Export to Refworks URL, called in _show_tools def refworks_export_url(document = @document) "http://www.refworks.com/express/expressimport.asp?vendor=#{CGI.escape(application_name)}&filter=MARC%20Format&encoding=65001&url=#{CGI.escape(catalog_path(document.id, :format => 'refworks_marc_txt', :only_path => false))}" end def render_document_class(document = @document) 'blacklight-' + document.get(Blacklight.config[:index][:record_display_type]).parameterize rescue nil end def render_document_sidebar_partial(document = @document) render :partial => 'show_sidebar' end def has_search_parameters? !params[:q].blank? or !params[:f].blank? or !params[:search_field].blank? end end