module Split::DashboardPaginationHelpers

Public Instance Methods

page_number() click to toggle source
# File lib/split/dashboard/pagination_helpers.rb, line 11
def page_number
  @page_number ||= (params[:page] || 1).to_i
end
paginated(collection) click to toggle source
# File lib/split/dashboard/pagination_helpers.rb, line 15
def paginated(collection)
  Split::DashboardPaginator.new(collection, page_number, pagination_per).paginate
end
pagination(collection) click to toggle source
# File lib/split/dashboard/pagination_helpers.rb, line 19
def pagination(collection)
  html = []
  html << first_page_tag if show_first_page_tag?
  html << ellipsis_tag if show_first_ellipsis_tag?
  html << prev_page_tag if show_prev_page_tag?
  html << current_page_tag
  html << next_page_tag if show_next_page_tag?(collection)
  html << ellipsis_tag if show_last_ellipsis_tag?(collection)
  html << last_page_tag(collection) if show_last_page_tag?(collection)
  html.join
end
pagination_per() click to toggle source
# File lib/split/dashboard/pagination_helpers.rb, line 6
def pagination_per
  default_per_page = Split.configuration.dashboard_pagination_default_per_page
  @pagination_per ||= (params[:per] || default_per_page).to_i
end

Private Instance Methods

current_page_tag() click to toggle source
# File lib/split/dashboard/pagination_helpers.rb, line 57
def current_page_tag
  "<span><b>#{page_number}</b></span>"
end
ellipsis_tag() click to toggle source
# File lib/split/dashboard/pagination_helpers.rb, line 45
def ellipsis_tag
  '<span>...</span>'
end
first_page_tag() click to toggle source
# File lib/split/dashboard/pagination_helpers.rb, line 37
def first_page_tag
  %Q(<a href="#{url.chop}?page=1&per=#{pagination_per}">1</a>)
end
last_page_tag(collection) click to toggle source
# File lib/split/dashboard/pagination_helpers.rb, line 81
def last_page_tag(collection)
  total = total_pages(collection)
  %Q(<a href="#{url.chop}?page=#{total}&per=#{pagination_per}">#{total}</a>)
end
next_page_tag() click to toggle source
# File lib/split/dashboard/pagination_helpers.rb, line 65
def next_page_tag
  %Q(<a href="#{url.chop}?page=#{page_number + 1}&per=#{pagination_per}">#{page_number + 1}</a>)
end
prev_page_tag() click to toggle source
# File lib/split/dashboard/pagination_helpers.rb, line 53
def prev_page_tag
  %Q(<a href="#{url.chop}?page=#{page_number - 1}&per=#{pagination_per}">#{page_number - 1}</a>)
end
show_first_ellipsis_tag?() click to toggle source
# File lib/split/dashboard/pagination_helpers.rb, line 41
def show_first_ellipsis_tag?
  page_number >= 4
end
show_first_page_tag?() click to toggle source
# File lib/split/dashboard/pagination_helpers.rb, line 33
def show_first_page_tag?
  page_number > 2
end
show_last_ellipsis_tag?(collection) click to toggle source
# File lib/split/dashboard/pagination_helpers.rb, line 69
def show_last_ellipsis_tag?(collection)
  (total_pages(collection) - page_number) >= 3
end
show_last_page_tag?(collection) click to toggle source
# File lib/split/dashboard/pagination_helpers.rb, line 77
def show_last_page_tag?(collection)
  page_number < (total_pages(collection) - 1)
end
show_next_page_tag?(collection) click to toggle source
# File lib/split/dashboard/pagination_helpers.rb, line 61
def show_next_page_tag?(collection)
  (page_number * pagination_per) < collection.count
end
show_prev_page_tag?() click to toggle source
# File lib/split/dashboard/pagination_helpers.rb, line 49
def show_prev_page_tag?
  page_number > 1
end
total_pages(collection) click to toggle source
# File lib/split/dashboard/pagination_helpers.rb, line 73
def total_pages(collection)
  collection.count / pagination_per + ((collection.count % pagination_per).zero? ? 0 : 1)
end