mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Dumping OrderCycle data via :javascript tags instead of ng-init, Angularising the selector stuff
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
Shop.factory 'OrderCycle', ($resource, Product) ->
|
||||
Shop.factory 'OrderCycle', ($resource, Product, orderCycleData) ->
|
||||
class OrderCycle
|
||||
@order_cycle = {
|
||||
order_cycle_id: null
|
||||
}
|
||||
|
||||
@order_cycle = orderCycleData
|
||||
@push_order_cycle: ->
|
||||
new $resource("/shop/order_cycle").save {order_cycle_id: @order_cycle.order_cycle_id}, ->
|
||||
new $resource("/shop/order_cycle").save {order_cycle_id: @order_cycle.order_cycle_id}, (order_data)->
|
||||
OrderCycle.order_cycle.orders_close_at = order_data.orders_close_at
|
||||
Product.update()
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
class OrderCycleSerializer < ActiveModel::Serializer
|
||||
attributes :orders_close_at
|
||||
attributes :orders_close_at, id: :order_cycle_id
|
||||
end
|
||||
|
||||
@@ -12,12 +12,14 @@
|
||||
%form.custom
|
||||
%strong.avenir Ready for
|
||||
%select.avenir#order_cycle_id{"ng-model" => "order_cycle.order_cycle_id",
|
||||
"ng-init" => "order_cycle.order_cycle_id = #{current_order_cycle.andand.id || nil}",
|
||||
"ng-change" => "changeOrderCycle()",
|
||||
"ng-options" => "oc.id as oc.time for oc in #{@order_cycles.map {|oc| {time: pickup_time(oc), id: oc.id}}.to_json}"}
|
||||
|
||||
:javascript
|
||||
angular.module('Shop').value('orderCycleData', #{OrderCycleSerializer.new(current_order_cycle).to_json})
|
||||
|
||||
%closing
|
||||
-#%img{src: "/icon/goes/here"}
|
||||
Orders close
|
||||
%strong= current_order_cycle.andand.orders_close_at.andand.strftime "%A %m"
|
||||
%strong {{ order_cycle.orders_close_at | date:'EEEE MM'}}
|
||||
|
||||
|
||||
@@ -6,10 +6,12 @@ describe 'OrderCycle service', ->
|
||||
}
|
||||
|
||||
beforeEach ->
|
||||
angular.module('Shop').value('orderCycleData', {})
|
||||
module 'Shop', ($provide)->
|
||||
$provide.value "Product", mockProduct
|
||||
null # IMPORTANT
|
||||
# You must return null because module() is a bit dumb
|
||||
|
||||
inject (_OrderCycle_, _$httpBackend_)->
|
||||
$httpBackend = _$httpBackend_
|
||||
OrderCycle = _OrderCycle_
|
||||
@@ -23,4 +25,11 @@ describe 'OrderCycle service', ->
|
||||
$httpBackend.flush()
|
||||
expect(mockProduct.update).toHaveBeenCalled()
|
||||
|
||||
it "updates the orders_close_at attr after update", ->
|
||||
datestring = "2013-12-20T00:00:00+11:00"
|
||||
$httpBackend.expectPOST("/shop/order_cycle").respond({orders_close_at: datestring})
|
||||
OrderCycle.push_order_cycle()
|
||||
$httpBackend.flush()
|
||||
expect(OrderCycle.order_cycle.orders_close_at).toEqual(datestring)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user