mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-28 01:53:25 +00:00
Order cycle admin does not allow save until page is loaded
This commit is contained in:
@@ -6,6 +6,9 @@ angular.module('order_cycle', ['ngResource'])
|
||||
|
||||
$scope.order_cycle = OrderCycle.order_cycle
|
||||
|
||||
$scope.loaded = ->
|
||||
Enterprise.loaded && EnterpriseFee.loaded
|
||||
|
||||
$scope.exchangeSelectedVariants = (exchange) ->
|
||||
OrderCycle.exchangeSelectedVariants(exchange)
|
||||
|
||||
@@ -77,6 +80,9 @@ angular.module('order_cycle', ['ngResource'])
|
||||
order_cycle_id = $location.absUrl().match(/\/admin\/order_cycles\/(\d+)/)[1]
|
||||
$scope.order_cycle = OrderCycle.load(order_cycle_id)
|
||||
|
||||
$scope.loaded = ->
|
||||
Enterprise.loaded && EnterpriseFee.loaded && OrderCycle.loaded
|
||||
|
||||
$scope.exchangeSelectedVariants = (exchange) ->
|
||||
OrderCycle.exchangeSelectedVariants(exchange)
|
||||
|
||||
@@ -156,6 +162,8 @@ angular.module('order_cycle', ['ngResource'])
|
||||
outgoing_exchanges: []
|
||||
coordinator_fees: []
|
||||
|
||||
loaded: false
|
||||
|
||||
exchangeSelectedVariants: (exchange) ->
|
||||
numActiveVariants = 0
|
||||
numActiveVariants++ for id, active of exchange.variants when active
|
||||
@@ -225,9 +233,8 @@ angular.module('order_cycle', ['ngResource'])
|
||||
exchange.variants[variant_id] = false
|
||||
|
||||
load: (order_cycle_id) ->
|
||||
service = this
|
||||
|
||||
OrderCycle.get {order_cycle_id: order_cycle_id}, (oc) ->
|
||||
service = this
|
||||
OrderCycle.get {order_cycle_id: order_cycle_id}, (oc) ->
|
||||
angular.extend(service.order_cycle, oc)
|
||||
service.order_cycle.incoming_exchanges = []
|
||||
service.order_cycle.outgoing_exchanges = []
|
||||
@@ -245,7 +252,8 @@ angular.module('order_cycle', ['ngResource'])
|
||||
else
|
||||
console.log('Exchange between two enterprises, neither of which is coordinator!')
|
||||
|
||||
delete(service.order_cycle.exchanges)
|
||||
delete(service.order_cycle.exchanges)
|
||||
service.loaded = true
|
||||
|
||||
this.order_cycle
|
||||
|
||||
@@ -301,6 +309,7 @@ angular.module('order_cycle', ['ngResource'])
|
||||
Enterprise: Enterprise
|
||||
enterprises: {}
|
||||
supplied_products: []
|
||||
loaded: false
|
||||
|
||||
index: ->
|
||||
service = this
|
||||
@@ -312,6 +321,8 @@ angular.module('order_cycle', ['ngResource'])
|
||||
for product in enterprise.supplied_products
|
||||
service.supplied_products.push(product)
|
||||
|
||||
service.loaded = true
|
||||
|
||||
this.enterprises
|
||||
|
||||
totalVariants: (enterprise) ->
|
||||
@@ -329,9 +340,13 @@ angular.module('order_cycle', ['ngResource'])
|
||||
{
|
||||
EnterpriseFee: EnterpriseFee
|
||||
enterprise_fees: {}
|
||||
loaded: false
|
||||
|
||||
index: ->
|
||||
this.enterprise_fees = EnterpriseFee.index()
|
||||
service = this
|
||||
EnterpriseFee.index (data) ->
|
||||
service.enterprise_fees = data
|
||||
service.loaded = true
|
||||
|
||||
forEnterprise: (enterprise_id) ->
|
||||
enterprise_fee for enterprise_fee in this.enterprise_fees when enterprise_fee.enterprise_id == enterprise_id
|
||||
|
||||
@@ -54,15 +54,19 @@
|
||||
= f.submit 'Add distributor', 'ng-click' => 'addDistributor($event)'
|
||||
|
||||
.actions
|
||||
= f.submit @order_cycle.new_record? ? 'Create' : 'Update'
|
||||
or
|
||||
= link_to 'Cancel', main_app.admin_order_cycles_path
|
||||
= f.submit @order_cycle.new_record? ? 'Create' : 'Update', 'ng-disabled' => '!loaded()'
|
||||
%span{'ng-show' => 'loaded()'}
|
||||
or
|
||||
= link_to 'Cancel', main_app.admin_order_cycles_path
|
||||
%span{'ng-hide' => 'loaded()'} Loading...
|
||||
|
||||
|
||||
- unless Rails.env.production?
|
||||
#order-cycles-debug
|
||||
%h2 Debug information
|
||||
|
||||
%pre loaded = {{ loaded() | json }}
|
||||
%hr/
|
||||
%pre order_cycle = {{ order_cycle | json }}
|
||||
%hr/
|
||||
%pre enterprises = {{ enterprises | json }}
|
||||
|
||||
@@ -53,6 +53,16 @@ describe 'OrderCycle controllers', ->
|
||||
it 'Loads order cycles', ->
|
||||
expect(scope.order_cycle).toEqual('my order cycle')
|
||||
|
||||
describe 'Reporting when all resources are loaded', ->
|
||||
it 'returns true when Enterprise and EnterpriseFee are loaded', ->
|
||||
Enterprise.loaded = EnterpriseFee.loaded = true
|
||||
expect(scope.loaded()).toBe(true)
|
||||
|
||||
it 'returns false otherwise', ->
|
||||
Enterprise.loaded = true
|
||||
EnterpriseFee.loaded = false
|
||||
expect(scope.loaded()).toBe(false)
|
||||
|
||||
it 'Delegates exchangeSelectedVariants to OrderCycle', ->
|
||||
expect(scope.exchangeSelectedVariants('exchange')).toEqual('variants selected')
|
||||
expect(OrderCycle.exchangeSelectedVariants).toHaveBeenCalledWith('exchange')
|
||||
@@ -192,6 +202,17 @@ describe 'OrderCycle controllers', ->
|
||||
it 'Loads order cycles', ->
|
||||
expect(OrderCycle.load).toHaveBeenCalledWith('27')
|
||||
|
||||
describe 'Reporting when all resources are loaded', ->
|
||||
it 'returns true when Enterprise, EnterpriseFee and OrderCycle are loaded', ->
|
||||
Enterprise.loaded = EnterpriseFee.loaded = OrderCycle.loaded = true
|
||||
expect(scope.loaded()).toBe(true)
|
||||
|
||||
it 'returns false otherwise', ->
|
||||
Enterprise.loaded = true
|
||||
EnterpriseFee.loaded = true
|
||||
OrderCycle.loaded = false
|
||||
expect(scope.loaded()).toBe(false)
|
||||
|
||||
it 'Delegates exchangeSelectedVariants to OrderCycle', ->
|
||||
expect(scope.exchangeSelectedVariants('exchange')).toEqual('variants selected')
|
||||
expect(OrderCycle.exchangeSelectedVariants).toHaveBeenCalledWith('exchange')
|
||||
@@ -300,6 +321,12 @@ describe 'OrderCycle services', ->
|
||||
2: new Enterprise.Enterprise({id: 2, name: 'Two', supplied_products: [3, 4]})
|
||||
3: new Enterprise.Enterprise({id: 3, name: 'Three', supplied_products: [5, 6]})
|
||||
|
||||
it 'reports its loadedness', ->
|
||||
expect(Enterprise.loaded).toBe(false)
|
||||
Enterprise.index()
|
||||
$httpBackend.flush()
|
||||
expect(Enterprise.loaded).toBe(true)
|
||||
|
||||
it 'collates all supplied products', ->
|
||||
enterprises = Enterprise.index()
|
||||
$httpBackend.flush()
|
||||
@@ -338,6 +365,12 @@ describe 'OrderCycle services', ->
|
||||
new EnterpriseFee.EnterpriseFee({id: 2, name: "FeeTwo", enterprise_id: 2})
|
||||
]
|
||||
|
||||
it 'reports its loadedness', ->
|
||||
expect(EnterpriseFee.loaded).toBe(false)
|
||||
EnterpriseFee.index()
|
||||
$httpBackend.flush()
|
||||
expect(EnterpriseFee.loaded).toBe(true)
|
||||
|
||||
it 'returns enterprise fees for an enterprise', ->
|
||||
all_enterprise_fees = EnterpriseFee.index()
|
||||
$httpBackend.flush()
|
||||
@@ -574,6 +607,13 @@ describe 'OrderCycle services', ->
|
||||
{variants: {123: false, 333: true}}
|
||||
]
|
||||
|
||||
describe 'loading an order cycle, reporting loadedness', ->
|
||||
it 'reports its loadedness', ->
|
||||
expect(OrderCycle.loaded).toBe(false)
|
||||
OrderCycle.load('123')
|
||||
$httpBackend.flush()
|
||||
expect(OrderCycle.loaded).toBe(true)
|
||||
|
||||
describe 'loading an order cycle', ->
|
||||
beforeEach ->
|
||||
OrderCycle.load('123')
|
||||
|
||||
Reference in New Issue
Block a user