# File app/models/elasticsearch/search.rb, line 256 def lastpage(total, per_page) last_page = total/per_page + 1 if total%per_page == 0 last_page = last_page - 1 end return last_page end
# File app/models/elasticsearch/search.rb, line 243 def link_to_page(text, page) # link_to_remote(text, :url => search_index_path(:criterio_id => @criterio.id, :page => page), :method => :post) link_params={:page => page} if @criterio.present? && !@criterio.new_record? link_params.merge!(:id => @criterio.id) link_uri='search_path' else link_uri = 'new_search_path' end link_params.merge!(:sort => @sort) if @sort.present? link_to(text, send(link_uri, link_params)) end
# File app/models/elasticsearch/search.rb, line 264 def minmaxpage(current, total_pages, option) min = current - 2 if min < 1 min = 1 max = 1 + 4 if max > total_pages then max = total_pages end end max = min + 4 if max > total_pages max = total_pages min = max - 4 while min < 1 min = min + 1 end end if option.eql?('min') then return min else return max end end
# File app/models/elasticsearch/search.rb, line 188 def will_paginate_search(collection, total) output=[] current=@page.to_i per_page=Elasticsearch::Base::ITEMS_PER_PAGE last_page=lastpage(total, per_page) min=minmaxpage(current, last_page, 'min') max=minmaxpage(current, last_page, 'max') # Previous page aux = [] if min < current aux << link_to_page(t('search.anterior'), current-1) else aux << content_tag(:span, t('search.anterior')) end output << content_tag(:li, aux, :class => 'prev_page') # Page numbers aux=[] if min > 1 aux << link_to_page(1, 1) aux << content_tag(:span, " ... ", :class => 'gap') end x=min while x <= max if x.to_i == current.to_i aux << content_tag(:span, x, :class => 'current') else aux << link_to_page(x.to_s, x) end x=x+1 end x=x-1 if x == 1 || total <= Elasticsearch::Base::ITEMS_PER_PAGE "" else if max < last_page aux << content_tag(:span, " ... ", :class => 'gap') aux << link_to_page(last_page.to_s, last_page) end output << content_tag(:li, aux.join(' '), :class => 'page_numbers') # Next page aux=[] if max > current aux << link_to_page(t('search.siguiente'), current + 1) else aux << content_tag(:span, t('search.siguiente')) end output << content_tag(:li, aux, :class => 'next_page') content_tag(:div, content_tag(:ul, output), :class => 'pagination') end end