From ae0f82b4790cb1c08170ac03c60d3ded6e8d0902 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Tue, 30 Jul 2013 10:19:38 +1000 Subject: [PATCH] Display only coordinator fees belonging to the selected coordinator --- .../admin/order_cycle.js.erb.coffee | 9 +++++++ app/views/admin/order_cycles/_form.html.haml | 2 +- .../unit/order_cycle_spec.js.coffee | 26 ++++++++++++++++--- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/admin/order_cycle.js.erb.coffee b/app/assets/javascripts/admin/order_cycle.js.erb.coffee index bf36171894..292aedb4b6 100644 --- a/app/assets/javascripts/admin/order_cycle.js.erb.coffee +++ b/app/assets/javascripts/admin/order_cycle.js.erb.coffee @@ -25,6 +25,9 @@ angular.module('order_cycle', ['ngResource']) $event.preventDefault() OrderCycle.toggleProducts(exchange) + $scope.enterpriseFeesForEnterprise = (enterprise_id) -> + EnterpriseFee.forEnterprise(parseInt(enterprise_id)) + $scope.addSupplier = ($event) -> $event.preventDefault() OrderCycle.addSupplier($scope.new_supplier_id) @@ -64,6 +67,9 @@ angular.module('order_cycle', ['ngResource']) $event.preventDefault() OrderCycle.toggleProducts(exchange) + $scope.enterpriseFeesForEnterprise = (enterprise_id) -> + EnterpriseFee.forEnterprise(parseInt(enterprise_id)) + $scope.addSupplier = ($event) -> $event.preventDefault() OrderCycle.addSupplier($scope.new_supplier_id) @@ -217,6 +223,9 @@ angular.module('order_cycle', ['ngResource']) index: -> this.enterprise_fees = EnterpriseFee.index() + + forEnterprise: (enterprise_id) -> + enterprise_fee for enterprise_fee in this.enterprise_fees when enterprise_fee.enterprise_id == enterprise_id }]) .directive('datetimepicker', ['$parse', ($parse) -> diff --git a/app/views/admin/order_cycles/_form.html.haml b/app/views/admin/order_cycles/_form.html.haml index 09936252a3..7ef327ce5a 100644 --- a/app/views/admin/order_cycles/_form.html.haml +++ b/app/views/admin/order_cycles/_form.html.haml @@ -34,7 +34,7 @@ %table %tr{'ng-repeat' => 'enterprise_fee in order_cycle.coordinator_fees'} - %td= select_tag 'order_cycle_coordinator_fee_{{ $index }}_id', nil, {'ng-model' => 'enterprise_fee.id', 'ng-options' => 'enterprise_fee.id as enterprise_fee.name for enterprise_fee in enterprise_fees'} + %td= select_tag 'order_cycle_coordinator_fee_{{ $index }}_id', nil, {'ng-model' => 'enterprise_fee.id', 'ng-options' => 'enterprise_fee.id as enterprise_fee.name for enterprise_fee in enterpriseFeesForEnterprise(order_cycle.coordinator_id)'} %h2 Outgoing diff --git a/spec/javascripts/unit/order_cycle_spec.js.coffee b/spec/javascripts/unit/order_cycle_spec.js.coffee index 314d2da22d..5498ab4f5a 100644 --- a/spec/javascripts/unit/order_cycle_spec.js.coffee +++ b/spec/javascripts/unit/order_cycle_spec.js.coffee @@ -27,6 +27,7 @@ describe 'OrderCycle controllers', -> totalVariants: jasmine.createSpy('totalVariants').andReturn('variants total') EnterpriseFee = index: jasmine.createSpy('index').andReturn('enterprise fees list') + forEnterprise: jasmine.createSpy('forEnterprise').andReturn('enterprise fees for enterprise') module('order_cycle') inject ($controller) -> @@ -66,6 +67,10 @@ describe 'OrderCycle controllers', -> expect(event.preventDefault).toHaveBeenCalled() expect(OrderCycle.toggleProducts).toHaveBeenCalledWith('exchange') + it 'Delegates enterpriseFeesForEnterprise to EnterpriseFee', -> + scope.enterpriseFeesForEnterprise('123') + expect(EnterpriseFee.forEnterprise).toHaveBeenCalledWith(123) + it 'Adds order cycle suppliers', -> scope.new_supplier_id = 'new supplier id' scope.addSupplier(event) @@ -113,6 +118,7 @@ describe 'OrderCycle controllers', -> totalVariants: jasmine.createSpy('totalVariants').andReturn('variants total') EnterpriseFee = index: jasmine.createSpy('index').andReturn('enterprise fees list') + forEnterprise: jasmine.createSpy('forEnterprise').andReturn('enterprise fees for enterprise') module('order_cycle') inject ($controller) -> @@ -151,6 +157,10 @@ describe 'OrderCycle controllers', -> expect(event.preventDefault).toHaveBeenCalled() expect(OrderCycle.toggleProducts).toHaveBeenCalledWith('exchange') + it 'Delegates enterpriseFeesForEnterprise to EnterpriseFee', -> + scope.enterpriseFeesForEnterprise('123') + expect(EnterpriseFee.forEnterprise).toHaveBeenCalledWith(123) + it 'Adds order cycle suppliers', -> scope.new_supplier_id = 'new supplier id' scope.addSupplier(event) @@ -218,16 +228,24 @@ describe 'OrderCycle services', -> EnterpriseFee = $injector.get('EnterpriseFee') $httpBackend = _$httpBackend_ $httpBackend.whenGET('/admin/enterprise_fees.json').respond [ - {id: 1, name: "Yayfee"} - {id: 2, name: "FeeTwo"} + {id: 1, name: "Yayfee", enterprise_id: 1} + {id: 2, name: "FeeTwo", enterprise_id: 2} ] it 'loads enterprise fees', -> enterprise_fees = EnterpriseFee.index() $httpBackend.flush() expect(enterprise_fees).toEqual [ - new EnterpriseFee.EnterpriseFee({id: 1, name: "Yayfee"}) - new EnterpriseFee.EnterpriseFee({id: 2, name: "FeeTwo"}) + new EnterpriseFee.EnterpriseFee({id: 1, name: "Yayfee", enterprise_id: 1}) + new EnterpriseFee.EnterpriseFee({id: 2, name: "FeeTwo", enterprise_id: 2}) + ] + + it 'returns enterprise fees for an enterprise', -> + all_enterprise_fees = EnterpriseFee.index() + $httpBackend.flush() + enterprise_fees = EnterpriseFee.forEnterprise(1) + expect(enterprise_fees).toEqual [ + new EnterpriseFee.EnterpriseFee({id: 1, name: "Yayfee", enterprise_id: 1}) ]