mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-07 22:46:06 +00:00
27 lines
566 B
Ruby
27 lines
566 B
Ruby
# frozen_string_literal: true
|
|
|
|
module PaginationData
|
|
extend ActiveSupport::Concern
|
|
|
|
def pagination_data(pagination)
|
|
return unless pagination.respond_to? :pages
|
|
|
|
{
|
|
results: pagination.count,
|
|
pages: pagination.pages,
|
|
page: (params[:page] || 1).to_i,
|
|
per_page: (params[:per_page] || default_per_page).to_i
|
|
}
|
|
end
|
|
|
|
def pagination_required?
|
|
params[:page].present? || params[:per_page].present?
|
|
end
|
|
|
|
def default_per_page
|
|
return unless defined? self.class::DEFAULT_PER_PAGE
|
|
|
|
self.class::DEFAULT_PER_PAGE
|
|
end
|
|
end
|