Outgoing exchanges can be tagged

Using panels infrastructure to display tags and products interfaces
This commit is contained in:
Rob Harrington
2016-05-01 14:08:55 +10:00
parent e81858c0dc
commit 9dc1294ec5
19 changed files with 232 additions and 144 deletions

View File

@@ -41,10 +41,6 @@ angular.module('admin.orderCycles')
$scope.enterprisesWithFees = ->
$scope.enterprises[id] for id in OrderCycle.participatingEnterpriseIds() when $scope.enterpriseFeesForEnterprise(id).length > 0
$scope.toggleProducts = ($event, exchange) ->
$event.preventDefault()
OrderCycle.toggleProducts(exchange)
$scope.enterpriseFeesForEnterprise = (enterprise_id) ->
EnterpriseFee.forEnterprise(parseInt(enterprise_id))

View File

@@ -45,10 +45,6 @@ angular.module('admin.orderCycles')
$scope.enterprisesWithFees = ->
$scope.enterprises[id] for id in OrderCycle.participatingEnterpriseIds() when $scope.enterpriseFeesForEnterprise(id).length > 0
$scope.toggleProducts = ($event, exchange) ->
$event.preventDefault()
OrderCycle.toggleProducts(exchange)
$scope.enterpriseFeesForEnterprise = (enterprise_id) ->
EnterpriseFee.forEnterprise(parseInt(enterprise_id))

View File

@@ -1,4 +1,4 @@
angular.module('admin.orderCycles', ['ngResource', 'admin.utils', 'admin.indexUtils'])
angular.module('admin.orderCycles', ['ngResource', 'admin.utils', 'admin.indexUtils', 'ngTagsInput'])
.config ($httpProvider) ->
$httpProvider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content')

View File

