mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Reduce assignment branching and complexity for ProductsRenderer#products
This commit is contained in:
@@ -35,15 +35,20 @@ module OpenFoodNetwork
|
||||
return unless order_cycle
|
||||
|
||||
@products ||= begin
|
||||
scoper = ScopeProductToHub.new(distributor)
|
||||
results = distributed_products.products_relation.order(taxon_order)
|
||||
|
||||
distributed_products.products_relation.
|
||||
order(taxon_order).
|
||||
ransack(params[:q]).result.page(params[:page] || 1).per(params[:per_page] || 10).
|
||||
each { |product| scoper.scope(product) }
|
||||
filter_and_paginate(results).each { |product| product_scoper.scope(product) }
|
||||
end
|
||||
end
|
||||
|
||||
def product_scoper
|
||||
ScopeProductToHub.new(distributor)
|
||||
end
|
||||
|
||||
def filter_and_paginate(query)
|
||||
query.ransack(params[:q]).result.page(params[:page] || 1).per(params[:per_page] || 10)
|
||||
end
|
||||
|
||||
def distributed_products
|
||||
OrderCycleDistributedProducts.new(distributor, order_cycle, customer)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user