From 3370865a013709281b39a175fac1d6fd744cd037 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Thu, 13 Mar 2014 14:50:06 +1100 Subject: [PATCH] Adding group siblings to the shop page --- app/controllers/shop/shop_controller.rb | 2 +- app/views/shop/shop/_groups.html.haml | 13 +++++++++++++ app/views/shop/shop/_modals.html.haml | 19 +++++++++++++++++++ .../shop/shop/_producer_details.html.haml | 9 --------- app/views/shop/shop/show.html.haml | 11 +++-------- spec/controllers/shop/shop_controller_spec.rb | 14 +++++++++++++- 6 files changed, 49 insertions(+), 19 deletions(-) create mode 100644 app/views/shop/shop/_groups.html.haml create mode 100644 app/views/shop/shop/_modals.html.haml delete mode 100644 app/views/shop/shop/_producer_details.html.haml diff --git a/app/controllers/shop/shop_controller.rb b/app/controllers/shop/shop_controller.rb index b7f124acfa..81c43f0b6a 100644 --- a/app/controllers/shop/shop_controller.rb +++ b/app/controllers/shop/shop_controller.rb @@ -7,6 +7,7 @@ class Shop::ShopController < BaseController def show # All suppliers of all our products @producers = Exchange.where(receiver_id: @distributor.id).map{ |ex| ex.variants.map {|v| v.product.supplier }}.flatten.uniq + @groups = current_distributor.groups end def products @@ -14,7 +15,6 @@ class Shop::ShopController < BaseController .products_distributed_by(current_distributor).andand .select { |p| p.has_stock_for_distribution?(current_order_cycle, current_distributor) }.andand .sort_by {|p| p.name } - render json: "", status: 404 end end diff --git a/app/views/shop/shop/_groups.html.haml b/app/views/shop/shop/_groups.html.haml new file mode 100644 index 0000000000..814067e043 --- /dev/null +++ b/app/views/shop/shop/_groups.html.haml @@ -0,0 +1,13 @@ +%section + %p.title.avenir{"data-section-title" => ""} + %a{href: "#groups"} Our Groups + .content{"data-section-content" => ""} + %ul + - for group in @groups + %li + %h4= group.name + %ul + - for sibling in group.enterprises.except(current_distributor) + %li + %a{"data-reveal-id" => "sibling_details_#{sibling.id}"} + = sibling.name diff --git a/app/views/shop/shop/_modals.html.haml b/app/views/shop/shop/_modals.html.haml new file mode 100644 index 0000000000..992f38d504 --- /dev/null +++ b/app/views/shop/shop/_modals.html.haml @@ -0,0 +1,19 @@ +- for producer in @producers + .reveal-modal{id: "producer_details_#{producer.id}"} + %h2 + %img.left{src: producer.logo.url(:thumb)} + = producer.name + %img.about.right{src: producer.promo_image.url(:large)} + = producer.description.andand.html_safe + %a.close-reveal-modal × + +- for group in @groups + - for sibling in group.enterprises.except(current_distributor) + .reveal-modal{id: "sibling_details_#{sibling.id}"} + %h2 + %img.left{src: sibling.logo.url(:thumb)} + = sibling.name + %img.about.right{src: sibling.promo_image.url(:large)} + = sibling.description.andand.html_safe + %a.close-reveal-modal × + diff --git a/app/views/shop/shop/_producer_details.html.haml b/app/views/shop/shop/_producer_details.html.haml deleted file mode 100644 index c763a65728..0000000000 --- a/app/views/shop/shop/_producer_details.html.haml +++ /dev/null @@ -1,9 +0,0 @@ -- for producer in @producers - .reveal-modal{id: "producer_details_#{producer.id}"} - %h2 - %img.left{src: producer.logo.url(:thumb)} - = producer.name - %img.about.right{src: producer.promo_image.url(:large)} - = producer.description.andand.html_safe - %a.close-reveal-modal × - diff --git a/app/views/shop/shop/show.html.haml b/app/views/shop/shop/show.html.haml index a7450e3145..1f6ed6defd 100644 --- a/app/views/shop/shop/show.html.haml +++ b/app/views/shop/shop/show.html.haml @@ -11,8 +11,8 @@ %strong {{ order_cycle.orders_close_at | date_in_words }} = render partial: "shop/details" - -# This partial generates the producer detail popovers - = render partial: "shop/shop/producer_details" + -# This partial generates the producer and group sibling modals + = render partial: "shop/shop/modals" %tabs .row @@ -20,12 +20,7 @@ = render 'shop/shop/about_us' = render 'shop/shop/producers' - - %section - %p.title.avenir{"data-section-title" => ""} - %a{href: "#groups"} Our Groups - .content{"data-section-content" => ""} - %p Coming Soon + = render 'shop/shop/groups' %section %p.title.avenir{"data-section-title" => ""} diff --git a/spec/controllers/shop/shop_controller_spec.rb b/spec/controllers/shop/shop_controller_spec.rb index f440da9805..258eb4d97b 100644 --- a/spec/controllers/shop/shop_controller_spec.rb +++ b/spec/controllers/shop/shop_controller_spec.rb @@ -14,6 +14,18 @@ describe Shop::ShopController do controller.stub(:current_distributor).and_return d end + describe "Tabs and plumbing" do + it "builds a list of sibling distributors" do + sibling1 = create(:distributor_enterprise) + sibling2 = create(:distributor_enterprise) + g1 = create(:enterprise_group, on_front_page: true, enterprises: [d, sibling1]) + g2 = create(:enterprise_group, on_front_page: true, enterprises: [d, sibling2]) + + spree_get :show + assigns[:groups].sort.should == [g1, g2].sort + end + end + describe "Selecting order cycles" do it "should select an order cycle when only one order cycle is open" do oc1 = create(:order_cycle, distributors: [d]) @@ -42,7 +54,7 @@ describe Shop::ShopController do it "should return the order cycle details when the oc is selected" do oc1 = create(:order_cycle, distributors: [d]) oc2 = create(:order_cycle, distributors: [d]) - + spree_post :order_cycle, order_cycle_id: oc2.id response.should be_success response.body.should have_content oc2.id