From 3adfb0db3f7ede25568c6258232f8d7909081df5 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 16 Dec 2016 15:37:30 +1100 Subject: [PATCH] Issues with updating orders are reported when saving standing orders --- .../order_update_issues_controller.js.coffee | 10 ++++++++ .../standing_order_prototype.js.coffee | 3 +++ .../utils/services/info_dialog.js.coffee | 5 ++-- .../_order_update_issues_dialog.html.haml | 25 +++++++++++++++++++ .../standing_orders/_orders_panel.html.haml | 2 +- .../_standing_line_items.html.haml | 6 ++--- .../admin/standing_orders/edit.html.haml | 1 + .../admin/standing_orders/index.html.haml | 1 + app/views/admin/standing_orders/new.html.haml | 1 + config/locales/en.yml | 1 + spec/features/admin/standing_orders_spec.rb | 24 +++++++++++++++++- 11 files changed, 72 insertions(+), 7 deletions(-) create mode 100644 app/assets/javascripts/admin/standing_orders/controllers/order_update_issues_controller.js.coffee create mode 100644 app/views/admin/standing_orders/_order_update_issues_dialog.html.haml diff --git a/app/assets/javascripts/admin/standing_orders/controllers/order_update_issues_controller.js.coffee b/app/assets/javascripts/admin/standing_orders/controllers/order_update_issues_controller.js.coffee new file mode 100644 index 0000000000..5e8591b2f6 --- /dev/null +++ b/app/assets/javascripts/admin/standing_orders/controllers/order_update_issues_controller.js.coffee @@ -0,0 +1,10 @@ +angular.module("admin.standingOrders").controller "OrderUpdateIssuesController", ($scope, OrderCycles) -> + $scope.proxyOrders = $scope.options.proxyOrders + + $scope.orderCycleName = (id) -> + OrderCycles.byID[id].name + + $scope.orderCycleCloses = (id) -> + closes_at = moment(OrderCycles.byID[id].orders_close_at) + text = if closes_at > moment() then t('closes') else t('closed') + "#{text} #{closes_at.fromNow()}" 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 4f9e17311d..3ed59df1af 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 @@ -29,6 +29,9 @@ angular.module("admin.standingOrders").factory 'StandingOrderPrototype', ($http, @$update().then (response) => StatusMessage.display 'success', 'Saved' $injector.get('StandingOrders').afterUpdate(@id) if $injector.has('StandingOrders') + orders_with_issues = @not_closed_proxy_orders.filter((po) -> po.update_issues.length > 0) + if orders_with_issues.length > 0 + InfoDialog.open('error', null, 'admin/order_update_issues_dialog.html', { proxyOrders: orders_with_issues}) , (response) => StatusMessage.display 'failure', 'Oh no! I was unable to save your changes.' angular.extend(@errors, response.data.errors) diff --git a/app/assets/javascripts/admin/utils/services/info_dialog.js.coffee b/app/assets/javascripts/admin/utils/services/info_dialog.js.coffee index 4d6e7a9d94..83809333fa 100644 --- a/app/assets/javascripts/admin/utils/services/info_dialog.js.coffee +++ b/app/assets/javascripts/admin/utils/services/info_dialog.js.coffee @@ -1,10 +1,11 @@ angular.module("admin.utils").factory 'InfoDialog', ($rootScope, $compile, $injector, $templateCache, DialogDefaults) -> new class InfoDialog - open: (type, message) -> + open: (type, message, templateUrl='admin/info_dialog.html', options={}) -> scope = $rootScope.$new() scope.message = message scope.dialog_class = type - template = $compile($templateCache.get('admin/info_dialog.html'))(scope) + scope.options = options + template = $compile($templateCache.get(templateUrl))(scope) template.dialog(DialogDefaults) template.dialog('open') scope.close = -> diff --git a/app/views/admin/standing_orders/_order_update_issues_dialog.html.haml b/app/views/admin/standing_orders/_order_update_issues_dialog.html.haml new file mode 100644 index 0000000000..ed38b101e9 --- /dev/null +++ b/app/views/admin/standing_orders/_order_update_issues_dialog.html.haml @@ -0,0 +1,25 @@ +%script{ type: "text/ng-template", id: "admin/order_update_issues_dialog.html" } + #order_update_issues_dialog + .message.clearfix.margin-bottom-30 + .text=t("admin.standing_orders.order_update_issues_msg") + %div{ ng: { controller: 'OrderUpdateIssuesController' } } + %table + %col{ style: 'width: 30%' } + %col{ style: 'width: 30%' } + %col{ style: 'width: 40%' } + %thead + %th= t('admin.standing_orders.number') + %th= t('admin.order_cycle') + %th= t('admin.standing_orders.issue') + %tbody + %tr.proxy_order{ :id => "ppo_{{proxyOrder.id}}", ng: { repeat: 'proxyOrder in options.proxyOrders' } } + %td + %a{ href: '{{::proxyOrder.edit_path}}', target: '_blank', ng: { bind: '::proxyOrder.number' } } + %td + %div{ ng: { bind: "::orderCycleName(proxyOrder.order_cycle_id)" } } + %div{ ng: { bind: "::orderCycleCloses(proxyOrder.order_cycle_id)" } } + %td.text-center{ ng: { bind: "proxyOrder.update_issues.join(', ')" } } + + .action-buttons.text-center + %button{ ng: { click: "close()" } } + OK diff --git a/app/views/admin/standing_orders/_orders_panel.html.haml b/app/views/admin/standing_orders/_orders_panel.html.haml index d569976016..4da549697e 100644 --- a/app/views/admin/standing_orders/_orders_panel.html.haml +++ b/app/views/admin/standing_orders/_orders_panel.html.haml @@ -21,6 +21,6 @@ %span.state{ ng: { class: "proxyOrder.state", bind: 'stateText(proxyOrder.state)' } } %td.text-center{ ng: { bind: 'proxyOrder.total | currency' } } %td.actions - %a.edit-order.icon-edit.no-text{ href: '{{::proxyOrder.edit_path}}', 'ofn-with-tip' => t(:edit_order) } + %a.edit-order.icon-edit.no-text{ href: '{{::proxyOrder.edit_path}}', target: '_blank', 'ofn-with-tip' => t(:edit_order) } %a.cancel-order.icon-remove.no-text{ href: 'javascript:void(0)', ng: { hide: "proxyOrder.state == 'canceled'", click: "cancelOrder(proxyOrder)" }, 'ofn-with-tip' => t(:cancel_order) } %a.resume-order.icon-resume.no-text{ href: 'javascript:void(0)', ng: { show: "proxyOrder.state == 'canceled'", click: "resumeOrder(proxyOrder)" }, 'ofn-with-tip' => t(:resume_order) } diff --git a/app/views/admin/standing_orders/_standing_line_items.html.haml b/app/views/admin/standing_orders/_standing_line_items.html.haml index f14e72cab3..4d665d9f10 100644 --- a/app/views/admin/standing_orders/_standing_line_items.html.haml +++ b/app/views/admin/standing_orders/_standing_line_items.html.haml @@ -9,7 +9,7 @@ %tr %th= t(:item_description) %th.price= t(:price) - %th.qty= t(:qty) + %th.quantity= t(:qty) %th.total %span= t(:total) %th.orders-actions.actions @@ -17,8 +17,8 @@ %tr.item{ id: "sli_{{$index}}", ng: { repeat: "item in standingOrder.standing_line_items | filter:{ _destroy: '!true' }", class: { even: 'even', odd: 'odd' } } } %td.description {{ item.description }} %td.price.align-center {{ item.price_estimate | currency }} - %td.qty - %input.qty{ name: 'quantity', type: 'number', min: 0, ng: { model: 'item.quantity' } } + %td.quantity + %input{ name: 'quantity', type: 'number', min: 0, ng: { model: 'item.quantity' } } %td.total.align-center {{ (item.price_estimate * item.quantity) | currency }} %td.actions %a.delete-item.icon-trash.no-text{ ng: { click: 'removeStandingLineItem(item)'}, :href => "javascript:void(0)" } diff --git a/app/views/admin/standing_orders/edit.html.haml b/app/views/admin/standing_orders/edit.html.haml index e5c440c655..06856c00b8 100644 --- a/app/views/admin/standing_orders/edit.html.haml +++ b/app/views/admin/standing_orders/edit.html.haml @@ -6,4 +6,5 @@ %div{ ng: { app: 'admin.standingOrders', controller: 'StandingOrderController', cloak: true } } = render 'data' + = render 'order_update_issues_dialog' = render 'form' diff --git a/app/views/admin/standing_orders/index.html.haml b/app/views/admin/standing_orders/index.html.haml index d19b23de89..80eb5b5c4c 100644 --- a/app/views/admin/standing_orders/index.html.haml +++ b/app/views/admin/standing_orders/index.html.haml @@ -11,6 +11,7 @@ = admin_inject_column_preferences module: 'admin.standingOrders' = render 'data' += render 'order_update_issues_dialog' %div{ ng: { controller: 'StandingOrdersController' } } = render 'filters' diff --git a/app/views/admin/standing_orders/new.html.haml b/app/views/admin/standing_orders/new.html.haml index da3ee1da0b..c928c0e791 100644 --- a/app/views/admin/standing_orders/new.html.haml +++ b/app/views/admin/standing_orders/new.html.haml @@ -9,4 +9,5 @@ %div{ ng: { app: 'admin.standingOrders', controller: 'StandingOrderController', cloak: true } } = render 'data' = render 'wizard_progress' + = render 'order_update_issues_dialog' = render 'form' diff --git a/config/locales/en.yml b/config/locales/en.yml index a69d0638de..605ea8e724 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -826,6 +826,7 @@ en: pause_failure_msg: 'Sorry, pausing failed!' confirm_unpause_msg: Are you sure you want to unpause this standing order? unpause_failure_msg: 'Sorry, unpausing failed!' + order_update_issues_msg: Some orders could not be automatically updated, this is most likely because they have been manually edited. Please review the issues listed below and make any adjustments to individual orders if required. stripe_connect_settings: edit: diff --git a/spec/features/admin/standing_orders_spec.rb b/spec/features/admin/standing_orders_spec.rb index 3a80d87d90..afaee71f47 100644 --- a/spec/features/admin/standing_orders_spec.rb +++ b/spec/features/admin/standing_orders_spec.rb @@ -246,7 +246,8 @@ feature 'Standing Orders' do schedule: schedule, payment_method: payment_method, shipping_method: shipping_method, - standing_line_items: [create(:standing_line_item, variant: variant1, quantity: 2)] + standing_line_items: [create(:standing_line_item, variant: variant1, quantity: 2)], + with_proxy_orders: true ) } it "passes the smoke test" do @@ -294,6 +295,27 @@ feature 'Standing Orders' do expect(standing_order.reload.standing_line_items.length).to eq 1 expect(standing_order.standing_line_items.first.variant).to eq variant2 end + + context "with initialised order that has been changed" do + let(:proxy_order) { standing_order.proxy_orders.first } + let(:order) { proxy_order.initialise_order! } + let(:line_item) { order.line_items.first } + + before { line_item.update_attributes(quantity: 3) } + + it "reports issues encountered during the update" do + visit edit_admin_standing_order_path(standing_order) + + within "#sli_0" do + fill_in 'quantity', with: "1" + end + + click_button 'Save Changes' + expect(page).to have_content 'Saved' + + expect(page).to have_selector "#order_update_issues_dialog .message", text: I18n.t("admin.standing_orders.order_update_issues_msg") + end + end end end end