From d353906bb849c5d89f971c85687b2bef967df2c4 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 10 Jul 2015 16:59:32 +1000 Subject: [PATCH 01/19] Content manage producer signup page --- app/controllers/admin/contents_controller.rb | 5 +- app/models/content_configuration.rb | 7 ++ app/views/admin/contents/edit.html.haml | 4 +- app/views/producers/signup.html.haml | 82 +------------------- 4 files changed, 15 insertions(+), 83 deletions(-) diff --git a/app/controllers/admin/contents_controller.rb b/app/controllers/admin/contents_controller.rb index a048981f5e..44ad851394 100644 --- a/app/controllers/admin/contents_controller.rb +++ b/app/controllers/admin/contents_controller.rb @@ -1,8 +1,9 @@ module Admin class ContentsController < Spree::Admin::BaseController def edit - @preferences_home = [:home_tagline_cta, :home_whats_happening] - @preferences_footer = [:footer_facebook_url, :footer_twitter_url, :footer_instagram_url, :footer_linkedin_url, :footer_googleplus_url, :footer_pinterest_url, :footer_email, :footer_links_md, :footer_about_url] + @preference_sections = [{name: 'Home page', preferences: [:home_tagline_cta, :home_whats_happening]}, + {name: 'Producer signup page', preferences: [:producer_signup_pricing_table_html, :producer_signup_case_studies_html, :producer_signup_detail_html]}, + {name: 'Footer', preferences: [:footer_facebook_url, :footer_twitter_url, :footer_instagram_url, :footer_linkedin_url, :footer_googleplus_url, :footer_pinterest_url, :footer_email, :footer_links_md, :footer_about_url]}] end def update diff --git a/app/models/content_configuration.rb b/app/models/content_configuration.rb index 6e36b67812..fbd274ba6c 100644 --- a/app/models/content_configuration.rb +++ b/app/models/content_configuration.rb @@ -1,7 +1,14 @@ class ContentConfiguration < Spree::Preferences::Configuration + # Home page preference :home_tagline_cta, :string, default: "Browse Open Food Network Australia" preference :home_whats_happening, :string, default: "Thanks for making the Open Food Network possible. Our vision is a better food system, and we're proud of what we're achieving together." + # Producer sign-up page + preference :producer_signup_pricing_table_html, :text, default: "(TODO: Pricing table)" + preference :producer_signup_case_studies_html, :text, default: "(TODO: Case studies)" + preference :producer_signup_detail_html, :text, default: "(TODO: Detail)" + + # Footer preference :footer_facebook_url, :string, default: "https://www.facebook.com/OpenFoodNet" preference :footer_twitter_url, :string, default: "https://twitter.com/OpenFoodNet" preference :footer_instagram_url, :string, default: "" diff --git a/app/views/admin/contents/edit.html.haml b/app/views/admin/contents/edit.html.haml index ef4467f09d..5de6a6ad1b 100644 --- a/app/views/admin/contents/edit.html.haml +++ b/app/views/admin/contents/edit.html.haml @@ -6,8 +6,8 @@ = form_tag main_app.admin_content_path, method: :put do #preferences - = render 'fieldset', name: 'Home page', preferences: @preferences_home - = render 'fieldset', name: 'Footer', preferences: @preferences_footer + - @preference_sections.each do |preference_section| + = render 'fieldset', name: preference_section[:name], preferences: preference_section[:preferences] .form-buttons.filter-actions.actions{"data-hook" => "buttons"} = button t(:update), 'icon-refresh' diff --git a/app/views/producers/signup.html.haml b/app/views/producers/signup.html.haml index 6f2cee2a5b..169d4b179f 100644 --- a/app/views/producers/signup.html.haml +++ b/app/views/producers/signup.html.haml @@ -20,79 +20,14 @@ -# If there is a time-sensitive offer you can write it here, e.g. -# Sign up before 30th June for an extra month free! %br - %table.signup-table.producers-table{cellpadding: "0", cellspacing: "0"} - %thead - %tr - %td - %h5 - %td.text-center{width: "20%"} - %h5 Basic - %td.text-center{width: "24%"} - %h5 Plus - %tr - %td - %p - %strong Profile - %p - %span.text-small Get a profile on the Open Food Network - including a listing on the Producers page and a pin on the OFN Map. These help people to find and connect with you. - %p - %span.text-small Option to add and manage your products on OFN, enabling you to act as a supplier to other OFN shopfronts. - %td.text-center - %i.ofn-i_003-check.text-big - %td.text-center - %i.ofn-i_003-check.text-big - %tr - %td - %p - %strong Shop - %p.text-small Get a shopfront on OFN to sell your produce direct! - %p.text-small Basic support included: - %ul.small - %li User manual - %li Post queries to discussion forum/via contact form - %li Report bugs/suggestions - %li Regular release notes – what's new - %td.text-center - %td.text-center - %i.ofn-i_003-check.text-big - %tfoot - %tr - %td - %td.text-center{valign: "top"} - %h2 Free - %td.text-center{valign: "top"} - %h2 - .text-small - first - %br - month - Free - %p.text-small - Then, 2% of total transactions - %br - %em - Capped at - %strong $50 - per month - %br - %em (Special offer for 2015) + = ContentConfig.producer_signup_pricing_table_html.html_safe #producer-case-studies .row .small-12.medium-10.medium-offset-1.columns %h2.text-center Stories from our producers. %br - .row - .small-12.medium-6.columns - = render 'shared/case_study', img_src: "/assets/case-studies/jonai.png", title: "Jonai Farms", description: "Jonai Farms is an ethical pork and beef “Community Supported Agriculture” farm that delivers to a range of hubs in Melbourne and central Victoria every month.", link: "http://www.jonaifarms.com.au" - .small-12.medium-6.columns - = render 'shared/case_study', img_src: "/assets/case-studies/wandiful.png", title: "Wandiful Produce", description: "Biodynamically grown in NE Victoria, Wandiful Produce supplies hazelnuts, chestnuts and associated products (bliss balls - yum!) shipped to your door.", link: "https://openfoodnetwork.org.au/wandiful-produce/shop" - .row - .small-12.medium-6.columns - = render 'shared/case_study', img_src: "/assets/case-studies/longley.png", title: "Longley Organic Farm", description: "Near Hobart, Longley Organic Farm provides berries and vegetables for local food cooperatives and small shops and through its roadside stall.", link: "https://openfoodnetwork.org.au/longley-organic-farm/shop" - .small-12.medium-6.columns - = render 'shared/case_study', img_src: "/assets/case-studies/jindivick.jpg", title: "Jindivick Hydroponics", description: "Selling through farmers markets and the South East Food Hub, Jindivick Hydroponics grow an ever increasing range of vegetables including tomatoes, cucumbers and beans.", link: "https://openfoodnetwork.org.au/producers#/#jindivick-hydroponics" - + = ContentConfig.producer_signup_case_studies_html.html_safe .pane#cta .row @@ -106,17 +41,6 @@ .row .small-12.medium-10.medium-offset-1.columns %h2.text-center Here's the detail. - = render 'shared/enterprise_type_flowchart', type: 'producers' - %h4 Join a marketplace of independent online food stores - %p Create an online shop front and join the network of online farmers markets on the Open Food Network. Set up a Producer Shop and sell your products direct to customers, or create a Food Hub and sell products from multiple producers. - - %h4 Connect with a new source of customers - %p Gain access to the growing crowd of conscientious buyers on the Open Food Network, all looking to make more ethical and sustainable choices when purchasing food. - %h4 Manage your business online - %p The Open Food Network provides online tools to help with the day-to-day running of your business. Manage your product listing and stock levels. Create, receive and manage orders from your buyers, and organise payments online. Generate invoices for orders and export them to your accounting software, and access a range of reports. - %h4 Start with a simple listing on our directory - %p Create a profile on the Open Food Network and gain exposure to a new marketplace of potential buyers. Tell your story in words and images, provide your contact details, and drive connections to your social and online presence. - %p Access new wholesale opportunities by connecting with food hubs in your region who can sell and distribute your products to buyers on the Open Food Network. - + = ContentConfig.producer_signup_detail_html.html_safe = render partial: "shared/footer" From a490d9696bcda77ac09d3b69035c1e68e8211dae Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 10 Jul 2015 17:11:06 +1000 Subject: [PATCH 02/19] Content manage hub signup page --- app/controllers/admin/contents_controller.rb | 1 + app/models/content_configuration.rb | 5 ++ app/views/shops/signup.html.haml | 78 +------------------- 3 files changed, 9 insertions(+), 75 deletions(-) diff --git a/app/controllers/admin/contents_controller.rb b/app/controllers/admin/contents_controller.rb index 44ad851394..ad66ca880c 100644 --- a/app/controllers/admin/contents_controller.rb +++ b/app/controllers/admin/contents_controller.rb @@ -3,6 +3,7 @@ module Admin def edit @preference_sections = [{name: 'Home page', preferences: [:home_tagline_cta, :home_whats_happening]}, {name: 'Producer signup page', preferences: [:producer_signup_pricing_table_html, :producer_signup_case_studies_html, :producer_signup_detail_html]}, + {name: 'Hub signup page', preferences: [:hub_signup_pricing_table_html, :hub_signup_case_studies_html, :hub_signup_detail_html]}, {name: 'Footer', preferences: [:footer_facebook_url, :footer_twitter_url, :footer_instagram_url, :footer_linkedin_url, :footer_googleplus_url, :footer_pinterest_url, :footer_email, :footer_links_md, :footer_about_url]}] end diff --git a/app/models/content_configuration.rb b/app/models/content_configuration.rb index fbd274ba6c..773d49f0b1 100644 --- a/app/models/content_configuration.rb +++ b/app/models/content_configuration.rb @@ -8,6 +8,11 @@ class ContentConfiguration < Spree::Preferences::Configuration preference :producer_signup_case_studies_html, :text, default: "(TODO: Case studies)" preference :producer_signup_detail_html, :text, default: "(TODO: Detail)" + # Hubs sign-up page + preference :hub_signup_pricing_table_html, :text, default: "(TODO: Pricing table)" + preference :hub_signup_case_studies_html, :text, default: "(TODO: Case studies)" + preference :hub_signup_detail_html, :text, default: "(TODO: Detail)" + # Footer preference :footer_facebook_url, :string, default: "https://www.facebook.com/OpenFoodNet" preference :footer_twitter_url, :string, default: "https://twitter.com/OpenFoodNet" diff --git a/app/views/shops/signup.html.haml b/app/views/shops/signup.html.haml index 72c319413f..a04f7d82e2 100644 --- a/app/views/shops/signup.html.haml +++ b/app/views/shops/signup.html.haml @@ -20,78 +20,14 @@ -# If there is a time-sensitive offer you can write it here, e.g. -# Sign up before 30th June for an extra month free! %br - %table.signup-table.hubs-table{cellpadding: "0", cellspacing: "0"} - %thead - %tr - %td - %h5 - %td.text-center{width: "20%"} - %h5 Basic - %td.text-center{width: "24%"} - %h5 Plus - %tr - %td - %p - %strong Profile - %p - %span.text-small Get a profile on the Open Food Network - including a listing on the Shops page and a pin on the OFN Map. These help people to find and connect with you. - %td.text-center - %i.ofn-i_003-check.text-big - %td.text-center - %i.ofn-i_003-check.text-big - %tr - %td - %p - %strong Shop - %p.text-small Get a shopfront on OFN to sell food from multiple suppliers & producers. - %p.text-small Basic support included: - %ul.small - %li User manual - %li Post queries to discussion forum/via contact form - %li Report bugs/suggestions - %li Regular release notes – what's new - %td.text-center - %td.text-center - %i.ofn-i_003-check.text-big - %tfoot - %tr - %td - %td.text-center{valign: "top"} - %h2 - Free - %td.text-center{valign: "top"} - %h2 - .text-small - First - %br - month - Free - %p.text-small - Then, 2% of transactions - %br - %em - Capped at - %strong $50 - per month - %br - %em (Special offer for 2015) + = ContentConfig.hub_signup_pricing_table_html.html_safe #shops-case-studies .row .small-12.medium-10.medium-offset-1.columns %h2.text-center Stories from our hubs. %br - .row - .small-12.medium-6.columns - = render 'shared/case_study', img_src: "/assets/case-studies/bfc_logo_square.png", title: "Bondi Food Collective", description: "Bondi Food Collective is a member-based not for profit that provide weekly fruit & veg picked fresh to order, plus dry foods - all organic and all Australian-grown.", link: "http://www.bondifoodcollective.org" - .small-12.medium-6.columns - = render 'shared/case_study', img_src: "/assets/case-studies/bonnie-beef-growers.png", title: "Bonnie Beef Growers", description: "Bonnie Beef Growers work on monthly order cycles for their wide range of beef products and also act as a hub for products from neighboring farms on the Sunshine Coast.", link: "http://www.bonniebeef.com.au" - .row - .small-12.medium-6.columns - = render 'shared/case_study', img_src: "/assets/case-studies/South_East_Food_Hub.png", title: "South East Food Hub", description: "South East Food Hub is a choose-your-own food box service supported by a collective of farmers in Melbourne’s south-east. It distributes food through buying groups or “food clubs”.", link: "http://www.southeastfoodhub.org" - .small-12.medium-6.columns - = render 'shared/case_study', img_src: "/assets/case-studies/baw-baw.png", title: "Baw Baw Organics", description: "A weekly seasonal vegetable box program, Baw Baw Organics services around 100 households with local produce in West Gippsland.", link: "https://bawbawfoodhub.org.au" - + = ContentConfig.hub_signup_case_studies_html.html_safe .pane#cta .row @@ -106,15 +42,7 @@ .row .small-12.medium-10.medium-offset-1.columns %h2.text-center Here's the detail. - = render 'shared/enterprise_type_flowchart', type: 'hubs' - - %h4 Join a marketplace of independent online food stores - %p Create a hub profile on the Open Food Network and gain exposure to a new marketplace of potential buyers. Tell your story in words and images, provide your contact details, and drive connections to your social and online presence. Set up a “Hub” shop and sell products from multiple producers. - %h4 Connect with a new source of customers and suppliers - %p Gain access to the growing crowd of conscientious buyers on the Open Food Network, all looking to make more ethical and sustainable choices when purchasing food. - %p Access new supply opportunities by connecting with producers in your region, sell their products in your shop. - %h4 Manage your business online - %p The Open Food Network provides online tools to help with the day-to-day running of your business. Manage your product listing and stock levels. Create, receive and manage orders from your buyers, and organise payments online. Generate invoices for orders and export them to your accounting software, and access a range of reports. + = ContentConfig.hub_signup_detail_html.html_safe = render partial: "shared/footer" From bd83dde89de3d23c23977ecb90ab7c6ebd43826d Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 10 Jul 2015 17:18:14 +1000 Subject: [PATCH 03/19] Content manage group signup page --- app/controllers/admin/contents_controller.rb | 4 +- app/models/content_configuration.rb | 5 ++ app/views/groups/signup.html.haml | 75 +------------------- 3 files changed, 11 insertions(+), 73 deletions(-) diff --git a/app/controllers/admin/contents_controller.rb b/app/controllers/admin/contents_controller.rb index ad66ca880c..15cfe4bb69 100644 --- a/app/controllers/admin/contents_controller.rb +++ b/app/controllers/admin/contents_controller.rb @@ -4,7 +4,9 @@ module Admin @preference_sections = [{name: 'Home page', preferences: [:home_tagline_cta, :home_whats_happening]}, {name: 'Producer signup page', preferences: [:producer_signup_pricing_table_html, :producer_signup_case_studies_html, :producer_signup_detail_html]}, {name: 'Hub signup page', preferences: [:hub_signup_pricing_table_html, :hub_signup_case_studies_html, :hub_signup_detail_html]}, - {name: 'Footer', preferences: [:footer_facebook_url, :footer_twitter_url, :footer_instagram_url, :footer_linkedin_url, :footer_googleplus_url, :footer_pinterest_url, :footer_email, :footer_links_md, :footer_about_url]}] + {name: 'Group signup page', preferences: [:group_signup_pricing_table_html, :group_signup_case_studies_html, :group_signup_detail_html]}, + {name: 'Footer', preferences: [:footer_facebook_url, :footer_twitter_url, :footer_instagram_url, :footer_linkedin_url, :footer_googleplus_url, :footer_pinterest_url, + :footer_email, :footer_links_md, :footer_about_url]}] end def update diff --git a/app/models/content_configuration.rb b/app/models/content_configuration.rb index 773d49f0b1..e06944933f 100644 --- a/app/models/content_configuration.rb +++ b/app/models/content_configuration.rb @@ -13,6 +13,11 @@ class ContentConfiguration < Spree::Preferences::Configuration preference :hub_signup_case_studies_html, :text, default: "(TODO: Case studies)" preference :hub_signup_detail_html, :text, default: "(TODO: Detail)" + # Groups sign-up page + preference :group_signup_pricing_table_html, :text, default: "(TODO: Pricing table)" + preference :group_signup_case_studies_html, :text, default: "(TODO: Case studies)" + preference :group_signup_detail_html, :text, default: "(TODO: Detail)" + # Footer preference :footer_facebook_url, :string, default: "https://www.facebook.com/OpenFoodNet" preference :footer_twitter_url, :string, default: "https://twitter.com/OpenFoodNet" diff --git a/app/views/groups/signup.html.haml b/app/views/groups/signup.html.haml index cbd44faec1..c1c885d0f0 100644 --- a/app/views/groups/signup.html.haml +++ b/app/views/groups/signup.html.haml @@ -35,63 +35,14 @@ -# / If there is a time-sensitive offer you can write it here, e.g. -# Time-sensitive offer goes here! %br - %table.signup-table.hubs-table{cellpadding: "0", cellspacing: "0"} - %thead - %tr - %td - %h5 - %td.text-center{width: "24%"} - %h5 OFN Group - %tr - %td - %p - %strong Promote your members - %br - %span.text-small Promote your local and/or member businesses through a group page - %td.text-center - %i.ofn-i_003-check.text-big - %tr - %td - %p - %strong Unique URL - %br - %span.text-small Your own organisation page/url on the Open Food Network. - %td.text-center - %i.ofn-i_003-check.text-big - %tr - %td - %p - %strong Region map & listings - %br - %span.text-small Easy search from your own list view and your own map - links through to profile pages for your member/local producers and/or food businesses. - %td.text-center - %i.ofn-i_003-check.text-big - %tr - %td - %p - %strong Opt-in extras - %p.text-small Available additional support: - %ul.small - %li Tailored workshop(s) for your stakeholders - %li Tailored training and support package - %td.text-center - %tfoot - %tr - %td - %td.text-center{valign: "top"} - %h2 - $5,500 + = ContentConfig.group_signup_pricing_table_html.html_safe #shops-case-studies .row .small-12.medium-10.medium-offset-1.columns %h2.text-center Case studies %br - .row - .small-12.medium-6.columns - = render 'shared/case_study', img_src: "/assets/case-studies/South_East_Food_Hub.png", title: "South East Food Group", description: "The South East Food Hub lists all its participating producers and hubs (food clubs) on its group page on the Open Food Network.", link: "https://openfoodnetwork.org.au/groups/6" - .small-12.medium-6.columns - = render 'shared/case_study', img_src: "/assets/case-studies/mt-alexander.png", title: "Mt Alexander Local Produce Network", description: "This community organisation promotes local sustainable food production and consumption through its group page. It lists sources of local sustenance — direct from the grower or through a range local shops and markets.".html_safe, link: "https://openfoodnetwork.org.au/groups/10" + = ContentConfig.group_signup_case_studies_html.html_safe .pane#cta .row @@ -105,26 +56,6 @@ .row .small-12.medium-10.medium-offset-1.columns %h2.text-center Here's the detail. - .row - .small-12.medium-6.columns - %h4 A sub-heading goes here - %p Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer in odio vel ex efficitur auctor. Nam rhoncus, tortor vel varius varius, magna lorem dignissim libero, at dignissim erat leo id tortor. Donec gravida quis augue sed pellentesque. Morbi laoreet efficitur mi, id tempus diam lacinia eu. - %h5 Smaller sub-heading goes here - %p.text-small Vestibulum eu quam neque. Aenean porta velit sit amet metus mattis, ut pulvinar dui semper. Nunc ornare scelerisque varius. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Cras a magna nec augue suscipit fermentum at ac urna. - %ul.text-small - %li A bullet point - %li Another point - %li A third point goes here - %p.text-small Quisque urna lacus, tristique sed rutrum a, volutpat eu diam. Nam placerat mi nec enim tincidunt, nec dapibus risus molestie. Praesent mattis eu dolor nec sollicitudin. Cras ut magna sem. Etiam vitae commodo augue, sit amet feugiat diam. - .small-12.medium-6.columns - %h4 A sub-heading goes here - %p Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer in odio vel ex efficitur auctor. Nam rhoncus, tortor vel varius varius, magna lorem dignissim libero, at dignissim erat leo id tortor. Donec gravida quis augue sed pellentesque. Morbi laoreet efficitur mi, id tempus diam lacinia eu. - %h5 Smaller sub-heading goes here - %p.text-small Vestibulum eu quam neque. Aenean porta velit sit amet metus mattis, ut pulvinar dui semper. Nunc ornare scelerisque varius. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Cras a magna nec augue suscipit fermentum at ac urna. - %ul.text-small - %li A bullet point - %li Another point - %li A third point goes here - %p.text-small Quisque urna lacus, tristique sed rutrum a, volutpat eu diam. Nam placerat mi nec enim tincidunt, nec dapibus risus molestie. Praesent mattis eu dolor nec sollicitudin. Cras ut magna sem. Etiam vitae commodo augue, sit amet feugiat diam. + = ContentConfig.group_signup_detail_html.html_safe = render partial: "shared/footer" From 1f72e4001cb0ffab62d2e5069c8c49bcd3dbe1dc Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 10 Jul 2015 17:28:49 +1000 Subject: [PATCH 04/19] Use site name config for hero title --- app/views/home/index.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml index 7388466973..28446b21da 100644 --- a/app/views/home/index.html.haml +++ b/app/views/home/index.html.haml @@ -7,7 +7,7 @@ %h1 / TODO: Rohan - logo asset & width is content manageable: -# TODO: SVGify - %img{src: "/assets/logo-white-notext.png", width: "250", title: "Open Food Network Australia"} + %img{src: "/assets/logo-white-notext.png", width: "250", title: Spree::Config.site_name} %br/ %a.button.transparent{href: "/shops"} Shop Now From 5de9a5eb546bf072626136610dde7fbf2b590fcb Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 10 Jul 2015 17:35:51 +1000 Subject: [PATCH 05/19] Add config setting to enable/disable stats on home page --- app/controllers/admin/contents_controller.rb | 2 +- app/controllers/home_controller.rb | 10 +++--- app/models/content_configuration.rb | 1 + app/views/home/_stats.html.haml | 33 ++++++++++---------- config/locales/en.yml | 1 + 5 files changed, 26 insertions(+), 21 deletions(-) diff --git a/app/controllers/admin/contents_controller.rb b/app/controllers/admin/contents_controller.rb index 15cfe4bb69..cdce47e0ff 100644 --- a/app/controllers/admin/contents_controller.rb +++ b/app/controllers/admin/contents_controller.rb @@ -1,7 +1,7 @@ module Admin class ContentsController < Spree::Admin::BaseController def edit - @preference_sections = [{name: 'Home page', preferences: [:home_tagline_cta, :home_whats_happening]}, + @preference_sections = [{name: 'Home page', preferences: [:home_tagline_cta, :home_whats_happening, :home_show_stats]}, {name: 'Producer signup page', preferences: [:producer_signup_pricing_table_html, :producer_signup_case_studies_html, :producer_signup_detail_html]}, {name: 'Hub signup page', preferences: [:hub_signup_pricing_table_html, :hub_signup_case_studies_html, :hub_signup_detail_html]}, {name: 'Group signup page', preferences: [:group_signup_pricing_table_html, :group_signup_case_studies_html, :group_signup_detail_html]}, diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index d1e1ae472c..07ba097f85 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -2,9 +2,11 @@ class HomeController < BaseController layout 'darkswarm' def index - @num_distributors = Enterprise.is_distributor.activated.visible.count - @num_producers = Enterprise.is_primary_producer.activated.visible.count - @num_users = Spree::User.joins(:orders).merge(Spree::Order.complete).count('DISTINCT spree_users.*') - @num_orders = Spree::Order.complete.count + if ContentConfig.home_show_stats + @num_distributors = Enterprise.is_distributor.activated.visible.count + @num_producers = Enterprise.is_primary_producer.activated.visible.count + @num_users = Spree::User.joins(:orders).merge(Spree::Order.complete).count('DISTINCT spree_users.*') + @num_orders = Spree::Order.complete.count + end end end diff --git a/app/models/content_configuration.rb b/app/models/content_configuration.rb index e06944933f..f4b782b99e 100644 --- a/app/models/content_configuration.rb +++ b/app/models/content_configuration.rb @@ -2,6 +2,7 @@ class ContentConfiguration < Spree::Preferences::Configuration # Home page preference :home_tagline_cta, :string, default: "Browse Open Food Network Australia" preference :home_whats_happening, :string, default: "Thanks for making the Open Food Network possible. Our vision is a better food system, and we're proud of what we're achieving together." + preference :home_show_stats, :boolean, default: true # Producer sign-up page preference :producer_signup_pricing_table_html, :text, default: "(TODO: Pricing table)" diff --git a/app/views/home/_stats.html.haml b/app/views/home/_stats.html.haml index 374a98cdbf..6c686a22b7 100644 --- a/app/views/home/_stats.html.haml +++ b/app/views/home/_stats.html.haml @@ -4,19 +4,20 @@ %h2 We're creating a new food system. .row.content - .small-12.medium-3.columns.text-center - %h4 - %strong= number_with_delimiter @num_producers - food producers - .small-12.medium-3.columns.text-center - %h4 - %strong= number_with_delimiter @num_distributors - food shops - .small-12.medium-3.columns.text-center - %h4 - %strong= number_with_delimiter @num_users - food shoppers - .small-12.medium-3.columns.text-center - %h4 - %strong= number_with_delimiter @num_orders - food orders + - if ContentConfig.home_show_stats + .small-12.medium-3.columns.text-center + %h4 + %strong= number_with_delimiter @num_producers + food producers + .small-12.medium-3.columns.text-center + %h4 + %strong= number_with_delimiter @num_distributors + food shops + .small-12.medium-3.columns.text-center + %h4 + %strong= number_with_delimiter @num_users + food shoppers + .small-12.medium-3.columns.text-center + %h4 + %strong= number_with_delimiter @num_orders + food orders diff --git a/config/locales/en.yml b/config/locales/en.yml index 05ad5113ee..ffa4e49702 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -20,6 +20,7 @@ en: producers_join: Australian producers are now welcome to join the Open Food Network. charges_sales_tax: Charges GST? + home_show_stats: "Show statistics" home_tagline_cta: "Tagline call to action" home_whats_happening: "What's happening" footer_facebook_url: "Facebook URL" From 372b17703a69f6424da4c954619c3b01c996316c Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 10 Jul 2015 17:39:21 +1000 Subject: [PATCH 06/19] Remove unused content fields and partial --- app/controllers/admin/contents_controller.rb | 2 +- app/models/content_configuration.rb | 2 -- .../shared/_enterprise_type_flowchart.html.haml | 16 ---------------- config/locales/en.yml | 2 -- 4 files changed, 1 insertion(+), 21 deletions(-) delete mode 100644 app/views/shared/_enterprise_type_flowchart.html.haml diff --git a/app/controllers/admin/contents_controller.rb b/app/controllers/admin/contents_controller.rb index cdce47e0ff..09c80128e9 100644 --- a/app/controllers/admin/contents_controller.rb +++ b/app/controllers/admin/contents_controller.rb @@ -1,7 +1,7 @@ module Admin class ContentsController < Spree::Admin::BaseController def edit - @preference_sections = [{name: 'Home page', preferences: [:home_tagline_cta, :home_whats_happening, :home_show_stats]}, + @preference_sections = [{name: 'Home page', preferences: [:home_show_stats]}, {name: 'Producer signup page', preferences: [:producer_signup_pricing_table_html, :producer_signup_case_studies_html, :producer_signup_detail_html]}, {name: 'Hub signup page', preferences: [:hub_signup_pricing_table_html, :hub_signup_case_studies_html, :hub_signup_detail_html]}, {name: 'Group signup page', preferences: [:group_signup_pricing_table_html, :group_signup_case_studies_html, :group_signup_detail_html]}, diff --git a/app/models/content_configuration.rb b/app/models/content_configuration.rb index f4b782b99e..5fd4e5e0f7 100644 --- a/app/models/content_configuration.rb +++ b/app/models/content_configuration.rb @@ -1,7 +1,5 @@ class ContentConfiguration < Spree::Preferences::Configuration # Home page - preference :home_tagline_cta, :string, default: "Browse Open Food Network Australia" - preference :home_whats_happening, :string, default: "Thanks for making the Open Food Network possible. Our vision is a better food system, and we're proud of what we're achieving together." preference :home_show_stats, :boolean, default: true # Producer sign-up page diff --git a/app/views/shared/_enterprise_type_flowchart.html.haml b/app/views/shared/_enterprise_type_flowchart.html.haml deleted file mode 100644 index 7fda2e0891..0000000000 --- a/app/views/shared/_enterprise_type_flowchart.html.haml +++ /dev/null @@ -1,16 +0,0 @@ -.enterprise-type-flowchart - = image_tag "enterprise-type.png" - %br - %br - %br - %br - %br - %p{style: "text-align: center;"} - %a{href: "http://www.openfoodnetwork.org/platform/features/"} More Features - \| - %a{href: "http://www.openfoodnetwork.org/platform/user-guide/"} User Guide - \| - - if type == 'hubs' - %a{href: "http://www.openfoodnetwork.org/platform/user-guide/faqs/hub-faqs/"} Hub FAQs - - elsif type == 'producers' - %a{href: "http://www.openfoodnetwork.org/platform/user-guide/faqs/producer-faqs/"} Producer FAQs diff --git a/config/locales/en.yml b/config/locales/en.yml index ffa4e49702..8f759b717d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -21,8 +21,6 @@ en: charges_sales_tax: Charges GST? home_show_stats: "Show statistics" - home_tagline_cta: "Tagline call to action" - home_whats_happening: "What's happening" footer_facebook_url: "Facebook URL" footer_twitter_url: "Twitter URL" footer_instagram_url: "Instagram URL" From 48878714741ea00547079d1c193f40f4d2ed3431 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 10 Jul 2015 17:41:03 +1000 Subject: [PATCH 07/19] Remove SVG TODOs - we'll ask admins to upload double-sized images for retina instead --- app/views/home/index.html.haml | 1 - app/views/shared/menu/_large_menu.html.haml | 1 - 2 files changed, 2 deletions(-) diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml index 28446b21da..3f284a5e37 100644 --- a/app/views/home/index.html.haml +++ b/app/views/home/index.html.haml @@ -6,7 +6,6 @@ .small-12.text-center.columns %h1 / TODO: Rohan - logo asset & width is content manageable: - -# TODO: SVGify %img{src: "/assets/logo-white-notext.png", width: "250", title: Spree::Config.site_name} %br/ %a.button.transparent{href: "/shops"} diff --git a/app/views/shared/menu/_large_menu.html.haml b/app/views/shared/menu/_large_menu.html.haml index 97a815a27a..52bb8a0f4a 100644 --- a/app/views/shared/menu/_large_menu.html.haml +++ b/app/views/shared/menu/_large_menu.html.haml @@ -3,7 +3,6 @@ %ul.left %li.ofn-logo %a{href: root_path} - -# TODO: SVGify (though this image is double-size for retina) %img{src: "/assets/logo-australia.png", width: "250", height: "51"} %ul.center %li From 1b17a7fb35d3fdb23082eb80e3e1106631c59fab Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Tue, 14 Jul 2015 14:54:05 +1000 Subject: [PATCH 08/19] Add logo field to ContentConfig --- app/models/content_configuration.rb | 10 +++++++ lib/open_food_network/paperclippable.rb | 35 +++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 lib/open_food_network/paperclippable.rb diff --git a/app/models/content_configuration.rb b/app/models/content_configuration.rb index 5fd4e5e0f7..dd2e76ed8b 100644 --- a/app/models/content_configuration.rb +++ b/app/models/content_configuration.rb @@ -1,4 +1,14 @@ +require 'open_food_network/paperclippable' + class ContentConfiguration < Spree::Preferences::Configuration + # Header + include OpenFoodNetwork::Paperclippable + preference :logo_file_name, :string + preference :logo_content_type, :string + preference :logo_file_size, :integer + preference :logo_updated_at, :string + has_attached_file :logo + # Home page preference :home_show_stats, :boolean, default: true diff --git a/lib/open_food_network/paperclippable.rb b/lib/open_food_network/paperclippable.rb new file mode 100644 index 0000000000..a66d52211e --- /dev/null +++ b/lib/open_food_network/paperclippable.rb @@ -0,0 +1,35 @@ +# Allow use of Paperclip's has_attached_file on non-ActiveRecord classes +# https://gist.github.com/basgys/5712426 + +module OpenFoodNetwork + module Paperclippable + def self.included(base) + base.send :extend, ActiveModel::Naming + base.send :extend, ActiveModel::Callbacks + base.send :include, ActiveModel::Validations + base.send :include, Paperclip::Glue + + # Paperclip required callbacks + base.send :define_model_callbacks, :save, only: [:after] + base.send :define_model_callbacks, :commit, only: [:after] + base.send :define_model_callbacks, :destroy, only: [:before, :after] + end + + # ActiveModel requirements + def to_model + self + end + + def valid?() true end + def new_record?() true end + def destroyed?() true end + + def errors + obj = Object.new + def obj.[](key) [] end + def obj.full_messages() [] end + def obj.any?() false end + obj + end + end +end From 1234b351998011ff72c26e7a0b5b52aeaed5e28e Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 16 Jul 2015 12:16:38 +1000 Subject: [PATCH 09/19] Add file handling to Spree::Preferences::Configuration --- .../preferences/configuration_decorator.rb | 38 ++++++++++++ .../spree/preferences/configuration_spec.rb | 60 +++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 app/models/spree/preferences/configuration_decorator.rb create mode 100644 spec/models/spree/preferences/configuration_spec.rb diff --git a/app/models/spree/preferences/configuration_decorator.rb b/app/models/spree/preferences/configuration_decorator.rb new file mode 100644 index 0000000000..dc0e5f1aef --- /dev/null +++ b/app/models/spree/preferences/configuration_decorator.rb @@ -0,0 +1,38 @@ +module Spree::Preferences + Configuration.class_eval do + def get_preference_with_files(key) + if !has_preference?(key) && has_attachment?(key) + send(key) + else + get_preference_without_files(key) + end + end + alias_method_chain :get_preference, :files + alias :[] :get_preference + + + def preference_type_with_files(name) + if has_attachment? name + :file + else + preference_type_without_files(name) + end + end + alias_method_chain :preference_type, :files + + + # Spree's Configuration responds to preference methods via method_missing, but doesn't + # override respond_to?, which consequently reports those methods as unavailable. Paperclip + # errors if respond_to? isn't correct, so we override it here. + def respond_to?(method, include_all=false) + name = method.to_s.gsub('=', '') + super(self.class.preference_getter_method(name), include_all) || super(method, include_all) + end + + + def has_attachment?(name) + self.class.respond_to?(:attachment_definitions) && + self.class.attachment_definitions.keys.include?(name) + end + end +end diff --git a/spec/models/spree/preferences/configuration_spec.rb b/spec/models/spree/preferences/configuration_spec.rb new file mode 100644 index 0000000000..77d8f03666 --- /dev/null +++ b/spec/models/spree/preferences/configuration_spec.rb @@ -0,0 +1,60 @@ +require 'spec_helper' + +module Spree + module Preferences + class TestConfiguration < Configuration + preference :name, :string + + include OpenFoodNetwork::Paperclippable + preference :logo_file_name, :string + preference :logo_content_type, :string + preference :logo_file_size, :integer + preference :logo_updated_at, :string + has_attached_file :logo + end + + describe Configuration do + let(:c) { TestConfiguration.new } + + describe "getting preferences" do + it "returns regular preferences" do + c.name = 'foo' + c.get_preference(:name).should == 'foo' + end + + it "returns file preferences" do + c.get_preference(:logo).should be_a Paperclip::Attachment + end + + it "returns regular preferences via []" do + c.name = 'foo' + c[:name].should == 'foo' + end + + it "returns file preferences via []" do + c[:logo].should be_a Paperclip::Attachment + end + end + + describe "getting preference types" do + it "returns regular preference types" do + c.preference_type(:name).should == :string + end + + it "returns file preference types" do + c.preference_type(:logo).should == :file + end + end + + describe "respond_to?" do + it "responds to preference getters" do + c.respond_to?(:name).should be_true + end + + it "responds to preference setters" do + c.respond_to?(:name=).should be_true + end + end + end + end +end From 0e67a116b6727f67d4808fcb43f11314475ad0b2 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 16 Jul 2015 12:22:21 +1000 Subject: [PATCH 10/19] Admin can upload logo for ContentConfig --- app/controllers/admin/contents_controller.rb | 12 +++++++++--- app/helpers/spree/admin/base_helper_decorator.rb | 10 ++++++++++ app/views/admin/contents/edit.html.haml | 2 +- lib/open_food_network/paperclippable.rb | 10 ++++++++++ spec/features/admin/content_spec.rb | 12 +++++++++++- 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin/contents_controller.rb b/app/controllers/admin/contents_controller.rb index 09c80128e9..02dc246930 100644 --- a/app/controllers/admin/contents_controller.rb +++ b/app/controllers/admin/contents_controller.rb @@ -1,7 +1,8 @@ module Admin class ContentsController < Spree::Admin::BaseController def edit - @preference_sections = [{name: 'Home page', preferences: [:home_show_stats]}, + @preference_sections = [{name: 'Header', preferences: [:logo]}, + {name: 'Home page', preferences: [:home_show_stats]}, {name: 'Producer signup page', preferences: [:producer_signup_pricing_table_html, :producer_signup_case_studies_html, :producer_signup_detail_html]}, {name: 'Hub signup page', preferences: [:hub_signup_pricing_table_html, :hub_signup_case_studies_html, :hub_signup_detail_html]}, {name: 'Group signup page', preferences: [:group_signup_pricing_table_html, :group_signup_case_studies_html, :group_signup_detail_html]}, @@ -11,9 +12,14 @@ module Admin def update params.each do |name, value| - next unless ContentConfig.has_preference? name - ContentConfig[name] = value + if ContentConfig.has_preference?(name) || ContentConfig.has_attachment?(name) + ContentConfig.send("#{name}=", value) + end end + + # Save any uploaded images + ContentConfig.save + flash[:success] = t(:successfully_updated, :resource => "Your content") redirect_to main_app.edit_admin_content_path diff --git a/app/helpers/spree/admin/base_helper_decorator.rb b/app/helpers/spree/admin/base_helper_decorator.rb index e278626c5c..82bf794073 100644 --- a/app/helpers/spree/admin/base_helper_decorator.rb +++ b/app/helpers/spree/admin/base_helper_decorator.rb @@ -15,6 +15,16 @@ module Spree link_to_with_icon('icon-trash', name, url, :class => "remove_fields #{options[:class]}", :data => {:action => 'remove'}, :title => t(:remove)) + f.hidden_field(:_destroy) end + + + def preference_field_tag_with_files(name, value, options) + if options[:type] == :file + file_field_tag name, preference_field_options(options) + else + preference_field_tag_without_files name, value, options + end + end + alias_method_chain :preference_field_tag, :files end end end diff --git a/app/views/admin/contents/edit.html.haml b/app/views/admin/contents/edit.html.haml index 5de6a6ad1b..82751abebc 100644 --- a/app/views/admin/contents/edit.html.haml +++ b/app/views/admin/contents/edit.html.haml @@ -4,7 +4,7 @@ Content -= form_tag main_app.admin_content_path, method: :put do += form_tag main_app.admin_content_path, method: :put, multipart: true do #preferences - @preference_sections.each do |preference_section| = render 'fieldset', name: preference_section[:name], preferences: preference_section[:preferences] diff --git a/lib/open_food_network/paperclippable.rb b/lib/open_food_network/paperclippable.rb index a66d52211e..78b4d1a100 100644 --- a/lib/open_food_network/paperclippable.rb +++ b/lib/open_food_network/paperclippable.rb @@ -13,6 +13,10 @@ module OpenFoodNetwork base.send :define_model_callbacks, :save, only: [:after] base.send :define_model_callbacks, :commit, only: [:after] base.send :define_model_callbacks, :destroy, only: [:before, :after] + + # Initialise an ID + base.send :attr_accessor, :id + base.instance_variable_set :@id, 1 end # ActiveModel requirements @@ -24,6 +28,12 @@ module OpenFoodNetwork def new_record?() true end def destroyed?() true end + def save + run_callbacks :save do + end + true + end + def errors obj = Object.new def obj.[](key) [] end diff --git a/spec/features/admin/content_spec.rb b/spec/features/admin/content_spec.rb index 00a162f0b4..073ae35e3c 100644 --- a/spec/features/admin/content_spec.rb +++ b/spec/features/admin/content_spec.rb @@ -7,11 +7,13 @@ feature %q{ include AuthenticationWorkflow include WebHelper - scenario "filling in a setting shows the result on the home page" do + before do login_to_admin_section click_link 'Configuration' click_link 'Content' + end + scenario "filling in a setting shows the result on the home page" do fill_in 'footer_facebook_url', with: '' fill_in 'footer_twitter_url', with: 'http://twitter.com/me' fill_in 'footer_links_md', with: '[markdown link](/)' @@ -27,4 +29,12 @@ feature %q{ # And markdown is rendered page.should have_link 'markdown link' end + + scenario "uploading logos" do + attach_file 'logo', "#{Rails.root}/app/assets/images/logo-white.png" + click_button 'Update' + page.should have_content 'Your content has been successfully updated!' + + ContentConfig.logo.to_s.should include "logo-white" + end end From 1d67e3b2b88601b61580507d71822c11c5d46295 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 17 Jul 2015 12:04:08 +1000 Subject: [PATCH 11/19] Fix image update, display logo on frontend --- app/models/spree/preferences/configuration_decorator.rb | 2 +- app/views/shared/menu/_large_menu.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/spree/preferences/configuration_decorator.rb b/app/models/spree/preferences/configuration_decorator.rb index dc0e5f1aef..3c01caa444 100644 --- a/app/models/spree/preferences/configuration_decorator.rb +++ b/app/models/spree/preferences/configuration_decorator.rb @@ -32,7 +32,7 @@ module Spree::Preferences def has_attachment?(name) self.class.respond_to?(:attachment_definitions) && - self.class.attachment_definitions.keys.include?(name) + self.class.attachment_definitions.keys.include?(name.to_sym) end end end diff --git a/app/views/shared/menu/_large_menu.html.haml b/app/views/shared/menu/_large_menu.html.haml index 52bb8a0f4a..4f71e1c93e 100644 --- a/app/views/shared/menu/_large_menu.html.haml +++ b/app/views/shared/menu/_large_menu.html.haml @@ -3,7 +3,7 @@ %ul.left %li.ofn-logo %a{href: root_path} - %img{src: "/assets/logo-australia.png", width: "250", height: "51"} + %img{src: ContentConfig.logo.url, width: "250", height: "51"} %ul.center %li %a{href: main_app.shops_path} From 66b4eb4c5ddf514517e9f567f9f27c3b60aa3a55 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 17 Jul 2015 15:18:07 +1000 Subject: [PATCH 12/19] Move Spree::Preferences::Configuration patches into superclass FileConfiguration --- app/models/content_configuration.rb | 7 +-- .../preferences/configuration_decorator.rb | 34 ------------- .../spree/preferences/file_configuration.rb | 50 +++++++++++++++++++ ...ion_spec.rb => file_configuration_spec.rb} | 9 ++-- 4 files changed, 55 insertions(+), 45 deletions(-) create mode 100644 app/models/spree/preferences/file_configuration.rb rename spec/models/spree/preferences/{configuration_spec.rb => file_configuration_spec.rb} (84%) diff --git a/app/models/content_configuration.rb b/app/models/content_configuration.rb index dd2e76ed8b..32a2065c5d 100644 --- a/app/models/content_configuration.rb +++ b/app/models/content_configuration.rb @@ -1,12 +1,9 @@ require 'open_food_network/paperclippable' -class ContentConfiguration < Spree::Preferences::Configuration +class ContentConfiguration < Spree::Preferences::FileConfiguration # Header include OpenFoodNetwork::Paperclippable - preference :logo_file_name, :string - preference :logo_content_type, :string - preference :logo_file_size, :integer - preference :logo_updated_at, :string + file_preference :logo has_attached_file :logo # Home page diff --git a/app/models/spree/preferences/configuration_decorator.rb b/app/models/spree/preferences/configuration_decorator.rb index 3c01caa444..04a9f35f6b 100644 --- a/app/models/spree/preferences/configuration_decorator.rb +++ b/app/models/spree/preferences/configuration_decorator.rb @@ -1,38 +1,4 @@ module Spree::Preferences Configuration.class_eval do - def get_preference_with_files(key) - if !has_preference?(key) && has_attachment?(key) - send(key) - else - get_preference_without_files(key) - end - end - alias_method_chain :get_preference, :files - alias :[] :get_preference - - - def preference_type_with_files(name) - if has_attachment? name - :file - else - preference_type_without_files(name) - end - end - alias_method_chain :preference_type, :files - - - # Spree's Configuration responds to preference methods via method_missing, but doesn't - # override respond_to?, which consequently reports those methods as unavailable. Paperclip - # errors if respond_to? isn't correct, so we override it here. - def respond_to?(method, include_all=false) - name = method.to_s.gsub('=', '') - super(self.class.preference_getter_method(name), include_all) || super(method, include_all) - end - - - def has_attachment?(name) - self.class.respond_to?(:attachment_definitions) && - self.class.attachment_definitions.keys.include?(name.to_sym) - end end end diff --git a/app/models/spree/preferences/file_configuration.rb b/app/models/spree/preferences/file_configuration.rb new file mode 100644 index 0000000000..5d84e37fdf --- /dev/null +++ b/app/models/spree/preferences/file_configuration.rb @@ -0,0 +1,50 @@ +module Spree::Preferences + class FileConfiguration < Configuration + + # Ideally, we'd alias_method_chain preference to add new type. However, failcake. + def self.file_preference(name) + preference "#{name}_file_name", :string + preference "#{name}_content_type", :string + preference "#{name}_file_size", :integer + preference "#{name}_updated_at", :string + end + + + # TODO: Rewrite with super + + def get_preference_with_files(key) + if !has_preference?(key) && has_attachment?(key) + send(key) + else + get_preference_without_files(key) + end + end + alias_method_chain :get_preference, :files + alias :[] :get_preference + + + def preference_type_with_files(name) + if has_attachment? name + :file + else + preference_type_without_files(name) + end + end + alias_method_chain :preference_type, :files + + + # Spree's Configuration responds to preference methods via method_missing, but doesn't + # override respond_to?, which consequently reports those methods as unavailable. Paperclip + # errors if respond_to? isn't correct, so we override it here. + def respond_to?(method, include_all=false) + name = method.to_s.gsub('=', '') + super(self.class.preference_getter_method(name), include_all) || super(method, include_all) + end + + + def has_attachment?(name) + self.class.respond_to?(:attachment_definitions) && + self.class.attachment_definitions.keys.include?(name.to_sym) + end + end +end diff --git a/spec/models/spree/preferences/configuration_spec.rb b/spec/models/spree/preferences/file_configuration_spec.rb similarity index 84% rename from spec/models/spree/preferences/configuration_spec.rb rename to spec/models/spree/preferences/file_configuration_spec.rb index 77d8f03666..77aabc637e 100644 --- a/spec/models/spree/preferences/configuration_spec.rb +++ b/spec/models/spree/preferences/file_configuration_spec.rb @@ -2,18 +2,15 @@ require 'spec_helper' module Spree module Preferences - class TestConfiguration < Configuration + class TestConfiguration < FileConfiguration preference :name, :string include OpenFoodNetwork::Paperclippable - preference :logo_file_name, :string - preference :logo_content_type, :string - preference :logo_file_size, :integer - preference :logo_updated_at, :string + file_preference :logo has_attached_file :logo end - describe Configuration do + describe FileConfiguration do let(:c) { TestConfiguration.new } describe "getting preferences" do From e4a4cdd9150e99aa107742c661b4d5cf618241b6 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 17 Jul 2015 15:22:44 +1000 Subject: [PATCH 13/19] Rewrite alias_method_chain to use super. Ahhhhh :) --- app/models/content_configuration.rb | 2 +- .../spree/preferences/file_configuration.rb | 36 +++++++++---------- .../preferences/file_configuration_spec.rb | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/app/models/content_configuration.rb b/app/models/content_configuration.rb index 32a2065c5d..0bf4c4e852 100644 --- a/app/models/content_configuration.rb +++ b/app/models/content_configuration.rb @@ -3,7 +3,7 @@ require 'open_food_network/paperclippable' class ContentConfiguration < Spree::Preferences::FileConfiguration # Header include OpenFoodNetwork::Paperclippable - file_preference :logo + preference :logo, :file has_attached_file :logo # Home page diff --git a/app/models/spree/preferences/file_configuration.rb b/app/models/spree/preferences/file_configuration.rb index 5d84e37fdf..fa1838a778 100644 --- a/app/models/spree/preferences/file_configuration.rb +++ b/app/models/spree/preferences/file_configuration.rb @@ -1,36 +1,36 @@ module Spree::Preferences class FileConfiguration < Configuration - # Ideally, we'd alias_method_chain preference to add new type. However, failcake. - def self.file_preference(name) - preference "#{name}_file_name", :string - preference "#{name}_content_type", :string - preference "#{name}_file_size", :integer - preference "#{name}_updated_at", :string - end + def self.preference(name, type, *args) + if type == :file + super "#{name}_file_name", :string, *args + super "#{name}_content_type", :string, *args + super "#{name}_file_size", :integer, *args + super "#{name}_updated_at", :string, *args - - # TODO: Rewrite with super - - def get_preference_with_files(key) - if !has_preference?(key) && has_attachment?(key) - send(key) else - get_preference_without_files(key) + super name, type, *args + end + end + + + def get_preference(key) + if !has_preference?(key) && has_attachment?(key) + send key + else + super key end end - alias_method_chain :get_preference, :files alias :[] :get_preference - def preference_type_with_files(name) + def preference_type(name) if has_attachment? name :file else - preference_type_without_files(name) + super name end end - alias_method_chain :preference_type, :files # Spree's Configuration responds to preference methods via method_missing, but doesn't diff --git a/spec/models/spree/preferences/file_configuration_spec.rb b/spec/models/spree/preferences/file_configuration_spec.rb index 77aabc637e..eb18b23e12 100644 --- a/spec/models/spree/preferences/file_configuration_spec.rb +++ b/spec/models/spree/preferences/file_configuration_spec.rb @@ -6,7 +6,7 @@ module Spree preference :name, :string include OpenFoodNetwork::Paperclippable - file_preference :logo + preference :logo, :file has_attached_file :logo end From 74f90dada367e6d42ce53471cf1e26024a4c8fa7 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 17 Jul 2015 15:56:38 +1000 Subject: [PATCH 14/19] Allow overriding mobile logo (raster and SVG) and home hero image --- app/controllers/admin/contents_controller.rb | 4 ++-- app/models/content_configuration.rb | 6 ++++++ app/models/spree/preferences/configuration_decorator.rb | 4 ---- app/views/home/index.html.haml | 4 ++++ app/views/shared/menu/_mobile_menu.html.haml | 4 ++-- 5 files changed, 14 insertions(+), 8 deletions(-) delete mode 100644 app/models/spree/preferences/configuration_decorator.rb diff --git a/app/controllers/admin/contents_controller.rb b/app/controllers/admin/contents_controller.rb index 02dc246930..d1c761d4ad 100644 --- a/app/controllers/admin/contents_controller.rb +++ b/app/controllers/admin/contents_controller.rb @@ -1,8 +1,8 @@ module Admin class ContentsController < Spree::Admin::BaseController def edit - @preference_sections = [{name: 'Header', preferences: [:logo]}, - {name: 'Home page', preferences: [:home_show_stats]}, + @preference_sections = [{name: 'Header', preferences: [:logo, :logo_mobile, :logo_mobile_svg]}, + {name: 'Home page', preferences: [:home_hero, :home_show_stats]}, {name: 'Producer signup page', preferences: [:producer_signup_pricing_table_html, :producer_signup_case_studies_html, :producer_signup_detail_html]}, {name: 'Hub signup page', preferences: [:hub_signup_pricing_table_html, :hub_signup_case_studies_html, :hub_signup_detail_html]}, {name: 'Group signup page', preferences: [:group_signup_pricing_table_html, :group_signup_case_studies_html, :group_signup_detail_html]}, diff --git a/app/models/content_configuration.rb b/app/models/content_configuration.rb index 0bf4c4e852..7614c207f9 100644 --- a/app/models/content_configuration.rb +++ b/app/models/content_configuration.rb @@ -4,10 +4,16 @@ class ContentConfiguration < Spree::Preferences::FileConfiguration # Header include OpenFoodNetwork::Paperclippable preference :logo, :file + preference :logo_mobile, :file + preference :logo_mobile_svg, :file has_attached_file :logo + has_attached_file :logo_mobile + has_attached_file :logo_mobile_svg # Home page preference :home_show_stats, :boolean, default: true + preference :home_hero, :file + has_attached_file :home_hero # Producer sign-up page preference :producer_signup_pricing_table_html, :text, default: "(TODO: Pricing table)" diff --git a/app/models/spree/preferences/configuration_decorator.rb b/app/models/spree/preferences/configuration_decorator.rb deleted file mode 100644 index 04a9f35f6b..0000000000 --- a/app/models/spree/preferences/configuration_decorator.rb +++ /dev/null @@ -1,4 +0,0 @@ -module Spree::Preferences - Configuration.class_eval do - end -end diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml index 3f284a5e37..ee4fca7b27 100644 --- a/app/views/home/index.html.haml +++ b/app/views/home/index.html.haml @@ -1,3 +1,7 @@ +:css + #tagline:before { background-image: url("#{ContentConfig.home_hero.url}") } + + %div{"ng-controller" => "HomeCtrl"} = render partial: "shared/menu/alert" diff --git a/app/views/shared/menu/_mobile_menu.html.haml b/app/views/shared/menu/_mobile_menu.html.haml index 869785fce5..d43c95ca46 100644 --- a/app/views/shared/menu/_mobile_menu.html.haml +++ b/app/views/shared/menu/_mobile_menu.html.haml @@ -6,7 +6,7 @@ %section.left .ofn-logo %a{href: root_path} - %img{src: "/assets/logo-black.png", srcset: "/assets/logo-black.svg", width: "75", height: "26"} + %img{src: ContentConfig.logo_mobile.url, srcset: ContentConfig.logo_mobile_svg.url, width: "75", height: "26"} %section.right{"ng-cloak" => true} .cart @@ -18,7 +18,7 @@ %ul.off-canvas-list %li.ofn-logo %a{href: root_path} - %img{src: "/assets/logo-black.png", srcset: "/assets/logo-black.svg", width: "75", height: "26"} + %img{src: ContentConfig.logo_mobile.url, srcset: ContentConfig.logo_mobile_svg.url, width: "75", height: "26"} %li.li-menu - if current_page? main_app.shops_path %a{"ofn-scroll-to" => "hubs"} From bb3a4170f541b4d29c327e51d7a883dfe5a7c680 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 17 Jul 2015 16:02:09 +1000 Subject: [PATCH 15/19] Add dimensions to image upload --- app/models/content_configuration.rb | 2 +- config/locales/en.yml | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/content_configuration.rb b/app/models/content_configuration.rb index 7614c207f9..de43c2f7a6 100644 --- a/app/models/content_configuration.rb +++ b/app/models/content_configuration.rb @@ -11,8 +11,8 @@ class ContentConfiguration < Spree::Preferences::FileConfiguration has_attached_file :logo_mobile_svg # Home page - preference :home_show_stats, :boolean, default: true preference :home_hero, :file + preference :home_show_stats, :boolean, default: true has_attached_file :home_hero # Producer sign-up page diff --git a/config/locales/en.yml b/config/locales/en.yml index 8f759b717d..6454f1b33a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -20,6 +20,10 @@ en: producers_join: Australian producers are now welcome to join the Open Food Network. charges_sales_tax: Charges GST? + logo: "Logo (640x130)" + logo_mobile: "Mobile logo (75x26)" + logo_mobile_svg: "Mobile logo (SVG)" + home_hero: "Hero image" home_show_stats: "Show statistics" footer_facebook_url: "Facebook URL" footer_twitter_url: "Twitter URL" From 5fd3dc1d283bb37a6637a2f07ef44ab60ce192ec Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 17 Jul 2015 16:24:07 +1000 Subject: [PATCH 16/19] Customise footer logo --- app/controllers/admin/contents_controller.rb | 3 ++- app/models/content_configuration.rb | 5 ++++- app/views/shared/_footer.html.haml | 2 +- config/locales/en.yml | 1 + 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/contents_controller.rb b/app/controllers/admin/contents_controller.rb index d1c761d4ad..0b5012244d 100644 --- a/app/controllers/admin/contents_controller.rb +++ b/app/controllers/admin/contents_controller.rb @@ -6,7 +6,8 @@ module Admin {name: 'Producer signup page', preferences: [:producer_signup_pricing_table_html, :producer_signup_case_studies_html, :producer_signup_detail_html]}, {name: 'Hub signup page', preferences: [:hub_signup_pricing_table_html, :hub_signup_case_studies_html, :hub_signup_detail_html]}, {name: 'Group signup page', preferences: [:group_signup_pricing_table_html, :group_signup_case_studies_html, :group_signup_detail_html]}, - {name: 'Footer', preferences: [:footer_facebook_url, :footer_twitter_url, :footer_instagram_url, :footer_linkedin_url, :footer_googleplus_url, :footer_pinterest_url, + {name: 'Footer', preferences: [:footer_logo, + :footer_facebook_url, :footer_twitter_url, :footer_instagram_url, :footer_linkedin_url, :footer_googleplus_url, :footer_pinterest_url, :footer_email, :footer_links_md, :footer_about_url]}] end diff --git a/app/models/content_configuration.rb b/app/models/content_configuration.rb index de43c2f7a6..32bb66b3ac 100644 --- a/app/models/content_configuration.rb +++ b/app/models/content_configuration.rb @@ -1,8 +1,9 @@ require 'open_food_network/paperclippable' class ContentConfiguration < Spree::Preferences::FileConfiguration - # Header include OpenFoodNetwork::Paperclippable + + # Header preference :logo, :file preference :logo_mobile, :file preference :logo_mobile_svg, :file @@ -31,6 +32,8 @@ class ContentConfiguration < Spree::Preferences::FileConfiguration preference :group_signup_detail_html, :text, default: "(TODO: Detail)" # Footer + preference :footer_logo, :file + has_attached_file :footer_logo preference :footer_facebook_url, :string, default: "https://www.facebook.com/OpenFoodNet" preference :footer_twitter_url, :string, default: "https://twitter.com/OpenFoodNet" preference :footer_instagram_url, :string, default: "" diff --git a/app/views/shared/_footer.html.haml b/app/views/shared/_footer.html.haml index de9d9e341a..db6c797570 100644 --- a/app/views/shared/_footer.html.haml +++ b/app/views/shared/_footer.html.haml @@ -116,7 +116,7 @@ .row .small-12.medium-3.medium-offset-2.columns.text-left %a{href: root_path} - %img{src: "/assets/logo-color.png", srcset: "/assets/logo-color.svg", width: "220px"} + %img{src: ContentConfig.footer_logo.url, width: "220"} .small-12.medium-5.columns.text-left %p.text-small Read our diff --git a/config/locales/en.yml b/config/locales/en.yml index 6454f1b33a..f7c23bee4d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -25,6 +25,7 @@ en: logo_mobile_svg: "Mobile logo (SVG)" home_hero: "Hero image" home_show_stats: "Show statistics" + footer_logo: "Logo (220x76)" footer_facebook_url: "Facebook URL" footer_twitter_url: "Twitter URL" footer_instagram_url: "Instagram URL" From b6892c82f1843707cb8a3079aa33e98feb004c79 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 17 Jul 2015 16:27:17 +1000 Subject: [PATCH 17/19] Rename australia-orange sass var to country-agnostic brand-colour --- .../stylesheets/darkswarm/home_panes.css.sass | 12 ++++++------ app/assets/stylesheets/darkswarm/menu.css.sass | 4 ++-- app/assets/stylesheets/darkswarm/mixins.sass | 2 +- app/assets/stylesheets/darkswarm/signup.css.sass | 16 ++++++++-------- .../stylesheets/darkswarm/variables.css.sass | 4 ++-- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/app/assets/stylesheets/darkswarm/home_panes.css.sass b/app/assets/stylesheets/darkswarm/home_panes.css.sass index dd3c6a0fca..ed74450317 100644 --- a/app/assets/stylesheets/darkswarm/home_panes.css.sass +++ b/app/assets/stylesheets/darkswarm/home_panes.css.sass @@ -76,7 +76,7 @@ width: 64px height: 64px margin: 0 auto - background-color: $australia-orange + background-color: $brand-colour background-position: center center background-repeat: no-repeat background-size: auto 100% @@ -90,13 +90,13 @@ h2 font-size: 70px font-weight: 300 - color: $australia-orange + color: $brand-colour @media all and (max-width: 640px) font-size: 45px a - color: $australia-orange + color: $brand-colour .home-icon-box-bottom margin-top: 1rem @@ -110,8 +110,8 @@ padding-left: 1rem padding-right: 1rem h4 - color: $australia-orange - border-bottom: 2px solid lighten($australia-orange, 20%) + color: $brand-colour + border-bottom: 2px solid lighten($brand-colour, 20%) text-align: center padding: 1rem 0 margin: 1.5rem 0 @@ -146,4 +146,4 @@ font-weight: 300 #shops-signup.pane - background-color: $australia-orange + background-color: $brand-colour diff --git a/app/assets/stylesheets/darkswarm/menu.css.sass b/app/assets/stylesheets/darkswarm/menu.css.sass index d92fac2d06..41b86f72ff 100644 --- a/app/assets/stylesheets/darkswarm/menu.css.sass +++ b/app/assets/stylesheets/darkswarm/menu.css.sass @@ -51,7 +51,7 @@ nav opacity: 1 .nav-branded - color: $australia-orange + color: $brand-colour span font-size: 13px .nav-primary @@ -102,7 +102,7 @@ nav color: rgba(0, 0, 0, 0.9) &:hover background-color: transparent - color: $australia-orange + color: $brand-colour @include transition(all 0.3s ease-in-out) .off-canvas-wrap.move-right ul.off-canvas-list i diff --git a/app/assets/stylesheets/darkswarm/mixins.sass b/app/assets/stylesheets/darkswarm/mixins.sass index 668ef2b59c..4e779bd2a5 100644 --- a/app/assets/stylesheets/darkswarm/mixins.sass +++ b/app/assets/stylesheets/darkswarm/mixins.sass @@ -7,7 +7,7 @@ @mixin tiledPane background-image: url("/assets/tile-wide.png") - background-color: $australia-orange + background-color: $brand-colour background-position: center center @include paneWhiteText diff --git a/app/assets/stylesheets/darkswarm/signup.css.sass b/app/assets/stylesheets/darkswarm/signup.css.sass index c4d055b3a6..cd6ebf458a 100644 --- a/app/assets/stylesheets/darkswarm/signup.css.sass +++ b/app/assets/stylesheets/darkswarm/signup.css.sass @@ -20,13 +20,13 @@ #producer-case-studies, #shops-case-studies padding-top: 100px padding-bottom: 100px - background-color: $australia-orange + background-color: $brand-colour background-image: url("/assets/hubs-bg.jpg") background-position: center center -webkit-filter: brightness(1.1) filter: brightness(1.1) h2 - color: $australia-orange + color: $brand-colour font-size: 3rem .case-study background-color: rgba(255, 255, 255, 0.5) @@ -42,7 +42,7 @@ @media all and (min-width: 640px) text-align: left h4, a - color: $australia-orange + color: $brand-colour a &, & * @include csstrans @@ -68,9 +68,9 @@ table.signup-table.hubs-table, table.signup-table.producers-table background-color: lighten($ofn-grey, 41%) td:last-child &, & i - color: $australia-orange - border-bottom: 1px solid rgba($australia-orange, 0.3) - background-color: lighten($australia-orange, 48%) + color: $brand-colour + border-bottom: 1px solid rgba($brand-colour, 0.3) + background-color: lighten($brand-colour, 48%) thead background-color: transparent tr @@ -85,7 +85,7 @@ table.signup-table.hubs-table, table.signup-table.producers-table td:last-child &, & * color: white - background: $australia-orange + background: $brand-colour h5 text-transform: uppercase color: $ofn-grey @@ -107,7 +107,7 @@ table.signup-table.hubs-table, table.signup-table.producers-table td:last-child &, & * color: white - background: $australia-orange + background: $brand-colour h2 .text-small text-transform: uppercase diff --git a/app/assets/stylesheets/darkswarm/variables.css.sass b/app/assets/stylesheets/darkswarm/variables.css.sass index 81018be6ec..1b958206c7 100644 --- a/app/assets/stylesheets/darkswarm/variables.css.sass +++ b/app/assets/stylesheets/darkswarm/variables.css.sass @@ -1,7 +1,7 @@ @import "foundation/functions" @import "foundation/components/global" -$australia-orange: rgba(242, 112, 82, 1) +$brand-colour: rgba(242, 112, 82, 1) // Topbar $topbar-height: rem-calc(75) @@ -11,7 +11,7 @@ $topbar-bg: $white $topbar-bg-color: $topbar-bg $topbar-link-color: $black -$topbar-link-color-hover: $australia-orange +$topbar-link-color-hover: $brand-colour $topbar-link-color-active: $black $topbar-link-color-active-hover: $white $topbar-link-bg-hover: $white From 61435b2deabc18c5bbd097f221c0d7166e1b5fa4 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 17 Jul 2015 17:05:44 +1000 Subject: [PATCH 18/19] Add brand guide colours next to definition --- app/assets/stylesheets/darkswarm/variables.css.sass | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/darkswarm/variables.css.sass b/app/assets/stylesheets/darkswarm/variables.css.sass index 1b958206c7..ea87d11fc4 100644 --- a/app/assets/stylesheets/darkswarm/variables.css.sass +++ b/app/assets/stylesheets/darkswarm/variables.css.sass @@ -1,7 +1,17 @@ @import "foundation/functions" @import "foundation/components/global" -$brand-colour: rgba(242, 112, 82, 1) +// Brand guide colours: +// International: #81c26e +// Australia: #f35746 +// Africa: #f35e32 +// South Africa: #f9a72b +// Norway: #4b83cc +// Scandanavia: #0c8bbc +// UK: #e6373f + +$brand-colour: #f27052 + // Topbar $topbar-height: rem-calc(75) From ec908fce928cd7c112603827daea5cc98422d676 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 31 Jul 2015 14:51:17 +1000 Subject: [PATCH 19/19] Make TOS URL configurable --- app/controllers/admin/contents_controller.rb | 2 +- app/models/content_configuration.rb | 1 + app/views/shared/_footer.html.haml | 2 +- config/locales/en.yml | 3 ++- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/contents_controller.rb b/app/controllers/admin/contents_controller.rb index 0b5012244d..87c86997d9 100644 --- a/app/controllers/admin/contents_controller.rb +++ b/app/controllers/admin/contents_controller.rb @@ -8,7 +8,7 @@ module Admin {name: 'Group signup page', preferences: [:group_signup_pricing_table_html, :group_signup_case_studies_html, :group_signup_detail_html]}, {name: 'Footer', preferences: [:footer_logo, :footer_facebook_url, :footer_twitter_url, :footer_instagram_url, :footer_linkedin_url, :footer_googleplus_url, :footer_pinterest_url, - :footer_email, :footer_links_md, :footer_about_url]}] + :footer_email, :footer_links_md, :footer_about_url, :footer_tos_url]}] end def update diff --git a/app/models/content_configuration.rb b/app/models/content_configuration.rb index 32bb66b3ac..2357f8dfa3 100644 --- a/app/models/content_configuration.rb +++ b/app/models/content_configuration.rb @@ -50,4 +50,5 @@ class ContentConfiguration < Spree::Preferences::FileConfiguration EOS preference :footer_about_url, :string, default: "http://www.openfoodnetwork.org/ofn-local/open-food-network-australia/" + preference :footer_tos_url, :string, default: "/Terms-of-service.pdf" end diff --git a/app/views/shared/_footer.html.haml b/app/views/shared/_footer.html.haml index db6c797570..7450966e5f 100644 --- a/app/views/shared/_footer.html.haml +++ b/app/views/shared/_footer.html.haml @@ -120,7 +120,7 @@ .small-12.medium-5.columns.text-left %p.text-small Read our - %a{href: "/Terms-of-service.pdf"} Terms & conditions + %a{href: ContentConfig.footer_tos_url} Terms & conditions | Find us on %a{href:"https://github.com/openfoodfoundation/openfoodnetwork", target: "_blank"} Github diff --git a/config/locales/en.yml b/config/locales/en.yml index f7c23bee4d..3149620eab 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -34,4 +34,5 @@ en: footer_pinterest_url: "Pinterest URL" footer_email: "Email" footer_links_md: "Links" - footer_about_url: "About URL" \ No newline at end of file + footer_about_url: "About URL" + footer_tos_url: "Terms of Service URL" \ No newline at end of file