@@ -1,4 +1,4 @@
angular.module('admin.orderCycles').factory 'OrderCycle', ($resource, $window, StatusMessage) ->
angular.module('admin.orderCycles').factory 'OrderCycle', ($resource, $window, StatusMessage, Panels) ->
OrderCycleResource = $resource '/admin/order_cycles/:action_name/:order_cycle_id.json', {}, {
'index': { method: 'GET', isArray: true}
'new' : { method: 'GET', params: { action_name: "new" } }
@@ -30,23 +30,25 @@ angular.module('admin.orderCycles').factory 'OrderCycle', ($resource, $window, S
exchangeDirection: (exchange) ->
if this.order_cycle.incoming_exchanges.indexOf(exchange) == -1 then 'outgoing' else 'incoming'
toggleProducts: (exchange) ->
exchange.showProducts = !exchange.showProducts
toggleAllProducts: (direction) ->
this.showProducts[direction] = !this.showProducts[direction]
exchange.showProducts = this.showProducts[direction] for exchange in this.exchangesByDirection(direction)
state = if this.showProducts[direction] then "open" else "closed"
exchanges = this.exchangesByDirection(direction)
Panels.toggle(exchange,'products',state) for exchange in exchanges
setExchangeVariants: (exchange, variants, selected) ->
direction = if exchange.incoming then "incoming" else "outgoing"
editable = @order_cycle["editable_variants_for_#{direction}_exchanges"][exchange.enterprise_id] || []
exchange.variants[variant] = selected for variant in variants when variant in editable
for variant in variants when variant in editable
exchange.variants[variant] = selected
@removeDistributionOfVariant(variant.id) if exchange.incoming
addSupplier: (new_supplier_id) ->
this.order_cycle.incoming_exchanges.push({enterprise_id: new_supplier_id, incoming: true, active: true, variants: {}, enterprise_fees: []})
addDistributor: (new_distributor_id) ->
this.order_cycle.outgoing_exchanges.push({enterprise_id: new_distributor_id, incoming: false, active: true, variants: {}, enterprise_fees: []})
this.order_cycle.outgoing_exchanges.push({enterprise_id: new_distributor_id, incoming: false, active: true, variants: {}, enterprise_fees: [], tags: [], tag_list: ""})
removeExchange: (exchange) ->
if exchange.incoming

View File

@@ -0,0 +1,31 @@
.row.exchange-distributed-products
.sixteen.columns.alpha.omega
.exchange-select-all-variants
%label
%input{ type: 'checkbox', name: 'order_cycle_outgoing_exchange_{{ $parent.$index }}_select_all_variants',
value: 1,
'ng-model' => 'exchange.select_all_variants',
'ng-change' => 'setExchangeVariants(exchange, incomingExchangeVariantsFor(exchange.enterprise_id), exchange.select_all_variants)',
'id' => 'order_cycle_outgoing_exchange_{{ $parent.$index }}_select_all_variants' }
Select all
.exchange-products
-# Scope product list based on permissions the current user has to view variants in this exchange
.exchange-product{'ng-repeat' => 'product in supplied_products | filter:productSuppliedToOrderCycle | visibleProducts:exchange:order_cycle.visible_variants_for_outgoing_exchanges | orderBy:"name"' }
.exchange-product-details
%label
-# MASTER_VARIANTS: No longer required
-# = check_box_tag 'order_cycle_outgoing_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}', 1, 1, 'ng-hide' => 'product.variants.length > 0', 'ng-model' => 'exchange.variants[product.master_id]', 'id' => 'order_cycle_outgoing_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}',
-# 'ng-disabled' => 'product.variants.length > 0 || !order_cycle.editable_variants_for_outgoing_exchanges.hasOwnProperty(exchange.enterprise_id) || order_cycle.editable_variants_for_outgoing_exchanges[exchange.enterprise_id].indexOf(product.master_id) < 0'
%img{'ng-src' => '{{ product.image_url }}'}
.name {{ product.name }}
.supplier {{ product.supplier_name }}
.exchange-product-variant{'ng-repeat' => 'variant in product.variants | visibleVariants:exchange:order_cycle.visible_variants_for_outgoing_exchanges | filter:variantSuppliedToOrderCycle'}
%label
%input{ type: 'checkbox', name: 'order_cycle_outgoing_exchange_{{ $parent.$parent.$index }}_variants_{{ variant.id }}',
value: 1,
'ng-model' => 'exchange.variants[variant.id]',
'id' => 'order_cycle_outgoing_exchange_{{ $parent.$parent.$index }}_variants_{{ variant.id }}',
'ng-disabled' => '!order_cycle.editable_variants_for_outgoing_exchanges.hasOwnProperty(exchange.enterprise_id) || order_cycle.editable_variants_for_outgoing_exchanges[exchange.enterprise_id].indexOf(variant.id) < 0' }
{{ variant.label }}

View File

@@ -0,0 +1,49 @@
.row.exchange-supplied-products
.sixteen.columns.alpha.omega
.exchange-select-all-variants
%label
%input{ type: 'checkbox', name: 'order_cycle_incoming_exchange_{{ $index }}_select_all_variants',
value: 1,
'ng-model' => 'exchange.select_all_variants',
'ng-change' => 'setExchangeVariants(exchange, suppliedVariants(exchange.enterprise_id), exchange.select_all_variants)',
'id' => 'order_cycle_incoming_exchange_{{ $index }}_select_all_variants' }
Select all
.exchange-products
-# No need to scope product list based on permissions, because if an incoming exchange is visible,
-# then all of the variants within it should be visible. May change in the future?
.exchange-product{'ng-repeat' => 'product in enterprises[exchange.enterprise_id].supplied_products'}
.exchange-product-details
%label
%input{ type: 'checkbox', name: 'order_cycle_incoming_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}',
value: 1,
'ng-hide' => 'product.variants.length > 0',
'ng-model' => 'exchange.variants[product.master_id]',
'ofn-sync-distributions' => '{{ product.master_id }}',
'id' => 'order_cycle_incoming_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}',
'ng-disabled' => 'product.variants.length > 0 || !order_cycle.editable_variants_for_incoming_exchanges.hasOwnProperty(exchange.enterprise_id) || order_cycle.editable_variants_for_incoming_exchanges[exchange.enterprise_id].indexOf(product.master_id) < 0' }
%img{'ng-src' => '{{ product.image_url }}'}
{{ product.name }}
-# When the master variant is in the order cycle but the product has variants, we want to
-# be able to remove the master variant, since it serves no purpose. Display a checkbox to do so.
.exchange-product-variant{'ng-show' => 'exchange.variants[product.master_id] && product.variants.length > 0'}
%label
%input{ type: 'checkbox', name: 'order_cycle_incoming_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}',
value: 1,
'ng-model' => 'exchange.variants[product.master_id]',
'ofn-sync-distributions' => '{{ product.master_id }}',
'id' => 'order_cycle_incoming_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}',
'ng-disabled' => '!order_cycle.editable_variants_for_incoming_exchanges.hasOwnProperty(exchange.enterprise_id) || order_cycle.editable_variants_for_incoming_exchanges[exchange.enterprise_id].indexOf(product.master_id) < 0' }
Obsolete master
.exchange-product-variant{'ng-repeat' => 'variant in product.variants'}
%label
%input{ type: 'checkbox', name: 'order_cycle_incoming_exchange_{{ $parent.$parent.$index }}_variants_{{ variant.id }}',
value: 1,
'ng-model' => 'exchange.variants[variant.id]',
'ofn-sync-distributions' => '{{ variant.id }}',
'id' => 'order_cycle_incoming_exchange_{{ $parent.$parent.$index }}_variants_{{ variant.id }}',
'ng-disabled' => '!order_cycle.editable_variants_for_incoming_exchanges.hasOwnProperty(exchange.enterprise_id) || order_cycle.editable_variants_for_incoming_exchanges[exchange.enterprise_id].indexOf(variant.id) < 0' }
{{ variant.label }}

View File

@@ -0,0 +1,5 @@
.row.exchange-tags
.sixteen.columns.alpha.omega
%span.text-normal Tags
%br
%tags-with-translation.fullwidth{ object: 'object' }

View File

@@ -79,10 +79,6 @@ form.order_cycle {
width: 20px;
}
tr.supplier td {
border-bottom: 2px solid #C3D9FF;
}
.exchange-select-all-variants {
clear: both;
margin: 5px;

View File

@@ -1,4 +1,6 @@
class Exchange < ActiveRecord::Base
acts_as_taggable
belongs_to :order_cycle
belongs_to :sender, :class_name => 'Enterprise'
belongs_to :receiver, :class_name => 'Enterprise'
@@ -58,6 +60,7 @@ class Exchange < ActiveRecord::Base
exchange.order_cycle = new_order_cycle
exchange.enterprise_fee_ids = self.enterprise_fee_ids
exchange.variant_ids = self.variant_ids
exchange.tag_ids = self.tag_ids
exchange.save!
exchange
end

View File

@@ -1,5 +1,6 @@
class Api::Admin::ExchangeSerializer < ActiveModel::Serializer
attributes :id, :sender_id, :receiver_id, :incoming, :variants, :receival_instructions, :pickup_time, :pickup_instructions
attributes :tags, :tag_list
has_many :enterprise_fees, serializer: Api::Admin::BasicEnterpriseFeeSerializer
@@ -35,4 +36,12 @@ class Api::Admin::ExchangeSerializer < ActiveModel::Serializer
OpenFoodNetwork::OrderCyclePermissions.new(options[:current_user], object.order_cycle)
.visible_variants_for_outgoing_exchanges_to(object.receiver)
end
def tag_list
object.tag_list.join(",")
end
def tags
object.tag_list.map{ |t| { text: t } }
end
end

View File

@@ -1,23 +0,0 @@
%td{:colspan => 4}
.exchange-select-all-variants
%label
= check_box_tag 'order_cycle_outgoing_exchange_{{ $parent.$index }}_select_all_variants', 1, 1, 'ng-model' => 'exchange.select_all_variants', 'ng-change' => 'setExchangeVariants(exchange, incomingExchangeVariantsFor(exchange.enterprise_id), exchange.select_all_variants)', 'id' => 'order_cycle_outgoing_exchange_{{ $parent.$index }}_select_all_variants'
Select all
.exchange-products
-# Scope product list based on permissions the current user has to view variants in this exchange
.exchange-product{'ng-repeat' => 'product in supplied_products | filter:productSuppliedToOrderCycle | visibleProducts:exchange:order_cycle.visible_variants_for_outgoing_exchanges | orderBy:"name"' }
.exchange-product-details
%label
-# MASTER_VARIANTS: No longer required
-# = check_box_tag 'order_cycle_outgoing_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}', 1, 1, 'ng-hide' => 'product.variants.length > 0', 'ng-model' => 'exchange.variants[product.master_id]', 'id' => 'order_cycle_outgoing_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}',
-# 'ng-disabled' => 'product.variants.length > 0 || !order_cycle.editable_variants_for_outgoing_exchanges.hasOwnProperty(exchange.enterprise_id) || order_cycle.editable_variants_for_outgoing_exchanges[exchange.enterprise_id].indexOf(product.master_id) < 0'
%img{'ng-src' => '{{ product.image_url }}'}
.name {{ product.name }}
.supplier {{ product.supplier_name }}
.exchange-product-variant{'ng-repeat' => 'variant in product.variants | visibleVariants:exchange:order_cycle.visible_variants_for_outgoing_exchanges | filter:variantSuppliedToOrderCycle'}
%label
= check_box_tag 'order_cycle_outgoing_exchange_{{ $parent.$parent.$index }}_variants_{{ variant.id }}', 1, 1, 'ng-model' => 'exchange.variants[variant.id]', 'id' => 'order_cycle_outgoing_exchange_{{ $parent.$parent.$index }}_variants_{{ variant.id }}',
'ng-disabled' => '!order_cycle.editable_variants_for_outgoing_exchanges.hasOwnProperty(exchange.enterprise_id) || order_cycle.editable_variants_for_outgoing_exchanges[exchange.enterprise_id].indexOf(variant.id) < 0'
{{ variant.label }}

View File

@@ -1,29 +1,42 @@
%td{:class => "#{type}_name"} {{ enterprises[exchange.enterprise_id].name }}
%td.products
= f.submit 'Products', 'ng-click' => 'toggleProducts($event, exchange)'
{{ exchangeSelectedVariants(exchange) }} /
%tr{ ng: { class: "'#{type} #{type}-{{ exchange.enterprise_id }}'" } }
%td{:class => "#{type}_name"} {{ enterprises[exchange.enterprise_id].name }}
%td.products.panel-toggle.text-center{ name: "products" }
{{ exchangeSelectedVariants(exchange) }} /
- if type == 'supplier'
{{ enterpriseTotalVariants(enterprises[exchange.enterprise_id]) }}
- else
{{ (incomingExchangeVariantsFor(exchange.enterprise_id)).length }}
selected
- if type == 'supplier'
{{ enterpriseTotalVariants(enterprises[exchange.enterprise_id]) }}
- else
{{ (incomingExchangeVariantsFor(exchange.enterprise_id)).length }}
selected
%td.receival-details
= text_field_tag 'order_cycle_incoming_exchange_{{ $index }}_receival_instructions', '', 'id' => 'order_cycle_incoming_exchange_{{ $index }}_receival_instructions', 'placeholder' => 'Receival instructions', 'ng-model' => 'exchange.receival_instructions'
- if type == 'distributor'
%td.tags.panel-toggle.text-center{ name: "tags", ng: { if: 'enterprises[exchange.enterprise_id].managed || order_cycle.viewing_as_coordinator' } }
{{ exchange.tags.length }}
%td.collection-details
= text_field_tag 'order_cycle_outgoing_exchange_{{ $index }}_pickup_time', '', 'id' => 'order_cycle_outgoing_exchange_{{ $index }}_pickup_time', 'placeholder' => 'Ready for (ie. Date / Time)', 'ng-model' => 'exchange.pickup_time', 'ng-disabled' => '!enterprises[exchange.enterprise_id].managed && !order_cycle.viewing_as_coordinator'
%br/
= text_field_tag 'order_cycle_outgoing_exchange_{{ $index }}_pickup_instructions', '', 'id' => 'order_cycle_outgoing_exchange_{{ $index }}_pickup_instructions', 'placeholder' => 'Pick-up instructions', 'ng-model' => 'exchange.pickup_instructions', 'ng-disabled' => '!enterprises[exchange.enterprise_id].managed && !order_cycle.viewing_as_coordinator'
%td.fees
%ol{ ng: { show: 'enterprises[exchange.enterprise_id].managed || order_cycle.viewing_as_coordinator' } }
%li{'ng-repeat' => 'enterprise_fee in exchange.enterprise_fees'}
= select_tag 'order_cycle_{{ exchangeDirection(exchange) }}_exchange_{{ $parent.$index }}_enterprise_fees_{{ $index }}_enterprise_id', nil, {'id' => 'order_cycle_{{ exchangeDirection(exchange) }}_exchange_{{ $parent.$index }}_enterprise_fees_{{ $index }}_enterprise_id', 'ng-model' => 'enterprise_fee.enterprise_id', 'ng-options' => 'enterprise.id as enterprise.name for enterprise in enterprisesWithFees()'}
= select_tag 'order_cycle_{{ exchangeDirection(exchange) }}_exchange_{{ $parent.$index }}_enterprise_fees_{{ $index }}_enterprise_fee_id', nil, {'id' => 'order_cycle_{{ exchangeDirection(exchange) }}_exchange_{{ $parent.$index }}_enterprise_fees_{{ $index }}_enterprise_fee_id', 'ng-model' => 'enterprise_fee.id', 'ng-options' => 'enterprise_fee.id as enterprise_fee.name for enterprise_fee in enterpriseFeesForEnterprise(enterprise_fee.enterprise_id)'}
= link_to 'Remove', '#', {'id' => 'order_cycle_{{ exchangeDirection(exchange) }}_exchange_{{ $parent.$index }}_enterprise_fees_{{ $index }}_remove', 'ng-click' => 'removeExchangeFee($event, exchange, $index)'}
= f.submit 'Add fee', 'ng-click' => 'addExchangeFee($event, exchange)', 'ng-hide' => '!enterprises[exchange.enterprise_id].managed && !order_cycle.viewing_as_coordinator'
%td.actions
%a{'ng-click' => 'removeExchange($event, exchange)', :class => "icon-trash no-text remove-exchange"}
- if type == 'supplier'
%td.receival-details
= text_field_tag 'order_cycle_incoming_exchange_{{ $index }}_receival_instructions', '', 'id' => 'order_cycle_incoming_exchange_{{ $index }}_receival_instructions', 'placeholder' => 'Receival instructions', 'ng-model' => 'exchange.receival_instructions'
%tr.panel-row{ object: "exchange",
panels: "{products: 'exchange_supplied_products'}",
locals: "$index,order_cycle,exchange,enterprises,setExchangeVariants,suppliedVariants,removeDistributionOfVariant",
colspan: 4 }
- if type == 'distributor'
%td.collection-details
= text_field_tag 'order_cycle_outgoing_exchange_{{ $index }}_pickup_time', '', 'id' => 'order_cycle_outgoing_exchange_{{ $index }}_pickup_time', 'placeholder' => 'Ready for (ie. Date / Time)', 'ng-model' => 'exchange.pickup_time', 'ng-disabled' => '!enterprises[exchange.enterprise_id].managed && !order_cycle.viewing_as_coordinator'
%br/
= text_field_tag 'order_cycle_outgoing_exchange_{{ $index }}_pickup_instructions', '', 'id' => 'order_cycle_outgoing_exchange_{{ $index }}_pickup_instructions', 'placeholder' => 'Pick-up instructions', 'ng-model' => 'exchange.pickup_instructions', 'ng-disabled' => '!enterprises[exchange.enterprise_id].managed && !order_cycle.viewing_as_coordinator'
%td.fees
%ol{ ng: { show: 'enterprises[exchange.enterprise_id].managed || order_cycle.viewing_as_coordinator' } }
%li{'ng-repeat' => 'enterprise_fee in exchange.enterprise_fees'}
= select_tag 'order_cycle_{{ exchangeDirection(exchange) }}_exchange_{{ $parent.$index }}_enterprise_fees_{{ $index }}_enterprise_id', nil, {'id' => 'order_cycle_{{ exchangeDirection(exchange) }}_exchange_{{ $parent.$index }}_enterprise_fees_{{ $index }}_enterprise_id', 'ng-model' => 'enterprise_fee.enterprise_id', 'ng-options' => 'enterprise.id as enterprise.name for enterprise in enterprisesWithFees()'}
= select_tag 'order_cycle_{{ exchangeDirection(exchange) }}_exchange_{{ $parent.$index }}_enterprise_fees_{{ $index }}_enterprise_fee_id', nil, {'id' => 'order_cycle_{{ exchangeDirection(exchange) }}_exchange_{{ $parent.$index }}_enterprise_fees_{{ $index }}_enterprise_fee_id', 'ng-model' => 'enterprise_fee.id', 'ng-options' => 'enterprise_fee.id as enterprise_fee.name for enterprise_fee in enterpriseFeesForEnterprise(enterprise_fee.enterprise_id)'}
= link_to 'Remove', '#', {'id' => 'order_cycle_{{ exchangeDirection(exchange) }}_exchange_{{ $parent.$index }}_enterprise_fees_{{ $index }}_remove', 'ng-click' => 'removeExchangeFee($event, exchange, $index)'}
= f.submit 'Add fee', 'ng-click' => 'addExchangeFee($event, exchange)', 'ng-hide' => '!enterprises[exchange.enterprise_id].managed && !order_cycle.viewing_as_coordinator'
%td.actions
%a{'ng-click' => 'removeExchange($event, exchange)', :class => "icon-trash no-text remove-exchange"}
%tr.panel-row{ object: "exchange",
panels: "{products: 'exchange_distributed_products', tags: 'exchange_tags'}",
locals: "$index,order_cycle,exchange,supplied_products,setExchangeVariants,incomingExchangeVariantsFor,productSuppliedToOrderCycle,variantSuppliedToOrderCycle",
colspan: 5 }

View File

@@ -17,11 +17,8 @@
%th Receival details
%th Fees
%th.actions
%tbody{'ng-repeat' => 'exchange in order_cycle.incoming_exchanges'}
%tr{'class' => "supplier supplier-{{ exchange.enterprise_id }}"}
= render 'exchange_form', :f => f, :type => 'supplier'
%tr.products{'ng-show' => 'exchange.showProducts'}
= render 'exchange_supplied_products_form'
%tbody.panel-ctrl{ object: 'exchange', 'ng-repeat' => 'exchange in order_cycle.incoming_exchanges'}
= render 'exchange_form', :f => f, :type => 'supplier'
- if Enterprise.managed_by(spree_current_user).include? @order_cycle.coordinator
= render 'add_exchange_form', f: f, type: 'supplier'
@@ -37,14 +34,13 @@
%a{href: '#', 'ng-click' => "OrderCycle.toggleAllProducts('outgoing')"}
%span{'ng-show' => "OrderCycle.showProducts['outgoing']"} Collapse all
%span{'ng-hide' => "OrderCycle.showProducts['outgoing']"} Expand all
%th{ ng: { if: 'enterprises[exchange.enterprise_id].managed || order_cycle.viewing_as_coordinator' } } Tags
%th Pickup / Delivery details
%th Fees
%th.actions
%tbody{'ng-repeat' => 'exchange in order_cycle.outgoing_exchanges'}
%tr{'class' => "distributor distributor-{{ exchange.enterprise_id }}"}
= render 'exchange_form', :f => f, :type => 'distributor'
%tr.products{'ng-show' => 'exchange.showProducts'}
= render 'exchange_distributed_products_form'
%tbody.panel-ctrl{ object: 'exchange', 'ng-repeat' => 'exchange in order_cycle.outgoing_exchanges'}
= render 'exchange_form', :f => f, :type => 'distributor'
- if Enterprise.managed_by(spree_current_user).include? @order_cycle.coordinator
= render 'add_exchange_form', f: f, type: 'distributor'

View File

@@ -14,7 +14,7 @@
%table.exchanges
%tbody{ng: {repeat: "exchange in order_cycle.incoming_exchanges"}}
%tr.products
= render 'exchange_supplied_products_form'
%td{ ng: { include: "'admin/panels/exchange_supplied_products.html'" } }
%br/
= label_tag 'Fees'

View File

@@ -42,13 +42,15 @@ module OpenFoodNetwork
{variant_ids: variant_ids,
enterprise_fee_ids: enterprise_fee_ids,
pickup_time: exchange[:pickup_time],
pickup_instructions: exchange[:pickup_instructions]})
pickup_instructions: exchange[:pickup_instructions],
tag_list: exchange[:tag_list]})
else
add_exchange(@order_cycle.coordinator_id, exchange[:enterprise_id], false,
{variant_ids: variant_ids,
enterprise_fee_ids: enterprise_fee_ids,
pickup_time: exchange[:pickup_time],
pickup_instructions: exchange[:pickup_instructions]})
pickup_instructions: exchange[:pickup_instructions],
tag_list: exchange[:tag_list]})
end
end
@@ -81,6 +83,7 @@ module OpenFoodNetwork
attrs.delete :enterprise_fee_ids
attrs.delete :pickup_time
attrs.delete :pickup_instructions
attrs.delete :tag_list
end
if permission_for exchange

