From 5de9a5eb546bf072626136610dde7fbf2b590fcb Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 10 Jul 2015 17:35:51 +1000 Subject: [PATCH] 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"