From e44853346ec7bc997746358766048a2a6f493977 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Thu, 29 May 2014 16:12:58 +1000 Subject: [PATCH] Dropping current producers, switching to suppliers and using Angular --- .../tabs/producers_controller.js.coffee | 2 ++ app/helpers/shared_helper.rb | 10 ------ app/views/json/_current_hub.rabl | 4 +++ app/views/json/_hubs.rabl | 6 +--- app/views/json/_producer.rabl | 5 +++ app/views/shopping_shared/_modals.html.haml | 19 ----------- .../shopping_shared/_producers.html.haml | 8 ++--- spec/helpers/shared_helper_spec.rb | 33 ------------------- 8 files changed, 15 insertions(+), 72 deletions(-) create mode 100644 app/assets/javascripts/darkswarm/controllers/tabs/producers_controller.js.coffee create mode 100644 app/views/json/_producer.rabl diff --git a/app/assets/javascripts/darkswarm/controllers/tabs/producers_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/tabs/producers_controller.js.coffee new file mode 100644 index 0000000000..92cf8dedfc --- /dev/null +++ b/app/assets/javascripts/darkswarm/controllers/tabs/producers_controller.js.coffee @@ -0,0 +1,2 @@ +Darkswarm.controller "ProducersTabCtrl", ($scope, CurrentHub) -> + $scope.CurrentHub = CurrentHub diff --git a/app/helpers/shared_helper.rb b/app/helpers/shared_helper.rb index 828277cb57..f856a088d1 100644 --- a/app/helpers/shared_helper.rb +++ b/app/helpers/shared_helper.rb @@ -14,16 +14,6 @@ module SharedHelper klass end - # all suppliers of current distributor's products - def current_producers - if current_distributor && current_order_cycle - variants = current_order_cycle.variants_distributed_by(current_distributor) - Enterprise.supplying_variant_in(variants) - else - [] - end - end - def enterprise_user? spree_current_user.andand.enterprises.andand.count.to_i > 0 end diff --git a/app/views/json/_current_hub.rabl b/app/views/json/_current_hub.rabl index ab67cce3cc..57731d9599 100644 --- a/app/views/json/_current_hub.rabl +++ b/app/views/json/_current_hub.rabl @@ -1,2 +1,6 @@ object current_distributor attributes :name, :id + +child suppliers: :producers do + extends "json/producer" +end diff --git a/app/views/json/_hubs.rabl b/app/views/json/_hubs.rabl index dc589b878b..c118b4504f 100644 --- a/app/views/json/_hubs.rabl +++ b/app/views/json/_hubs.rabl @@ -6,11 +6,7 @@ child distributed_taxons: :taxons do end child suppliers: :producers do - attributes :name, :id, :description, :long_description - - node :promo_image do |producer| - producer.promo_image.url - end + extends "json/producer" end node :pickup do |hub| diff --git a/app/views/json/_producer.rabl b/app/views/json/_producer.rabl new file mode 100644 index 0000000000..4c0efae8e1 --- /dev/null +++ b/app/views/json/_producer.rabl @@ -0,0 +1,5 @@ +attributes :name, :id, :description, :long_description + +node :promo_image do |producer| + producer.promo_image.url +end diff --git a/app/views/shopping_shared/_modals.html.haml b/app/views/shopping_shared/_modals.html.haml index ad92f1957f..83a162a470 100644 --- a/app/views/shopping_shared/_modals.html.haml +++ b/app/views/shopping_shared/_modals.html.haml @@ -1,22 +1,3 @@ -- for producer in current_producers - .reveal-modal{id: "producer_details_#{producer.id}", "data-reveal" => ""} - .row - - if producer.logo.exists? - .large-1.columns - %img.left{src: producer.logo.url(:thumb)} - .large-11.columns - %h2 - = producer.name - .row - .large-8.columns - = producer.long_description.andand.html_safe - - - if producer.promo_image.exists? - .large-4.columns - %img.about.right{src: producer.promo_image.url(:large)} - %a.close-reveal-modal × - - - for group in current_distributor.groups - for sibling in group.enterprises.except(current_distributor) .reveal-modal{id: "sibling_details_#{sibling.id}", "data-reveal" => ""} diff --git a/app/views/shopping_shared/_producers.html.haml b/app/views/shopping_shared/_producers.html.haml index 32f09869e8..584d75ff35 100644 --- a/app/views/shopping_shared/_producers.html.haml +++ b/app/views/shopping_shared/_producers.html.haml @@ -1,6 +1,4 @@ -.content#producers +.content#producers{"ng-controller" => "ProducersTabCtrl"} %ul - - for producer in current_producers - %li - %a{"data-reveal-id" => "producer_details_#{producer.id}", "data-reveal" => ""} - = producer.name + %li{"ng-repeat" => "producer in CurrentHub.producers"} + = render partial: "modals/producer" diff --git a/spec/helpers/shared_helper_spec.rb b/spec/helpers/shared_helper_spec.rb index d28a6eb7b3..92c688d1ae 100644 --- a/spec/helpers/shared_helper_spec.rb +++ b/spec/helpers/shared_helper_spec.rb @@ -23,37 +23,4 @@ describe SharedHelper do helper.stub(:current_order) { order } helper.distributor_link_class(d1).should =~ /empties-cart/ end - - describe "finding current producers" do - it "finds producers for the current distribution" do - s = create(:supplier_enterprise) - d = create(:distributor_enterprise) - p = create(:simple_product) - oc = create(:simple_order_cycle, suppliers: [s], distributors: [d], variants: [p.master]) - - helper.stub(:current_order_cycle) { oc } - helper.stub(:current_distributor) { d } - - helper.current_producers.should == [s] - end - - it "returns [] when no order cycle set" do - d = double(:distributor) - - helper.stub(:current_order_cycle) { nil } - helper.stub(:current_distributor) { d } - - helper.current_producers.should == [] - end - - it "returns [] when no distributor set" do - oc = double(:order_cycle) - - helper.stub(:current_order_cycle) { oc } - helper.stub(:current_distributor) { nil } - - helper.current_producers.should == [] - - end - end end