mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Adapt shopfront_helper to show/hide panels and display new tabs
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user