From 14bcba081da597c8519601649f893e8162f31336 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Tue, 7 Jan 2020 22:58:47 +0100 Subject: [PATCH] Adapt shopfront_helper to show/hide panels and display new tabs --- app/helpers/shop_helper.rb | 29 ++++++++++------------- app/views/shopping_shared/_tabs.html.haml | 13 ++++++---- config/locales/en.yml | 4 +++- spec/helpers/shop_helper_spec.rb | 21 +++++++++------- 4 files changed, 38 insertions(+), 29 deletions(-) diff --git a/app/helpers/shop_helper.rb b/app/helpers/shop_helper.rb index 96e4a58857..1fe8b2909b 100644 --- a/app/helpers/shop_helper.rb +++ b/app/helpers/shop_helper.rb @@ -20,27 +20,24 @@ module ShopHelper ) end - def base_shop_tabs(column_sizes) + def shop_tabs [ - { name: 'about', cols: column_sizes[0], - title: t(:shopping_tabs_about, distributor: current_distributor.name) }, - { name: 'producers', cols: column_sizes[1], - title: t(:label_producers) }, - { name: 'contact', cols: column_sizes[2], - title: t(:shopping_tabs_contact) } + { name: 'home', title: t(:shopping_tabs_home), show: show_home_tab? }, + { name: 'shop', title: t(:shopping_tabs_shop), show: !require_customer? }, + { name: 'about', title: t(:shopping_tabs_about), show: true }, + { name: 'producers', title: t(:label_producers), show: true }, + { name: 'contact', title: t(:shopping_tabs_contact), show: true }, + { name: 'groups', title: t(:label_groups), show: current_distributor.groups.any? }, ] end - def tabs_with_groups - tabs = base_shop_tabs([6, 2, 2]) - tabs << { name: 'groups', title: t(:label_groups), cols: 2 } + private + + def show_home_tab? + require_customer? || shopfront_closed_message? || current_distributor.preferred_shopfront_message.present? end - def tabs_without_groups - base_shop_tabs([4, 4, 4]) - end - - def shop_tabs - current_distributor.groups.present? ? tabs_with_groups : tabs_without_groups + def shopfront_closed_message? + @order_cycles && @order_cycles.empty? && current_distributor.preferred_shopfront_closed_message.present? end end diff --git a/app/views/shopping_shared/_tabs.html.haml b/app/views/shopping_shared/_tabs.html.haml index 7161f0eed3..ede1a9c0c6 100644 --- a/app/views/shopping_shared/_tabs.html.haml +++ b/app/views/shopping_shared/_tabs.html.haml @@ -1,9 +1,14 @@ - shop_tabs.each do |tab| - = render "shopping_shared/tabs/#{tab[:name]}" + - if tab[:show] + = render "shopping_shared/tabs/#{tab[:name]}" .tabset-ctrl#shop-tabs{ navigate: 'true', prefix: 'shop', ng: { cloak: true } } + .tab-buttons + .row + - shop_tabs.each do |tab| + - if tab[:show] + .tab{ id: "tab_#{tab[:name]}", name: tab[:name] } + %a{ href: 'javascript:void(0)' }=tab[:title] + .row - - shop_tabs.each do |tab| - .small-12.columns.tab{ id: "tab_#{tab[:name]}", name: tab[:name], class: "" } - %a{ href: 'javascript:void(0)' }=tab[:title] .small-12.columns.tab-view diff --git a/config/locales/en.yml b/config/locales/en.yml index e2ef2352e3..471570804a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1597,7 +1597,9 @@ See the %{link} to find out more about %{sitename}'s features and to start using shopping_oc_closed_description: "Please wait until the next cycle opens (or contact us directly to see if we can accept any late orders)" shopping_oc_last_closed: "The last cycle closed %{distance_of_time} ago" shopping_oc_next_open: "The next cycle opens in %{distance_of_time}" - shopping_tabs_about: "About %{distributor}" + shopping_tabs_home: "Home" + shopping_tabs_shop: "Shop" + shopping_tabs_about: "About" shopping_tabs_contact: "Contact" shopping_contact_address: "Address" shopping_contact_web: "Contact" diff --git a/spec/helpers/shop_helper_spec.rb b/spec/helpers/shop_helper_spec.rb index fcd6bf7d65..7166674bb2 100644 --- a/spec/helpers/shop_helper_spec.rb +++ b/spec/helpers/shop_helper_spec.rb @@ -14,10 +14,12 @@ describe ShopHelper, type: :helper do let(:distributor) { create(:distributor_enterprise, groups: [group]) } let(:expectation) { [ - { name: 'about', title: t(:shopping_tabs_about, distributor: distributor.name), cols: 6 }, - { name: 'producers', title: t(:label_producers), cols: 2 }, - { name: 'contact', title: t(:shopping_tabs_contact), cols: 2 }, - { name: 'groups', title: t(:label_groups), cols: 2 } + {name: "home", show: false, title: "Home"}, + {name: "shop", show: true, title: "Shop"}, + {name: "about", show: true, title: "About"}, + {name: "producers", show: true, title: "Producers"}, + {name: "contact", show: true, title: "Contact"}, + {name: "groups", show: true, title: "Groups"} ] } @@ -26,7 +28,7 @@ describe ShopHelper, type: :helper do end it "should return the groups tab" do - expect(helper.shop_tabs).to eq(expectation) + expect(helper.shop_tabs).to eq(expectation) # end end @@ -34,9 +36,12 @@ describe ShopHelper, type: :helper do let(:distributor) { create(:distributor_enterprise) } let(:expectation) { [ - { name: 'about', title: t(:shopping_tabs_about, distributor: distributor.name), cols: 4 }, - { name: 'producers', title: t(:label_producers), cols: 4 }, - { name: 'contact', title: t(:shopping_tabs_contact), cols: 4 } + {name: "home", show: false, title: "Home"}, + {name: "shop", show: true, title: "Shop"}, + {name: "about", show: true, title: "About"}, + {name: "producers", show: true, title: "Producers"}, + {name: "contact", show: true, title: "Contact"}, + {name: "groups", show: false, title: "Groups"} ] }