2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-08-17 05:44:54 +00:00
|
|
|
|
2021-09-07 10:34:10 +00:00
|
|
|
class CanPaginate::Pagination
|
2021-08-17 05:44:54 +00:00
|
|
|
|
|
|
|
def initialize(params, default: nil, max: nil)
|
|
|
|
@params = params
|
|
|
|
@default = default.presence || 100
|
|
|
|
@max = max.presence || 500
|
|
|
|
end
|
|
|
|
|
|
|
|
def limit
|
|
|
|
limit = @params[:per_page] || @params[:limit] || @default
|
|
|
|
|
|
|
|
[limit.to_i, @max].min
|
|
|
|
end
|
|
|
|
|
|
|
|
def page
|
|
|
|
@params[:page]&.to_i || 1
|
|
|
|
end
|
|
|
|
|
|
|
|
def offset
|
|
|
|
(page - 1) * limit
|
|
|
|
end
|
|
|
|
end
|