mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-04 02:31:33 +00:00
Admin can view an order cycle in the simple edit form
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
angular.module('admin.order_cycles').controller "AdminSimpleEditOrderCycleCtrl", ($scope, $location, OrderCycle, Enterprise, EnterpriseFee) ->
|
||||
$scope.enterprises = Enterprise.index()
|
||||
$scope.enterprise_fees = EnterpriseFee.index()
|
||||
$scope.order_cycle = OrderCycle.load $scope.orderCycleId(), (order_cycle) =>
|
||||
$scope.init()
|
||||
|
||||
$scope.orderCycleId = ->
|
||||
$location.absUrl().match(/\/admin\/order_cycles\/(\d+)/)[1]
|
||||
|
||||
$scope.init = ->
|
||||
$scope.outgoing_exchange = OrderCycle.order_cycle.outgoing_exchanges[0]
|
||||
|
||||
$scope.enterpriseFeesForEnterprise = (enterprise_id) ->
|
||||
EnterpriseFee.forEnterprise(parseInt(enterprise_id))
|
||||
@@ -84,7 +84,7 @@ angular.module('admin.order_cycles').factory('OrderCycle', ($resource, $window)
|
||||
for exchange in this.order_cycle.outgoing_exchanges
|
||||
exchange.variants[variant_id] = false
|
||||
|
||||
load: (order_cycle_id) ->
|
||||
load: (order_cycle_id, callback=null) ->
|
||||
service = this
|
||||
OrderCycle.get {order_cycle_id: order_cycle_id}, (oc) ->
|
||||
angular.extend(service.order_cycle, oc)
|
||||
@@ -104,6 +104,8 @@ angular.module('admin.order_cycles').factory('OrderCycle', ($resource, $window)
|
||||
delete(service.order_cycle.exchanges)
|
||||
service.loaded = true
|
||||
|
||||
(callback || angular.noop)(service.order_cycle)
|
||||
|
||||
this.order_cycle
|
||||
|
||||
create: ->
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
%h1 Edit Order Cycle
|
||||
|
||||
= form_for [main_app, :admin, @order_cycle], :url => '', :html => {:class => 'ng order_cycle', 'ng-app' => 'admin.order_cycles', 'ng-controller' => 'AdminEditOrderCycleCtrl', 'ng-submit' => 'submit()'} do |f|
|
||||
= render 'form', :f => f
|
||||
- ng_controller = order_cycles_simple_view ? 'AdminSimpleEditOrderCycleCtrl' : 'AdminEditOrderCycleCtrl'
|
||||
|
||||
= form_for [main_app, :admin, @order_cycle], :url => '', :html => {:class => 'ng order_cycle', 'ng-app' => 'admin.order_cycles', 'ng-controller' => ng_controller, 'ng-submit' => 'submit()'} do |f|
|
||||
- if order_cycles_simple_view
|
||||
= render 'simple_form', f: f
|
||||
- else
|
||||
= render 'form', f: f
|
||||
|
||||
@@ -648,6 +648,37 @@ feature %q{
|
||||
ex.pickup_time.should == 'pickup time'
|
||||
ex.pickup_instructions.should == 'pickup instructions'
|
||||
end
|
||||
|
||||
scenario "editing an order cycle" do
|
||||
# Given an order cycle
|
||||
fee = create(:enterprise_fee, name: 'my fee', enterprise: enterprise)
|
||||
oc = create(:simple_order_cycle, suppliers: [enterprise], coordinator: enterprise, distributors: [enterprise], variants: [p1.master], coordinator_fees: [fee])
|
||||
|
||||
# And the order cycle has a pickup time and pickup instructions
|
||||
ex = oc.exchanges.outgoing.first
|
||||
ex.update_attributes! pickup_time: 'pickup time', pickup_instructions: 'pickup instructions'
|
||||
|
||||
# When I edit it
|
||||
login_to_admin_section
|
||||
click_link 'Order Cycles'
|
||||
click_link oc.name
|
||||
wait_until { page.find('#order_cycle_name').value.present? }
|
||||
|
||||
# Then I should see the basic settings
|
||||
page.should have_field 'order_cycle_name', with: oc.name
|
||||
page.should have_field 'order_cycle_orders_open_at', with: oc.orders_open_at.to_s
|
||||
page.should have_field 'order_cycle_orders_close_at', with: oc.orders_close_at.to_s
|
||||
page.should have_field 'order_cycle_outgoing_exchange_0_pickup_time', with: 'pickup time'
|
||||
page.should have_field 'order_cycle_outgoing_exchange_0_pickup_instructions', with: 'pickup instructions'
|
||||
|
||||
# And I should see the products
|
||||
page.should have_checked_field "order_cycle_incoming_exchange_0_variants_#{p1.master.id}"
|
||||
page.should have_unchecked_field "order_cycle_incoming_exchange_0_variants_#{p2.master.id}"
|
||||
page.should have_unchecked_field "order_cycle_incoming_exchange_0_variants_#{v.id}"
|
||||
|
||||
# And I should see the coordinator fees
|
||||
page.should have_select 'order_cycle_coordinator_fee_0_id', selected: 'my fee'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
describe "AdminSimpleEditOrderCycleCtrl", ->
|
||||
ctrl = null
|
||||
scope = {}
|
||||
location = {}
|
||||
OrderCycle = {}
|
||||
Enterprise = {}
|
||||
EnterpriseFee = {}
|
||||
incoming_exchange = {}
|
||||
outgoing_exchange = {}
|
||||
|
||||
beforeEach ->
|
||||
scope = {}
|
||||
location =
|
||||
absUrl: ->
|
||||
'example.com/admin/order_cycles/27/edit'
|
||||
OrderCycle =
|
||||
order_cycle:
|
||||
incoming_exchanges: [incoming_exchange]
|
||||
outgoing_exchanges: [outgoing_exchange]
|
||||
load: jasmine.createSpy()
|
||||
Enterprise =
|
||||
index: jasmine.createSpy()
|
||||
EnterpriseFee =
|
||||
index: jasmine.createSpy()
|
||||
|
||||
module('admin.order_cycles')
|
||||
inject ($controller) ->
|
||||
ctrl = $controller 'AdminSimpleEditOrderCycleCtrl', {$scope: scope, $location: location, OrderCycle: OrderCycle, Enterprise: Enterprise, EnterpriseFee: EnterpriseFee}
|
||||
|
||||
describe "initialisation", ->
|
||||
enterprise = {id: 123}
|
||||
enterprises = {123: enterprise}
|
||||
|
||||
beforeEach ->
|
||||
scope.init(enterprises)
|
||||
|
||||
it "sets the outgoing exchange", ->
|
||||
expect(scope.outgoing_exchange).toEqual outgoing_exchange
|
||||
Reference in New Issue
Block a user