View File

@@ -103,7 +103,7 @@ feature %q{
select 'My supplier', from: 'new_supplier_id'
click_button 'Add supplier'
fill_in 'order_cycle_incoming_exchange_0_receival_instructions', with: 'receival instructions'
page.find('table.exchanges tr.supplier td.products input').click
page.find('table.exchanges tr.supplier td.products').click
check "order_cycle_incoming_exchange_0_variants_#{v1.id}"
check "order_cycle_incoming_exchange_0_variants_#{v2.id}"
@@ -124,10 +124,15 @@ feature %q{
fill_in 'order_cycle_outgoing_exchange_0_pickup_time', with: 'pickup time'
fill_in 'order_cycle_outgoing_exchange_0_pickup_instructions', with: 'pickup instructions'
page.find('table.exchanges tr.distributor td.products input').click
page.find('table.exchanges tr.distributor td.products').click
check "order_cycle_outgoing_exchange_0_variants_#{v1.id}"
check "order_cycle_outgoing_exchange_0_variants_#{v2.id}"
page.find('table.exchanges tr.distributor td.tags').click
within ".exchange-tags" do
find(:css, "tags-input .tags input").set "wholesale\n"
end
# And I add a distributor fee
within("tr.distributor-#{distributor.id}") { click_button 'Add fee' }
select 'My distributor', from: 'order_cycle_outgoing_exchange_0_enterprise_fees_0_enterprise_id'
@@ -165,6 +170,7 @@ feature %q{
exchange = oc.exchanges.outgoing.first
exchange.pickup_time.should == 'pickup time'
exchange.pickup_instructions.should == 'pickup instructions'
exchange.tag_list.should == ['wholesale']
end
@@ -196,13 +202,13 @@ feature %q{
page.should have_field 'order_cycle_incoming_exchange_1_receival_instructions', with: 'instructions 1'
# And the suppliers should have products
page.all('table.exchanges tbody tr.supplier').each do |row|
row.find('td.products input').click
page.all('table.exchanges tbody tr.supplier').each_with_index do |row, i|
row.find('td.products').click
products_row = page.all('table.exchanges tr.products').select { |r| r.visible? }.first
products_row.should have_selector "input[type='checkbox'][checked='checked']"
products_panel = page.all('table.exchanges tr.panel-row .exchange-supplied-products').select { |r| r.visible? }.first
products_panel.should have_selector "input[name='order_cycle_incoming_exchange_#{i}_select_all_variants']"
row.find('td.products input').click
row.find('td.products').click
end
# And the suppliers should have fees
@@ -227,13 +233,13 @@ feature %q{
page.driver.resize(1280, 3600)
# And the distributors should have products
page.all('table.exchanges tbody tr.distributor').each do |row|
row.find('td.products input').click
page.all('table.exchanges tbody tr.distributor').each_with_index do |row, i|
row.find('td.products').click
products_row = page.all('table.exchanges tr.products').select { |r| r.visible? }.first
products_row.should have_selector "input[type='checkbox'][checked='checked']"
products_panel = page.all('table.exchanges tr.panel-row .exchange-distributed-products').select { |r| r.visible? }.first
products_panel.should have_selector "input[name='order_cycle_outgoing_exchange_#{i}_select_all_variants']"
row.find('td.products input').click
row.find('td.products').click
end
# And the distributors should have fees
@@ -323,7 +329,7 @@ feature %q{
# And I add a supplier and some products
select 'My supplier', from: 'new_supplier_id'
click_button 'Add supplier'
page.all("table.exchanges tr.supplier td.products input").each { |e| e.click }
page.all("table.exchanges tr.supplier td.products").each { |e| e.click }
page.should have_selector "#order_cycle_incoming_exchange_1_variants_#{initial_variants.last.id}", visible: true
page.find("#order_cycle_incoming_exchange_1_variants_#{initial_variants.last.id}", visible: true).click # uncheck (with visible:true filter)
@@ -349,7 +355,12 @@ feature %q{
fill_in 'order_cycle_outgoing_exchange_1_pickup_time', with: 'New time 1'
fill_in 'order_cycle_outgoing_exchange_1_pickup_instructions', with: 'New instructions 1'
page.all("table.exchanges tr.distributor td.products input").each { |e| e.click }
page.find("table.exchanges tr.distributor-#{distributor.id} td.tags").click
within ".exchange-tags" do
find(:css, "tags-input .tags input").set "wholesale\n"
end
page.all("table.exchanges tr.distributor td.products").each { |e| e.click }
uncheck "order_cycle_outgoing_exchange_2_variants_#{v1.id}"
check "order_cycle_outgoing_exchange_2_variants_#{v2.id}"
@@ -389,6 +400,9 @@ feature %q{
# And my distributor fees should have been configured
OrderCycle.last.exchanges.outgoing.last.enterprise_fee_ids.should == [distributor_fee2.id]
# And my tags should have been save
OrderCycle.last.exchanges.outgoing.last.tag_list.should == ['wholesale']
# And it should have some variants selected
selected_initial_variants = initial_variants.take initial_variants.size - 1
OrderCycle.last.variants.map(&:id).should match_array (selected_initial_variants.map(&:id) + [v1.id, v2.id])
@@ -465,7 +479,7 @@ feature %q{
login_to_admin_section
click_link 'Order Cycles'
click_link oc.name
within("table.exchanges tbody tr.supplier") { page.find('td.products input').click }
within("table.exchanges tbody tr.supplier") { page.find('td.products').click }
page.find("#order_cycle_incoming_exchange_0_variants_#{p.master.id}", visible: true).trigger('click') # uncheck
click_button "Update"
@@ -591,6 +605,11 @@ feature %q{
page.should_not have_select 'order_cycle_coordinator_id', with_options: [enterprise_name]
end
page.find("table.exchanges tr.distributor-#{distributor_managed.id} td.tags").click
within ".exchange-tags" do
find(:css, "tags-input .tags input").set "wholesale\n"
end
click_button 'Create'
flash_message.should == "Your order cycle has been created."
@@ -598,6 +617,8 @@ feature %q{
order_cycle.suppliers.should match_array [supplier_managed, supplier_permitted]
order_cycle.coordinator.should == distributor_managed
order_cycle.distributors.should match_array [distributor_managed, distributor_permitted]
exchange = order_cycle.exchanges.outgoing.to_enterprise(distributor_managed).first
exchange.tag_list.should == ["wholesale"]
end
scenario "editing an order cycle we can see (and for now, edit) all exchanges in the order cycle" do
@@ -614,12 +635,17 @@ feature %q{
expect(page).to have_selector "tr.supplier-#{supplier_managed.id}"
expect(page).to have_selector "tr.supplier-#{supplier_permitted.id}"
expect(page).to have_selector "tr.supplier-#{supplier_unmanaged.id}"
expect(page.all('tr.supplier').count).to be 3
expect(page).to have_selector 'tr.supplier', count: 3
expect(page).to have_selector "tr.distributor-#{distributor_managed.id}"
expect(page).to have_selector "tr.distributor-#{distributor_permitted.id}"
expect(page).to have_selector "tr.distributor-#{distributor_unmanaged.id}"
expect(page.all('tr.distributor').count).to be 3
expect(page).to have_selector 'tr.distributor', count: 3
# When I save, then those exchanges should remain
click_button 'Update'
page.should have_content "Your order cycle has been updated."
oc.reload
oc.suppliers.should match_array [supplier_managed, supplier_permitted, supplier_unmanaged]
@@ -640,7 +666,6 @@ feature %q{
page.find("tr.supplier-#{supplier_permitted.id} a.remove-exchange").click
page.find("tr.distributor-#{distributor_managed.id} a.remove-exchange").click
page.find("tr.distributor-#{distributor_permitted.id} a.remove-exchange").click
click_button 'Update'
# Then the exchanges should be removed
@@ -707,7 +732,7 @@ feature %q{
# Open the products list for managed_supplier's incoming exchange
within "tr.distributor-#{distributor_managed.id}" do
page.find("td.products input").click
page.find("td.products").click
end
# I should be able to see and toggle v1
@@ -716,6 +741,12 @@ feature %q{
# I should be able to see but not toggle v2, because I don't have permission
expect(page).to have_field "order_cycle_outgoing_exchange_0_variants_#{v2.id}", disabled: true
page.should_not have_selector "table.exchanges tr.distributor-#{distributor_managed.id} td.tags"
# When I save, any exchanges that I can't manage remain
click_button 'Update'
page.should have_content "Your order cycle has been updated."
oc.reload
oc.suppliers.should match_array [supplier_managed, supplier_permitted, supplier_unmanaged]
oc.coordinator.should == distributor_managed
@@ -759,7 +790,7 @@ feature %q{
# Open the products list for managed_supplier's incoming exchange
within "tr.supplier-#{supplier_managed.id}" do
page.find("td.products input").click
page.find("td.products").click
end
# I should be able to see and toggle v1
@@ -768,6 +799,12 @@ feature %q{
# I should be able to see but not toggle v2, because I don't have permission
expect(page).to have_field "order_cycle_incoming_exchange_0_variants_#{v2.id}", disabled: true
page.should have_selector "table.exchanges tr.distributor-#{my_distributor.id} td.tags"
# When I save, any exchange that I can't manage remains
click_button 'Update'
page.should have_content "Your order cycle has been updated."
oc.reload
oc.suppliers.should match_array [supplier_managed, supplier_permitted, supplier_unmanaged]
oc.coordinator.should == distributor_managed
@@ -956,7 +993,7 @@ feature %q{
private
def select_incoming_variant(supplier, exchange_no, variant)
page.find("table.exchanges tr.supplier-#{supplier.id} td.products input").click
page.find("table.exchanges tr.supplier-#{supplier.id} td.products").click
check "order_cycle_incoming_exchange_#{exchange_no}_variants_#{variant.id}"
end
end

View File

@@ -106,11 +106,6 @@ describe 'OrderCycle controllers', ->
{id: 2, name: 'Pepper Tree Place'}
])
it 'Delegates toggleProducts to OrderCycle', ->
scope.toggleProducts(event, 'exchange')
expect(event.preventDefault).toHaveBeenCalled()
expect(OrderCycle.toggleProducts).toHaveBeenCalledWith('exchange')
it 'Delegates enterpriseFeesForEnterprise to EnterpriseFee', ->
scope.enterpriseFeesForEnterprise('123')
expect(EnterpriseFee.forEnterprise).toHaveBeenCalledWith(123)
@@ -272,11 +267,6 @@ describe 'OrderCycle controllers', ->
{id: 2, name: 'Pepper Tree Place'}
])
it 'Delegates toggleProducts to OrderCycle', ->
scope.toggleProducts(event, 'exchange')
expect(event.preventDefault).toHaveBeenCalled()
expect(OrderCycle.toggleProducts).toHaveBeenCalledWith('exchange')
it 'Delegates enterpriseFeesForEnterprise to EnterpriseFee', ->
scope.enterpriseFeesForEnterprise('123')
expect(EnterpriseFee.forEnterprise).toHaveBeenCalledWith(123)
@@ -534,26 +524,6 @@ describe 'OrderCycle services', ->
OrderCycle.order_cycle.outgoing_exchanges = [exchange]
expect(OrderCycle.exchangeDirection(exchange)).toEqual 'outgoing'
describe 'toggling products', ->
exchange = null
beforeEach ->
exchange = {}
it 'sets a blank value to true', ->
OrderCycle.toggleProducts(exchange)
expect(exchange.showProducts).toEqual(true)
it 'sets a true value to false', ->
exchange.showProducts = true
OrderCycle.toggleProducts(exchange)
expect(exchange.showProducts).toEqual(false)
it 'sets a false value to true', ->
exchange.showProducts = false
OrderCycle.toggleProducts(exchange)
expect(exchange.showProducts).toEqual(true)
describe "setting exchange variants", ->
describe "when I have permissions to edit the variants", ->
beforeEach ->
@@ -598,7 +568,7 @@ describe 'OrderCycle services', ->
it 'adds the distributor to outgoing exchanges', ->
OrderCycle.addDistributor('123')
expect(OrderCycle.order_cycle.outgoing_exchanges).toEqual [
{enterprise_id: '123', incoming: false, active: true, variants: {}, enterprise_fees: []}
{enterprise_id: '123', incoming: false, active: true, variants: {}, enterprise_fees: [], tags: [], tag_list: ""}
]
describe 'removing exchanges', ->

View File

@@ -29,7 +29,7 @@ module OpenFoodNetwork
coordinator_id = 123
distributor_id = 456
outgoing_exchange = {:enterprise_id => distributor_id, :incoming => false, :variants => {'1' => true, '2' => false, '3' => true}, :enterprise_fee_ids => [1, 2], :pickup_time => 'pickup time', :pickup_instructions => 'pickup instructions'}
outgoing_exchange = {:enterprise_id => distributor_id, :incoming => false, :variants => {'1' => true, '2' => false, '3' => true}, :enterprise_fee_ids => [1, 2], :pickup_time => 'pickup time', :pickup_instructions => 'pickup instructions', tag_list: 'wholesale'}
oc = double(:order_cycle, :coordinator_id => coordinator_id, :exchanges => [], :incoming_exchanges => [], :outgoing_exchanges => [outgoing_exchange])
@@ -37,7 +37,7 @@ module OpenFoodNetwork
applicator.should_receive(:outgoing_exchange_variant_ids).with(outgoing_exchange).and_return([1, 3])
applicator.should_receive(:exchange_exists?).with(coordinator_id, distributor_id, false).and_return(false)
applicator.should_receive(:add_exchange).with(coordinator_id, distributor_id, false, {:variant_ids => [1, 3], :enterprise_fee_ids => [1, 2], :pickup_time => 'pickup time', :pickup_instructions => 'pickup instructions'})
applicator.should_receive(:add_exchange).with(coordinator_id, distributor_id, false, {:variant_ids => [1, 3], :enterprise_fee_ids => [1, 2], :pickup_time => 'pickup time', :pickup_instructions => 'pickup instructions', tag_list: 'wholesale'})
applicator.should_receive(:destroy_untouched_exchanges)
applicator.go!
@@ -69,7 +69,7 @@ module OpenFoodNetwork
coordinator_id = 123
distributor_id = 456
outgoing_exchange = {:enterprise_id => distributor_id, :incoming => false, :variants => {'1' => true, '2' => false, '3' => true}, :enterprise_fee_ids => [1, 2], :pickup_time => 'pickup time', :pickup_instructions => 'pickup instructions'}
outgoing_exchange = {:enterprise_id => distributor_id, :incoming => false, :variants => {'1' => true, '2' => false, '3' => true}, :enterprise_fee_ids => [1, 2], :pickup_time => 'pickup time', :pickup_instructions => 'pickup instructions', tag_list: 'wholesale'}
oc = double(:order_cycle,
:coordinator_id => coordinator_id,
@@ -81,7 +81,7 @@ module OpenFoodNetwork
applicator.should_receive(:outgoing_exchange_variant_ids).with(outgoing_exchange).and_return([1, 3])
applicator.should_receive(:exchange_exists?).with(coordinator_id, distributor_id, false).and_return(true)
applicator.should_receive(:update_exchange).with(coordinator_id, distributor_id, false, {:variant_ids => [1, 3], :enterprise_fee_ids => [1, 2], :pickup_time => 'pickup time', :pickup_instructions => 'pickup instructions'})
applicator.should_receive(:update_exchange).with(coordinator_id, distributor_id, false, {:variant_ids => [1, 3], :enterprise_fee_ids => [1, 2], :pickup_time => 'pickup time', :pickup_instructions => 'pickup instructions', tag_list: 'wholesale'})
applicator.should_receive(:destroy_untouched_exchanges)
applicator.go!
@@ -375,15 +375,16 @@ module OpenFoodNetwork
allow(applicator).to receive(:manager_for) { false }
allow(applicator).to receive(:permission_for) { true }
applicator.send(:touched_exchanges=, [])
applicator.send(:update_exchange, sender.id, receiver.id, incoming, {:variant_ids => [variant1.id, variant3.id], :enterprise_fee_ids => [enterprise_fee2.id, enterprise_fee3.id], :pickup_time => 'New Pickup Time', :pickup_instructions => 'New Pickup Instructions'})
applicator.send(:update_exchange, sender.id, receiver.id, incoming, {:variant_ids => [variant1.id, variant3.id], :enterprise_fee_ids => [enterprise_fee2.id, enterprise_fee3.id], :pickup_time => 'New Pickup Time', :pickup_instructions => 'New Pickup Instructions', tag_list: 'wholesale'})
end
it "updates the variants, enterprise fees and pickup information of the exchange" do
it "updates the variants, enterprise fees tags, and pickup information of the exchange" do
exchange.reload
expect(exchange.variants).to match_array [variant1, variant3]
expect(exchange.enterprise_fees).to match_array [enterprise_fee2, enterprise_fee3]
expect(exchange.pickup_time).to eq 'New Pickup Time'
expect(exchange.pickup_instructions).to eq 'New Pickup Instructions'
expect(exchange.tag_list).to eq ['wholesale']
expect(applicator.send(:touched_exchanges)).to eq [exchange]
end
end
@@ -394,15 +395,16 @@ module OpenFoodNetwork
allow(applicator).to receive(:manager_for) { true }
allow(applicator).to receive(:permission_for) { true }
applicator.send(:touched_exchanges=, [])
applicator.send(:update_exchange, sender.id, receiver.id, incoming, {:variant_ids => [variant1.id, variant3.id], :enterprise_fee_ids => [enterprise_fee2.id, enterprise_fee3.id], :pickup_time => 'New Pickup Time', :pickup_instructions => 'New Pickup Instructions'})
applicator.send(:update_exchange, sender.id, receiver.id, incoming, {:variant_ids => [variant1.id, variant3.id], :enterprise_fee_ids => [enterprise_fee2.id, enterprise_fee3.id], :pickup_time => 'New Pickup Time', :pickup_instructions => 'New Pickup Instructions', tag_list: 'wholesale'})
end
it "updates the variants, enterprise fees and pickup information of the exchange" do
it "updates the variants, enterprise fees, tags and pickup information of the exchange" do
exchange.reload
expect(exchange.variants).to match_array [variant1, variant3]
expect(exchange.enterprise_fees).to match_array [enterprise_fee2, enterprise_fee3]
expect(exchange.pickup_time).to eq 'New Pickup Time'
expect(exchange.pickup_instructions).to eq 'New Pickup Instructions'
expect(exchange.tag_list).to eq ['wholesale']
expect(applicator.send(:touched_exchanges)).to eq [exchange]
end
end
@@ -413,15 +415,16 @@ module OpenFoodNetwork
allow(applicator).to receive(:manager_for) { false }
allow(applicator).to receive(:permission_for) { true }
applicator.send(:touched_exchanges=, [])
applicator.send(:update_exchange, sender.id, receiver.id, incoming, {:variant_ids => [variant1.id, variant3.id], :enterprise_fee_ids => [enterprise_fee2.id, enterprise_fee3.id], :pickup_time => 'New Pickup Time', :pickup_instructions => 'New Pickup Instructions'})
applicator.send(:update_exchange, sender.id, receiver.id, incoming, {:variant_ids => [variant1.id, variant3.id], :enterprise_fee_ids => [enterprise_fee2.id, enterprise_fee3.id], :pickup_time => 'New Pickup Time', :pickup_instructions => 'New Pickup Instructions', tag_list: 'wholesale'})
end
it "updates the variants in the exchange, but not the fees or pickup information" do
it "updates the variants in the exchange, but not the fees, tags or pickup information" do
exchange.reload
expect(exchange.variants).to match_array [variant1, variant3]
expect(exchange.enterprise_fees).to match_array [enterprise_fee1, enterprise_fee2]
expect(exchange.pickup_time).to_not eq 'New Pickup Time'
expect(exchange.pickup_instructions).to_not eq 'New Pickup Instructions'
expect(exchange.tag_list).to eq []
expect(applicator.send(:touched_exchanges)).to eq [exchange]
end
end

View File

@@ -282,9 +282,11 @@ describe Exchange do
new_oc = create(:simple_order_cycle)
ex1 = oc.exchanges.last
ex1.update_attribute(:tag_list, "wholesale")
ex2 = ex1.clone! new_oc
ex1.eql?(ex2).should be_true
expect(ex2.reload.tag_list).to eq ["wholesale"]
end
describe "converting to hash" do