From 48c667d2dd9ee3ffbd7336b69dc299988d9957dc Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Wed, 27 Jan 2021 10:25:05 +0100 Subject: [PATCH 1/4] add onLocationChangeSuccess event handler watch this event and toggle class if needed. --- .../darkswarm/directives/tabset_ctrl.js.coffee | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/darkswarm/directives/tabset_ctrl.js.coffee b/app/assets/javascripts/darkswarm/directives/tabset_ctrl.js.coffee index dd8d9a279b..4587a7cca4 100644 --- a/app/assets/javascripts/darkswarm/directives/tabset_ctrl.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/tabset_ctrl.js.coffee @@ -1,4 +1,4 @@ -Darkswarm.directive "tabsetCtrl", (Tabsets, $location) -> +Darkswarm.directive "tabsetCtrl", (Tabsets, $location, $rootScope) -> restrict: "C" scope: id: "@" @@ -9,7 +9,13 @@ Darkswarm.directive "tabsetCtrl", (Tabsets, $location) -> if $scope.navigate path = $location.path()?.match(/^\/\w+$/)?[0] $scope.selected = path[1..] if path - + + # Watch location change success event to operate back/forward buttons + $rootScope.$on "$locationChangeSuccess", -> + if $scope.navigate + path = $location.path()?.match(/^\/\w+$/)?[0] + Tabsets.toggle($scope.id, path[1..] if path) + this.toggle = (name) -> Tabsets.toggle($scope.id, name) From 0242e1a0c9e02db5d09070cf1943fe0afaad549f Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Wed, 27 Jan 2021 10:26:05 +0100 Subject: [PATCH 2/4] avoid unnecessary javascript:void(0) --- app/views/spree/users/show.html.haml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/spree/users/show.html.haml b/app/views/spree/users/show.html.haml index bddce94ce9..f791fba4ae 100644 --- a/app/views/spree/users/show.html.haml +++ b/app/views/spree/users/show.html.haml @@ -22,14 +22,14 @@ .row.tabset-ctrl#account-tabs{ style: 'margin-bottom: 100px', navigate: 'true', selected: 'orders', prefix: 'account' } .small.12.medium-3.columns.tab{ name: "orders" } - %a{ href: 'javascript:void(0)' }=t('.tabs.orders') + %a{ }=t('.tabs.orders') - if Spree::Config.stripe_connect_enabled && Stripe.publishable_key .small.12.medium-3.columns.tab{ name: "cards" } - %a{ href: 'javascript:void(0)' }=t('.tabs.cards') + %a{ }=t('.tabs.cards') .small.12.medium-3.columns.tab{ name: "transactions" } - %a{ href: 'javascript:void(0)' }=t('.tabs.transactions') + %a{ }=t('.tabs.transactions') .small.12.medium-3.columns.tab{ name: "settings" } - %a{ href: 'javascript:void(0)' }=t('.tabs.settings') + %a{ }=t('.tabs.settings') .small-12.columns.tab-view = render partial: "shared/footer" From bb21543ae0ae95fd356830cdc28940db41076ecb Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Wed, 27 Jan 2021 21:35:55 +0100 Subject: [PATCH 3/4] remove useless brackets --- app/views/spree/users/show.html.haml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/spree/users/show.html.haml b/app/views/spree/users/show.html.haml index f791fba4ae..36cfb4c442 100644 --- a/app/views/spree/users/show.html.haml +++ b/app/views/spree/users/show.html.haml @@ -22,14 +22,14 @@ .row.tabset-ctrl#account-tabs{ style: 'margin-bottom: 100px', navigate: 'true', selected: 'orders', prefix: 'account' } .small.12.medium-3.columns.tab{ name: "orders" } - %a{ }=t('.tabs.orders') + %a=t('.tabs.orders') - if Spree::Config.stripe_connect_enabled && Stripe.publishable_key .small.12.medium-3.columns.tab{ name: "cards" } - %a{ }=t('.tabs.cards') + %a=t('.tabs.cards') .small.12.medium-3.columns.tab{ name: "transactions" } - %a{ }=t('.tabs.transactions') + %a=t('.tabs.transactions') .small.12.medium-3.columns.tab{ name: "settings" } - %a{ }=t('.tabs.settings') + %a=t('.tabs.settings') .small-12.columns.tab-view = render partial: "shared/footer" From 553053bad1cbec97d2db786fd773bf43b3d72c6b Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 28 Jan 2021 09:45:24 +0100 Subject: [PATCH 4/4] use find instead of click_link because element no longer has href attribute - click_link only looks for element with href attribute - Use a regexp for a case-insensitive search (as CSS use a uppercase transform) --- spec/features/consumer/account/cards_spec.rb | 2 +- spec/features/consumer/account/settings_spec.rb | 4 ++-- spec/features/consumer/account_spec.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/features/consumer/account/cards_spec.rb b/spec/features/consumer/account/cards_spec.rb index fe5884e58b..d2f6b673dd 100644 --- a/spec/features/consumer/account/cards_spec.rb +++ b/spec/features/consumer/account/cards_spec.rb @@ -39,7 +39,7 @@ feature "Credit Cards", js: true do it "passes the smoke test" do visit "/account" - click_link I18n.t('spree.users.show.tabs.cards') + find("a", :text => %r{#{I18n.t('spree.users.show.tabs.cards')}}i).click expect(page).to have_content I18n.t(:saved_cards) diff --git a/spec/features/consumer/account/settings_spec.rb b/spec/features/consumer/account/settings_spec.rb index 99abb4e52d..964a8d0fbe 100644 --- a/spec/features/consumer/account/settings_spec.rb +++ b/spec/features/consumer/account/settings_spec.rb @@ -18,7 +18,7 @@ feature "Account Settings", js: true do setup_email login_as user visit "/account" - click_link I18n.t('spree.users.show.tabs.settings') + find("a", :text => %r{#{I18n.t('spree.users.show.tabs.settings')}}i).click expect(page).to have_content I18n.t('spree.users.form.account_settings') end @@ -37,7 +37,7 @@ feature "Account Settings", js: true do user.reload expect(user.email).to eq 'old@email.com' expect(user.unconfirmed_email).to eq 'new@email.com' - click_link I18n.t('spree.users.show.tabs.settings') + find("a", :text => %r{#{I18n.t('spree.users.show.tabs.settings')}}i).click expect(page).to have_content I18n.t('spree.users.show.unconfirmed_email', unconfirmed_email: 'new@email.com') end diff --git a/spec/features/consumer/account_spec.rb b/spec/features/consumer/account_spec.rb index 84cb4e3731..5e9d9543f5 100644 --- a/spec/features/consumer/account_spec.rb +++ b/spec/features/consumer/account_spec.rb @@ -54,7 +54,7 @@ feature ' href: "#{distributor_credit.permalink}/shop", count: 1) # Viewing transaction history - click_link I18n.t('spree.users.show.tabs.transactions') + find("a", :text => %r{#{I18n.t('spree.users.show.tabs.transactions')}}i).click # It shows all hubs that have been ordered from with balance or credit expect(page).to have_content distributor1.name