diff --git a/app/assets/javascripts/darkswarm/controllers/checkout/accordion_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/checkout/accordion_controller.js.coffee index accfcaec9a..b9bc76ced5 100644 --- a/app/assets/javascripts/darkswarm/controllers/checkout/accordion_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/checkout/accordion_controller.js.coffee @@ -4,7 +4,7 @@ Darkswarm.controller "AccordionCtrl", ($scope, storage, $timeout, CurrentHub) -> shipping: false payment: false billing: false - storage.bind $scope, "accordion", {storeName: "accordion_#{$scope.order.id}#{CurrentHub.id}#{$scope.order.user_id}"} + storage.bind $scope, "accordion", {storeName: "accordion_#{$scope.order.id}#{CurrentHub.hub.id}#{$scope.order.user_id}"} $scope.show = (name)-> $scope.accordion[name] = true diff --git a/app/assets/javascripts/darkswarm/controllers/hub_node_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/hub_node_controller.js.coffee index b43b97e560..e73ca5fa27 100644 --- a/app/assets/javascripts/darkswarm/controllers/hub_node_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/hub_node_controller.js.coffee @@ -6,4 +6,4 @@ Darkswarm.controller "HubNodeCtrl", ($scope, HashNavigation, Navigation, $locati HashNavigation.active $scope.hub.hash $scope.current = -> - $scope.hub.id is CurrentHub.id + $scope.hub.id is CurrentHub.hub.id diff --git a/app/assets/javascripts/darkswarm/directives/active_table_hub_link.js.coffee b/app/assets/javascripts/darkswarm/directives/active_table_hub_link.js.coffee index d86d566022..ff220d0d5e 100644 --- a/app/assets/javascripts/darkswarm/directives/active_table_hub_link.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/active_table_hub_link.js.coffee @@ -6,7 +6,7 @@ Darkswarm.directive "activeTableHubLink", (CurrentHub, CurrentOrder) -> link: (scope, elm, attr)-> # Swap out the text of the hub link depending on whether it'll change current hub # To be used with ofnEmptiesCart - if CurrentHub.id and CurrentHub.id isnt scope.hub.id + if CurrentHub.hub.id and CurrentHub.hub.id isnt scope.hub.id scope.action = attr.change else scope.action = attr.shop diff --git a/app/assets/javascripts/darkswarm/directives/empties_cart.js.coffee b/app/assets/javascripts/darkswarm/directives/empties_cart.js.coffee index 4ee4c9ce25..b71196c40c 100644 --- a/app/assets/javascripts/darkswarm/directives/empties_cart.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/empties_cart.js.coffee @@ -3,7 +3,7 @@ Darkswarm.directive "ofnEmptiesCart", (CurrentHub, CurrentOrder, Navigation, sto link: (scope, elm, attr)-> hub = scope.$eval(attr.ofnEmptiesCart) # A hub is selected, we're changing to a different hub, and the cart isn't empty - if CurrentHub.id and CurrentHub.id isnt hub.id + if CurrentHub.hub.id and CurrentHub.hub.id isnt hub.id unless CurrentOrder.empty() elm.bind 'click', (ev)-> ev.preventDefault() diff --git a/app/assets/javascripts/darkswarm/services/current_hub.js.coffee b/app/assets/javascripts/darkswarm/services/current_hub.js.coffee index dc281b0da5..5e6a385b8a 100644 --- a/app/assets/javascripts/darkswarm/services/current_hub.js.coffee +++ b/app/assets/javascripts/darkswarm/services/current_hub.js.coffee @@ -1,2 +1,3 @@ -Darkswarm.factory 'CurrentHub', ($location, $filter, currentHub, Enterprises) -> - Enterprises.enterprises_by_id[currentHub.id] || {} +Darkswarm.factory 'CurrentHub', ($location, $filter, currentHub) -> + new class CurrentHub + hub: currentHub diff --git a/app/assets/javascripts/darkswarm/services/enterprises.js.coffee b/app/assets/javascripts/darkswarm/services/enterprises.js.coffee index 0c73d0db1e..81baad7368 100644 --- a/app/assets/javascripts/darkswarm/services/enterprises.js.coffee +++ b/app/assets/javascripts/darkswarm/services/enterprises.js.coffee @@ -1,4 +1,4 @@ -Darkswarm.factory 'Enterprises', (enterprises)-> +Darkswarm.factory 'Enterprises', (enterprises, CurrentHub)-> new class Enterprises enterprises_by_id: {} # id/object pairs for lookup constructor: -> @@ -8,6 +8,9 @@ Darkswarm.factory 'Enterprises', (enterprises)-> @dereference() dereference: -> + if CurrentHub.hub + CurrentHub.hub = @enterprises_by_id[CurrentHub.hub.id] + for enterprise in @enterprises if enterprise.hubs for hub, i in enterprise.hubs diff --git a/app/assets/javascripts/darkswarm/services/order.js.coffee b/app/assets/javascripts/darkswarm/services/order.js.coffee index e119365685..479d21f90b 100644 --- a/app/assets/javascripts/darkswarm/services/order.js.coffee +++ b/app/assets/javascripts/darkswarm/services/order.js.coffee @@ -10,7 +10,7 @@ Darkswarm.factory 'Order', ($resource, order, $http, Navigation, storage, Curren # Bind all the fields from fieldsToBind, + anything on the Order class bindFieldsToLocalStorage: (scope)=> - prefix = "order_#{@order.id}#{@order.user_id}#{CurrentHub.id}" + prefix = "order_#{@order.id}#{@order.user_id}#{CurrentHub.hub.id}" for field in @fieldsToBind storage.bind scope, "Order.order.#{field}", storeName: "#{prefix}_#{field}" diff --git a/app/assets/javascripts/templates/partials/contact.html.haml b/app/assets/javascripts/templates/partials/contact.html.haml index 9cc9382015..b3dea0cfbb 100644 --- a/app/assets/javascripts/templates/partials/contact.html.haml +++ b/app/assets/javascripts/templates/partials/contact.html.haml @@ -1,4 +1,4 @@ -%div.modal-centered{"bo-if" => "enterprise.email || enterprise.website || enterprise.phone"} +%div.modal-centered{bindonce: true, "bo-if" => "enterprise.email || enterprise.website || enterprise.phone"} %h5.modal-header Contact %p{"ng-if" => "enterprise.phone"} {{ enterprise.phone }} diff --git a/app/assets/javascripts/templates/partials/follow.html.haml b/app/assets/javascripts/templates/partials/follow.html.haml index cde2f5986f..33ef1cf52b 100644 --- a/app/assets/javascripts/templates/partials/follow.html.haml +++ b/app/assets/javascripts/templates/partials/follow.html.haml @@ -1,4 +1,4 @@ -%div.modal-centered{"bo-if" => "producer.twitter || producer.facebook || producer.linkedin || producer.instagram"} +%div.modal-centered{"ng-if" => "producer.twitter || producer.facebook || producer.linkedin || producer.instagram"} %h5.modal-header Follow .follow-icons{bindonce: true} %span{"ng-if" => "producer.twitter"} diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 957a0df64f..cc8640c8aa 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -156,7 +156,7 @@ class Enterprise < ActiveRecord::Base end def distributors - self.relatives.is_distributor + self.relatives.is_distributor.visible end def website @@ -170,7 +170,7 @@ class Enterprise < ActiveRecord::Base end def suppliers - self.relatives.is_primary_producer + self.relatives.is_primary_producer.visible end def distributed_variants diff --git a/app/views/json/_current_hub.rabl b/app/views/json/_current_hub.rabl index 33bacd38b1..103baf9fb3 100644 --- a/app/views/json/_current_hub.rabl +++ b/app/views/json/_current_hub.rabl @@ -1,2 +1,6 @@ object current_distributor -attributes :id +extends 'json/partials/enterprise' + +child suppliers: :producers do + attributes :id +end diff --git a/app/views/json/partials/_hub.rabl b/app/views/json/partials/_hub.rabl index 15de4d4e1d..2df71001cb 100644 --- a/app/views/json/partials/_hub.rabl +++ b/app/views/json/partials/_hub.rabl @@ -14,7 +14,7 @@ node :delivery do |hub| hub.shipping_methods.where(:require_ship_address => true).present? end node :active do |hub| - @active_distributors.andand.include?(hub) + @active_distributors.include?(hub) end node :orders_close_at do |hub| OrderCycle.first_closing_for(hub).andand.orders_close_at diff --git a/app/views/map/index.html.haml b/app/views/map/index.html.haml index 3c9e9b64ec..e7f6006ae4 100644 --- a/app/views/map/index.html.haml +++ b/app/views/map/index.html.haml @@ -1,3 +1,5 @@ += inject_enterprises + .map-container{"fill-vertical" => true} %map{"ng-controller" => "MapCtrl"} %google-map{options: "map.additional_options", center: "map.center", zoom: "map.zoom", styles: "map.styles", draggable: "true"} diff --git a/app/views/shared/menu/_large_menu.html.haml b/app/views/shared/menu/_large_menu.html.haml index 49e82d2632..22618b50c4 100644 --- a/app/views/shared/menu/_large_menu.html.haml +++ b/app/views/shared/menu/_large_menu.html.haml @@ -32,10 +32,10 @@ - else = render 'shared/signed_in' %li.divider - %li.current_hub{"ng-controller" => "CurrentHubCtrl", "ng-show" => "CurrentHub.id"} + %li.current_hub{"ng-controller" => "CurrentHubCtrl", "ng-show" => "CurrentHub.hub.id"} %a{href: main_app.shop_path} %em Shopping @ - %span.nav-primary.nav-branded {{ CurrentHub.name }} + %span.nav-primary.nav-branded {{ CurrentHub.hub.name }} %li.divider %li.cart = render partial: "shared/menu/cart" diff --git a/app/views/shared/menu/_mobile_menu.html.haml b/app/views/shared/menu/_mobile_menu.html.haml index 22e65030b0..1cbc09e578 100644 --- a/app/views/shared/menu/_mobile_menu.html.haml +++ b/app/views/shared/menu/_mobile_menu.html.haml @@ -5,7 +5,7 @@ %section.right = render partial: "shared/menu/cart" %a{href: main_app.shop_path} - {{ CurrentHub.name }} + {{ CurrentHub.hub.name }} %aside.left-off-canvas-menu.show-for-medium-down %ul.off-canvas-list diff --git a/app/views/shopping_shared/_about.html.haml b/app/views/shopping_shared/_about.html.haml index 397ae1f041..1cd8f91c49 100644 --- a/app/views/shopping_shared/_about.html.haml +++ b/app/views/shopping_shared/_about.html.haml @@ -1,9 +1,9 @@ .content#about{"ng-controller" => "AboutUsCtrl", bindonce: true} .row .small-12.large-6.columns - %img.hero-img-small{"bo-src" => "CurrentHub.promo_image"} - %p.small-text{"bo-html" => "CurrentHub.long_description"} + %img.hero-img-small{"bo-src" => "CurrentHub.hub.promo_image"} + %p.small-text{"bo-html" => "CurrentHub.hub.long_description"} .small-12.large-3.columns   .small-12.large-3.columns - %img{"bo-src" => "CurrentHub.logo", "bo-if" => "CurrentHub.logo"} + %img{"bo-src" => "CurrentHub.hub.logo", "bo-if" => "CurrentHub.hub.logo"} diff --git a/app/views/shopping_shared/_producers.html.haml b/app/views/shopping_shared/_producers.html.haml index a736cac763..3ccaaf72ab 100644 --- a/app/views/shopping_shared/_producers.html.haml +++ b/app/views/shopping_shared/_producers.html.haml @@ -4,5 +4,5 @@ %h5 = "#{current_distributor.name}'s producers:" %ul.bullet-list - %li{"ng-repeat" => "enterprise in CurrentHub.producers"} + %li{"ng-repeat" => "enterprise in CurrentHub.hub.producers"} = render partial: "modals/producer" diff --git a/app/views/spree/orders/edit.html.haml b/app/views/spree/orders/edit.html.haml index 1ece630628..76b22aeb36 100644 --- a/app/views/spree/orders/edit.html.haml +++ b/app/views/spree/orders/edit.html.haml @@ -1,5 +1,3 @@ -= inject_enterprises - - @body_id = 'cart' .darkswarm - content_for :order_cycle_form do diff --git a/app/views/spree/orders/show.html.haml b/app/views/spree/orders/show.html.haml index 269011cfc7..f0fe766696 100644 --- a/app/views/spree/orders/show.html.haml +++ b/app/views/spree/orders/show.html.haml @@ -1,5 +1,3 @@ -= inject_enterprises - .darkswarm - content_for :order_cycle_form do %strong.avenir diff --git a/spec/javascripts/unit/darkswarm/controllers/checkout/accordion_controller_spec.js.coffee b/spec/javascripts/unit/darkswarm/controllers/checkout/accordion_controller_spec.js.coffee index 9c2545b851..5e98318f4f 100644 --- a/spec/javascripts/unit/darkswarm/controllers/checkout/accordion_controller_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/controllers/checkout/accordion_controller_spec.js.coffee @@ -2,7 +2,8 @@ describe "AccordionCtrl", -> ctrl = null scope = null CurrentHubMock = - id: 1 + hub: + id: 1 beforeEach -> module "Darkswarm" diff --git a/spec/javascripts/unit/darkswarm/controllers/hub_node_controller_spec.js.coffee b/spec/javascripts/unit/darkswarm/controllers/hub_node_controller_spec.js.coffee index cb77cb1703..34c9bc06ff 100644 --- a/spec/javascripts/unit/darkswarm/controllers/hub_node_controller_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/controllers/hub_node_controller_spec.js.coffee @@ -9,7 +9,8 @@ describe "HubNodeCtrl", -> scope = hub: {} CurrentHub = - id: 99 + hub: + id: 99 inject ($controller, $location)-> ctrl = $controller 'HubNodeCtrl', {$scope: scope, CurrentHub: CurrentHub, $location : $location} diff --git a/spec/javascripts/unit/darkswarm/services/enterprise_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/enterprise_spec.js.coffee index ec0475b93b..ebf480d9e8 100644 --- a/spec/javascripts/unit/darkswarm/services/enterprise_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/enterprise_spec.js.coffee @@ -1,5 +1,6 @@ describe "Enterprises service", -> Enterprises = null + CurrentHubMock = {} enterprises = [ {id: 1, type: "hub", producers: [{id: 2}]}, {id: 2, type: "producer", hubs: [{id: 1}]}, @@ -7,6 +8,9 @@ describe "Enterprises service", -> ] beforeEach -> module 'Darkswarm' + module ($provide)-> + $provide.value "CurrentHub", CurrentHubMock + null angular.module('Darkswarm').value('enterprises', enterprises) inject ($injector)-> diff --git a/spec/javascripts/unit/darkswarm/services/hubs_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/hubs_spec.js.coffee index 41828242a8..6b1238d1d1 100644 --- a/spec/javascripts/unit/darkswarm/services/hubs_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/hubs_spec.js.coffee @@ -1,6 +1,7 @@ describe "Hubs service", -> Hubs = null Enterprises = null + CurrentHubMock = {} hubs = [ { id: 2 @@ -26,6 +27,9 @@ describe "Hubs service", -> beforeEach -> module 'Darkswarm' angular.module('Darkswarm').value('enterprises', hubs) + module ($provide)-> + $provide.value "CurrentHub", CurrentHubMock + null inject ($injector)-> Enterprises = $injector.get("Enterprises") Hubs = $injector.get("Hubs") diff --git a/spec/javascripts/unit/darkswarm/services/map_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/map_spec.js.coffee index 67acef2770..c10c2c22f8 100644 --- a/spec/javascripts/unit/darkswarm/services/map_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/map_spec.js.coffee @@ -1,5 +1,6 @@ describe "Hubs service", -> OfnMap = null + CurrentHubMock = {} enterprises = [ { id: 2 @@ -12,6 +13,9 @@ describe "Hubs service", -> beforeEach -> module 'Darkswarm' angular.module('Darkswarm').value('enterprises', enterprises) + module ($provide)-> + $provide.value "CurrentHub", CurrentHubMock + null inject ($injector)-> OfnMap = $injector.get("OfnMap") diff --git a/spec/javascripts/unit/darkswarm/services/order_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/order_spec.js.coffee index 58b2838ac4..7dfb9e25e6 100644 --- a/spec/javascripts/unit/darkswarm/services/order_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/order_spec.js.coffee @@ -7,7 +7,8 @@ describe 'Order service', -> storage = null scope = null CurrentHubMock = - id: 1 + hub: + id: 1 FlashLoaderMock = loadFlash: (arg)-> @@ -66,13 +67,13 @@ describe 'Order service', -> spyOn(storage, "bind") Order.fieldsToBind = ["testy"] Order.bindFieldsToLocalStorage({}) - prefix = "order_#{Order.order.id}#{Order.order.user_id}#{CurrentHubMock.id}" + prefix = "order_#{Order.order.id}#{Order.order.user_id}#{CurrentHubMock.hub.id}" expect(storage.bind).toHaveBeenCalledWith({}, "Order.order.testy", {storeName: "#{prefix}_testy"}) expect(storage.bind).toHaveBeenCalledWith({}, "Order.ship_address_same_as_billing", {storeName: "#{prefix}_sameasbilling", defaultValue: true}) it "binds order to local storage", -> Order.bindFieldsToLocalStorage(scope) - prefix = "order_#{Order.order.id}#{Order.order.user_id}#{CurrentHubMock.id}" + prefix = "order_#{Order.order.id}#{Order.order.user_id}#{CurrentHubMock.hub.id}" expect(localStorage.getItem("#{prefix}_email")).toMatch "test@test.com" it "does not store secrets in local storage", -> diff --git a/spec/javascripts/unit/darkswarm/services/producers_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/producers_spec.js.coffee index 282e4725de..dc9ac0fc8f 100644 --- a/spec/javascripts/unit/darkswarm/services/producers_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/producers_spec.js.coffee @@ -1,12 +1,18 @@ describe "Producers service", -> Producers = null Enterprises = null + CurrentHubMock = + hub: + id: 1 enterprises = [ {is_primary_producer: true} ] beforeEach -> module 'Darkswarm' + module ($provide)-> + $provide.value "CurrentHub", CurrentHubMock + null angular.module('Darkswarm').value('enterprises', enterprises) inject ($injector)-> Producers = $injector.get("Producers") diff --git a/spec/javascripts/unit/darkswarm/services/product_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/product_spec.js.coffee index bddd8168f6..389c0696ae 100644 --- a/spec/javascripts/unit/darkswarm/services/product_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/product_spec.js.coffee @@ -2,6 +2,7 @@ describe 'Product service', -> $httpBackend = null Product = null Enterprises = null + CurrentHubMock = {} product = test: "cats" supplier: @@ -9,6 +10,9 @@ describe 'Product service', -> beforeEach -> module 'Darkswarm' + module ($provide)-> + $provide.value "CurrentHub", CurrentHubMock + null inject ($injector, _$httpBackend_)-> Product = $injector.get("Product") Enterprises = $injector.get("Enterprises") diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index bdf5574baf..0354f6b41d 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -39,15 +39,17 @@ describe Enterprise do e.relatives.sort.should == [p, c].sort end - it "scopes relatives to distributors" do + it "scopes relatives to visible distributors" do e.should_receive(:relatives).and_return(relatives = []) - relatives.should_receive(:is_distributor) + relatives.should_receive(:is_distributor).and_return relatives + relatives.should_receive(:visible) e.distributors end - it "scopes relatives to producers" do + it "scopes relatives to visible producers" do e.should_receive(:relatives).and_return(relatives = []) - relatives.should_receive(:is_primary_producer) + relatives.should_receive(:is_primary_producer).and_return relatives + relatives.should_receive(:visible) e.suppliers end end