From ef0e41e624ec626c17cb17855e75cd23e0b14470 Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Wed, 20 Apr 2016 15:31:11 +1000 Subject: [PATCH 01/29] Use save bar on order cycle form --- .../admin/order_cycles/controllers/edit.js.coffee | 5 +++++ app/assets/javascripts/templates/admin/save_bar.html.haml | 2 +- app/views/admin/order_cycles/edit.html.haml | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee b/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee index fd426eb455..a17f52e42c 100644 --- a/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee +++ b/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee @@ -12,6 +12,9 @@ angular.module('admin.orderCycles') $scope.StatusMessage = StatusMessage + $scope.$watch 'order_cycle_form.$dirty', (newValue) -> + StatusMessage.display 'notice', 'You have unsaved changes' if newValue + $scope.loaded = -> Enterprise.loaded && EnterpriseFee.loaded && OrderCycle.loaded @@ -81,4 +84,6 @@ angular.module('admin.orderCycles') OrderCycle.removeDistributionOfVariant(variant_id) $scope.submit = (destination) -> + StatusMessage.display 'progress', "Saving..." OrderCycle.update(destination) + this.order_cycle_form.$setPristine() diff --git a/app/assets/javascripts/templates/admin/save_bar.html.haml b/app/assets/javascripts/templates/admin/save_bar.html.haml index 452e81f6e3..ac4fa55de5 100644 --- a/app/assets/javascripts/templates/admin/save_bar.html.haml +++ b/app/assets/javascripts/templates/admin/save_bar.html.haml @@ -1,4 +1,4 @@ -#save-bar.animate-show{ ng: { show: 'form.$dirty || StatusMessage.active()' } } +#save-bar.animate-show{ ng: { show: 'StatusMessage.active()' } } .twelve.columns.alpha %h5#status-message{ ng: { style: 'StatusMessage.statusMessage.style' } } {{ StatusMessage.statusMessage.text || " " }} diff --git a/app/views/admin/order_cycles/edit.html.haml b/app/views/admin/order_cycles/edit.html.haml index f3b0bdb721..6ecb65d87e 100644 --- a/app/views/admin/order_cycles/edit.html.haml +++ b/app/views/admin/order_cycles/edit.html.haml @@ -27,7 +27,9 @@ - ng_controller = order_cycles_simple_form ? 'AdminSimpleEditOrderCycleCtrl' : 'AdminEditOrderCycleCtrl' -= form_for [main_app, :admin, @order_cycle], :url => '', :html => {:class => 'ng order_cycle', 'ng-app' => 'admin.orderCycles', 'ng-controller' => ng_controller} do |f| += form_for [main_app, :admin, @order_cycle], :url => '', :html => {:class => 'ng order_cycle', 'ng-app' => 'admin.orderCycles', 'ng-controller' => ng_controller, name: 'order_cycle_form'} do |f| + %save-bar{ save: "submit()", form: "order_cycle_form" } + - if order_cycles_simple_form = render 'simple_form', f: f - else From 00858656b5b4f16cf4e9d04c72529663db9704c0 Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Wed, 27 Apr 2016 12:15:20 +1000 Subject: [PATCH 02/29] Extend save_bar directive to support more buttons --- .../javascripts/admin/utils/directives/save_bar.js.coffee | 1 + app/assets/javascripts/templates/admin/save_bar.html.haml | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/admin/utils/directives/save_bar.js.coffee b/app/assets/javascripts/admin/utils/directives/save_bar.js.coffee index 13e4f84bc6..9cd25d97cd 100644 --- a/app/assets/javascripts/admin/utils/directives/save_bar.js.coffee +++ b/app/assets/javascripts/admin/utils/directives/save_bar.js.coffee @@ -3,6 +3,7 @@ angular.module("admin.utils").directive "saveBar", (StatusMessage) -> scope: save: "&" form: "=" + buttons: "=" templateUrl: "admin/save_bar.html" link: (scope, element, attrs) -> scope.StatusMessage = StatusMessage diff --git a/app/assets/javascripts/templates/admin/save_bar.html.haml b/app/assets/javascripts/templates/admin/save_bar.html.haml index ac4fa55de5..83beac81a5 100644 --- a/app/assets/javascripts/templates/admin/save_bar.html.haml +++ b/app/assets/javascripts/templates/admin/save_bar.html.haml @@ -3,4 +3,6 @@ %h5#status-message{ ng: { style: 'StatusMessage.statusMessage.style' } } {{ StatusMessage.statusMessage.text || " " }} .four.columns.omega.text-right - %input.red{type: "button", value: "Save Changes", ng: { disabled: '!form.$dirty', click: "save()" } } + + %input.red{"ng-repeat" => "button in buttons", type: "button", value: "{{button.text}}", ng: { disabled: '!form.$dirty', click: "save({param: button.param})" } } + From 33d0f9fc1b2598aa27d161d17d3e763894a65adf Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Wed, 27 Apr 2016 12:16:13 +1000 Subject: [PATCH 03/29] Use save_bar on order cycle update form --- app/views/admin/order_cycles/_form.html.haml | 14 ++++++-------- .../admin/order_cycles/_simple_form.html.haml | 13 +++++-------- app/views/admin/order_cycles/edit.html.haml | 3 ++- .../admin/variant_overrides/_products.html.haml | 2 +- .../spree/admin/orders/bulk_management.html.haml | 2 +- 5 files changed, 15 insertions(+), 19 deletions(-) diff --git a/app/views/admin/order_cycles/_form.html.haml b/app/views/admin/order_cycles/_form.html.haml index c447d35d58..13b317c314 100644 --- a/app/views/admin/order_cycles/_form.html.haml +++ b/app/views/admin/order_cycles/_form.html.haml @@ -52,14 +52,12 @@ .actions - if @order_cycle.new_record? = f.submit 'Create', 'ng-click' => "submit('#{main_app.admin_order_cycles_path}')", 'ng-disabled' => '!loaded()' - - else - = f.submit 'Update', 'ng-click' => "submit(null)", 'ng-disabled' => '!loaded()' - = f.submit 'Update and Close', 'ng-click' => "submit('#{main_app.admin_order_cycles_path}')", 'ng-disabled' => '!loaded()' - %span{'ng-show' => 'loaded()'} - or - = link_to 'Cancel', main_app.admin_order_cycles_path - %span{'ng-hide' => 'loaded()'} Loading... - = render 'spree/admin/shared/status_message' + + %span{'ng-show' => 'loaded()'} + or + = link_to 'Cancel', main_app.admin_order_cycles_path + %span{'ng-hide' => 'loaded()'} Loading... + = render 'spree/admin/shared/status_message' - unless Rails.env.production? diff --git a/app/views/admin/order_cycles/_simple_form.html.haml b/app/views/admin/order_cycles/_simple_form.html.haml index 4dc64a012b..34ea062102 100644 --- a/app/views/admin/order_cycles/_simple_form.html.haml +++ b/app/views/admin/order_cycles/_simple_form.html.haml @@ -23,12 +23,9 @@ .actions - if @order_cycle.new_record? = f.submit 'Create', 'ng-click' => "submit('#{main_app.admin_order_cycles_path}')", 'ng-disabled' => '!loaded()' - - else - = f.submit 'Update', 'ng-click' => "submit(null)", 'ng-disabled' => '!loaded()' - = f.submit 'Update and Close', 'ng-click' => "submit('#{main_app.admin_order_cycles_path}')", 'ng-disabled' => '!loaded()' - %span{'ng-show' => 'loaded()'} - or - = link_to 'Cancel', main_app.admin_order_cycles_path - %span{'ng-hide' => 'loaded()'} Loading... - = render 'spree/admin/shared/status_message' + %span{'ng-show' => 'loaded()'} + or + = link_to 'Cancel', main_app.admin_order_cycles_path + %span{'ng-hide' => 'loaded()'} Loading... + = render 'spree/admin/shared/status_message' diff --git a/app/views/admin/order_cycles/edit.html.haml b/app/views/admin/order_cycles/edit.html.haml index 6ecb65d87e..4b2a397e49 100644 --- a/app/views/admin/order_cycles/edit.html.haml +++ b/app/views/admin/order_cycles/edit.html.haml @@ -28,7 +28,8 @@ - ng_controller = order_cycles_simple_form ? 'AdminSimpleEditOrderCycleCtrl' : 'AdminEditOrderCycleCtrl' = form_for [main_app, :admin, @order_cycle], :url => '', :html => {:class => 'ng order_cycle', 'ng-app' => 'admin.orderCycles', 'ng-controller' => ng_controller, name: 'order_cycle_form'} do |f| - %save-bar{ save: "submit()", form: "order_cycle_form" } + + %save-bar{ buttons: "[{text: 'Update', param: null}, {text: 'Update and Close', param: '#{main_app.admin_order_cycles_path}'}]", save: "submit(param)", form: "order_cycle_form" } - if order_cycles_simple_form = render 'simple_form', f: f diff --git a/app/views/admin/variant_overrides/_products.html.haml b/app/views/admin/variant_overrides/_products.html.haml index c17e4c189a..70ae2c79bf 100644 --- a/app/views/admin/variant_overrides/_products.html.haml +++ b/app/views/admin/variant_overrides/_products.html.haml @@ -1,5 +1,5 @@ %form{ name: 'variant_overrides_form', ng: { show: "views.inventory.visible" } } - %save-bar{ save: "update()", form: "variant_overrides_form" } + %save-bar{ save: "update()", form: "variant_overrides_form", buttons: "[{text: 'Save Changes'}]" } %table.index.bulk#variant-overrides %col.producer{ width: "20%", ng: { show: 'columns.producer.visible' } } %col.product{ width: "20%", ng: { show: 'columns.product.visible' } } diff --git a/app/views/spree/admin/orders/bulk_management.html.haml b/app/views/spree/admin/orders/bulk_management.html.haml index 43983e87ea..b4d7de740d 100644 --- a/app/views/spree/admin/orders/bulk_management.html.haml +++ b/app/views/spree/admin/orders/bulk_management.html.haml @@ -10,7 +10,7 @@ = render :partial => 'spree/admin/shared/order_sub_menu' %div{ ng: { controller: 'LineItemsCtrl' } } - %save-bar{ save: "submit()", form: "bulk_order_form" } + %save-bar{ save: "submit()", form: "bulk_order_form", buttons: "[{text: 'Save Changes'}]" } .filters{ :class => "sixteen columns alpha" } .date_filter{ :class => "two columns alpha" } %label{ :for => 'start_date_filter' } From 70ce58f5e1d87dbc57ae831469c4ea29d257894f Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Wed, 27 Apr 2016 13:47:04 +1000 Subject: [PATCH 04/29] Tweak save_bar css --- app/assets/stylesheets/admin/components/save_bar.sass | 2 +- app/assets/stylesheets/admin/openfoodnetwork.css.scss | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/admin/components/save_bar.sass b/app/assets/stylesheets/admin/components/save_bar.sass index c6b1236490..fcc60dbfc3 100644 --- a/app/assets/stylesheets/admin/components/save_bar.sass +++ b/app/assets/stylesheets/admin/components/save_bar.sass @@ -3,7 +3,7 @@ bottom: 0px padding: 8px 10px font-weight: bold - background-color: #fff + background-color: #eff5fc color: #5498da h5 color: #5498da diff --git a/app/assets/stylesheets/admin/openfoodnetwork.css.scss b/app/assets/stylesheets/admin/openfoodnetwork.css.scss index 17d43ff3a5..1fc95face8 100644 --- a/app/assets/stylesheets/admin/openfoodnetwork.css.scss +++ b/app/assets/stylesheets/admin/openfoodnetwork.css.scss @@ -37,6 +37,7 @@ text-angular .ta-editor { input.red { background-color: #DA5354; + margin-right: 5px; } input.search { From 63b644551cef53c0d484369d04a029987abc8fc0 Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Fri, 29 Apr 2016 10:43:28 +1000 Subject: [PATCH 05/29] Keep the action with save button --- .../javascripts/admin/order_cycles/controllers/edit.js.coffee | 2 +- .../javascripts/admin/utils/directives/save_bar.js.coffee | 1 - app/assets/javascripts/templates/admin/save_bar.html.haml | 4 ++-- app/views/admin/order_cycles/edit.html.haml | 2 +- app/views/admin/variant_overrides/_products.html.haml | 2 +- app/views/spree/admin/orders/bulk_management.html.haml | 2 +- 6 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee b/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee index a17f52e42c..068447d161 100644 --- a/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee +++ b/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee @@ -86,4 +86,4 @@ angular.module('admin.orderCycles') $scope.submit = (destination) -> StatusMessage.display 'progress', "Saving..." OrderCycle.update(destination) - this.order_cycle_form.$setPristine() + $scope.order_cycle_form.$setPristine() diff --git a/app/assets/javascripts/admin/utils/directives/save_bar.js.coffee b/app/assets/javascripts/admin/utils/directives/save_bar.js.coffee index 9cd25d97cd..0999679394 100644 --- a/app/assets/javascripts/admin/utils/directives/save_bar.js.coffee +++ b/app/assets/javascripts/admin/utils/directives/save_bar.js.coffee @@ -1,7 +1,6 @@ angular.module("admin.utils").directive "saveBar", (StatusMessage) -> restrict: "E" scope: - save: "&" form: "=" buttons: "=" templateUrl: "admin/save_bar.html" diff --git a/app/assets/javascripts/templates/admin/save_bar.html.haml b/app/assets/javascripts/templates/admin/save_bar.html.haml index 83beac81a5..ddc535d001 100644 --- a/app/assets/javascripts/templates/admin/save_bar.html.haml +++ b/app/assets/javascripts/templates/admin/save_bar.html.haml @@ -1,8 +1,8 @@ -#save-bar.animate-show{ ng: { show: 'StatusMessage.active()' } } +#save-bar.animate-show{ ng: { show: 'form.$dirty || StatusMessage.active()' } } .twelve.columns.alpha %h5#status-message{ ng: { style: 'StatusMessage.statusMessage.style' } } {{ StatusMessage.statusMessage.text || " " }} .four.columns.omega.text-right - %input.red{"ng-repeat" => "button in buttons", type: "button", value: "{{button.text}}", ng: { disabled: '!form.$dirty', click: "save({param: button.param})" } } + %input.red{"ng-repeat" => "button in buttons", type: "button", value: "{{button.text}}", ng: { disabled: '!form.$dirty', click: "button.action(button.param)" } } diff --git a/app/views/admin/order_cycles/edit.html.haml b/app/views/admin/order_cycles/edit.html.haml index 4b2a397e49..4f3e5d8516 100644 --- a/app/views/admin/order_cycles/edit.html.haml +++ b/app/views/admin/order_cycles/edit.html.haml @@ -29,7 +29,7 @@ - ng_controller = order_cycles_simple_form ? 'AdminSimpleEditOrderCycleCtrl' : 'AdminEditOrderCycleCtrl' = form_for [main_app, :admin, @order_cycle], :url => '', :html => {:class => 'ng order_cycle', 'ng-app' => 'admin.orderCycles', 'ng-controller' => ng_controller, name: 'order_cycle_form'} do |f| - %save-bar{ buttons: "[{text: 'Update', param: null}, {text: 'Update and Close', param: '#{main_app.admin_order_cycles_path}'}]", save: "submit(param)", form: "order_cycle_form" } + %save-bar{ buttons: "[{ text: 'Update', action: submit, param: null }, { text: 'Update and Close', action: submit, param: '#{main_app.admin_order_cycles_path}' }]", form: "order_cycle_form" } - if order_cycles_simple_form = render 'simple_form', f: f diff --git a/app/views/admin/variant_overrides/_products.html.haml b/app/views/admin/variant_overrides/_products.html.haml index 70ae2c79bf..34c8d02bb2 100644 --- a/app/views/admin/variant_overrides/_products.html.haml +++ b/app/views/admin/variant_overrides/_products.html.haml @@ -1,5 +1,5 @@ %form{ name: 'variant_overrides_form', ng: { show: "views.inventory.visible" } } - %save-bar{ save: "update()", form: "variant_overrides_form", buttons: "[{text: 'Save Changes'}]" } + %save-bar{ form: "variant_overrides_form", buttons: "[{ text: 'Save Changes', action: update }]" } %table.index.bulk#variant-overrides %col.producer{ width: "20%", ng: { show: 'columns.producer.visible' } } %col.product{ width: "20%", ng: { show: 'columns.product.visible' } } diff --git a/app/views/spree/admin/orders/bulk_management.html.haml b/app/views/spree/admin/orders/bulk_management.html.haml index b4d7de740d..2bd58a4cc5 100644 --- a/app/views/spree/admin/orders/bulk_management.html.haml +++ b/app/views/spree/admin/orders/bulk_management.html.haml @@ -10,7 +10,7 @@ = render :partial => 'spree/admin/shared/order_sub_menu' %div{ ng: { controller: 'LineItemsCtrl' } } - %save-bar{ save: "submit()", form: "bulk_order_form", buttons: "[{text: 'Save Changes'}]" } + %save-bar{ form: "bulk_order_form", buttons: "[{ text: 'Save Changes', action: submit }]" } .filters{ :class => "sixteen columns alpha" } .date_filter{ :class => "two columns alpha" } %label{ :for => 'start_date_filter' } From 885d489bc3431f09ee8677ff381fd162ad62e4a9 Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Fri, 29 Apr 2016 15:23:19 +1000 Subject: [PATCH 06/29] Fix failed test for the default form --- .../order_cycles/controllers/edit.js.coffee | 1 + spec/features/admin/order_cycles_spec.rb | 23 ++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee b/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee index 068447d161..db63a8cbaa 100644 --- a/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee +++ b/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee @@ -63,6 +63,7 @@ angular.module('admin.orderCycles') $scope.removeExchange = ($event, exchange) -> $event.preventDefault() OrderCycle.removeExchange(exchange) + $scope.order_cycle_form.$dirty = true $scope.addCoordinatorFee = ($event) -> $event.preventDefault() diff --git a/spec/features/admin/order_cycles_spec.rb b/spec/features/admin/order_cycles_spec.rb index aafaa5ee77..4827f9b916 100644 --- a/spec/features/admin/order_cycles_spec.rb +++ b/spec/features/admin/order_cycles_spec.rb @@ -317,10 +317,10 @@ feature %q{ # And I add a supplier and some products select 'My supplier', from: 'new_supplier_id' click_button 'Add supplier' - page.all("table.exchanges tr.supplier td.products input").each { |e| e.click } + page.all("table.exchanges tr.supplier td.products input").each { |e| e.trigger('click') } page.should have_selector "#order_cycle_incoming_exchange_1_variants_#{initial_variants.last.id}", visible: true - page.find("#order_cycle_incoming_exchange_1_variants_#{initial_variants.last.id}", visible: true).click # uncheck (with visible:true filter) + page.find("#order_cycle_incoming_exchange_1_variants_#{initial_variants.last.id}", visible: true).trigger('click') # uncheck (with visible:true filter) check "order_cycle_incoming_exchange_2_variants_#{v1.id}" check "order_cycle_incoming_exchange_2_variants_#{v2.id}" @@ -343,7 +343,7 @@ feature %q{ fill_in 'order_cycle_outgoing_exchange_1_pickup_time', with: 'New time 1' fill_in 'order_cycle_outgoing_exchange_1_pickup_instructions', with: 'New instructions 1' - page.all("table.exchanges tr.distributor td.products input").each { |e| e.click } + page.all("table.exchanges tr.distributor td.products input").each { |e| e.trigger('click') } uncheck "order_cycle_outgoing_exchange_2_variants_#{v1.id}" check "order_cycle_outgoing_exchange_2_variants_#{v2.id}" @@ -359,7 +359,8 @@ feature %q{ select 'Distributor fee 2', from: 'order_cycle_outgoing_exchange_2_enterprise_fees_0_enterprise_fee_id' # And I click Update - click_button 'Update and Close' + expect(page).to have_selector "#save-bar" + find_button('Update and Close').trigger('click') # Then my order cycle should have been updated page.should have_content 'Your order cycle has been updated.' @@ -607,9 +608,9 @@ feature %q{ page.all('tr.supplier').count.should == 3 page.all('tr.distributor').count.should == 3 - # When I save, then those exchanges should remain - click_button 'Update' - page.should have_content "Your order cycle has been updated." + # # When I save, then those exchanges should remain + # click_button 'Update' + # page.should have_content "Your order cycle has been updated." oc.reload oc.suppliers.should match_array [supplier_managed, supplier_permitted, supplier_unmanaged] @@ -699,8 +700,8 @@ feature %q{ expect(page).to have_field "order_cycle_outgoing_exchange_0_variants_#{v2.id}", disabled: true # When I save, any exchanges that I can't manage remain - click_button 'Update' - page.should have_content "Your order cycle has been updated." + # click_button 'Update' + # page.should have_content "Your order cycle has been updated." oc.reload oc.suppliers.should match_array [supplier_managed, supplier_permitted, supplier_unmanaged] @@ -752,8 +753,8 @@ feature %q{ expect(page).to have_field "order_cycle_incoming_exchange_0_variants_#{v2.id}", disabled: true # When I save, any exchange that I can't manage remains - click_button 'Update' - page.should have_content "Your order cycle has been updated." + # click_button 'Update' + # page.should have_content "Your order cycle has been updated." oc.reload oc.suppliers.should match_array [supplier_managed, supplier_permitted, supplier_unmanaged] From 019e16c5ba87b403370e992e0208de559546ebd1 Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Tue, 3 May 2016 22:58:09 +1000 Subject: [PATCH 07/29] Update AdminEditOrderCycleCtrl unit tests --- spec/javascripts/unit/order_cycle_spec.js.coffee | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spec/javascripts/unit/order_cycle_spec.js.coffee b/spec/javascripts/unit/order_cycle_spec.js.coffee index 973b348383..2f1893bc43 100644 --- a/spec/javascripts/unit/order_cycle_spec.js.coffee +++ b/spec/javascripts/unit/order_cycle_spec.js.coffee @@ -9,7 +9,7 @@ describe 'OrderCycle controllers', -> EnterpriseFee = null beforeEach -> - scope = {} + scope = { order_cycle_form: { $dirty: false}} event = preventDefault: jasmine.createSpy('preventDefault') OrderCycle = @@ -169,7 +169,9 @@ describe 'OrderCycle controllers', -> EnterpriseFee = null beforeEach -> - scope = {} + scope = + order_cycle_form: jasmine.createSpyObj('order_cycle_form', ['$dirty', '$setPristine']) + $watch: jasmine.createSpy('$watch') event = preventDefault: jasmine.createSpy('preventDefault') location = @@ -292,6 +294,7 @@ describe 'OrderCycle controllers', -> scope.removeExchange(event, 'exchange') expect(event.preventDefault).toHaveBeenCalled() expect(OrderCycle.removeExchange).toHaveBeenCalledWith('exchange') + expect(scope.order_cycle_form.$dirty).toEqual true it 'Adds coordinator fees', -> scope.addCoordinatorFee(event) @@ -320,6 +323,7 @@ describe 'OrderCycle controllers', -> it 'Submits the order cycle via OrderCycle update', -> scope.submit('/admin/order_cycles') expect(OrderCycle.update).toHaveBeenCalledWith('/admin/order_cycles') + expect(scope.order_cycle_form.$setPristine.calls.length).toEqual 1 describe 'OrderCycle services', -> From 1833f0dd5d2283c6e0e52b82325ba9073aeec6b8 Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Wed, 4 May 2016 11:22:25 +1000 Subject: [PATCH 08/29] Add save_bar to the order cycles simple editing form --- .../order_cycles/controllers/simple_edit.js.coffee | 4 ++++ spec/features/admin/order_cycles_spec.rb | 13 +++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/admin/order_cycles/controllers/simple_edit.js.coffee b/app/assets/javascripts/admin/order_cycles/controllers/simple_edit.js.coffee index bf00bb3df1..99c2e2649c 100644 --- a/app/assets/javascripts/admin/order_cycles/controllers/simple_edit.js.coffee +++ b/app/assets/javascripts/admin/order_cycles/controllers/simple_edit.js.coffee @@ -9,6 +9,9 @@ angular.module('admin.orderCycles').controller "AdminSimpleEditOrderCycleCtrl", $scope.order_cycle = OrderCycle.load $scope.orderCycleId(), (order_cycle) => $scope.init() + $scope.$watch 'order_cycle_form.$dirty', (newValue) -> + StatusMessage.display 'notice', 'You have unsaved changes' if newValue + $scope.loaded = -> Enterprise.loaded && EnterpriseFee.loaded && OrderCycle.loaded @@ -35,5 +38,6 @@ angular.module('admin.orderCycles').controller "AdminSimpleEditOrderCycleCtrl", OrderCycle.removeCoordinatorFee(index) $scope.submit = (destination) -> + StatusMessage.display 'progress', "Saving..." OrderCycle.mirrorIncomingToOutgoingProducts() OrderCycle.update(destination) diff --git a/spec/features/admin/order_cycles_spec.rb b/spec/features/admin/order_cycles_spec.rb index 4827f9b916..8b451fa7c0 100644 --- a/spec/features/admin/order_cycles_spec.rb +++ b/spec/features/admin/order_cycles_spec.rb @@ -889,10 +889,10 @@ feature %q{ fill_in 'order_cycle_outgoing_exchange_0_pickup_instructions', with: 'zzy' # And I make some product selections - uncheck "order_cycle_incoming_exchange_0_variants_#{v1.id}" - check "order_cycle_incoming_exchange_0_variants_#{v2.id}" - check "order_cycle_incoming_exchange_0_variants_#{v3.id}" - uncheck "order_cycle_incoming_exchange_0_variants_#{v3.id}" + find("#order_cycle_incoming_exchange_0_variants_#{v1.id}").trigger('click') + find("#order_cycle_incoming_exchange_0_variants_#{v2.id}").trigger('click') + find("#order_cycle_incoming_exchange_0_variants_#{v3.id}").trigger('click') + find("#order_cycle_incoming_exchange_0_variants_#{v3.id}").trigger('click') # And I select some fees and update click_link 'order_cycle_coordinator_fee_0_remove' @@ -901,9 +901,10 @@ feature %q{ select 'that fee', from: 'order_cycle_coordinator_fee_0_id' # When I update, or update and close, both work - click_button 'Update' + find_button('Update').trigger('click') page.should have_content 'Your order cycle has been updated.' - click_button 'Update and Close' + + find_button('Update and Close').trigger('click') # Then my order cycle should have been updated page.should have_content 'Your order cycle has been updated.' From 8b5e5105a8ce940e6fa6782852c2bb1776c96b29 Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Wed, 4 May 2016 12:11:03 +1000 Subject: [PATCH 09/29] Fix failed tests --- spec/features/admin/order_cycles_spec.rb | 10 +++++----- .../order_cycles/controllers/simple_edit.js.coffee | 3 ++- spec/javascripts/unit/order_cycle_spec.js.coffee | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/spec/features/admin/order_cycles_spec.rb b/spec/features/admin/order_cycles_spec.rb index 8b451fa7c0..99069e9f7c 100644 --- a/spec/features/admin/order_cycles_spec.rb +++ b/spec/features/admin/order_cycles_spec.rb @@ -624,10 +624,10 @@ feature %q{ visit edit_admin_order_cycle_path(oc) # When I remove all the exchanges and save - page.find("tr.supplier-#{supplier_managed.id} a.remove-exchange").click - page.find("tr.supplier-#{supplier_permitted.id} a.remove-exchange").click - page.find("tr.distributor-#{distributor_managed.id} a.remove-exchange").click - page.find("tr.distributor-#{distributor_permitted.id} a.remove-exchange").click + page.find("tr.supplier-#{supplier_managed.id} a.remove-exchange").trigger('click') + page.find("tr.supplier-#{supplier_permitted.id} a.remove-exchange").trigger('click') + page.find("tr.distributor-#{distributor_managed.id} a.remove-exchange").trigger('click') + page.find("tr.distributor-#{distributor_permitted.id} a.remove-exchange").trigger('click') click_button 'Update' # Then the exchanges should be removed @@ -897,7 +897,7 @@ feature %q{ # And I select some fees and update click_link 'order_cycle_coordinator_fee_0_remove' page.should_not have_select 'order_cycle_coordinator_fee_0_id' - click_button 'Add coordinator fee' + find_button('Add coordinator fee').trigger('click') select 'that fee', from: 'order_cycle_coordinator_fee_0_id' # When I update, or update and close, both work diff --git a/spec/javascripts/unit/admin/order_cycles/controllers/simple_edit.js.coffee b/spec/javascripts/unit/admin/order_cycles/controllers/simple_edit.js.coffee index dbad5a9f05..f5ccd25aac 100644 --- a/spec/javascripts/unit/admin/order_cycles/controllers/simple_edit.js.coffee +++ b/spec/javascripts/unit/admin/order_cycles/controllers/simple_edit.js.coffee @@ -10,7 +10,8 @@ describe "AdminSimpleEditOrderCycleCtrl", -> outgoing_exchange = {} beforeEach -> - scope = {} + scope = + $watch: jasmine.createSpy('$watch') location = absUrl: -> 'example.com/admin/order_cycles/27/edit' diff --git a/spec/javascripts/unit/order_cycle_spec.js.coffee b/spec/javascripts/unit/order_cycle_spec.js.coffee index 2f1893bc43..b66acfcb1d 100644 --- a/spec/javascripts/unit/order_cycle_spec.js.coffee +++ b/spec/javascripts/unit/order_cycle_spec.js.coffee @@ -9,7 +9,7 @@ describe 'OrderCycle controllers', -> EnterpriseFee = null beforeEach -> - scope = { order_cycle_form: { $dirty: false}} + scope = {} event = preventDefault: jasmine.createSpy('preventDefault') OrderCycle = From 57ec7bb9a967df03b922e113241e088cfa187f26 Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Wed, 4 May 2016 12:27:24 +1000 Subject: [PATCH 10/29] Remove unused test code --- .../stylesheets/admin/components/save_bar.sass | 2 +- spec/features/admin/order_cycles_spec.rb | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/app/assets/stylesheets/admin/components/save_bar.sass b/app/assets/stylesheets/admin/components/save_bar.sass index fcc60dbfc3..c6b1236490 100644 --- a/app/assets/stylesheets/admin/components/save_bar.sass +++ b/app/assets/stylesheets/admin/components/save_bar.sass @@ -3,7 +3,7 @@ bottom: 0px padding: 8px 10px font-weight: bold - background-color: #eff5fc + background-color: #fff color: #5498da h5 color: #5498da diff --git a/spec/features/admin/order_cycles_spec.rb b/spec/features/admin/order_cycles_spec.rb index 99069e9f7c..8caf156af4 100644 --- a/spec/features/admin/order_cycles_spec.rb +++ b/spec/features/admin/order_cycles_spec.rb @@ -608,10 +608,6 @@ feature %q{ page.all('tr.supplier').count.should == 3 page.all('tr.distributor').count.should == 3 - # # When I save, then those exchanges should remain - # click_button 'Update' - # page.should have_content "Your order cycle has been updated." - oc.reload oc.suppliers.should match_array [supplier_managed, supplier_permitted, supplier_unmanaged] oc.coordinator.should == distributor_managed @@ -699,10 +695,6 @@ feature %q{ # I should be able to see but not toggle v2, because I don't have permission expect(page).to have_field "order_cycle_outgoing_exchange_0_variants_#{v2.id}", disabled: true - # When I save, any exchanges that I can't manage remain - # click_button 'Update' - # page.should have_content "Your order cycle has been updated." - oc.reload oc.suppliers.should match_array [supplier_managed, supplier_permitted, supplier_unmanaged] oc.coordinator.should == distributor_managed @@ -752,10 +744,6 @@ feature %q{ # I should be able to see but not toggle v2, because I don't have permission expect(page).to have_field "order_cycle_incoming_exchange_0_variants_#{v2.id}", disabled: true - # When I save, any exchange that I can't manage remains - # click_button 'Update' - # page.should have_content "Your order cycle has been updated." - oc.reload oc.suppliers.should match_array [supplier_managed, supplier_permitted, supplier_unmanaged] oc.coordinator.should == distributor_managed From 3cac9c452f2cb78d8cb7ad32089a54759d2c6b10 Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Wed, 4 May 2016 14:48:15 +1000 Subject: [PATCH 11/29] Tweaks --- app/views/admin/order_cycles/_form.html.haml | 8 +++----- app/views/admin/order_cycles/_simple_form.html.haml | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/app/views/admin/order_cycles/_form.html.haml b/app/views/admin/order_cycles/_form.html.haml index 13b317c314..ed2d3acbc2 100644 --- a/app/views/admin/order_cycles/_form.html.haml +++ b/app/views/admin/order_cycles/_form.html.haml @@ -53,11 +53,9 @@ - if @order_cycle.new_record? = f.submit 'Create', 'ng-click' => "submit('#{main_app.admin_order_cycles_path}')", 'ng-disabled' => '!loaded()' - %span{'ng-show' => 'loaded()'} - or - = link_to 'Cancel', main_app.admin_order_cycles_path - %span{'ng-hide' => 'loaded()'} Loading... - = render 'spree/admin/shared/status_message' + %span{'ng-show' => 'loaded()'} + = link_to 'Cancel', main_app.admin_order_cycles_path + %span{'ng-hide' => 'loaded()'} Loading... - unless Rails.env.production? diff --git a/app/views/admin/order_cycles/_simple_form.html.haml b/app/views/admin/order_cycles/_simple_form.html.haml index 34ea062102..9364d080ff 100644 --- a/app/views/admin/order_cycles/_simple_form.html.haml +++ b/app/views/admin/order_cycles/_simple_form.html.haml @@ -24,8 +24,6 @@ - if @order_cycle.new_record? = f.submit 'Create', 'ng-click' => "submit('#{main_app.admin_order_cycles_path}')", 'ng-disabled' => '!loaded()' - %span{'ng-show' => 'loaded()'} - or - = link_to 'Cancel', main_app.admin_order_cycles_path - %span{'ng-hide' => 'loaded()'} Loading... - = render 'spree/admin/shared/status_message' + %span{'ng-show' => 'loaded()'} + = link_to 'Cancel', main_app.admin_order_cycles_path + %span{'ng-hide' => 'loaded()'} Loading... From 064e3c426ebf37028540d629dff22a059e2d33ae Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Fri, 6 May 2016 11:00:34 +1000 Subject: [PATCH 12/29] Make the save bar look better --- .../javascripts/templates/admin/save_bar.html.haml | 12 ++++++------ .../stylesheets/admin/components/save_bar.sass | 6 ++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/templates/admin/save_bar.html.haml b/app/assets/javascripts/templates/admin/save_bar.html.haml index ddc535d001..0a4a055c87 100644 --- a/app/assets/javascripts/templates/admin/save_bar.html.haml +++ b/app/assets/javascripts/templates/admin/save_bar.html.haml @@ -1,8 +1,8 @@ #save-bar.animate-show{ ng: { show: 'form.$dirty || StatusMessage.active()' } } - .twelve.columns.alpha - %h5#status-message{ ng: { style: 'StatusMessage.statusMessage.style' } } - {{ StatusMessage.statusMessage.text || " " }} - .four.columns.omega.text-right - - %input.red{"ng-repeat" => "button in buttons", type: "button", value: "{{button.text}}", ng: { disabled: '!form.$dirty', click: "button.action(button.param)" } } + .container + .twelve.columns.alpha + %h5#status-message{ ng: { style: 'StatusMessage.statusMessage.style' } } + {{ StatusMessage.statusMessage.text || " " }} + .four.columns.omega.text-right + %input.red{"ng-repeat" => "button in buttons", type: "button", value: "{{button.text}}", ng: { disabled: '!form.$dirty', click: "button.action(button.param)" } } diff --git a/app/assets/stylesheets/admin/components/save_bar.sass b/app/assets/stylesheets/admin/components/save_bar.sass index c6b1236490..23585d05f5 100644 --- a/app/assets/stylesheets/admin/components/save_bar.sass +++ b/app/assets/stylesheets/admin/components/save_bar.sass @@ -1,9 +1,11 @@ #save-bar position: fixed + width: 100% bottom: 0px - padding: 8px 10px + left: 0 + padding: 8px 8px font-weight: bold - background-color: #fff + background-color: #eff5fc color: #5498da h5 color: #5498da From 08f0011244cf47a31a236b3bcf2d45d497c9528e Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Fri, 6 May 2016 12:43:50 +1000 Subject: [PATCH 13/29] Make the page long enough to avoid the save bar overlaying the form --- spec/features/admin/order_cycles_spec.rb | 38 ++++++++++++++---------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/spec/features/admin/order_cycles_spec.rb b/spec/features/admin/order_cycles_spec.rb index 8caf156af4..701780622f 100644 --- a/spec/features/admin/order_cycles_spec.rb +++ b/spec/features/admin/order_cycles_spec.rb @@ -267,6 +267,9 @@ feature %q{ scenario "updating an order cycle", js: true do + # Make the page long enough to avoid the save bar overlaying the form + page.driver.resize(1280, 3600) + # Given an order cycle with all the settings oc = create(:order_cycle) initial_variants = oc.variants.sort_by &:id @@ -317,10 +320,10 @@ feature %q{ # And I add a supplier and some products select 'My supplier', from: 'new_supplier_id' click_button 'Add supplier' - page.all("table.exchanges tr.supplier td.products input").each { |e| e.trigger('click') } + page.all("table.exchanges tr.supplier td.products input").each { |e| e.click } page.should have_selector "#order_cycle_incoming_exchange_1_variants_#{initial_variants.last.id}", visible: true - page.find("#order_cycle_incoming_exchange_1_variants_#{initial_variants.last.id}", visible: true).trigger('click') # uncheck (with visible:true filter) + page.find("#order_cycle_incoming_exchange_1_variants_#{initial_variants.last.id}", visible: true).click # uncheck (with visible:true filter) check "order_cycle_incoming_exchange_2_variants_#{v1.id}" check "order_cycle_incoming_exchange_2_variants_#{v2.id}" @@ -343,7 +346,7 @@ feature %q{ fill_in 'order_cycle_outgoing_exchange_1_pickup_time', with: 'New time 1' fill_in 'order_cycle_outgoing_exchange_1_pickup_instructions', with: 'New instructions 1' - page.all("table.exchanges tr.distributor td.products input").each { |e| e.trigger('click') } + page.all("table.exchanges tr.distributor td.products input").each { |e| e.click } uncheck "order_cycle_outgoing_exchange_2_variants_#{v1.id}" check "order_cycle_outgoing_exchange_2_variants_#{v2.id}" @@ -360,7 +363,8 @@ feature %q{ # And I click Update expect(page).to have_selector "#save-bar" - find_button('Update and Close').trigger('click') + save_screenshot('abc.png') + click_button 'Update and Close' # Then my order cycle should have been updated page.should have_content 'Your order cycle has been updated.' @@ -620,10 +624,11 @@ feature %q{ visit edit_admin_order_cycle_path(oc) # When I remove all the exchanges and save - page.find("tr.supplier-#{supplier_managed.id} a.remove-exchange").trigger('click') - page.find("tr.supplier-#{supplier_permitted.id} a.remove-exchange").trigger('click') - page.find("tr.distributor-#{distributor_managed.id} a.remove-exchange").trigger('click') - page.find("tr.distributor-#{distributor_permitted.id} a.remove-exchange").trigger('click') + page.find("tr.supplier-#{supplier_managed.id} a.remove-exchange").click + page.find("tr.supplier-#{supplier_permitted.id} a.remove-exchange").click + page.find("tr.distributor-#{distributor_managed.id} a.remove-exchange").click + page.find("tr.distributor-#{distributor_permitted.id} a.remove-exchange").click + click_button 'Update' # Then the exchanges should be removed @@ -857,6 +862,9 @@ feature %q{ end scenario "updating an order cycle" do + # Make the page long enough to avoid the save bar overlaying the form + page.driver.resize(1280, 3600) + # Given an order cycle with pickup time and instructions fee1 = create(:enterprise_fee, name: 'my fee', enterprise: enterprise) fee2 = create(:enterprise_fee, name: 'that fee', enterprise: enterprise) @@ -877,22 +885,22 @@ feature %q{ fill_in 'order_cycle_outgoing_exchange_0_pickup_instructions', with: 'zzy' # And I make some product selections - find("#order_cycle_incoming_exchange_0_variants_#{v1.id}").trigger('click') - find("#order_cycle_incoming_exchange_0_variants_#{v2.id}").trigger('click') - find("#order_cycle_incoming_exchange_0_variants_#{v3.id}").trigger('click') - find("#order_cycle_incoming_exchange_0_variants_#{v3.id}").trigger('click') + uncheck "order_cycle_incoming_exchange_0_variants_#{v1.id}" + check "order_cycle_incoming_exchange_0_variants_#{v2.id}" + check "order_cycle_incoming_exchange_0_variants_#{v3.id}" + uncheck "order_cycle_incoming_exchange_0_variants_#{v3.id}" # And I select some fees and update click_link 'order_cycle_coordinator_fee_0_remove' page.should_not have_select 'order_cycle_coordinator_fee_0_id' - find_button('Add coordinator fee').trigger('click') + click_button 'Add coordinator fee' select 'that fee', from: 'order_cycle_coordinator_fee_0_id' # When I update, or update and close, both work - find_button('Update').trigger('click') + click_button 'Update' page.should have_content 'Your order cycle has been updated.' - find_button('Update and Close').trigger('click') + click_button 'Update and Close' # Then my order cycle should have been updated page.should have_content 'Your order cycle has been updated.' From a37820a9636e6359a96828587f7d7438c7ebe7e6 Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Fri, 6 May 2016 14:55:16 +1000 Subject: [PATCH 14/29] Resize window to fix failed test --- spec/features/admin/order_cycles_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/features/admin/order_cycles_spec.rb b/spec/features/admin/order_cycles_spec.rb index 701780622f..cd5ef0a07e 100644 --- a/spec/features/admin/order_cycles_spec.rb +++ b/spec/features/admin/order_cycles_spec.rb @@ -619,6 +619,9 @@ feature %q{ end scenario "editing an order cycle" do + # Make the page long enough to avoid the save bar overlaying the form + page.driver.resize(1280, 3600) + oc = create(:simple_order_cycle, { suppliers: [supplier_managed, supplier_permitted, supplier_unmanaged], coordinator: distributor_managed, distributors: [distributor_managed, distributor_permitted, distributor_unmanaged], name: 'Order Cycle 1' } ) visit edit_admin_order_cycle_path(oc) From 38efa218d08db5c3e696a1d1f656b97ed05fbf80 Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Wed, 20 Apr 2016 15:31:11 +1000 Subject: [PATCH 15/29] Use save bar on order cycle form --- .../admin/order_cycles/controllers/edit.js.coffee | 5 +++++ app/assets/javascripts/templates/admin/save_bar.html.haml | 2 +- app/views/admin/order_cycles/edit.html.haml | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee b/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee index fd426eb455..a17f52e42c 100644 --- a/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee +++ b/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee @@ -12,6 +12,9 @@ angular.module('admin.orderCycles') $scope.StatusMessage = StatusMessage + $scope.$watch 'order_cycle_form.$dirty', (newValue) -> + StatusMessage.display 'notice', 'You have unsaved changes' if newValue + $scope.loaded = -> Enterprise.loaded && EnterpriseFee.loaded && OrderCycle.loaded @@ -81,4 +84,6 @@ angular.module('admin.orderCycles') OrderCycle.removeDistributionOfVariant(variant_id) $scope.submit = (destination) -> + StatusMessage.display 'progress', "Saving..." OrderCycle.update(destination) + this.order_cycle_form.$setPristine() diff --git a/app/assets/javascripts/templates/admin/save_bar.html.haml b/app/assets/javascripts/templates/admin/save_bar.html.haml index 452e81f6e3..ac4fa55de5 100644 --- a/app/assets/javascripts/templates/admin/save_bar.html.haml +++ b/app/assets/javascripts/templates/admin/save_bar.html.haml @@ -1,4 +1,4 @@ -#save-bar.animate-show{ ng: { show: 'form.$dirty || StatusMessage.active()' } } +#save-bar.animate-show{ ng: { show: 'StatusMessage.active()' } } .twelve.columns.alpha %h5#status-message{ ng: { style: 'StatusMessage.statusMessage.style' } } {{ StatusMessage.statusMessage.text || " " }} diff --git a/app/views/admin/order_cycles/edit.html.haml b/app/views/admin/order_cycles/edit.html.haml index f3b0bdb721..6ecb65d87e 100644 --- a/app/views/admin/order_cycles/edit.html.haml +++ b/app/views/admin/order_cycles/edit.html.haml @@ -27,7 +27,9 @@ - ng_controller = order_cycles_simple_form ? 'AdminSimpleEditOrderCycleCtrl' : 'AdminEditOrderCycleCtrl' -= form_for [main_app, :admin, @order_cycle], :url => '', :html => {:class => 'ng order_cycle', 'ng-app' => 'admin.orderCycles', 'ng-controller' => ng_controller} do |f| += form_for [main_app, :admin, @order_cycle], :url => '', :html => {:class => 'ng order_cycle', 'ng-app' => 'admin.orderCycles', 'ng-controller' => ng_controller, name: 'order_cycle_form'} do |f| + %save-bar{ save: "submit()", form: "order_cycle_form" } + - if order_cycles_simple_form = render 'simple_form', f: f - else From d10719330daaae1475c4e7e9d1d9d86edaa635a2 Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Wed, 27 Apr 2016 12:15:20 +1000 Subject: [PATCH 16/29] Extend save_bar directive to support more buttons --- .../javascripts/admin/utils/directives/save_bar.js.coffee | 1 + app/assets/javascripts/templates/admin/save_bar.html.haml | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/admin/utils/directives/save_bar.js.coffee b/app/assets/javascripts/admin/utils/directives/save_bar.js.coffee index 13e4f84bc6..9cd25d97cd 100644 --- a/app/assets/javascripts/admin/utils/directives/save_bar.js.coffee +++ b/app/assets/javascripts/admin/utils/directives/save_bar.js.coffee @@ -3,6 +3,7 @@ angular.module("admin.utils").directive "saveBar", (StatusMessage) -> scope: save: "&" form: "=" + buttons: "=" templateUrl: "admin/save_bar.html" link: (scope, element, attrs) -> scope.StatusMessage = StatusMessage diff --git a/app/assets/javascripts/templates/admin/save_bar.html.haml b/app/assets/javascripts/templates/admin/save_bar.html.haml index ac4fa55de5..83beac81a5 100644 --- a/app/assets/javascripts/templates/admin/save_bar.html.haml +++ b/app/assets/javascripts/templates/admin/save_bar.html.haml @@ -3,4 +3,6 @@ %h5#status-message{ ng: { style: 'StatusMessage.statusMessage.style' } } {{ StatusMessage.statusMessage.text || " " }} .four.columns.omega.text-right - %input.red{type: "button", value: "Save Changes", ng: { disabled: '!form.$dirty', click: "save()" } } + + %input.red{"ng-repeat" => "button in buttons", type: "button", value: "{{button.text}}", ng: { disabled: '!form.$dirty', click: "save({param: button.param})" } } + From 2214c83ec7c644a172e25fab22d85a6294a82bce Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Wed, 27 Apr 2016 12:16:13 +1000 Subject: [PATCH 17/29] Use save_bar on order cycle update form --- app/views/admin/order_cycles/_form.html.haml | 14 ++++++-------- .../admin/order_cycles/_simple_form.html.haml | 13 +++++-------- app/views/admin/order_cycles/edit.html.haml | 3 ++- .../admin/variant_overrides/_products.html.haml | 2 +- .../spree/admin/orders/bulk_management.html.haml | 2 +- 5 files changed, 15 insertions(+), 19 deletions(-) diff --git a/app/views/admin/order_cycles/_form.html.haml b/app/views/admin/order_cycles/_form.html.haml index c447d35d58..13b317c314 100644 --- a/app/views/admin/order_cycles/_form.html.haml +++ b/app/views/admin/order_cycles/_form.html.haml @@ -52,14 +52,12 @@ .actions - if @order_cycle.new_record? = f.submit 'Create', 'ng-click' => "submit('#{main_app.admin_order_cycles_path}')", 'ng-disabled' => '!loaded()' - - else - = f.submit 'Update', 'ng-click' => "submit(null)", 'ng-disabled' => '!loaded()' - = f.submit 'Update and Close', 'ng-click' => "submit('#{main_app.admin_order_cycles_path}')", 'ng-disabled' => '!loaded()' - %span{'ng-show' => 'loaded()'} - or - = link_to 'Cancel', main_app.admin_order_cycles_path - %span{'ng-hide' => 'loaded()'} Loading... - = render 'spree/admin/shared/status_message' + + %span{'ng-show' => 'loaded()'} + or + = link_to 'Cancel', main_app.admin_order_cycles_path + %span{'ng-hide' => 'loaded()'} Loading... + = render 'spree/admin/shared/status_message' - unless Rails.env.production? diff --git a/app/views/admin/order_cycles/_simple_form.html.haml b/app/views/admin/order_cycles/_simple_form.html.haml index 4dc64a012b..34ea062102 100644 --- a/app/views/admin/order_cycles/_simple_form.html.haml +++ b/app/views/admin/order_cycles/_simple_form.html.haml @@ -23,12 +23,9 @@ .actions - if @order_cycle.new_record? = f.submit 'Create', 'ng-click' => "submit('#{main_app.admin_order_cycles_path}')", 'ng-disabled' => '!loaded()' - - else - = f.submit 'Update', 'ng-click' => "submit(null)", 'ng-disabled' => '!loaded()' - = f.submit 'Update and Close', 'ng-click' => "submit('#{main_app.admin_order_cycles_path}')", 'ng-disabled' => '!loaded()' - %span{'ng-show' => 'loaded()'} - or - = link_to 'Cancel', main_app.admin_order_cycles_path - %span{'ng-hide' => 'loaded()'} Loading... - = render 'spree/admin/shared/status_message' + %span{'ng-show' => 'loaded()'} + or + = link_to 'Cancel', main_app.admin_order_cycles_path + %span{'ng-hide' => 'loaded()'} Loading... + = render 'spree/admin/shared/status_message' diff --git a/app/views/admin/order_cycles/edit.html.haml b/app/views/admin/order_cycles/edit.html.haml index 6ecb65d87e..4b2a397e49 100644 --- a/app/views/admin/order_cycles/edit.html.haml +++ b/app/views/admin/order_cycles/edit.html.haml @@ -28,7 +28,8 @@ - ng_controller = order_cycles_simple_form ? 'AdminSimpleEditOrderCycleCtrl' : 'AdminEditOrderCycleCtrl' = form_for [main_app, :admin, @order_cycle], :url => '', :html => {:class => 'ng order_cycle', 'ng-app' => 'admin.orderCycles', 'ng-controller' => ng_controller, name: 'order_cycle_form'} do |f| - %save-bar{ save: "submit()", form: "order_cycle_form" } + + %save-bar{ buttons: "[{text: 'Update', param: null}, {text: 'Update and Close', param: '#{main_app.admin_order_cycles_path}'}]", save: "submit(param)", form: "order_cycle_form" } - if order_cycles_simple_form = render 'simple_form', f: f diff --git a/app/views/admin/variant_overrides/_products.html.haml b/app/views/admin/variant_overrides/_products.html.haml index c17e4c189a..70ae2c79bf 100644 --- a/app/views/admin/variant_overrides/_products.html.haml +++ b/app/views/admin/variant_overrides/_products.html.haml @@ -1,5 +1,5 @@ %form{ name: 'variant_overrides_form', ng: { show: "views.inventory.visible" } } - %save-bar{ save: "update()", form: "variant_overrides_form" } + %save-bar{ save: "update()", form: "variant_overrides_form", buttons: "[{text: 'Save Changes'}]" } %table.index.bulk#variant-overrides %col.producer{ width: "20%", ng: { show: 'columns.producer.visible' } } %col.product{ width: "20%", ng: { show: 'columns.product.visible' } } diff --git a/app/views/spree/admin/orders/bulk_management.html.haml b/app/views/spree/admin/orders/bulk_management.html.haml index 43983e87ea..b4d7de740d 100644 --- a/app/views/spree/admin/orders/bulk_management.html.haml +++ b/app/views/spree/admin/orders/bulk_management.html.haml @@ -10,7 +10,7 @@ = render :partial => 'spree/admin/shared/order_sub_menu' %div{ ng: { controller: 'LineItemsCtrl' } } - %save-bar{ save: "submit()", form: "bulk_order_form" } + %save-bar{ save: "submit()", form: "bulk_order_form", buttons: "[{text: 'Save Changes'}]" } .filters{ :class => "sixteen columns alpha" } .date_filter{ :class => "two columns alpha" } %label{ :for => 'start_date_filter' } From 7fc37e4737339fca09eff6232facf39870c18632 Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Wed, 27 Apr 2016 13:47:04 +1000 Subject: [PATCH 18/29] Tweak save_bar css --- app/assets/stylesheets/admin/components/save_bar.sass | 2 +- app/assets/stylesheets/admin/openfoodnetwork.css.scss | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/admin/components/save_bar.sass b/app/assets/stylesheets/admin/components/save_bar.sass index c6b1236490..fcc60dbfc3 100644 --- a/app/assets/stylesheets/admin/components/save_bar.sass +++ b/app/assets/stylesheets/admin/components/save_bar.sass @@ -3,7 +3,7 @@ bottom: 0px padding: 8px 10px font-weight: bold - background-color: #fff + background-color: #eff5fc color: #5498da h5 color: #5498da diff --git a/app/assets/stylesheets/admin/openfoodnetwork.css.scss b/app/assets/stylesheets/admin/openfoodnetwork.css.scss index 17d43ff3a5..1fc95face8 100644 --- a/app/assets/stylesheets/admin/openfoodnetwork.css.scss +++ b/app/assets/stylesheets/admin/openfoodnetwork.css.scss @@ -37,6 +37,7 @@ text-angular .ta-editor { input.red { background-color: #DA5354; + margin-right: 5px; } input.search { From 78b4a35d129843f4140608074cd5b62c18a36f48 Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Fri, 29 Apr 2016 10:43:28 +1000 Subject: [PATCH 19/29] Keep the action with save button --- .../javascripts/admin/order_cycles/controllers/edit.js.coffee | 2 +- .../javascripts/admin/utils/directives/save_bar.js.coffee | 1 - app/assets/javascripts/templates/admin/save_bar.html.haml | 4 ++-- app/views/admin/order_cycles/edit.html.haml | 2 +- app/views/admin/variant_overrides/_products.html.haml | 2 +- app/views/spree/admin/orders/bulk_management.html.haml | 2 +- 6 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee b/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee index a17f52e42c..068447d161 100644 --- a/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee +++ b/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee @@ -86,4 +86,4 @@ angular.module('admin.orderCycles') $scope.submit = (destination) -> StatusMessage.display 'progress', "Saving..." OrderCycle.update(destination) - this.order_cycle_form.$setPristine() + $scope.order_cycle_form.$setPristine() diff --git a/app/assets/javascripts/admin/utils/directives/save_bar.js.coffee b/app/assets/javascripts/admin/utils/directives/save_bar.js.coffee index 9cd25d97cd..0999679394 100644 --- a/app/assets/javascripts/admin/utils/directives/save_bar.js.coffee +++ b/app/assets/javascripts/admin/utils/directives/save_bar.js.coffee @@ -1,7 +1,6 @@ angular.module("admin.utils").directive "saveBar", (StatusMessage) -> restrict: "E" scope: - save: "&" form: "=" buttons: "=" templateUrl: "admin/save_bar.html" diff --git a/app/assets/javascripts/templates/admin/save_bar.html.haml b/app/assets/javascripts/templates/admin/save_bar.html.haml index 83beac81a5..ddc535d001 100644 --- a/app/assets/javascripts/templates/admin/save_bar.html.haml +++ b/app/assets/javascripts/templates/admin/save_bar.html.haml @@ -1,8 +1,8 @@ -#save-bar.animate-show{ ng: { show: 'StatusMessage.active()' } } +#save-bar.animate-show{ ng: { show: 'form.$dirty || StatusMessage.active()' } } .twelve.columns.alpha %h5#status-message{ ng: { style: 'StatusMessage.statusMessage.style' } } {{ StatusMessage.statusMessage.text || " " }} .four.columns.omega.text-right - %input.red{"ng-repeat" => "button in buttons", type: "button", value: "{{button.text}}", ng: { disabled: '!form.$dirty', click: "save({param: button.param})" } } + %input.red{"ng-repeat" => "button in buttons", type: "button", value: "{{button.text}}", ng: { disabled: '!form.$dirty', click: "button.action(button.param)" } } diff --git a/app/views/admin/order_cycles/edit.html.haml b/app/views/admin/order_cycles/edit.html.haml index 4b2a397e49..4f3e5d8516 100644 --- a/app/views/admin/order_cycles/edit.html.haml +++ b/app/views/admin/order_cycles/edit.html.haml @@ -29,7 +29,7 @@ - ng_controller = order_cycles_simple_form ? 'AdminSimpleEditOrderCycleCtrl' : 'AdminEditOrderCycleCtrl' = form_for [main_app, :admin, @order_cycle], :url => '', :html => {:class => 'ng order_cycle', 'ng-app' => 'admin.orderCycles', 'ng-controller' => ng_controller, name: 'order_cycle_form'} do |f| - %save-bar{ buttons: "[{text: 'Update', param: null}, {text: 'Update and Close', param: '#{main_app.admin_order_cycles_path}'}]", save: "submit(param)", form: "order_cycle_form" } + %save-bar{ buttons: "[{ text: 'Update', action: submit, param: null }, { text: 'Update and Close', action: submit, param: '#{main_app.admin_order_cycles_path}' }]", form: "order_cycle_form" } - if order_cycles_simple_form = render 'simple_form', f: f diff --git a/app/views/admin/variant_overrides/_products.html.haml b/app/views/admin/variant_overrides/_products.html.haml index 70ae2c79bf..34c8d02bb2 100644 --- a/app/views/admin/variant_overrides/_products.html.haml +++ b/app/views/admin/variant_overrides/_products.html.haml @@ -1,5 +1,5 @@ %form{ name: 'variant_overrides_form', ng: { show: "views.inventory.visible" } } - %save-bar{ save: "update()", form: "variant_overrides_form", buttons: "[{text: 'Save Changes'}]" } + %save-bar{ form: "variant_overrides_form", buttons: "[{ text: 'Save Changes', action: update }]" } %table.index.bulk#variant-overrides %col.producer{ width: "20%", ng: { show: 'columns.producer.visible' } } %col.product{ width: "20%", ng: { show: 'columns.product.visible' } } diff --git a/app/views/spree/admin/orders/bulk_management.html.haml b/app/views/spree/admin/orders/bulk_management.html.haml index b4d7de740d..2bd58a4cc5 100644 --- a/app/views/spree/admin/orders/bulk_management.html.haml +++ b/app/views/spree/admin/orders/bulk_management.html.haml @@ -10,7 +10,7 @@ = render :partial => 'spree/admin/shared/order_sub_menu' %div{ ng: { controller: 'LineItemsCtrl' } } - %save-bar{ save: "submit()", form: "bulk_order_form", buttons: "[{text: 'Save Changes'}]" } + %save-bar{ form: "bulk_order_form", buttons: "[{ text: 'Save Changes', action: submit }]" } .filters{ :class => "sixteen columns alpha" } .date_filter{ :class => "two columns alpha" } %label{ :for => 'start_date_filter' } From d59dea29ab8967fa8bb19eda77ba460e87d4860a Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Fri, 29 Apr 2016 15:23:19 +1000 Subject: [PATCH 20/29] Fix failed test for the default form --- .../order_cycles/controllers/edit.js.coffee | 1 + spec/features/admin/order_cycles_spec.rb | 23 ++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee b/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee index 068447d161..db63a8cbaa 100644 --- a/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee +++ b/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee @@ -63,6 +63,7 @@ angular.module('admin.orderCycles') $scope.removeExchange = ($event, exchange) -> $event.preventDefault() OrderCycle.removeExchange(exchange) + $scope.order_cycle_form.$dirty = true $scope.addCoordinatorFee = ($event) -> $event.preventDefault() diff --git a/spec/features/admin/order_cycles_spec.rb b/spec/features/admin/order_cycles_spec.rb index aafaa5ee77..4827f9b916 100644 --- a/spec/features/admin/order_cycles_spec.rb +++ b/spec/features/admin/order_cycles_spec.rb @@ -317,10 +317,10 @@ feature %q{ # And I add a supplier and some products select 'My supplier', from: 'new_supplier_id' click_button 'Add supplier' - page.all("table.exchanges tr.supplier td.products input").each { |e| e.click } + page.all("table.exchanges tr.supplier td.products input").each { |e| e.trigger('click') } page.should have_selector "#order_cycle_incoming_exchange_1_variants_#{initial_variants.last.id}", visible: true - page.find("#order_cycle_incoming_exchange_1_variants_#{initial_variants.last.id}", visible: true).click # uncheck (with visible:true filter) + page.find("#order_cycle_incoming_exchange_1_variants_#{initial_variants.last.id}", visible: true).trigger('click') # uncheck (with visible:true filter) check "order_cycle_incoming_exchange_2_variants_#{v1.id}" check "order_cycle_incoming_exchange_2_variants_#{v2.id}" @@ -343,7 +343,7 @@ feature %q{ fill_in 'order_cycle_outgoing_exchange_1_pickup_time', with: 'New time 1' fill_in 'order_cycle_outgoing_exchange_1_pickup_instructions', with: 'New instructions 1' - page.all("table.exchanges tr.distributor td.products input").each { |e| e.click } + page.all("table.exchanges tr.distributor td.products input").each { |e| e.trigger('click') } uncheck "order_cycle_outgoing_exchange_2_variants_#{v1.id}" check "order_cycle_outgoing_exchange_2_variants_#{v2.id}" @@ -359,7 +359,8 @@ feature %q{ select 'Distributor fee 2', from: 'order_cycle_outgoing_exchange_2_enterprise_fees_0_enterprise_fee_id' # And I click Update - click_button 'Update and Close' + expect(page).to have_selector "#save-bar" + find_button('Update and Close').trigger('click') # Then my order cycle should have been updated page.should have_content 'Your order cycle has been updated.' @@ -607,9 +608,9 @@ feature %q{ page.all('tr.supplier').count.should == 3 page.all('tr.distributor').count.should == 3 - # When I save, then those exchanges should remain - click_button 'Update' - page.should have_content "Your order cycle has been updated." + # # When I save, then those exchanges should remain + # click_button 'Update' + # page.should have_content "Your order cycle has been updated." oc.reload oc.suppliers.should match_array [supplier_managed, supplier_permitted, supplier_unmanaged] @@ -699,8 +700,8 @@ feature %q{ expect(page).to have_field "order_cycle_outgoing_exchange_0_variants_#{v2.id}", disabled: true # When I save, any exchanges that I can't manage remain - click_button 'Update' - page.should have_content "Your order cycle has been updated." + # click_button 'Update' + # page.should have_content "Your order cycle has been updated." oc.reload oc.suppliers.should match_array [supplier_managed, supplier_permitted, supplier_unmanaged] @@ -752,8 +753,8 @@ feature %q{ expect(page).to have_field "order_cycle_incoming_exchange_0_variants_#{v2.id}", disabled: true # When I save, any exchange that I can't manage remains - click_button 'Update' - page.should have_content "Your order cycle has been updated." + # click_button 'Update' + # page.should have_content "Your order cycle has been updated." oc.reload oc.suppliers.should match_array [supplier_managed, supplier_permitted, supplier_unmanaged] From 26bb1a9beb353c36039b2c95fa52293b7860e67c Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Tue, 3 May 2016 22:58:09 +1000 Subject: [PATCH 21/29] Update AdminEditOrderCycleCtrl unit tests --- spec/javascripts/unit/order_cycle_spec.js.coffee | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spec/javascripts/unit/order_cycle_spec.js.coffee b/spec/javascripts/unit/order_cycle_spec.js.coffee index 973b348383..2f1893bc43 100644 --- a/spec/javascripts/unit/order_cycle_spec.js.coffee +++ b/spec/javascripts/unit/order_cycle_spec.js.coffee @@ -9,7 +9,7 @@ describe 'OrderCycle controllers', -> EnterpriseFee = null beforeEach -> - scope = {} + scope = { order_cycle_form: { $dirty: false}} event = preventDefault: jasmine.createSpy('preventDefault') OrderCycle = @@ -169,7 +169,9 @@ describe 'OrderCycle controllers', -> EnterpriseFee = null beforeEach -> - scope = {} + scope = + order_cycle_form: jasmine.createSpyObj('order_cycle_form', ['$dirty', '$setPristine']) + $watch: jasmine.createSpy('$watch') event = preventDefault: jasmine.createSpy('preventDefault') location = @@ -292,6 +294,7 @@ describe 'OrderCycle controllers', -> scope.removeExchange(event, 'exchange') expect(event.preventDefault).toHaveBeenCalled() expect(OrderCycle.removeExchange).toHaveBeenCalledWith('exchange') + expect(scope.order_cycle_form.$dirty).toEqual true it 'Adds coordinator fees', -> scope.addCoordinatorFee(event) @@ -320,6 +323,7 @@ describe 'OrderCycle controllers', -> it 'Submits the order cycle via OrderCycle update', -> scope.submit('/admin/order_cycles') expect(OrderCycle.update).toHaveBeenCalledWith('/admin/order_cycles') + expect(scope.order_cycle_form.$setPristine.calls.length).toEqual 1 describe 'OrderCycle services', -> From 3760a34b2ba66f6e5bc615af8d41eb861219d97a Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Wed, 4 May 2016 11:22:25 +1000 Subject: [PATCH 22/29] Add save_bar to the order cycles simple editing form --- .../order_cycles/controllers/simple_edit.js.coffee | 4 ++++ spec/features/admin/order_cycles_spec.rb | 13 +++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/admin/order_cycles/controllers/simple_edit.js.coffee b/app/assets/javascripts/admin/order_cycles/controllers/simple_edit.js.coffee index bf00bb3df1..99c2e2649c 100644 --- a/app/assets/javascripts/admin/order_cycles/controllers/simple_edit.js.coffee +++ b/app/assets/javascripts/admin/order_cycles/controllers/simple_edit.js.coffee @@ -9,6 +9,9 @@ angular.module('admin.orderCycles').controller "AdminSimpleEditOrderCycleCtrl", $scope.order_cycle = OrderCycle.load $scope.orderCycleId(), (order_cycle) => $scope.init() + $scope.$watch 'order_cycle_form.$dirty', (newValue) -> + StatusMessage.display 'notice', 'You have unsaved changes' if newValue + $scope.loaded = -> Enterprise.loaded && EnterpriseFee.loaded && OrderCycle.loaded @@ -35,5 +38,6 @@ angular.module('admin.orderCycles').controller "AdminSimpleEditOrderCycleCtrl", OrderCycle.removeCoordinatorFee(index) $scope.submit = (destination) -> + StatusMessage.display 'progress', "Saving..." OrderCycle.mirrorIncomingToOutgoingProducts() OrderCycle.update(destination) diff --git a/spec/features/admin/order_cycles_spec.rb b/spec/features/admin/order_cycles_spec.rb index 4827f9b916..8b451fa7c0 100644 --- a/spec/features/admin/order_cycles_spec.rb +++ b/spec/features/admin/order_cycles_spec.rb @@ -889,10 +889,10 @@ feature %q{ fill_in 'order_cycle_outgoing_exchange_0_pickup_instructions', with: 'zzy' # And I make some product selections - uncheck "order_cycle_incoming_exchange_0_variants_#{v1.id}" - check "order_cycle_incoming_exchange_0_variants_#{v2.id}" - check "order_cycle_incoming_exchange_0_variants_#{v3.id}" - uncheck "order_cycle_incoming_exchange_0_variants_#{v3.id}" + find("#order_cycle_incoming_exchange_0_variants_#{v1.id}").trigger('click') + find("#order_cycle_incoming_exchange_0_variants_#{v2.id}").trigger('click') + find("#order_cycle_incoming_exchange_0_variants_#{v3.id}").trigger('click') + find("#order_cycle_incoming_exchange_0_variants_#{v3.id}").trigger('click') # And I select some fees and update click_link 'order_cycle_coordinator_fee_0_remove' @@ -901,9 +901,10 @@ feature %q{ select 'that fee', from: 'order_cycle_coordinator_fee_0_id' # When I update, or update and close, both work - click_button 'Update' + find_button('Update').trigger('click') page.should have_content 'Your order cycle has been updated.' - click_button 'Update and Close' + + find_button('Update and Close').trigger('click') # Then my order cycle should have been updated page.should have_content 'Your order cycle has been updated.' From e5d2e5010b72d93a9751091c017896141bfc2eac Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Wed, 4 May 2016 12:11:03 +1000 Subject: [PATCH 23/29] Fix failed tests --- spec/features/admin/order_cycles_spec.rb | 10 +++++----- .../order_cycles/controllers/simple_edit.js.coffee | 3 ++- spec/javascripts/unit/order_cycle_spec.js.coffee | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/spec/features/admin/order_cycles_spec.rb b/spec/features/admin/order_cycles_spec.rb index 8b451fa7c0..99069e9f7c 100644 --- a/spec/features/admin/order_cycles_spec.rb +++ b/spec/features/admin/order_cycles_spec.rb @@ -624,10 +624,10 @@ feature %q{ visit edit_admin_order_cycle_path(oc) # When I remove all the exchanges and save - page.find("tr.supplier-#{supplier_managed.id} a.remove-exchange").click - page.find("tr.supplier-#{supplier_permitted.id} a.remove-exchange").click - page.find("tr.distributor-#{distributor_managed.id} a.remove-exchange").click - page.find("tr.distributor-#{distributor_permitted.id} a.remove-exchange").click + page.find("tr.supplier-#{supplier_managed.id} a.remove-exchange").trigger('click') + page.find("tr.supplier-#{supplier_permitted.id} a.remove-exchange").trigger('click') + page.find("tr.distributor-#{distributor_managed.id} a.remove-exchange").trigger('click') + page.find("tr.distributor-#{distributor_permitted.id} a.remove-exchange").trigger('click') click_button 'Update' # Then the exchanges should be removed @@ -897,7 +897,7 @@ feature %q{ # And I select some fees and update click_link 'order_cycle_coordinator_fee_0_remove' page.should_not have_select 'order_cycle_coordinator_fee_0_id' - click_button 'Add coordinator fee' + find_button('Add coordinator fee').trigger('click') select 'that fee', from: 'order_cycle_coordinator_fee_0_id' # When I update, or update and close, both work diff --git a/spec/javascripts/unit/admin/order_cycles/controllers/simple_edit.js.coffee b/spec/javascripts/unit/admin/order_cycles/controllers/simple_edit.js.coffee index dbad5a9f05..f5ccd25aac 100644 --- a/spec/javascripts/unit/admin/order_cycles/controllers/simple_edit.js.coffee +++ b/spec/javascripts/unit/admin/order_cycles/controllers/simple_edit.js.coffee @@ -10,7 +10,8 @@ describe "AdminSimpleEditOrderCycleCtrl", -> outgoing_exchange = {} beforeEach -> - scope = {} + scope = + $watch: jasmine.createSpy('$watch') location = absUrl: -> 'example.com/admin/order_cycles/27/edit' diff --git a/spec/javascripts/unit/order_cycle_spec.js.coffee b/spec/javascripts/unit/order_cycle_spec.js.coffee index 2f1893bc43..b66acfcb1d 100644 --- a/spec/javascripts/unit/order_cycle_spec.js.coffee +++ b/spec/javascripts/unit/order_cycle_spec.js.coffee @@ -9,7 +9,7 @@ describe 'OrderCycle controllers', -> EnterpriseFee = null beforeEach -> - scope = { order_cycle_form: { $dirty: false}} + scope = {} event = preventDefault: jasmine.createSpy('preventDefault') OrderCycle = From ed1a06495bb38bfa8d6fe8c5786f43754548d754 Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Wed, 4 May 2016 12:27:24 +1000 Subject: [PATCH 24/29] Remove unused test code --- .../stylesheets/admin/components/save_bar.sass | 2 +- spec/features/admin/order_cycles_spec.rb | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/app/assets/stylesheets/admin/components/save_bar.sass b/app/assets/stylesheets/admin/components/save_bar.sass index fcc60dbfc3..c6b1236490 100644 --- a/app/assets/stylesheets/admin/components/save_bar.sass +++ b/app/assets/stylesheets/admin/components/save_bar.sass @@ -3,7 +3,7 @@ bottom: 0px padding: 8px 10px font-weight: bold - background-color: #eff5fc + background-color: #fff color: #5498da h5 color: #5498da diff --git a/spec/features/admin/order_cycles_spec.rb b/spec/features/admin/order_cycles_spec.rb index 99069e9f7c..8caf156af4 100644 --- a/spec/features/admin/order_cycles_spec.rb +++ b/spec/features/admin/order_cycles_spec.rb @@ -608,10 +608,6 @@ feature %q{ page.all('tr.supplier').count.should == 3 page.all('tr.distributor').count.should == 3 - # # When I save, then those exchanges should remain - # click_button 'Update' - # page.should have_content "Your order cycle has been updated." - oc.reload oc.suppliers.should match_array [supplier_managed, supplier_permitted, supplier_unmanaged] oc.coordinator.should == distributor_managed @@ -699,10 +695,6 @@ feature %q{ # I should be able to see but not toggle v2, because I don't have permission expect(page).to have_field "order_cycle_outgoing_exchange_0_variants_#{v2.id}", disabled: true - # When I save, any exchanges that I can't manage remain - # click_button 'Update' - # page.should have_content "Your order cycle has been updated." - oc.reload oc.suppliers.should match_array [supplier_managed, supplier_permitted, supplier_unmanaged] oc.coordinator.should == distributor_managed @@ -752,10 +744,6 @@ feature %q{ # I should be able to see but not toggle v2, because I don't have permission expect(page).to have_field "order_cycle_incoming_exchange_0_variants_#{v2.id}", disabled: true - # When I save, any exchange that I can't manage remains - # click_button 'Update' - # page.should have_content "Your order cycle has been updated." - oc.reload oc.suppliers.should match_array [supplier_managed, supplier_permitted, supplier_unmanaged] oc.coordinator.should == distributor_managed From 7bf6881cb2f6707f3e1629457896918cfe4ac47f Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Wed, 4 May 2016 14:48:15 +1000 Subject: [PATCH 25/29] Tweaks --- app/views/admin/order_cycles/_form.html.haml | 8 +++----- app/views/admin/order_cycles/_simple_form.html.haml | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/app/views/admin/order_cycles/_form.html.haml b/app/views/admin/order_cycles/_form.html.haml index 13b317c314..ed2d3acbc2 100644 --- a/app/views/admin/order_cycles/_form.html.haml +++ b/app/views/admin/order_cycles/_form.html.haml @@ -53,11 +53,9 @@ - if @order_cycle.new_record? = f.submit 'Create', 'ng-click' => "submit('#{main_app.admin_order_cycles_path}')", 'ng-disabled' => '!loaded()' - %span{'ng-show' => 'loaded()'} - or - = link_to 'Cancel', main_app.admin_order_cycles_path - %span{'ng-hide' => 'loaded()'} Loading... - = render 'spree/admin/shared/status_message' + %span{'ng-show' => 'loaded()'} + = link_to 'Cancel', main_app.admin_order_cycles_path + %span{'ng-hide' => 'loaded()'} Loading... - unless Rails.env.production? diff --git a/app/views/admin/order_cycles/_simple_form.html.haml b/app/views/admin/order_cycles/_simple_form.html.haml index 34ea062102..9364d080ff 100644 --- a/app/views/admin/order_cycles/_simple_form.html.haml +++ b/app/views/admin/order_cycles/_simple_form.html.haml @@ -24,8 +24,6 @@ - if @order_cycle.new_record? = f.submit 'Create', 'ng-click' => "submit('#{main_app.admin_order_cycles_path}')", 'ng-disabled' => '!loaded()' - %span{'ng-show' => 'loaded()'} - or - = link_to 'Cancel', main_app.admin_order_cycles_path - %span{'ng-hide' => 'loaded()'} Loading... - = render 'spree/admin/shared/status_message' + %span{'ng-show' => 'loaded()'} + = link_to 'Cancel', main_app.admin_order_cycles_path + %span{'ng-hide' => 'loaded()'} Loading... From 89ae77dfd9eee0ae0ff1c4932a90653215bff161 Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Fri, 6 May 2016 11:00:34 +1000 Subject: [PATCH 26/29] Make the save bar look better --- .../javascripts/templates/admin/save_bar.html.haml | 12 ++++++------ .../stylesheets/admin/components/save_bar.sass | 6 ++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/templates/admin/save_bar.html.haml b/app/assets/javascripts/templates/admin/save_bar.html.haml index ddc535d001..0a4a055c87 100644 --- a/app/assets/javascripts/templates/admin/save_bar.html.haml +++ b/app/assets/javascripts/templates/admin/save_bar.html.haml @@ -1,8 +1,8 @@ #save-bar.animate-show{ ng: { show: 'form.$dirty || StatusMessage.active()' } } - .twelve.columns.alpha - %h5#status-message{ ng: { style: 'StatusMessage.statusMessage.style' } } - {{ StatusMessage.statusMessage.text || " " }} - .four.columns.omega.text-right - - %input.red{"ng-repeat" => "button in buttons", type: "button", value: "{{button.text}}", ng: { disabled: '!form.$dirty', click: "button.action(button.param)" } } + .container + .twelve.columns.alpha + %h5#status-message{ ng: { style: 'StatusMessage.statusMessage.style' } } + {{ StatusMessage.statusMessage.text || " " }} + .four.columns.omega.text-right + %input.red{"ng-repeat" => "button in buttons", type: "button", value: "{{button.text}}", ng: { disabled: '!form.$dirty', click: "button.action(button.param)" } } diff --git a/app/assets/stylesheets/admin/components/save_bar.sass b/app/assets/stylesheets/admin/components/save_bar.sass index c6b1236490..23585d05f5 100644 --- a/app/assets/stylesheets/admin/components/save_bar.sass +++ b/app/assets/stylesheets/admin/components/save_bar.sass @@ -1,9 +1,11 @@ #save-bar position: fixed + width: 100% bottom: 0px - padding: 8px 10px + left: 0 + padding: 8px 8px font-weight: bold - background-color: #fff + background-color: #eff5fc color: #5498da h5 color: #5498da From fed3ae9e858d4d60aa25251da43107e193fa1567 Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Fri, 6 May 2016 12:43:50 +1000 Subject: [PATCH 27/29] Make the page long enough to avoid the save bar overlaying the form --- spec/features/admin/order_cycles_spec.rb | 38 ++++++++++++++---------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/spec/features/admin/order_cycles_spec.rb b/spec/features/admin/order_cycles_spec.rb index 8caf156af4..701780622f 100644 --- a/spec/features/admin/order_cycles_spec.rb +++ b/spec/features/admin/order_cycles_spec.rb @@ -267,6 +267,9 @@ feature %q{ scenario "updating an order cycle", js: true do + # Make the page long enough to avoid the save bar overlaying the form + page.driver.resize(1280, 3600) + # Given an order cycle with all the settings oc = create(:order_cycle) initial_variants = oc.variants.sort_by &:id @@ -317,10 +320,10 @@ feature %q{ # And I add a supplier and some products select 'My supplier', from: 'new_supplier_id' click_button 'Add supplier' - page.all("table.exchanges tr.supplier td.products input").each { |e| e.trigger('click') } + page.all("table.exchanges tr.supplier td.products input").each { |e| e.click } page.should have_selector "#order_cycle_incoming_exchange_1_variants_#{initial_variants.last.id}", visible: true - page.find("#order_cycle_incoming_exchange_1_variants_#{initial_variants.last.id}", visible: true).trigger('click') # uncheck (with visible:true filter) + page.find("#order_cycle_incoming_exchange_1_variants_#{initial_variants.last.id}", visible: true).click # uncheck (with visible:true filter) check "order_cycle_incoming_exchange_2_variants_#{v1.id}" check "order_cycle_incoming_exchange_2_variants_#{v2.id}" @@ -343,7 +346,7 @@ feature %q{ fill_in 'order_cycle_outgoing_exchange_1_pickup_time', with: 'New time 1' fill_in 'order_cycle_outgoing_exchange_1_pickup_instructions', with: 'New instructions 1' - page.all("table.exchanges tr.distributor td.products input").each { |e| e.trigger('click') } + page.all("table.exchanges tr.distributor td.products input").each { |e| e.click } uncheck "order_cycle_outgoing_exchange_2_variants_#{v1.id}" check "order_cycle_outgoing_exchange_2_variants_#{v2.id}" @@ -360,7 +363,8 @@ feature %q{ # And I click Update expect(page).to have_selector "#save-bar" - find_button('Update and Close').trigger('click') + save_screenshot('abc.png') + click_button 'Update and Close' # Then my order cycle should have been updated page.should have_content 'Your order cycle has been updated.' @@ -620,10 +624,11 @@ feature %q{ visit edit_admin_order_cycle_path(oc) # When I remove all the exchanges and save - page.find("tr.supplier-#{supplier_managed.id} a.remove-exchange").trigger('click') - page.find("tr.supplier-#{supplier_permitted.id} a.remove-exchange").trigger('click') - page.find("tr.distributor-#{distributor_managed.id} a.remove-exchange").trigger('click') - page.find("tr.distributor-#{distributor_permitted.id} a.remove-exchange").trigger('click') + page.find("tr.supplier-#{supplier_managed.id} a.remove-exchange").click + page.find("tr.supplier-#{supplier_permitted.id} a.remove-exchange").click + page.find("tr.distributor-#{distributor_managed.id} a.remove-exchange").click + page.find("tr.distributor-#{distributor_permitted.id} a.remove-exchange").click + click_button 'Update' # Then the exchanges should be removed @@ -857,6 +862,9 @@ feature %q{ end scenario "updating an order cycle" do + # Make the page long enough to avoid the save bar overlaying the form + page.driver.resize(1280, 3600) + # Given an order cycle with pickup time and instructions fee1 = create(:enterprise_fee, name: 'my fee', enterprise: enterprise) fee2 = create(:enterprise_fee, name: 'that fee', enterprise: enterprise) @@ -877,22 +885,22 @@ feature %q{ fill_in 'order_cycle_outgoing_exchange_0_pickup_instructions', with: 'zzy' # And I make some product selections - find("#order_cycle_incoming_exchange_0_variants_#{v1.id}").trigger('click') - find("#order_cycle_incoming_exchange_0_variants_#{v2.id}").trigger('click') - find("#order_cycle_incoming_exchange_0_variants_#{v3.id}").trigger('click') - find("#order_cycle_incoming_exchange_0_variants_#{v3.id}").trigger('click') + uncheck "order_cycle_incoming_exchange_0_variants_#{v1.id}" + check "order_cycle_incoming_exchange_0_variants_#{v2.id}" + check "order_cycle_incoming_exchange_0_variants_#{v3.id}" + uncheck "order_cycle_incoming_exchange_0_variants_#{v3.id}" # And I select some fees and update click_link 'order_cycle_coordinator_fee_0_remove' page.should_not have_select 'order_cycle_coordinator_fee_0_id' - find_button('Add coordinator fee').trigger('click') + click_button 'Add coordinator fee' select 'that fee', from: 'order_cycle_coordinator_fee_0_id' # When I update, or update and close, both work - find_button('Update').trigger('click') + click_button 'Update' page.should have_content 'Your order cycle has been updated.' - find_button('Update and Close').trigger('click') + click_button 'Update and Close' # Then my order cycle should have been updated page.should have_content 'Your order cycle has been updated.' From 7040e4baae444804b1f9b8b1d4e534ae4bf39e0a Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Fri, 6 May 2016 14:55:16 +1000 Subject: [PATCH 28/29] Resize window to fix failed test --- spec/features/admin/order_cycles_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/features/admin/order_cycles_spec.rb b/spec/features/admin/order_cycles_spec.rb index 701780622f..cd5ef0a07e 100644 --- a/spec/features/admin/order_cycles_spec.rb +++ b/spec/features/admin/order_cycles_spec.rb @@ -619,6 +619,9 @@ feature %q{ end scenario "editing an order cycle" do + # Make the page long enough to avoid the save bar overlaying the form + page.driver.resize(1280, 3600) + oc = create(:simple_order_cycle, { suppliers: [supplier_managed, supplier_permitted, supplier_unmanaged], coordinator: distributor_managed, distributors: [distributor_managed, distributor_permitted, distributor_unmanaged], name: 'Order Cycle 1' } ) visit edit_admin_order_cycle_path(oc) From f8ec0d316a943d019b8194ff7b43edb1d61710f4 Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Thu, 12 May 2016 10:52:48 +1000 Subject: [PATCH 29/29] Save bar can support cancel button --- .../admin/order_cycles/controllers/edit.js.coffee | 5 ++++- app/assets/javascripts/templates/admin/save_bar.html.haml | 6 +++--- app/assets/stylesheets/admin/components/save_bar.sass | 2 ++ app/assets/stylesheets/admin/openfoodnetwork.css.scss | 1 - app/views/admin/order_cycles/edit.html.haml | 2 +- app/views/admin/variant_overrides/_products.html.haml | 2 +- app/views/spree/admin/orders/bulk_management.html.haml | 2 +- 7 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee b/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee index db63a8cbaa..227c6a3045 100644 --- a/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee +++ b/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee @@ -1,5 +1,5 @@ angular.module('admin.orderCycles') - .controller 'AdminEditOrderCycleCtrl', ($scope, $filter, $location, OrderCycle, Enterprise, EnterpriseFee, StatusMessage) -> + .controller 'AdminEditOrderCycleCtrl', ($scope, $filter, $location, $window, OrderCycle, Enterprise, EnterpriseFee, StatusMessage) -> order_cycle_id = $location.absUrl().match(/\/admin\/order_cycles\/(\d+)/)[1] $scope.enterprises = Enterprise.index(order_cycle_id: order_cycle_id) $scope.supplier_enterprises = Enterprise.producer_enterprises @@ -88,3 +88,6 @@ angular.module('admin.orderCycles') StatusMessage.display 'progress', "Saving..." OrderCycle.update(destination) $scope.order_cycle_form.$setPristine() + + $scope.cancel = (destination) -> + $window.location = destination diff --git a/app/assets/javascripts/templates/admin/save_bar.html.haml b/app/assets/javascripts/templates/admin/save_bar.html.haml index 0a4a055c87..0d4919dcde 100644 --- a/app/assets/javascripts/templates/admin/save_bar.html.haml +++ b/app/assets/javascripts/templates/admin/save_bar.html.haml @@ -1,8 +1,8 @@ #save-bar.animate-show{ ng: { show: 'form.$dirty || StatusMessage.active()' } } .container - .twelve.columns.alpha + .eight.columns.alpha %h5#status-message{ ng: { style: 'StatusMessage.statusMessage.style' } } {{ StatusMessage.statusMessage.text || " " }} - .four.columns.omega.text-right - %input.red{"ng-repeat" => "button in buttons", type: "button", value: "{{button.text}}", ng: { disabled: '!form.$dirty', click: "button.action(button.param)" } } + .eight.columns.omega.text-right + %input{"ng-repeat" => "button in buttons", type: "button", value: "{{button.text}}", ng: { class: "button.class", click: "button.action(button.param)" } } diff --git a/app/assets/stylesheets/admin/components/save_bar.sass b/app/assets/stylesheets/admin/components/save_bar.sass index 23585d05f5..87dcce82f9 100644 --- a/app/assets/stylesheets/admin/components/save_bar.sass +++ b/app/assets/stylesheets/admin/components/save_bar.sass @@ -9,3 +9,5 @@ color: #5498da h5 color: #5498da + input + margin-right: 5px diff --git a/app/assets/stylesheets/admin/openfoodnetwork.css.scss b/app/assets/stylesheets/admin/openfoodnetwork.css.scss index 1fc95face8..17d43ff3a5 100644 --- a/app/assets/stylesheets/admin/openfoodnetwork.css.scss +++ b/app/assets/stylesheets/admin/openfoodnetwork.css.scss @@ -37,7 +37,6 @@ text-angular .ta-editor { input.red { background-color: #DA5354; - margin-right: 5px; } input.search { diff --git a/app/views/admin/order_cycles/edit.html.haml b/app/views/admin/order_cycles/edit.html.haml index 4f3e5d8516..9f85261224 100644 --- a/app/views/admin/order_cycles/edit.html.haml +++ b/app/views/admin/order_cycles/edit.html.haml @@ -29,7 +29,7 @@ - ng_controller = order_cycles_simple_form ? 'AdminSimpleEditOrderCycleCtrl' : 'AdminEditOrderCycleCtrl' = form_for [main_app, :admin, @order_cycle], :url => '', :html => {:class => 'ng order_cycle', 'ng-app' => 'admin.orderCycles', 'ng-controller' => ng_controller, name: 'order_cycle_form'} do |f| - %save-bar{ buttons: "[{ text: 'Update', action: submit, param: null }, { text: 'Update and Close', action: submit, param: '#{main_app.admin_order_cycles_path}' }]", form: "order_cycle_form" } + %save-bar{ buttons: "[{ text: 'Update', action: submit, param: null, class: 'red' }, { text: 'Update and Close', action: submit, param: '#{main_app.admin_order_cycles_path}', class: 'red' }, { text: 'Cancel', action: cancel, param: '#{main_app.admin_order_cycles_path}', class: '' }]", form: "order_cycle_form" } - if order_cycles_simple_form = render 'simple_form', f: f diff --git a/app/views/admin/variant_overrides/_products.html.haml b/app/views/admin/variant_overrides/_products.html.haml index 34c8d02bb2..f255d86e0b 100644 --- a/app/views/admin/variant_overrides/_products.html.haml +++ b/app/views/admin/variant_overrides/_products.html.haml @@ -1,5 +1,5 @@ %form{ name: 'variant_overrides_form', ng: { show: "views.inventory.visible" } } - %save-bar{ form: "variant_overrides_form", buttons: "[{ text: 'Save Changes', action: update }]" } + %save-bar{ form: "variant_overrides_form", buttons: "[{ text: 'Save Changes', action: update, class: 'red' }]" } %table.index.bulk#variant-overrides %col.producer{ width: "20%", ng: { show: 'columns.producer.visible' } } %col.product{ width: "20%", ng: { show: 'columns.product.visible' } } diff --git a/app/views/spree/admin/orders/bulk_management.html.haml b/app/views/spree/admin/orders/bulk_management.html.haml index 2bd58a4cc5..d8228b5c83 100644 --- a/app/views/spree/admin/orders/bulk_management.html.haml +++ b/app/views/spree/admin/orders/bulk_management.html.haml @@ -10,7 +10,7 @@ = render :partial => 'spree/admin/shared/order_sub_menu' %div{ ng: { controller: 'LineItemsCtrl' } } - %save-bar{ form: "bulk_order_form", buttons: "[{ text: 'Save Changes', action: submit }]" } + %save-bar{ form: "bulk_order_form", buttons: "[{ text: 'Save Changes', action: submit, class: 'red' }]" } .filters{ :class => "sixteen columns alpha" } .date_filter{ :class => "two columns alpha" } %label{ :for => 'start_date_filter' }