2018-08-18 07:19:57 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-10 09:01:38 -04:00
|
|
|
module PaginationHelper
|
2020-10-14 14:08:47 -04:00
|
|
|
# total_pages will be inferred from the collection if nil. It is ignored if
|
|
|
|
# the collection is a Kaminari::PaginatableWithoutCount
|
|
|
|
def paginate_collection(collection, remote: nil, total_pages: nil)
|
2017-08-10 09:01:38 -04:00
|
|
|
if collection.is_a?(Kaminari::PaginatableWithoutCount)
|
|
|
|
paginate_without_count(collection)
|
|
|
|
elsif collection.respond_to?(:total_pages)
|
2020-10-14 14:08:47 -04:00
|
|
|
paginate_with_count(collection, remote: remote, total_pages: total_pages)
|
2017-08-10 09:01:38 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def paginate_without_count(collection)
|
|
|
|
render(
|
|
|
|
'kaminari/gitlab/without_count',
|
|
|
|
previous_path: path_to_prev_page(collection),
|
|
|
|
next_path: path_to_next_page(collection)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2020-10-14 14:08:47 -04:00
|
|
|
def paginate_with_count(collection, remote: nil, total_pages: nil)
|
|
|
|
paginate(collection, remote: remote, theme: 'gitlab', total_pages: total_pages)
|
2017-08-10 09:01:38 -04:00
|
|
|
end
|
2022-03-11 07:07:56 -05:00
|
|
|
|
|
|
|
def page_size
|
|
|
|
Kaminari.config.default_per_page
|
|
|
|
end
|
2017-08-10 09:01:38 -04:00
|
|
|
end
|