mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-02 02:11:33 +00:00
Dropping current producers, switching to suppliers and using Angular
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
Darkswarm.controller "ProducersTabCtrl", ($scope, CurrentHub) ->
|
||||
$scope.CurrentHub = CurrentHub
|
||||
@@ -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
|
||||
|
||||
@@ -1,2 +1,6 @@
|
||||
object current_distributor
|
||||
attributes :name, :id
|
||||
|
||||
child suppliers: :producers do
|
||||
extends "json/producer"
|
||||
end
|
||||
|
||||
@@ -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|
|
||||
|
||||
5
app/views/json/_producer.rabl
Normal file
5
app/views/json/_producer.rabl
Normal file
@@ -0,0 +1,5 @@
|
||||
attributes :name, :id, :description, :long_description
|
||||
|
||||
node :promo_image do |producer|
|
||||
producer.promo_image.url
|
||||
end
|
||||
@@ -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" => ""}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user