From 8bf472e970be4f1f7b99d7c1934d5a5fbe0bf67e Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 22 Oct 2014 12:16:28 +1100 Subject: [PATCH] Split dashboard into single and multiple enterprise views --- .../admin/overview_controller_decorator.rb | 7 +++++ app/models/spree/user_decorator.rb | 4 +++ .../_multi_enterprise_dashboard.html.haml | 24 ++++++++++++++ .../_single_enterprise_dashboard.html.haml | 17 ++++++++++ .../spree/admin/overview/index.html.haml | 24 -------------- .../spree/admin/overview_controller_spec.rb | 31 +++++++++++++++++++ 6 files changed, 83 insertions(+), 24 deletions(-) create mode 100644 app/views/spree/admin/overview/_multi_enterprise_dashboard.html.haml create mode 100644 app/views/spree/admin/overview/_single_enterprise_dashboard.html.haml delete mode 100644 app/views/spree/admin/overview/index.html.haml create mode 100644 spec/controllers/spree/admin/overview_controller_spec.rb diff --git a/app/controllers/spree/admin/overview_controller_decorator.rb b/app/controllers/spree/admin/overview_controller_decorator.rb index 4ae1c1b095..ddaddb5dc3 100644 --- a/app/controllers/spree/admin/overview_controller_decorator.rb +++ b/app/controllers/spree/admin/overview_controller_decorator.rb @@ -4,6 +4,13 @@ Spree::Admin::OverviewController.class_eval do @enterprises = Enterprise.managed_by(spree_current_user).order('is_primary_producer ASC, name') @product_count = Spree::Product.active.managed_by(spree_current_user).count @order_cycle_count = OrderCycle.active.managed_by(spree_current_user).count + + if spree_current_user.manages_one_enterprise? + @enterprise = @enterprises.first + render partial: "single_enterprise_dashboard" + else + render partial: "multi_enterprise_dashboard" + end end end diff --git a/app/models/spree/user_decorator.rb b/app/models/spree/user_decorator.rb index 06a413b469..e8b75f6466 100644 --- a/app/models/spree/user_decorator.rb +++ b/app/models/spree/user_decorator.rb @@ -19,6 +19,10 @@ Spree.user_class.class_eval do end end + def manages_one_enterprise? + enterprises.length == 1 + end + def send_signup_confirmation Spree::UserMailer.signup_confirmation(self).deliver end diff --git a/app/views/spree/admin/overview/_multi_enterprise_dashboard.html.haml b/app/views/spree/admin/overview/_multi_enterprise_dashboard.html.haml new file mode 100644 index 0000000000..f230d7e44e --- /dev/null +++ b/app/views/spree/admin/overview/_multi_enterprise_dashboard.html.haml @@ -0,0 +1,24 @@ +%h1{ :style => 'margin-bottom: 30px'} Dashboard + +- if @enterprises.unconfirmed.any? + + = render partial: "unconfirmed" + + %hr + +- if @enterprises.empty? + + = render partial: "enterprises" + +- else + + - if can? :admin, Spree::Product + = render partial: "products" + + %div.two.columns +   + + - if can? :admin, OrderCycle + = render partial: "order_cycles" + + = render partial: "enterprises" \ No newline at end of file diff --git a/app/views/spree/admin/overview/_single_enterprise_dashboard.html.haml b/app/views/spree/admin/overview/_single_enterprise_dashboard.html.haml new file mode 100644 index 0000000000..e407c1dbe7 --- /dev/null +++ b/app/views/spree/admin/overview/_single_enterprise_dashboard.html.haml @@ -0,0 +1,17 @@ +-# - if @enterprise.sells == "unconfirmed" +-# %h1 Welcome to the Open Food Network + + +- if @enterprise.is_primary_producer + // Basic Producer + + // Producer with Shopfront + + // Coming soon - Full Hub + // Email us if you want this option + +- else + // Shop Profile + + // Coming soon - Full Hub + // Email us if you want this option diff --git a/app/views/spree/admin/overview/index.html.haml b/app/views/spree/admin/overview/index.html.haml deleted file mode 100644 index d83a71bc40..0000000000 --- a/app/views/spree/admin/overview/index.html.haml +++ /dev/null @@ -1,24 +0,0 @@ -%h1{ :style => 'margin-bottom: 30px'} Dashboard - -- if @enterprises.unconfirmed.any? - - = render partial: "spree/admin/overview/unconfirmed" - - %hr - -- if @enterprises.empty? - - = render partial: "spree/admin/overview/enterprises" - -- else - - - if can? :admin, Spree::Product - = render partial: "spree/admin/overview/products" - - %div.two.columns -   - - - if can? :admin, OrderCycle - = render partial: "spree/admin/overview/order_cycles" - - = render partial: "spree/admin/overview/enterprises" diff --git a/spec/controllers/spree/admin/overview_controller_spec.rb b/spec/controllers/spree/admin/overview_controller_spec.rb new file mode 100644 index 0000000000..62443c2cfb --- /dev/null +++ b/spec/controllers/spree/admin/overview_controller_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe Spree::Admin::OverviewController do + include AuthenticationWorkflow + context "loading overview" do + let(:user) { create_enterprise_user(enterprise_limit: 2) } + + before do + controller.stub spree_current_user: user + end + + context "when user own only one enterprise" do + let!(:enterprise) { create(:distributor_enterprise, owner: user) } + + it "renders the single enterprise dashboard" do + spree_get :index + response.should render_template partial: "_single_enterprise_dashboard" + end + end + + context "when user owns multiple enterprises" do + let!(:enterprise1) { create(:distributor_enterprise, owner: user) } + let!(:enterprise2) { create(:distributor_enterprise, owner: user) } + + it "renders the multi enterprise dashboard" do + spree_get :index + response.should render_template partial: "_multi_enterprise_dashboard" + end + end + end +end \ No newline at end of file