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:
Matt-Yorkley
2021-01-05 18:55:22 +00:00
parent 47f9a3f08a
commit 4bb2653306
2 changed files with 5 additions and 8 deletions

View File

@@ -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

View File

@@ -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