mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Major refactoring
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}"
|
||||
|
||||
@@ -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 }}
|
||||
|
||||
@@ -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"}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,2 +1,6 @@
|
||||
object current_distributor
|
||||
attributes :id
|
||||
extends 'json/partials/enterprise'
|
||||
|
||||
child suppliers: :producers do
|
||||
attributes :id
|
||||
end
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
= inject_enterprises
|
||||
|
||||
- @body_id = 'cart'
|
||||
.darkswarm
|
||||
- content_for :order_cycle_form do
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
= inject_enterprises
|
||||
|
||||
.darkswarm
|
||||
- content_for :order_cycle_form do
|
||||
%strong.avenir
|
||||
|
||||
@@ -2,7 +2,8 @@ describe "AccordionCtrl", ->
|
||||
ctrl = null
|
||||
scope = null
|
||||
CurrentHubMock =
|
||||
id: 1
|
||||
hub:
|
||||
id: 1
|
||||
|
||||
beforeEach ->
|
||||
module "Darkswarm"
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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)->
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
@@ -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", ->
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user