mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Split orders into 2 angular controllers
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
angular.module("admin.orders").controller "orderCtrl", ($scope, shops, orderCycles, $compile, $attrs, Orders) ->
|
||||
$scope.$compile = $compile
|
||||
$scope.shops = shops
|
||||
$scope.orderCycles = orderCycles
|
||||
|
||||
$scope.distributor_id = parseInt($attrs.ofnDistributorId)
|
||||
$scope.order_cycle_id = parseInt($attrs.ofnOrderCycleId)
|
||||
|
||||
$scope.validOrderCycle = (oc) ->
|
||||
$scope.orderCycleHasDistributor oc, parseInt($scope.distributor_id)
|
||||
|
||||
$scope.distributorHasOrderCycles = (distributor) ->
|
||||
(oc for oc in $scope.orderCycles when @orderCycleHasDistributor(oc, distributor.id)).length > 0
|
||||
|
||||
$scope.orderCycleHasDistributor = (oc, distributor_id) ->
|
||||
distributor_ids = (d.id for d in oc.distributors)
|
||||
distributor_ids.indexOf(distributor_id) != -1
|
||||
|
||||
$scope.distributionChosen = ->
|
||||
$scope.distributor_id && $scope.order_cycle_id
|
||||
|
||||
for oc in $scope.orderCycles
|
||||
oc.name_and_status = "#{oc.name} (#{oc.status})"
|
||||
|
||||
for shop in $scope.shops
|
||||
shop.disabled = !$scope.distributorHasOrderCycles(shop)
|
||||
@@ -1,11 +1,4 @@
|
||||
angular.module("admin.orders").controller "ordersCtrl", ($scope, $injector, RequestMonitor, $compile, $attrs, Orders, SortOptions) ->
|
||||
$scope.$compile = $compile
|
||||
$scope.shops = shops
|
||||
$scope.orderCycles = orderCycles
|
||||
|
||||
$scope.distributor_id = parseInt($attrs.ofnDistributorId)
|
||||
$scope.order_cycle_id = parseInt($attrs.ofnOrderCycleId)
|
||||
|
||||
angular.module("admin.orders").controller "ordersCtrl", ($scope, RequestMonitor, Orders, SortOptions) ->
|
||||
$scope.RequestMonitor = RequestMonitor
|
||||
$scope.pagination = Orders.pagination
|
||||
$scope.orders = Orders.all
|
||||
@@ -43,25 +36,6 @@ angular.module("admin.orders").controller "ordersCtrl", ($scope, $injector, Requ
|
||||
$scope.fetchResults()
|
||||
, true
|
||||
|
||||
$scope.validOrderCycle = (oc) ->
|
||||
$scope.orderCycleHasDistributor oc, parseInt($scope.distributor_id)
|
||||
|
||||
$scope.distributorHasOrderCycles = (distributor) ->
|
||||
(oc for oc in orderCycles when @orderCycleHasDistributor(oc, distributor.id)).length > 0
|
||||
|
||||
$scope.orderCycleHasDistributor = (oc, distributor_id) ->
|
||||
distributor_ids = (d.id for d in oc.distributors)
|
||||
distributor_ids.indexOf(distributor_id) != -1
|
||||
|
||||
$scope.distributionChosen = ->
|
||||
$scope.distributor_id && $scope.order_cycle_id
|
||||
|
||||
$scope.changePage = (newPage) ->
|
||||
$scope.page = newPage
|
||||
$scope.fetchResults(newPage)
|
||||
|
||||
for oc in $scope.orderCycles
|
||||
oc.name_and_status = "#{oc.name} (#{oc.status})"
|
||||
|
||||
for shop in $scope.shops
|
||||
shop.disabled = !$scope.distributorHasOrderCycles(shop)
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
%div{"data-hook" => "admin_order_edit_header"}
|
||||
= render 'spree/shared/error_messages', target: @order
|
||||
|
||||
%div{"ng-app" => "admin.orders", "ng-controller" => "ordersCtrl", "ofn-distributor-id" => @order.distributor_id, "ofn-order-cycle-id" => @order.order_cycle_id}
|
||||
%div{"ng-app" => "admin.orders", "ng-controller" => "orderCtrl", "ofn-distributor-id" => @order.distributor_id, "ofn-order-cycle-id" => @order.order_cycle_id}
|
||||
= render 'add_product'
|
||||
|
||||
%div{"data-hook" => "admin_order_edit_form"}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
%div{"data-hook" => "admin_order_new_header"}
|
||||
= render 'spree/shared/error_messages', :target => @order
|
||||
|
||||
%div{"ng-app" => "admin.orders", "ng-controller" => "ordersCtrl"}
|
||||
%div{"ng-app" => "admin.orders", "ng-controller" => "orderCtrl"}
|
||||
%div{"ng-show" => "distributionChosen()"}
|
||||
= render 'add_product'
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
%div{"data-hook" => "admin_order_new_header"}
|
||||
= render 'spree/shared/error_messages', :target => @order
|
||||
|
||||
%div{"ng-app" => "admin.orders", "ng-controller" => "ordersCtrl"}
|
||||
%div{"ng-app" => "admin.orders", "ng-controller" => "orderCtrl"}
|
||||
= form_for @order, url: admin_order_url(@order), method: :put do |f|
|
||||
= render 'spree/admin/orders/_form/distribution_fields'
|
||||
-# This param passed to stop validation error in next page due to no line items in order yet:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
describe "ordersCtrl", ->
|
||||
describe "orderCtrl", ->
|
||||
ctrl = null
|
||||
scope = {}
|
||||
attrs = {}
|
||||
@@ -7,25 +7,13 @@ describe "ordersCtrl", ->
|
||||
{id: 10, name: 'Ten', status: 'open', distributors: [{id: 1, name: 'One'}]}
|
||||
{id: 20, name: 'Twenty', status: 'closed', distributors: [{id: 2, name: 'Two', status: 'closed'}]}
|
||||
]
|
||||
SortOptions = {
|
||||
predicate: "",
|
||||
reverse: false
|
||||
}
|
||||
|
||||
beforeEach ->
|
||||
scope = {}
|
||||
shops = []
|
||||
orderCycles = [
|
||||
{id: 10, name: 'Ten', status: 'open', distributors: [{id: 1, name: 'One'}]}
|
||||
{id: 20, name: 'Twenty', status: 'closed', distributors: [{id: 2, name: 'Two', status: 'closed'}]}
|
||||
]
|
||||
|
||||
module 'admin.orders', ($provide)->
|
||||
$provide.provider('shops', shops)
|
||||
$provide.provider('orderCycles', orderCycles)
|
||||
inject (_$injector_, $controller) ->
|
||||
$injector = _$injector_
|
||||
ctrl = $controller 'ordersCtrl', {$scope: scope, $attrs: attrs, $injector: $injector, SortOptions: SortOptions}
|
||||
module 'admin.orders'
|
||||
inject ($controller) ->
|
||||
ctrl = $controller 'orderCtrl', {$scope: scope, $attrs: attrs, shops: shops, orderCycles: orderCycles}
|
||||
|
||||
it "initialises name_and_status", ->
|
||||
expect(scope.orderCycles[0].name_and_status).toEqual "Ten (open)"
|
||||
Reference in New Issue
Block a user