mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-03 22:06:07 +00:00
Simplify exchange products/variants JSON output format, bind angular to this
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
class ExchangePresenter
|
||||
attr_accessor :exchange
|
||||
|
||||
def initialize(exchange)
|
||||
@exchange = exchange
|
||||
end
|
||||
|
||||
delegate :id, :sender_id, :receiver_id, :exchange_variants, :to => :exchange
|
||||
|
||||
def exchange_products
|
||||
@exchange.exchange_variants.group_by { |ev| ev.variant.product }
|
||||
end
|
||||
|
||||
end
|
||||
@@ -27,11 +27,11 @@
|
||||
%td{:colspan => 3}
|
||||
.exchange-product{'ng-repeat' => 'product in enterprises[exchange.enterprise_id].supplied_products'}
|
||||
|
||||
= check_box_tag 'order_cycle_exchange_{{ $parent.$index }}_exchange_variants_{{ product.master_id }}', 1, 1, 'ng-model' => 'exchange.exchange_variants[product.master_id]', 'id' => 'order_cycle_exchange_{{ $parent.$index }}_exchange_variants_{{ product.master_id }}'
|
||||
= check_box_tag 'order_cycle_exchange_{{ $parent.$index }}_exchange_variants_{{ product.master_id }}', 1, 1, 'ng-model' => 'exchange.variants[product.master_id]', 'id' => 'order_cycle_exchange_{{ $parent.$index }}_exchange_variants_{{ product.master_id }}'
|
||||
%img{'ng-src' => '{{ product.image_url }}'}
|
||||
{{ product.name }}
|
||||
.exchange-product-variant{'ng-repeat' => 'variant in product.variants'}
|
||||
= check_box_tag 'order_cycle_exchange_{{ $parent.$index }}_exchange_variants_{{ variant.id }}', 1, 1, 'ng-model' => 'exchange.exchange_variants[variant.id]', 'id' => 'order_cycle_exchange_{{ $parent.$index }}_exchange_variants_{{ variant.id }}'
|
||||
= check_box_tag 'order_cycle_exchange_{{ $parent.$index }}_exchange_variants_{{ variant.id }}', 1, 1, 'ng-model' => 'exchange.variants[variant.id]', 'id' => 'order_cycle_exchange_{{ $parent.$index }}_exchange_variants_{{ variant.id }}'
|
||||
{{ variant.label }}
|
||||
|
||||
= select_tag :new_supplier_id, options_from_collection_for_select(Enterprise.is_primary_producer, :id, :name), {'ng-model' => 'new_supplier_id'}
|
||||
|
||||
@@ -4,17 +4,10 @@ r.element :order_cycle, @order_cycle do
|
||||
r.element :orders_open_at
|
||||
r.element :orders_close_at
|
||||
r.element :coordinator_id
|
||||
r.list_of :exchanges, @order_cycle.exchanges.map { |e| ExchangePresenter.new(e) } do
|
||||
r.list_of :exchanges do |exchange|
|
||||
r.element :sender_id
|
||||
r.element :receiver_id
|
||||
r.list_of :exchange_products do |product, exchange_variants|
|
||||
r.element :id, product.id
|
||||
r.element :name, product.name
|
||||
r.element :image_url, product.images.first.attachment.url(:mini)
|
||||
r.list_of :variants, exchange_variants.map { |ev| VariantPresenter.new(ev.variant) } do
|
||||
r.element :id
|
||||
r.element :image_url
|
||||
end
|
||||
end
|
||||
|
||||
r.element :variants, Hash[ exchange.variants.map { |v| [v.id, true] } ], {}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user