diff --git a/app/assets/javascripts/admin/order_cycles/controllers/outgoing_controller.js.coffee b/app/assets/javascripts/admin/order_cycles/controllers/outgoing_controller.js.coffee index 893666b1a5..ce5e348d05 100644 --- a/app/assets/javascripts/admin/order_cycles/controllers/outgoing_controller.js.coffee +++ b/app/assets/javascripts/admin/order_cycles/controllers/outgoing_controller.js.coffee @@ -1,8 +1,7 @@ angular.module('admin.orderCycles').controller 'AdminOrderCycleOutgoingCtrl', ($scope, $controller, $filter, $location, OrderCycle, ocInstance, StatusMessage) -> $controller('AdminOrderCycleExchangesCtrl', {$scope: $scope, ocInstance: ocInstance, $location: $location}) - $scope.productSuppliedToOrderCycle = (product) -> - OrderCycle.productSuppliedToOrderCycle(product) + $scope.view = 'outgoing' $scope.variantSuppliedToOrderCycle = (variant) -> OrderCycle.variantSuppliedToOrderCycle(variant) diff --git a/app/assets/javascripts/admin/order_cycles/services/order_cycle.js.coffee b/app/assets/javascripts/admin/order_cycles/services/order_cycle.js.coffee index 58493d0214..98f9b81406 100644 --- a/app/assets/javascripts/admin/order_cycles/services/order_cycle.js.coffee +++ b/app/assets/javascripts/admin/order_cycles/services/order_cycle.js.coffee @@ -71,18 +71,6 @@ angular.module('admin.orderCycles').factory 'OrderCycle', ($resource, $window, S removeExchangeFee: (exchange, index) -> exchange.enterprise_fees.splice(index, 1) - productSuppliedToOrderCycle: (product) -> - product_variant_ids = (variant.id for variant in product.variants) - variant_ids = [product.master_id].concat(product_variant_ids) - incomingExchangesVariants = this.incomingExchangesVariants() - - # TODO: This is an O(n^2) implementation of set intersection and thus is slooow. - # Use a better algorithm if needed. - # Also, incomingExchangesVariants is called every time, when it only needs to be - # called once per change to incoming variants. Some sort of caching? - ids = (variant_id for variant_id in variant_ids when incomingExchangesVariants.indexOf(variant_id) != -1) - ids.length > 0 - variantSuppliedToOrderCycle: (variant) -> this.incomingExchangesVariants().indexOf(variant.id) != -1 diff --git a/app/assets/javascripts/templates/admin/panels/exchange_distributed_products.html.haml b/app/assets/javascripts/templates/admin/panels/exchange_distributed_products.html.haml index 4253f54aae..5fe23e6826 100644 --- a/app/assets/javascripts/templates/admin/panels/exchange_distributed_products.html.haml +++ b/app/assets/javascripts/templates/admin/panels/exchange_distributed_products.html.haml @@ -11,7 +11,7 @@ .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' } + .exchange-product{'ng-repeat' => 'product in enterprises[exchange.enterprise_id].supplied_products | filter:visibleProducts:exchange:order_cycle.visible_variants_for_outgoing_exchanges' } .exchange-product-details %label %img{'ng-src' => '{{ product.image_url }}'} diff --git a/app/views/admin/order_cycles/_exchange_form.html.haml b/app/views/admin/order_cycles/_exchange_form.html.haml index 6e5a2c3df1..da9cf926f9 100644 --- a/app/views/admin/order_cycles/_exchange_form.html.haml +++ b/app/views/admin/order_cycles/_exchange_form.html.haml @@ -40,5 +40,5 @@ - if type == 'distributor' %tr.panel-row{ object: "exchange", panels: "{products: 'exchange_distributed_products', tags: 'exchange_tags'}", - locals: "$index,order_cycle,exchange,supplied_products,setExchangeVariants,incomingExchangeVariantsFor,productSuppliedToOrderCycle,variantSuppliedToOrderCycle", + locals: "$index,order_cycle,exchange,enterprises,setExchangeVariants,incomingExchangeVariantsFor,variantSuppliedToOrderCycle", colspan: 5 } diff --git a/spec/javascripts/unit/admin/order_cycles/controllers/outgoing_controller_spec.js.coffee b/spec/javascripts/unit/admin/order_cycles/controllers/outgoing_controller_spec.js.coffee index 1b206bb683..c8c138b17b 100644 --- a/spec/javascripts/unit/admin/order_cycles/controllers/outgoing_controller_spec.js.coffee +++ b/spec/javascripts/unit/admin/order_cycles/controllers/outgoing_controller_spec.js.coffee @@ -14,7 +14,6 @@ describe 'AdminOrderCycleOutgoingCtrl', -> absUrl: -> 'example.com/admin/order_cycles/27/edit' OrderCycle = - productSuppliedToOrderCycle: jasmine.createSpy('productSuppliedToOrderCycle').and.returnValue('product supplied') variantSuppliedToOrderCycle: jasmine.createSpy('variantSuppliedToOrderCycle').and.returnValue('variant supplied') ocInstance = {} @@ -22,10 +21,6 @@ describe 'AdminOrderCycleOutgoingCtrl', -> inject ($controller) -> ctrl = $controller 'AdminOrderCycleOutgoingCtrl', {$scope: scope, $location: location, OrderCycle: OrderCycle, Enterprise: Enterprise, EnterpriseFee: EnterpriseFee, ocInstance: ocInstance} - it 'Delegates productSuppliedToOrderCycle to OrderCycle', -> - expect(scope.productSuppliedToOrderCycle('product')).toEqual('product supplied') - expect(OrderCycle.productSuppliedToOrderCycle).toHaveBeenCalledWith('product') - it 'Delegates variantSuppliedToOrderCycle to OrderCycle', -> expect(scope.variantSuppliedToOrderCycle('variant')).toEqual('variant supplied') expect(OrderCycle.variantSuppliedToOrderCycle).toHaveBeenCalledWith('variant') diff --git a/spec/javascripts/unit/admin/order_cycles/services/order_cycle_spec.js.coffee b/spec/javascripts/unit/admin/order_cycles/services/order_cycle_spec.js.coffee index 4570f8d545..a078ec2bf4 100644 --- a/spec/javascripts/unit/admin/order_cycles/services/order_cycle_spec.js.coffee +++ b/spec/javascripts/unit/admin/order_cycles/services/order_cycle_spec.js.coffee @@ -232,42 +232,6 @@ describe 'OrderCycle service', -> ] expect(OrderCycle.incomingExchangesVariants()).toEqual [1, 4, 5] - describe 'checking whether a product is supplied to the order cycle', -> - product_master_present = product_variant_present = product_master_absent = product_variant_absent = null - - beforeEach -> - product_master_present = - name: "Linseed (500g)" - master_id: 1 - variants: [] - product_variant_present = - name: "Linseed (500g)" - master_id: 2 - variants: [{id: 3}, {id: 4}] - product_master_absent = - name: "Linseed (500g)" - master_id: 5 - variants: [] - product_variant_absent = - name: "Linseed (500g)" - master_id: 6 - variants: [{id: 7}, {id: 8}] - - spyOn(OrderCycle, 'incomingExchangesVariants').and.returnValue([1, 3]) - - it 'returns true for products whose master is supplied', -> - expect(OrderCycle.productSuppliedToOrderCycle(product_master_present)).toBeTruthy() - - it 'returns true for products for whom a variant is supplied', -> - expect(OrderCycle.productSuppliedToOrderCycle(product_variant_present)).toBeTruthy() - - it 'returns false for products whose master is not supplied', -> - expect(OrderCycle.productSuppliedToOrderCycle(product_master_absent)).toBeFalsy() - - it 'returns false for products whose variants are not supplied', -> - expect(OrderCycle.productSuppliedToOrderCycle(product_variant_absent)).toBeFalsy() - - describe 'checking whether a variant is supplied to the order cycle', -> beforeEach -> spyOn(OrderCycle, 'incomingExchangesVariants').and.returnValue([1, 3])