mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-26 05:55:15 +00:00
apply pagination data concern to bulk line items controller
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
module Admin
|
||||
class BulkLineItemsController < Spree::Admin::BaseController
|
||||
include PaginationData
|
||||
|
||||
DEFAULT_PAGE = 1
|
||||
# GET /admin/bulk_line_items.json
|
||||
#
|
||||
def index
|
||||
@@ -12,9 +15,9 @@ module Admin
|
||||
ransack(params[:q]).result.
|
||||
reorder('spree_line_items.order_id ASC, spree_line_items.id ASC')
|
||||
|
||||
@line_items = @line_items.page(page).per(params[:per_page]) if using_pagination?
|
||||
@line_items = @line_items.page(page).per(params[:per_page]) if pagination_required?
|
||||
|
||||
render json: { line_items: serialized_line_items, pagination: pagination_data }
|
||||
render json: { line_items: serialized_line_items, pagination: (pagination_required? ? pagination_data(@line_items, default_page: DEFAULT_PAGE) : nil) }
|
||||
end
|
||||
|
||||
# PUT /admin/bulk_line_items/:id.json
|
||||
@@ -87,23 +90,8 @@ module Admin
|
||||
::Permissions::Order.new(spree_current_user)
|
||||
end
|
||||
|
||||
def using_pagination?
|
||||
params[:per_page]
|
||||
end
|
||||
|
||||
def pagination_data
|
||||
return unless using_pagination?
|
||||
|
||||
{
|
||||
results: @line_items.total_count,
|
||||
pages: @line_items.num_pages,
|
||||
page: page.to_i,
|
||||
per_page: params[:per_page].to_i
|
||||
}
|
||||
end
|
||||
|
||||
def page
|
||||
params[:page] || 1
|
||||
params[:page] || DEFAULT_PAGE
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user