mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Delete angular ordersCtrl
This commit is contained in:
@@ -1,117 +0,0 @@
|
||||
angular.module("admin.orders").controller "ordersCtrl", ($scope, $timeout, RequestMonitor, Orders, SortOptions, $window, $filter, $location, KeyValueMapStore) ->
|
||||
$scope.RequestMonitor = RequestMonitor
|
||||
$scope.pagination = Orders.pagination
|
||||
$scope.orders = Orders.all
|
||||
$scope.sortOptions = SortOptions
|
||||
$scope.per_page_options = [
|
||||
{id: 15, name: t('js.admin.orders.index.per_page', results: 15)},
|
||||
{id: 50, name: t('js.admin.orders.index.per_page', results: 50)},
|
||||
{id: 100, name: t('js.admin.orders.index.per_page', results: 100)}
|
||||
]
|
||||
$scope.selected_orders = []
|
||||
$scope.checkboxes = {}
|
||||
$scope.selected = false
|
||||
$scope.select_all = false
|
||||
$scope.poll = 0
|
||||
$scope.rowStatus = {}
|
||||
|
||||
KeyValueMapStore.localStorageKey = 'ordersFilters'
|
||||
KeyValueMapStore.storableKeys = ["q", "sorting", "page", "per_page"]
|
||||
|
||||
$scope.initialise = ->
|
||||
unless KeyValueMapStore.restoreValues($scope)
|
||||
$scope.setDefaults()
|
||||
|
||||
$scope.fetchResults()
|
||||
|
||||
$scope.setDefaults = ->
|
||||
$scope.per_page = 15
|
||||
$scope.q = {
|
||||
completed_at_not_null: true
|
||||
}
|
||||
e = new CustomEvent("flatpickr_clear");
|
||||
window.dispatchEvent(e)
|
||||
|
||||
$scope.clearFilters = () ->
|
||||
KeyValueMapStore.clearKeyValueMap()
|
||||
$scope.setDefaults()
|
||||
$scope.fetchResults()
|
||||
|
||||
$scope.fetchResults = (page=1) ->
|
||||
startDateWithTime = $scope.appendStringIfNotEmpty($scope.q?.completed_at_gteq, ' 00:00:00')
|
||||
endDateWithTime = $scope.appendStringIfNotEmpty($scope.q?.completed_at_lteq, ' 23:59:59')
|
||||
|
||||
$scope.resetSelected()
|
||||
params = {
|
||||
'q[completed_at_gteq]': startDateWithTime,
|
||||
'q[completed_at_lteq]': endDateWithTime,
|
||||
'q[state_eq]': $scope.q?.state_eq,
|
||||
'q[number_cont]': $scope.q?.number_cont,
|
||||
'q[email_cont]': $scope.q?.email_cont,
|
||||
'q[bill_address_firstname_start]': $scope.q?.bill_address_firstname_start,
|
||||
'q[bill_address_lastname_start]': $scope.q?.bill_address_lastname_start,
|
||||
# Set default checkbox values to null. See: https://github.com/openfoodfoundation/openfoodnetwork/pull/3076#issuecomment-440010498
|
||||
'q[completed_at_not_null]': $scope.q?.completed_at_not_null || null,
|
||||
'q[distributor_id_in][]': $scope.q?.distributor_id_in,
|
||||
'q[order_cycle_id_in][]': $scope.q?.order_cycle_id_in,
|
||||
'q[s]': $scope.sorting || 'completed_at desc',
|
||||
shipping_method_id: $scope.q?.shipping_method_id,
|
||||
per_page: $scope.per_page,
|
||||
page: page
|
||||
}
|
||||
KeyValueMapStore.setStoredValues($scope)
|
||||
RequestMonitor.load(Orders.index(params).$promise)
|
||||
|
||||
$scope.appendStringIfNotEmpty = (baseString, stringToAppend) ->
|
||||
return baseString unless baseString
|
||||
return baseString if baseString.endsWith(stringToAppend)
|
||||
|
||||
baseString + stringToAppend
|
||||
|
||||
$scope.resetSelected = ->
|
||||
$scope.selected_orders.length = 0
|
||||
$scope.selected = false
|
||||
$scope.select_all = false
|
||||
$scope.checkboxes = {}
|
||||
|
||||
$scope.toggleSelection = (id) ->
|
||||
index = $scope.selected_orders.indexOf(id)
|
||||
|
||||
if index == -1
|
||||
$scope.selected_orders.push(id)
|
||||
else
|
||||
$scope.selected_orders.splice(index, 1)
|
||||
|
||||
$scope.toggleAll = ->
|
||||
$scope.selected_orders.length = 0
|
||||
$scope.orders.forEach (order) ->
|
||||
$scope.checkboxes[order.id] = $scope.select_all
|
||||
$scope.selected_orders.push order.id if $scope.select_all
|
||||
|
||||
$scope.$watch 'sortOptions', (sort) ->
|
||||
return unless sort && sort.predicate != ""
|
||||
|
||||
$scope.sorting = sort.getSortingExpr()
|
||||
$scope.fetchResults()
|
||||
, true
|
||||
|
||||
$scope.capturePayment = (order) ->
|
||||
$scope.rowAction('capture', order)
|
||||
|
||||
$scope.shipOrder = (order) ->
|
||||
$scope.rowAction('ship', order)
|
||||
|
||||
$scope.rowAction = (action, order) ->
|
||||
$scope.rowStatus[order.id] = "loading"
|
||||
|
||||
Orders[action](order).$promise.then (data) ->
|
||||
$scope.rowStatus[order.id] = "success"
|
||||
$timeout(->
|
||||
$scope.rowStatus[order.id] = null
|
||||
, 1500)
|
||||
, (error) ->
|
||||
$scope.rowStatus[order.id] = "error"
|
||||
|
||||
$scope.changePage = (newPage) ->
|
||||
$scope.page = newPage
|
||||
$scope.fetchResults(newPage)
|
||||
@@ -8,8 +8,8 @@
|
||||
%li= event_links
|
||||
= render partial: 'spree/admin/shared/order_links'
|
||||
- if can?(:admin, Spree::Order)
|
||||
%li{"ng-controller" => "ordersCtrl"}
|
||||
%a.button.icon-arrow-left{icon: 'icon-arrow-left', ng: { href: admin_orders_path }}
|
||||
%li
|
||||
%a.button.icon-arrow-left{icon: 'icon-arrow-left', href: admin_orders_path }
|
||||
= t(:back_to_orders_list)
|
||||
|
||||
= render partial: "spree/admin/shared/order_page_title"
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
describe "ordersCtrl", ->
|
||||
ctrl = null
|
||||
Orders = null
|
||||
$scope = null
|
||||
orders = [
|
||||
{ id: 8, order_cycle: { id: 4 }, distributor: { id: 5 }, number: "R123456" }
|
||||
{ id: 9, order_cycle: { id: 5 }, distributor: { id: 7 }, number: "R213776" }
|
||||
{ id: 10, order_cycle: { id: 6 }, distributor: { id: 8 }, number: "R213777" }
|
||||
]
|
||||
form = {
|
||||
q: {
|
||||
created_at_lt: ''
|
||||
created_at_gt: ''
|
||||
completed_at_not_null: true
|
||||
}
|
||||
}
|
||||
|
||||
beforeEach ->
|
||||
module 'admin.orders'
|
||||
inject ($controller, $rootScope, RequestMonitor, SortOptions) ->
|
||||
$scope = $rootScope.$new()
|
||||
Orders =
|
||||
index: jasmine.createSpy('index').and.returnValue(orders)
|
||||
all: orders
|
||||
ctrl = $controller 'ordersCtrl', { $scope: $scope, RequestMonitor: RequestMonitor, SortOptions: SortOptions, Orders: Orders }
|
||||
$scope.q = form.q
|
||||
|
||||
describe "initialising the controller", ->
|
||||
it "fetches orders", ->
|
||||
$scope.initialise()
|
||||
expect(Orders.index).toHaveBeenCalled()
|
||||
expect($scope.orders).toEqual orders
|
||||
|
||||
it "fetches them sorted by completed_at by default", ->
|
||||
$scope.initialise()
|
||||
expect(Orders.index).toHaveBeenCalledWith(jasmine.objectContaining({
|
||||
'q[s]': 'completed_at desc'
|
||||
}))
|
||||
|
||||
describe "using pagination", ->
|
||||
it "changes the page", ->
|
||||
$scope.changePage(2)
|
||||
expect($scope.page).toEqual 2
|
||||
expect(Orders.index).toHaveBeenCalled()
|
||||
|
||||
describe "sorting orders", ->
|
||||
it "sorts orders", ->
|
||||
spyOn $scope, "fetchResults"
|
||||
|
||||
$scope.sortOptions.toggle('number')
|
||||
$scope.$apply()
|
||||
|
||||
expect($scope.sorting).toEqual 'number asc'
|
||||
expect($scope.fetchResults).toHaveBeenCalled()
|
||||
|
||||
describe "filtering orders", ->
|
||||
it "filters orders by all selected order cycles", ->
|
||||
$scope['q']['order_cycle_id_in'] = ['4', '5']
|
||||
|
||||
$scope.fetchResults()
|
||||
|
||||
# Fetched with correct square brackets in field name for array value
|
||||
expect(Orders.index).toHaveBeenCalledWith(jasmine.objectContaining({
|
||||
'q[order_cycle_id_in][]': ['4', '5']
|
||||
}))
|
||||
|
||||
it "filters orders on inclusive dates", ->
|
||||
$scope['q']['completed_at_gteq'] = '2020-06-08'
|
||||
$scope['q']['completed_at_lteq'] = '2020-06-09'
|
||||
|
||||
$scope.fetchResults()
|
||||
|
||||
expect(Orders.index).toHaveBeenCalledWith(jasmine.objectContaining({
|
||||
'q[completed_at_gteq]': '2020-06-08 00:00:00'
|
||||
'q[completed_at_lteq]': '2020-06-09 23:59:59'
|
||||
}))
|
||||
Reference in New Issue
Block a user