From 9c2e67e953399f6e25c3313a37f742afe1222b78 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 8 Dec 2016 12:02:58 +1100 Subject: [PATCH] Cancelling a standing order just changes the state, does not remove it from the page --- .../controllers/standing_orders_controller.js.coffee | 3 +-- .../services/standing_order_prototype.js.coffee | 4 +--- .../services/standing_orders.js.coffee | 12 ------------ app/views/admin/standing_orders/_table.html.haml | 2 +- spec/features/admin/standing_orders_spec.rb | 6 ++++-- .../standing_orders_controller_spec.js.coffee | 2 +- 6 files changed, 8 insertions(+), 21 deletions(-) diff --git a/app/assets/javascripts/admin/standing_orders/controllers/standing_orders_controller.js.coffee b/app/assets/javascripts/admin/standing_orders/controllers/standing_orders_controller.js.coffee index 08a5050740..f1a6eb830c 100644 --- a/app/assets/javascripts/admin/standing_orders/controllers/standing_orders_controller.js.coffee +++ b/app/assets/javascripts/admin/standing_orders/controllers/standing_orders_controller.js.coffee @@ -4,11 +4,10 @@ angular.module("admin.standingOrders").controller "StandingOrdersController", ($ $scope.shop_id = if shops.length == 1 then shops[0].id else null $scope.shippingMethodsByID = ShippingMethods.byID $scope.paymentMethodsByID = PaymentMethods.byID - $scope.standingOrders = StandingOrders.all $scope.$watch "shop_id", -> if $scope.shop_id? - StandingOrders.index("q[shop_id_eq]": $scope.shop_id, "q[canceled_at_null]": true) + $scope.standingOrders = StandingOrders.index("q[shop_id_eq]": $scope.shop_id, "q[canceled_at_null]": true) $scope.itemCount = (standingOrder) -> standingOrder.standing_line_items.reduce (sum, sli) -> diff --git a/app/assets/javascripts/admin/standing_orders/services/standing_order_prototype.js.coffee b/app/assets/javascripts/admin/standing_orders/services/standing_order_prototype.js.coffee index 231be61165..bfce8a1502 100644 --- a/app/assets/javascripts/admin/standing_orders/services/standing_order_prototype.js.coffee +++ b/app/assets/javascripts/admin/standing_orders/services/standing_order_prototype.js.coffee @@ -36,9 +36,7 @@ angular.module("admin.standingOrders").factory 'StandingOrderPrototype', ($http, cancel: -> ConfirmDialog.open('error', t('admin.standing_orders.confirm_cancel_msg'), {cancel: t('back'), confirm: t('yes_i_am_sure')}) .then => - @$cancel().then (response) => - $injector.get('StandingOrders').afterCancel(@) if $injector.has('StandingOrders') - , -> + @$cancel().then angular.noop, -> InfoDialog.open 'error', t('admin.standing_orders.cancel_failure_msg') pause: -> diff --git a/app/assets/javascripts/admin/standing_orders/services/standing_orders.js.coffee b/app/assets/javascripts/admin/standing_orders/services/standing_orders.js.coffee index 355a6156f8..0fe055c7bb 100644 --- a/app/assets/javascripts/admin/standing_orders/services/standing_orders.js.coffee +++ b/app/assets/javascripts/admin/standing_orders/services/standing_orders.js.coffee @@ -1,6 +1,5 @@ angular.module("admin.standingOrders").factory 'StandingOrders', ($q, StandingOrderResource, StandingOrder) -> new class StandingOrders - all: [] byID: {} pristineByID: {} @@ -9,9 +8,7 @@ angular.module("admin.standingOrders").factory 'StandingOrders', ($q, StandingOr @load(data) load: (standingOrders) -> - @clear() for standingOrder in standingOrders - @all.push standingOrder @byID[standingOrder.id] = standingOrder @pristineByID[standingOrder.id] = angular.copy(standingOrder) @@ -23,16 +20,7 @@ angular.module("admin.standingOrders").factory 'StandingOrders', ($q, StandingOr return unless @byID[id]? @pristineByID[id] = angular.copy(@byID[id]) - afterCancel: (item) -> - i = @all.indexOf(item) - @all.splice(i,1) if i >= 0 - delete @byID[item.id] - delete @pristineByID[item.id] - afterRemoveItem: (id, deletedItemID) -> return unless @pristineByID[id]? for item, i in @pristineByID[id].standing_line_items when item.id == deletedItemID @pristineByID[id].standing_line_items.splice(i, 1) - - clear: -> - @all.length = 0 diff --git a/app/views/admin/standing_orders/_table.html.haml b/app/views/admin/standing_orders/_table.html.haml index 3feed5a5c9..e5d3286d65 100644 --- a/app/views/admin/standing_orders/_table.html.haml +++ b/app/views/admin/standing_orders/_table.html.haml @@ -54,6 +54,6 @@ %a.edit-standing-order.icon-edit.no-text{ ng: { href: '{{standingOrder.edit_path}}'}, 'ofn-with-tip' => t('.edit_standing_order') } %a.pause-standing-order.icon-pause.no-text{ ng: { click: 'standingOrder.pause()', hide: '!!standingOrder.paused_at' }, 'ofn-with-tip' => t('.pause_standing_order') , href: 'javascript:void(0)' } %a.unpause-standing-order.icon-play.no-text{ ng: { click: 'standingOrder.unpause()', show: '!!standingOrder.paused_at' }, 'ofn-with-tip' => t('.unpause_standing_order') , href: 'javascript:void(0)' } - %a.cancel-standing-order.icon-remove.no-text{ ng: { click: 'standingOrder.cancel()'}, 'ofn-with-tip' => t('.cancel_standing_order') , href: 'javascript:void(0)' } + %a.cancel-standing-order.icon-remove.no-text{ ng: { click: 'standingOrder.cancel()', hide: '!!standingOrder.canceled_at'}, 'ofn-with-tip' => t('.cancel_standing_order') , href: 'javascript:void(0)' } %tr.panel-row{ object: "standingOrder", panels: "{products: 'standing_order_products', orders: 'standing_order_orders'}" } diff --git a/spec/features/admin/standing_orders_spec.rb b/spec/features/admin/standing_orders_spec.rb index 23b0bdd77d..c8167b8c11 100644 --- a/spec/features/admin/standing_orders_spec.rb +++ b/spec/features/admin/standing_orders_spec.rb @@ -123,8 +123,10 @@ feature 'Standing Orders' do find("a.cancel-standing-order").click end click_button "Yes, I'm sure" - expect(page).to have_no_selector "tr#so_#{standing_order.id}" - expect(standing_order.reload.canceled_at).to be_within(5.seconds).of Time.zone.now + within "tr#so_#{standing_order.id}" do + expect(page).to have_selector ".state.canceled", text: "CANCELLED" + expect(standing_order.reload.canceled_at).to be_within(5.seconds).of Time.zone.now + end end end diff --git a/spec/javascripts/unit/admin/standing_orders/controllers/standing_orders_controller_spec.js.coffee b/spec/javascripts/unit/admin/standing_orders/controllers/standing_orders_controller_spec.js.coffee index 18d15c6b58..c42b56c2e0 100644 --- a/spec/javascripts/unit/admin/standing_orders/controllers/standing_orders_controller_spec.js.coffee +++ b/spec/javascripts/unit/admin/standing_orders/controllers/standing_orders_controller_spec.js.coffee @@ -31,7 +31,7 @@ describe "StandingOrdersCtrl", -> standingOrders = [standingOrder] beforeEach -> - http.expectGET('/admin/standing_orders.json?q%5Bshop_id_eq%5D=3').respond 200, standingOrders + http.expectGET('/admin/standing_orders.json?q%5Bcanceled_at_null%5D=true&q%5Bshop_id_eq%5D=3').respond 200, standingOrders scope.$apply -> scope.shop_id = 3 http.flush()