mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Tidy up pagination in Api::ProductsController#overridable and Angular PagedFetcher service
Refactors away some unnecessary mess and unblocks the last remaining issue in upgrading the Kaminari gem (deprecated calls to #num_pages method)
This commit is contained in:
@@ -16,7 +16,7 @@ angular.module("admin.indexUtils").factory "PagedFetcher", (dataFetcher) ->
|
||||
fetchPages: (url, page, pageCallback) ->
|
||||
dataFetcher(@urlForPage(url, page)).then (data) =>
|
||||
@page++
|
||||
@last_page = data.pages
|
||||
@last_page = data.pagination.pages
|
||||
|
||||
pageCallback(data) if pageCallback
|
||||
|
||||
|
||||
@@ -130,18 +130,15 @@ module Api
|
||||
end
|
||||
|
||||
def render_paged_products(products, product_serializer = ::Api::Admin::ProductSerializer)
|
||||
serializer = ActiveModel::ArraySerializer.new(
|
||||
serialized_products = ActiveModel::ArraySerializer.new(
|
||||
products,
|
||||
each_serializer: product_serializer
|
||||
)
|
||||
|
||||
render text: {
|
||||
products: serializer,
|
||||
# This line is used by the PagedFetcher JS service (inventory).
|
||||
pages: products.num_pages,
|
||||
# This hash is used by the BulkProducts JS service.
|
||||
render json: {
|
||||
products: serialized_products,
|
||||
pagination: pagination_data(products)
|
||||
}.to_json
|
||||
}
|
||||
end
|
||||
|
||||
def query_params_with_defaults
|
||||
|
||||
Reference in New Issue
Block a user