diff --git a/app/assets/images/browser-logos/chrome.png b/app/assets/images/browser-logos/chrome.png
new file mode 100644
index 0000000000..79a0b8e064
Binary files /dev/null and b/app/assets/images/browser-logos/chrome.png differ
diff --git a/app/assets/images/browser-logos/firefox.png b/app/assets/images/browser-logos/firefox.png
new file mode 100644
index 0000000000..c77db6ebbf
Binary files /dev/null and b/app/assets/images/browser-logos/firefox.png differ
diff --git a/app/assets/images/browser-logos/internet-explorer.png b/app/assets/images/browser-logos/internet-explorer.png
new file mode 100644
index 0000000000..c67631a65e
Binary files /dev/null and b/app/assets/images/browser-logos/internet-explorer.png differ
diff --git a/app/assets/javascripts/darkswarm/controllers/products_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/products_controller.js.coffee
index 323df2fc4e..3860a2d56e 100644
--- a/app/assets/javascripts/darkswarm/controllers/products_controller.js.coffee
+++ b/app/assets/javascripts/darkswarm/controllers/products_controller.js.coffee
@@ -1,11 +1,11 @@
Darkswarm.controller "ProductsCtrl", ($scope, $rootScope, Product, OrderCycle) ->
- $scope.data = Product.data
+ $scope.Product = Product
$scope.limit = 3
$scope.ordering = {order: "name"}
$scope.order_cycle = OrderCycle.order_cycle
$scope.incrementLimit = ->
- if $scope.limit < $scope.data.products.length
+ if $scope.limit < $scope.Product.products.length
$scope.limit = $scope.limit + 1
$scope.searchKeypress = (e)->
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
new file mode 100644
index 0000000000..ee658796b0
--- /dev/null
+++ b/app/assets/javascripts/darkswarm/directives/active_table_hub_link.js.coffee
@@ -0,0 +1,12 @@
+Darkswarm.directive "activeTableHubLink", (CurrentHub, CurrentOrder) ->
+ restrict: "A"
+ scope:
+ hub: '=activeTableHubLink'
+ template: "{{action}} {{hub.name}}"
+ 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
+ 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 4691d9b830..4ee4c9ce25 100644
--- a/app/assets/javascripts/darkswarm/directives/empties_cart.js.coffee
+++ b/app/assets/javascripts/darkswarm/directives/empties_cart.js.coffee
@@ -1,17 +1,12 @@
Darkswarm.directive "ofnEmptiesCart", (CurrentHub, CurrentOrder, Navigation, storage) ->
restrict: "A"
- scope:
- hub: '=ofnEmptiesCart'
- template: "{{action}} {{hub.name}}"
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 scope.hub.id
- scope.action = attr.change
+ if CurrentHub.id and CurrentHub.id isnt hub.id
unless CurrentOrder.empty()
elm.bind 'click', (ev)->
ev.preventDefault()
if confirm "Are you sure? This will change your selected Hub and remove any items in you shopping cart."
storage.clearAll() # One day this will have to be moar GRANULAR
Navigation.go scope.hub.path
- else
- scope.action = attr.shop
diff --git a/app/assets/javascripts/darkswarm/services/hub.js.coffee b/app/assets/javascripts/darkswarm/services/current_hub.js.coffee
similarity index 100%
rename from app/assets/javascripts/darkswarm/services/hub.js.coffee
rename to app/assets/javascripts/darkswarm/services/current_hub.js.coffee
diff --git a/app/assets/javascripts/darkswarm/services/enterprises.js.coffee b/app/assets/javascripts/darkswarm/services/enterprises.js.coffee
new file mode 100644
index 0000000000..0c73d0db1e
--- /dev/null
+++ b/app/assets/javascripts/darkswarm/services/enterprises.js.coffee
@@ -0,0 +1,18 @@
+Darkswarm.factory 'Enterprises', (enterprises)->
+ new class Enterprises
+ enterprises_by_id: {} # id/object pairs for lookup
+ constructor: ->
+ @enterprises = enterprises
+ for enterprise in enterprises
+ @enterprises_by_id[enterprise.id] = enterprise
+ @dereference()
+
+ dereference: ->
+ for enterprise in @enterprises
+ if enterprise.hubs
+ for hub, i in enterprise.hubs
+ enterprise.hubs[i] = @enterprises_by_id[hub.id]
+
+ if enterprise.producers
+ for producer, i in enterprise.producers
+ enterprise.producers[i] = @enterprises_by_id[producer.id]
diff --git a/app/assets/javascripts/darkswarm/services/hubs.js.coffee b/app/assets/javascripts/darkswarm/services/hubs.js.coffee
index a3f2b03f23..5d55fa7de9 100644
--- a/app/assets/javascripts/darkswarm/services/hubs.js.coffee
+++ b/app/assets/javascripts/darkswarm/services/hubs.js.coffee
@@ -1,4 +1,8 @@
-Darkswarm.factory 'Hubs', ($location, hubs, $filter, CurrentHub) ->
+Darkswarm.factory 'Hubs', ($filter, Enterprises) ->
new class Hubs
constructor: ->
- @hubs = $filter('orderBy')(hubs, ['-active', '+orders_close_at'])
+ @hubs = @order Enterprises.enterprises.filter (hub)->
+ hub.is_distributor
+
+ order: (hubs)->
+ $filter('orderBy')(hubs, ['-active', '+orders_close_at'])
diff --git a/app/assets/javascripts/darkswarm/services/map.js.coffee b/app/assets/javascripts/darkswarm/services/map.js.coffee
index eb1a195490..ed4bc8dae4 100644
--- a/app/assets/javascripts/darkswarm/services/map.js.coffee
+++ b/app/assets/javascripts/darkswarm/services/map.js.coffee
@@ -1,12 +1,17 @@
-Darkswarm.factory "OfnMap", (enterprisesForMap, MapModal)->
+Darkswarm.factory "OfnMap", (Enterprises, MapModal)->
new class OfnMap
constructor: ->
- @enterprises = (@extend(enterprise) for enterprise in enterprisesForMap)
+ @enterprises = (@extend(enterprise) for enterprise in Enterprises.enterprises)
+
# Adding methods to each enterprise
extend: (enterprise)->
new class MapMarker
- constructor: ->
- @[k] = v for k, v of enterprise
+ # We're whitelisting attributes because GMaps tries to crawl
+ # our data, and our data is recursive, so it breaks
+ latitude: enterprise.latitude
+ longitude: enterprise.longitude
+ icon: enterprise.icon
+ id: enterprise.id
reveal: =>
- MapModal.open @
+ MapModal.open enterprise
diff --git a/app/assets/javascripts/darkswarm/services/map_modal.js.coffee b/app/assets/javascripts/darkswarm/services/map_modal.js.coffee
index e6631a92f4..cd82edbe98 100644
--- a/app/assets/javascripts/darkswarm/services/map_modal.js.coffee
+++ b/app/assets/javascripts/darkswarm/services/map_modal.js.coffee
@@ -2,5 +2,10 @@ Darkswarm.factory "MapModal", ($modal, $rootScope)->
new class MapModal
open: (enterprise)->
scope = $rootScope.$new(true) # Spawn an isolate to contain the enterprise
- scope.enterprise = enterprise
- $modal.open(templateUrl: "map_modal.html", scope: scope)
+
+ if enterprise.is_distributor
+ scope.hub = enterprise
+ $modal.open(templateUrl: "map_modal_hub.html", scope: scope)
+ else
+ scope.producer = enterprise
+ $modal.open(templateUrl: "map_modal_producer.html", scope: scope)
diff --git a/app/assets/javascripts/darkswarm/services/producers.js.coffee b/app/assets/javascripts/darkswarm/services/producers.js.coffee
index 62a5087642..ac8354c101 100644
--- a/app/assets/javascripts/darkswarm/services/producers.js.coffee
+++ b/app/assets/javascripts/darkswarm/services/producers.js.coffee
@@ -1,4 +1,6 @@
-Darkswarm.factory 'Producers', (producers) ->
+Darkswarm.factory 'Producers', (Enterprises) ->
new class Producers
constructor: ->
- @producers = producers
+ @producers = Enterprises.enterprises.filter (enterprise)->
+ enterprise.is_primary_producer
+
diff --git a/app/assets/javascripts/darkswarm/services/product.js.coffee b/app/assets/javascripts/darkswarm/services/product.js.coffee
index 406e122de1..21c0921e41 100644
--- a/app/assets/javascripts/darkswarm/services/product.js.coffee
+++ b/app/assets/javascripts/darkswarm/services/product.js.coffee
@@ -5,11 +5,11 @@ Darkswarm.factory 'Product', ($resource) ->
# TODO: don't need to scope this into object
# Already on object as far as controller scope is concerned
- data:
- products: null
- loading: true
+ products: null
+ loading: true
update: =>
- @data.products = $resource("/shop/products").query =>
- @data.loading = false
- @data
+ @loading = true
+ @products = $resource("/shop/products").query =>
+ @loading = false
+ @
diff --git a/app/assets/javascripts/templates/authentication.html.haml b/app/assets/javascripts/templates/authentication.html.haml
index 3f219240e6..db1b5ecd7d 100644
--- a/app/assets/javascripts/templates/authentication.html.haml
+++ b/app/assets/javascripts/templates/authentication.html.haml
@@ -4,4 +4,4 @@
%ng-include{src: "'signup.html'"}
%ng-include{src: "'forgot.html'"}
%a.close-reveal-modal{"ng-click" => "$close()"}
- %i.ofn-i_009-close
\ No newline at end of file
+ %i.ofn-i_009-close
diff --git a/app/assets/javascripts/templates/map_modal.html.haml b/app/assets/javascripts/templates/map_modal_hub.html.haml
similarity index 95%
rename from app/assets/javascripts/templates/map_modal.html.haml
rename to app/assets/javascripts/templates/map_modal_hub.html.haml
index 54c834253a..546f83d9b2 100644
--- a/app/assets/javascripts/templates/map_modal.html.haml
+++ b/app/assets/javascripts/templates/map_modal_hub.html.haml
@@ -1,7 +1,7 @@
.row
.small-12.columns.producer-hero
%h3.producer-name
- %i.ofn-i_036-producers
+ %i.ofn-i_040-hub
{{ enterprise.name }}
{{ enterprise.id }}
%img.producer-hero-img{"ng-src" => "{{enterprise.promo_image}}"}
@@ -45,5 +45,5 @@
%i.ofn-i_043-instagram
{{ enterprise.instagram }}
- %a.close-reveal-modal{"ng-click" => "$close()"}
+ %a.close-reveal-modal.outside{"ng-click" => "$close()"}
%i.ofn-i_009-close
diff --git a/app/assets/javascripts/templates/map_modal_producer.html.haml b/app/assets/javascripts/templates/map_modal_producer.html.haml
new file mode 100644
index 0000000000..589e2f84d6
--- /dev/null
+++ b/app/assets/javascripts/templates/map_modal_producer.html.haml
@@ -0,0 +1,34 @@
+.highlight
+ .highlight-row
+ %p.right
+ {{ hub.address.city }} , {{hub.address.state}}
+ %h3
+ %i.ofn-i_036-producers
+ {{ producer.name }}
+
+ %img.producer-hero-img{"ng-src" => "{{producer.promo_image}}"}
+
+.row.pad-top{bindonce: true}
+ .small-12.large-6.columns
+ %img.producer-logo{"bo-src" => "producer.logo", "bo-if" => "producer.logo"}
+ %h5.modal-header About
+ %p{"ng-bind-html" => "producer.long_description"}
+
+ .small-12.large-6.columns
+ %ng-include{src: "'partials/contact.html'"}
+ %ng-include{src: "'partials/follow.html'"}
+
+.row{bindonce: true}
+ .modal-hubs
+ %h5 Shop for {{producer.name}} products at:
+ %a.button.primary.hub{"ng-repeat" => "hub in producer.hubs",
+ "bo-href" => "hub.path",
+ "bo-class" => "{active: hub.active, inactive: !hub.active}",
+ "ofn-empties-cart" => "hub"}
+ %i.ofn-i_033-open-sign{"bo-if" => "hub.active"}
+ %i.ofn-i_032-closed-sign{"bo-if" => "!hub.active"}
+ {{hub.name}}
+ ( {{ hub.address.city }} , {{hub.address.state}} )
+
+%a.close-reveal-modal.outside{"ng-click" => "$close()"}
+ %i.ofn-i_009-close
diff --git a/app/assets/javascripts/templates/partials/contact.html.haml b/app/assets/javascripts/templates/partials/contact.html.haml
new file mode 100644
index 0000000000..2811a221a5
--- /dev/null
+++ b/app/assets/javascripts/templates/partials/contact.html.haml
@@ -0,0 +1,12 @@
+%div.modal-centered{"bo-if" => "producer.email || producer.website || producer.address.phone"}
+ %h5.modal-header Contact
+ %p{"ng-if" => "producer.address.phone"}
+ {{ producer.address.phone }}
+
+ %p{"bo-if" => "producer.email"}
+ %a{"ng-href" => "mailto:{{producer.email | stripUrl}}", target: "_blank" }
+ {{ producer.email | stripUrl }}
+
+ %p{"ng-if" => "producer.website"}
+ %a{"ng-href" => "http://{{producer.website | stripUrl}}", target: "_blank" }
+ {{ producer.website | stripUrl }}
diff --git a/app/assets/javascripts/templates/partials/follow.html.haml b/app/assets/javascripts/templates/partials/follow.html.haml
new file mode 100644
index 0000000000..c4d101af7b
--- /dev/null
+++ b/app/assets/javascripts/templates/partials/follow.html.haml
@@ -0,0 +1,19 @@
+%div.modal-centered{"bo-if" => "producer.twitter || producer.facebook || producer.linkedin || producer.instagram"}
+ %h5.modal-header Follow
+ %ul.small-block-grid-1{bindonce: true}
+ %li{"ng-if" => "producer.twitter"}
+ %a{"ng-href" => "http://twitter.com/{{producer.twitter}}", target: "_blank"}
+ %i.ofn-i_041-twitter
+
+ %li{"ng-if" => "producer.facebook"}
+ %a{"ng-href" => "http://{{producer.facebook | stripUrl}}", target: "_blank"}
+ %i.ofn-i_044-facebook
+
+ %li{"ng-if" => "producer.linkedin"}
+ %a{"ng-href" => "http://{{producer.linkedin | stripUrl}}", target: "_blank"}
+ %i.ofn-i_042-linkedin
+
+ %li{"ng-if" => "producer.instagram"}
+ %a{"ng-href" => "http://instagram.com/{{producer.instagram}}", target: "_blank"}
+ %i.ofn-i_043-instagram
+
diff --git a/app/assets/stylesheets/darkswarm/home_tagline.css.sass b/app/assets/stylesheets/darkswarm/home_tagline.css.sass
index 2c3d01661d..3d00cb7a96 100644
--- a/app/assets/stylesheets/darkswarm/home_tagline.css.sass
+++ b/app/assets/stylesheets/darkswarm/home_tagline.css.sass
@@ -15,6 +15,9 @@
margin-bottom: 1em
h2
font-size: 1.6875rem
+ max-width: 610px
+ margin: 0 auto
+
a
color: $clr-brick-bright
&:hover, &:active, &:focus
diff --git a/app/assets/stylesheets/darkswarm/hub_node.css.sass b/app/assets/stylesheets/darkswarm/hub_node.css.sass
index 7dd6686d09..d13831661b 100644
--- a/app/assets/stylesheets/darkswarm/hub_node.css.sass
+++ b/app/assets/stylesheets/darkswarm/hub_node.css.sass
@@ -36,22 +36,6 @@
//Open row
&.open
- .fat-taxons
- @include csstrans
- margin-right: 0.5rem
- text-transform: uppercase
- font-size: 1rem
- line-height: 1
- color: $dark-grey
- // border: 1px solid $disabled-bright
- display: inline-block
- padding: 0.2rem 0.5rem 0.35rem 0.35rem
-
- object.taxon
- height: 20px
- // &:hover, &.hover, &:active
- // background: rgba(255,255,255,0.5)
-
.active_table_row:first-child
border-top: 1px solid $clr-brick
border-left: 1px solid $clr-brick
diff --git a/app/assets/stylesheets/darkswarm/ie_warning.sass b/app/assets/stylesheets/darkswarm/ie_warning.sass
new file mode 100644
index 0000000000..ede86a3083
--- /dev/null
+++ b/app/assets/stylesheets/darkswarm/ie_warning.sass
@@ -0,0 +1,32 @@
+#ie-warning
+ margin-bottom: 0
+ padding-bottom: 2rem
+ .ie-msg
+ background: rgba(255,255,255,0.15)
+ padding: 0.5rem
+ margin-bottom: 1rem
+ margin-top: 1rem
+ .browserbtn
+ text-align: center
+ margin-bottom: 1rem
+ a
+ color: white
+ font-size: 1rem
+ filter: alpha(opacity=70)
+ opacity: 0.7
+ &:hover, &:active, &:focus
+ filter: alpha(opacity=100)
+ opacity: 1
+
+ a.browserlogo
+ display: block
+ width: 100%
+ i
+ font-size: 5rem
+ color: white
+ text-align: center
+ display: block
+
+
+
+
diff --git a/app/assets/stylesheets/darkswarm/images.css.sass b/app/assets/stylesheets/darkswarm/images.css.sass
index 90207a2239..59fde9b48d 100644
--- a/app/assets/stylesheets/darkswarm/images.css.sass
+++ b/app/assets/stylesheets/darkswarm/images.css.sass
@@ -15,23 +15,12 @@
padding: 0
.producer-hero-img
- background-color: #999
+ background-color: #333
width: 100%
min-height: 160px
height: inherit
max-height: 260px
overflow: hidden
- margin-top: 2em
- margin-bottom: 1em
-
-
-h3.producer-name
- background-color: rgba(255,255,255,0.65)
- height: 2.5em
- width: 100%
- position: absolute
- bottom: 0
- padding: 0.5em
.producer-logo
max-width: 220px
diff --git a/app/assets/stylesheets/darkswarm/loading.sass b/app/assets/stylesheets/darkswarm/loading.sass
index cebb7edfd3..d2950f07fd 100644
--- a/app/assets/stylesheets/darkswarm/loading.sass
+++ b/app/assets/stylesheets/darkswarm/loading.sass
@@ -16,7 +16,9 @@
right: 0
@include user-select(none)
h1
+ -webkit-animation: blurFadeIn 0.8s ease-in-out 0s
color: white
+ font-size: 1.15rem
position: fixed
text-align: center
left: 0
@@ -24,7 +26,6 @@
margin: 0 auto
top: 55%
width: 100%
- height: 400px
overflow: visible
.loader
@@ -55,6 +56,20 @@
li:nth-child(3)
-webkit-animation: loadbars 0.6s ease-in-out infinite -0.4s
+@-webkit-keyframes blurFadeIn
+ 0%
+ opacity: 0
+ text-shadow: 0px 0px 10px #fff
+ -webkit-transform: scale(1.3)
+ 50%
+ opacity: 0.5
+ text-shadow: 0px 0px 5px #fff
+ -webkit-transform: scale(1.1)
+ 100%
+ opacity: 1
+ text-shadow: 0px 0px 0px #fff
+ -webkit-transform: scale(1)
+
@-webkit-keyframes 'loadbars'
0%
height: 10px
diff --git a/app/assets/stylesheets/darkswarm/mixins.sass b/app/assets/stylesheets/darkswarm/mixins.sass
index a9894a5b10..6cadb271c2 100644
--- a/app/assets/stylesheets/darkswarm/mixins.sass
+++ b/app/assets/stylesheets/darkswarm/mixins.sass
@@ -32,6 +32,33 @@
transition: all 100ms ease-in-out
-webkit-transform-style: preserve-3d
+@mixin animate-in
+ -webkit-animation: cssAnimation 100ms 1 ease-in
+ -moz-animation: cssAnimation 100ms 1 ease-in
+ -o-animation: cssAnimation 100ms 1 ease-in
+
+ @-webkit-keyframes cssAnimation
+ from
+ -webkit-transform: rotate(180deg) scale(0.25) skew(0deg) translate(0px)
+ to
+ -webkit-transform: rotate(0deg) scale(1) skew(0deg) translate(0px)
+
+
+ @-moz-keyframes cssAnimation
+ from
+ -moz-transform: rotate(180deg) scale(0.25) skew(0deg) translate(0px)
+ to
+ -moz-transform: rotate(0deg) scale(1) skew(0deg) translate(0px)
+
+
+ @-o-keyframes cssAnimation
+ from
+ -o-transform: rotate(180deg) scale(0.25) skew(0deg) translate(0px)
+ to
+ -o-transform: rotate(0deg) scale(1) skew(0deg) translate(0px)
+
+
+
@mixin box-shadow($box-shadow)
-moz-box-shadow: $box-shadow
-webkit-box-shadow: $box-shadow
diff --git a/app/assets/stylesheets/darkswarm/modals.css.sass b/app/assets/stylesheets/darkswarm/modals.css.sass
new file mode 100644
index 0000000000..de9d64645d
--- /dev/null
+++ b/app/assets/stylesheets/darkswarm/modals.css.sass
@@ -0,0 +1,49 @@
+@import branding
+@import mixins
+
+dialog, .reveal-modal
+ border: none
+ outline: none
+
+.reveal-modal-bg
+ background-color: rgba(0,0,0,0.65)
+
+.modal-centered
+ text-align: center
+ p
+ margin-bottom: 0
+
+.modal-header
+ text-align: center
+ text-transform: uppercase
+ border-bottom: 1px solid black
+
+dialog .close-reveal-modal.outside, .reveal-modal .close-reveal-modal.outside
+ @include csstrans
+ top: -2.2rem
+ right: -2.2rem
+ font-size: 2rem
+ color: white
+ text-shadow: none
+ &:hover, &:active, &:focus
+ color: $clr-brick-light-bright
+ text-shadow: 0 1px 3px #333
+
+.highlight
+ position: relative
+
+.highlight-row
+ padding: 0.75rem 0.9375rem
+ width: 100%
+ overflow: hidden
+ background-color: rgba(255,255,255,0.5)
+ position: absolute
+ bottom: 0
+ h3, p
+ margin-top: 0
+ margin-bottom: 0
+ padding-bottom: 0
+ line-height: 1
+ p
+ line-height: 2
+
diff --git a/app/assets/stylesheets/darkswarm/shop.css.sass b/app/assets/stylesheets/darkswarm/shop.css.sass
index b37c985884..312efb2188 100644
--- a/app/assets/stylesheets/darkswarm/shop.css.sass
+++ b/app/assets/stylesheets/darkswarm/shop.css.sass
@@ -124,9 +124,6 @@
.summary-header
@include csstrans
font-size: 1.15rem
-
- object.taxon
- height: 18px
&, & *
@include avenir
diff --git a/app/assets/stylesheets/darkswarm/taxons.css.sass b/app/assets/stylesheets/darkswarm/taxons.css.sass
new file mode 100644
index 0000000000..57ae6e6b70
--- /dev/null
+++ b/app/assets/stylesheets/darkswarm/taxons.css.sass
@@ -0,0 +1,33 @@
+@import branding
+@import mixins
+
+.fat-taxons
+ @include csstrans
+ display: inline-block
+ line-height: 1
+ margin-right: 0.5rem
+ margin-bottom: 0.2rem
+ text-transform: uppercase
+ font-size: 1rem
+ // border: 1px solid $disabled-bright
+ padding: 0.25rem 0.5rem 0.25rem 0.35rem
+ render-svg
+ svg
+ width: 16px
+ height: 16px
+ path
+ fill: $dark-grey
+ &, &*
+ display: inline-block
+ color: $dark-grey
+ // &:hover, &.hover, &:active
+ // background: rgba(255,255,255,0.5)
+
+.summary-header
+ @include csstrans
+ render-svg
+ svg
+ width: 18px
+ height: 18px
+ path
+ fill: $clr-brick
\ No newline at end of file
diff --git a/app/controllers/base_controller.rb b/app/controllers/base_controller.rb
index ba53ff4a0f..2ac35fa3ad 100644
--- a/app/controllers/base_controller.rb
+++ b/app/controllers/base_controller.rb
@@ -11,4 +11,8 @@ class BaseController < ApplicationController
include Spree::ProductsHelper
before_filter :check_order_cycle_expiry
+
+ def load_active_distributors
+ @active_distributors ||= Enterprise.distributors_with_active_order_cycles
+ end
end
diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb
index 592388c243..76e179ed22 100644
--- a/app/controllers/home_controller.rb
+++ b/app/controllers/home_controller.rb
@@ -1,10 +1,11 @@
class HomeController < BaseController
layout 'darkswarm'
+ before_filter :load_active_distributors
def index
- @active_distributors ||= Enterprise.distributors_with_active_order_cycles
end
def about_us
end
end
+
diff --git a/app/controllers/map_controller.rb b/app/controllers/map_controller.rb
index e4c4627f5f..a980ba8f40 100644
--- a/app/controllers/map_controller.rb
+++ b/app/controllers/map_controller.rb
@@ -1,6 +1,7 @@
class MapController < BaseController
layout 'darkswarm'
+ before_filter :load_active_distributors
+
def index
- @enterprises = Enterprise.visible
end
end
diff --git a/app/controllers/producers_controller.rb b/app/controllers/producers_controller.rb
index c5a133a798..b101a95b7f 100644
--- a/app/controllers/producers_controller.rb
+++ b/app/controllers/producers_controller.rb
@@ -1,7 +1,7 @@
class ProducersController < BaseController
layout 'darkswarm'
+ before_filter :load_active_distributors
def index
- @producers = Enterprise.is_primary_producer.visible
end
end
diff --git a/app/helpers/shared_helper.rb b/app/helpers/shared_helper.rb
index 3dee7eefbf..b552ccd554 100644
--- a/app/helpers/shared_helper.rb
+++ b/app/helpers/shared_helper.rb
@@ -1,7 +1,10 @@
module SharedHelper
+ def inject_enterprises
+ inject_json "enterprises" , "enterprises"
+ end
def inject_json(name, partial, opts = {})
- render "json/injection", {name: name, partial: partial}.merge(opts)
+ render partial: "json/injection", locals: {name: name, partial: partial}.merge(opts)
end
def distributor_link_class(distributor)
diff --git a/app/views/home/_fat.html.haml b/app/views/home/_fat.html.haml
index 25c48006e8..488547a651 100644
--- a/app/views/home/_fat.html.haml
+++ b/app/views/home/_fat.html.haml
@@ -24,11 +24,25 @@
%li{"ng-repeat" => "producer in hub.producers"}
= render partial: "modals/producer"
-.row.active_table_row.link{"ng-show" => "open()", "ng-if" => "hub.active"}
+.row.active_table_row.link{"ng-show" => "open()", "bo-if" => "hub.active"}
.columns.small-11
- %a{"bo-href" => "hub.path", "ofn-empties-cart" => "hub",
+ %a{"bo-href" => "hub.path", "ofn-empties-cart" => "hub",
+ "active-table-hub-link" => "hub",
change: "Change hub to", shop: "Shop at"}
.columns.small-1.text-right
%a{"bo-href" => "hub.path"}
%i.ofn-i_007-caret-right
+
+.row.active_table_row.link{"ng-show" => "open()", "bo-if" => "!hub.active"}
+ .columns.small-11
+ %a{"bo-href" => "hub.path", "ofn-empties-cart" => "hub",
+ "active-table-hub-link" => "hub",
+ change: "Change hub to (disabled)", shop: "Shop at (disabled)"}
+
+ .columns.small-1.text-right
+
+ %a{"bo-href" => "hub.path"}
+ %i.ofn-i_007-caret-right
+
+
diff --git a/app/views/home/_hubs.html.haml b/app/views/home/_hubs.html.haml
index c96ec6698c..55b8cc29ca 100644
--- a/app/views/home/_hubs.html.haml
+++ b/app/views/home/_hubs.html.haml
@@ -1,6 +1,5 @@
#hubs.hubs{"ng-controller" => "HubsCtrl"}
- :javascript
- angular.module('Darkswarm').value('hubs', #{render "json/hubs"})
+ = inject_enterprises
.row
.small-12.columns.text-center
diff --git a/app/views/json/_enterprises.rabl b/app/views/json/_enterprises.rabl
index 2f2f82c944..0f01743bfc 100644
--- a/app/views/json/_enterprises.rabl
+++ b/app/views/json/_enterprises.rabl
@@ -1,14 +1,7 @@
-# DON'T USE DIRECTLY - for inheritance
-attributes :name, :id, :description
-
-child :address do
- extends "json/partials/address"
-end
-
-node :path do |enterprise|
- shop_enterprise_path(enterprise)
-end
-
-node :hash do |enterprise|
- enterprise.to_param
-end
+# TODO: This should be moved into the controller
+# RABL is tricky to pass variables into: so we do this as a workaround for now
+# I noticed some vague comments on Rabl github about this, but haven't looked into
+collection Enterprise.visible
+extends 'json/partials/enterprise'
+extends 'json/partials/producer'
+extends 'json/partials/hub'
diff --git a/app/views/json/_hubs.rabl b/app/views/json/_hubs.rabl
index c118b4504f..7f8c4ac7b4 100644
--- a/app/views/json/_hubs.rabl
+++ b/app/views/json/_hubs.rabl
@@ -1,26 +1,4 @@
-collection Enterprise.visible.is_distributor
-extends 'json/enterprises'
+collection Enterprise.is_distributor.visible
+extends 'json/partials/enterprise'
+extends 'json/partials/hub'
-child distributed_taxons: :taxons do
- extends "json/taxon"
-end
-
-child suppliers: :producers do
- extends "json/producer"
-end
-
-node :pickup do |hub|
- not hub.shipping_methods.where(:require_ship_address => false).empty?
-end
-
-node :delivery do |hub|
- not hub.shipping_methods.where(:require_ship_address => true).empty?
-end
-
-node :active do |hub|
- @active_distributors.include?(hub)
-end
-
-node :orders_close_at do |hub|
- OrderCycle.first_closing_for(hub).andand.orders_close_at
-end
diff --git a/app/views/json/_injection.html.haml b/app/views/json/_injection.html.haml
index 95b921406b..ca58b4a943 100644
--- a/app/views/json/_injection.html.haml
+++ b/app/views/json/_injection.html.haml
@@ -1,2 +1,2 @@
:javascript
- angular.module('Darkswarm').value("#{name.to_s}", #{render "json/#{partial.to_s}"})
+ angular.module('Darkswarm').value("#{name.to_s}", #{render partial: "json/#{partial.to_s}"})
diff --git a/app/views/json/_producers.rabl b/app/views/json/_producers.rabl
index 95a133a182..cad5b29062 100644
--- a/app/views/json/_producers.rabl
+++ b/app/views/json/_producers.rabl
@@ -1,21 +1,3 @@
-collection @producers
-extends 'json/enterprises'
-
-child supplied_taxons: :taxons do
- extends 'json/taxon'
-end
-
-child distributors: :distributors do
- attributes :name, :id
- node :path do |distributor|
- shop_enterprise_path(distributor)
- end
-end
-
-node :path do |producer|
- producer_path(producer)
-end
-
-node :hash do |producer|
- producer.to_param
-end
+collection Enterprise.is_primary_producer.visible
+extends 'json/partials/enterprise'
+extends 'json/partials/producer'
diff --git a/app/views/json/partials/_address.rabl b/app/views/json/partials/_address.rabl
index b40bbc790b..04cc456a29 100644
--- a/app/views/json/partials/_address.rabl
+++ b/app/views/json/partials/_address.rabl
@@ -1,4 +1,4 @@
-attributes :city, :zipcode
+attributes :city, :zipcode, :phone
node :state do |address|
address.state.abbr
end
diff --git a/app/views/json/_enterprises_for_map.rabl b/app/views/json/partials/_enterprise.rabl
similarity index 54%
rename from app/views/json/_enterprises_for_map.rabl
rename to app/views/json/partials/_enterprise.rabl
index 006f2e3cca..20c7ff2332 100644
--- a/app/views/json/_enterprises_for_map.rabl
+++ b/app/views/json/partials/_enterprise.rabl
@@ -1,10 +1,21 @@
-collection @enterprises
-extends 'json/enterprises'
-attributes :latitude, :longitude, :long_description, :website, :instagram, :linkedin, :twitter, :facebook
+attributes :name, :id, :description, :latitude, :longitude, :long_description, :website, :instagram, :linkedin, :twitter, :facebook, :is_primary_producer, :is_distributor
+
+node :email do |enterprise|
+ enterprise.email.to_s.reverse
+end
+
+child :address do
+ extends "json/partials/address"
+end
+
+node :hash do |enterprise|
+ enterprise.to_param
+end
node :logo do |enterprise|
enterprise.logo(:medium) if enterprise.logo.exists?
end
+
node :promo_image do |enterprise|
enterprise.promo_image(:large) if enterprise.promo_image.exists?
end
diff --git a/app/views/json/partials/_hub.rabl b/app/views/json/partials/_hub.rabl
new file mode 100644
index 0000000000..1c11b23005
--- /dev/null
+++ b/app/views/json/partials/_hub.rabl
@@ -0,0 +1,21 @@
+child distributed_taxons: :taxons do
+ extends "json/taxon"
+end
+child suppliers: :producers do
+ attributes :id
+end
+node :path do |enterprise|
+ shop_enterprise_path(enterprise)
+end
+node :pickup do |hub|
+ hub.shipping_methods.where(:require_ship_address => false).present?
+end
+node :delivery do |hub|
+ hub.shipping_methods.where(:require_ship_address => true).present?
+end
+node :active do |hub|
+ @active_distributors.include?(hub)
+end
+node :orders_close_at do |hub|
+ OrderCycle.first_closing_for(hub).andand.orders_close_at
+end
diff --git a/app/views/json/partials/_producer.rabl b/app/views/json/partials/_producer.rabl
new file mode 100644
index 0000000000..a3f7975b40
--- /dev/null
+++ b/app/views/json/partials/_producer.rabl
@@ -0,0 +1,9 @@
+child supplied_taxons: :taxons do
+ extends 'json/taxon'
+end
+child distributors: :hubs do
+ attributes :id
+end
+node :path do |producer|
+ producer_path(producer)
+end
diff --git a/app/views/layouts/darkswarm.html.haml b/app/views/layouts/darkswarm.html.haml
index da314d514c..35b58a9e39 100644
--- a/app/views/layouts/darkswarm.html.haml
+++ b/app/views/layouts/darkswarm.html.haml
@@ -1,4 +1,3 @@
-!!!
%html
%head
%meta{charset: 'utf-8'}/
@@ -18,6 +17,34 @@
= csrf_meta_tags
%body.off-canvas{"ng-app" => "Darkswarm"}
+ / [if lte IE 8]
+ .alert-box.alert#ie-warning{"data-alert" => ""}
+ .row.ie-msg
+ .small-4.large-2.columns
+ %i.ofn-i_012-warning
+ .small-8.large-10.columns
+ %h3 Your browser is out of date :-(
+ %p For the best Open Food Network experience, we strongly recommend upgrading your browser:
+ .row
+ .small-4.columns.browserbtn
+ %a.browserlogo{href: "https://www.google.com/intl/en_au/chrome/browser/", target: "_blank"}
+ %img{src: "assets/browser-logos/chrome.png"}
+ %a{href: "https://www.google.com/intl/en_au/chrome/browser/", target: "_blank"} Download Chrome
+ .small-4.columns.browserbtn
+ %a.browserlogo{href: "http://www.mozilla.org/en-US/firefox/new/", target: "_blank"}
+ %img{src: "assets/browser-logos/firefox.png"}
+ %a{href: "http://www.mozilla.org/en-US/firefox/new/", target: "_blank"} Download Firefox
+ .small-4.columns.browserbtn
+ %a.browserlogo{href: "http://windows.microsoft.com/en-AU/internet-explorer/download-ie", target: "_blank"}
+ %img{src: "assets/browser-logos/internet-explorer.png"}
+ %a{href: "http://windows.microsoft.com/en-AU/internet-explorer/download-ie", target: "_blank"} Upgrade Internet Explorer
+ .row.ie-msg
+ .small-12.large-12.columns
+ .text-center
+ %em Can't upgrade your browser? Try Open Food Network on your smartphone :-)
+ %a.close{href: "#"} ×
+
+
= inject_json "currentHub", "current_hub"
= inject_json "currentOrder", "current_order"
= inject_json "user", "current_user"
diff --git a/app/views/map/index.html.haml b/app/views/map/index.html.haml
index 277178bfdc..e7f6006ae4 100644
--- a/app/views/map/index.html.haml
+++ b/app/views/map/index.html.haml
@@ -1,4 +1,4 @@
-= inject_json "enterprisesForMap" , "enterprises_for_map", collection: @enterprises
+= inject_enterprises
.map-container{"fill-vertical" => true}
%map{"ng-controller" => "MapCtrl"}
diff --git a/app/views/modals/_product.html.haml b/app/views/modals/_product.html.haml
index b2281d64ca..7c45a6ccab 100644
--- a/app/views/modals/_product.html.haml
+++ b/app/views/modals/_product.html.haml
@@ -4,7 +4,7 @@
%img.product-img{"ng-src" => "{{product.master.images[0].large_url}}", "ng-if" => "product.master.images[0]"}
.columns.small-12.large-6
%h2
- %img{"ng-src" => "{{product.primary_taxon.icon}}"}
+ %render-svg{path: "{{product.primary_taxon.icon}}"}
{{product.name}}
%p {{product.description}}
%a.close-reveal-modal{"ng-click" => "$close()"}
diff --git a/app/views/producers/index.haml b/app/views/producers/index.haml
index 7c4b6a5b62..2c3253a141 100644
--- a/app/views/producers/index.haml
+++ b/app/views/producers/index.haml
@@ -1,8 +1,5 @@
.producers{"ng-controller" => "ProducersCtrl"}
- :javascript
- angular.module('Darkswarm').value('producers', #{render partial: "json/producers", object: @producers})
- -#%pre
- -#{{ Producers.producers | json }}
+ = inject_enterprises
.row
.small-12.columns.text-center.pad-top
diff --git a/app/views/shop/products/_form.html.haml b/app/views/shop/products/_form.html.haml
index 95bfdac31d..724ec7b249 100644
--- a/app/views/shop/products/_form.html.haml
+++ b/app/views/shop/products/_form.html.haml
@@ -14,7 +14,7 @@
%div{bindonce: true}
%product{"ng-controller" => "ProductNodeCtrl",
- "ng-repeat" => "product in data.products | filter:query | orderBy:ordering.order | limitTo: limit track by product.id"}
+ "ng-repeat" => "product in Product.products | filter:query | orderBy:ordering.order | limitTo: limit track by product.id"}
%div
= render partial: "shop/products/summary"
%div{"bo-if" => "hasVariants"}
@@ -22,12 +22,10 @@
.variants.row{"bo-if" => "!hasVariants"}
= render partial: "shop/products/master"
- %product{"ng-show" => "data.loading"}
+ %product{"ng-show" => "Product.loading"}
.row.summary
.small-12.columns.text-center
Loading products
-
-
.row
.small-12.columns
%input.button.primary.right.add_to_cart{type: :submit, value: "Add to Cart"}
diff --git a/app/views/shop/products/_master.html.haml b/app/views/shop/products/_master.html.haml
index 59c0911cfd..c06acb5cb1 100644
--- a/app/views/shop/products/_master.html.haml
+++ b/app/views/shop/products/_master.html.haml
@@ -15,7 +15,7 @@
name: "variants[{{product.master.id}}]",
id: "variants_{{product.master.id}}",
"ng-model" => "product.quantity"}
- {{ product.master.unit_to_display }}
+ %small {{ product.master.unit_to_display }}
-# WITH GROUP BUY
.small-2.columns{"bo-if" => "product.group_buy"}
diff --git a/app/views/shop/products/_variants.html.haml b/app/views/shop/products/_variants.html.haml
index 1863bf7c1c..9faaa5e8b1 100644
--- a/app/views/shop/products/_variants.html.haml
+++ b/app/views/shop/products/_variants.html.haml
@@ -18,7 +18,7 @@
max: "{{variant.on_demand && 9999 || variant.count_on_hand }}",
name: "variants[{{variant.id}}]", id: "variants_{{variant.id}}",
"bo-model" => "variant.quantity"}
- {{ variant.unit_to_display }}
+ %small {{ variant.unit_to_display }}
-# WITH GROUP BUY
.small-2.columns{"bo-if" => "product.group_buy"}
@@ -39,7 +39,7 @@
max: "{{variant.on_demand && 9999 || variant.count_on_hand }}",
name: "variant_attributes[{{variant.id}}][max_quantity]",
"ng-model" => "variant.max_quantity"}
- {{ variant.unit_to_display }}
+ %small {{ variant.unit_to_display }}
.small-2.columns.text-right.price
{{ variant.price | currency }}
diff --git a/app/views/shop/show.html.haml b/app/views/shop/show.html.haml
index ad0080edae..8b1d08d08f 100644
--- a/app/views/shop/show.html.haml
+++ b/app/views/shop/show.html.haml
@@ -6,9 +6,9 @@
Next order closing
%strong {{ OrderCycle.orders_close_at() | date_in_words }}
- %span Ready for pickup
+ %span Ready for
- / Will this label should be a variable to reflect pickup or delivery as appropriate
+ / Will this label should be a variable to reflect 'Ready for pickup / delivery' as appropriate
%select.avenir#order_cycle_id{"ng-model" => "order_cycle.order_cycle_id",
"ng-change" => "changeOrderCycle()",
diff --git a/spec/controllers/base_controller_spec.rb b/spec/controllers/base_controller_spec.rb
index 8269c9374d..e431f14e3f 100644
--- a/spec/controllers/base_controller_spec.rb
+++ b/spec/controllers/base_controller_spec.rb
@@ -18,4 +18,9 @@ describe BaseController do
response.should redirect_to root_url
flash[:info].should == "The order cycle you've selected has just closed. Please try again!"
end
+
+ it "loads active_distributors" do
+ Enterprise.should_receive(:distributors_with_active_order_cycles)
+ controller.load_active_distributors
+ end
end
diff --git a/spec/controllers/map_controller_spec.rb b/spec/controllers/map_controller_spec.rb
index dedb534b1b..f3d56853f9 100644
--- a/spec/controllers/map_controller_spec.rb
+++ b/spec/controllers/map_controller_spec.rb
@@ -1,8 +1,8 @@
require 'spec_helper'
describe MapController do
- it "loads all visible enterprises" do
- Enterprise.should_receive(:visible)
+ it "loads active distributors" do
+ Enterprise.should_receive(:distributors_with_active_order_cycles)
get :index
end
end
diff --git a/spec/controllers/producers_controller_spec.rb b/spec/controllers/producers_controller_spec.rb
index 885b3981a1..d5a90a77d3 100644
--- a/spec/controllers/producers_controller_spec.rb
+++ b/spec/controllers/producers_controller_spec.rb
@@ -1,9 +1,15 @@
require 'spec_helper'
describe ProducersController do
- it "gets all active producers" do
- Enterprise.stub_chain(:is_primary_producer, :visible)
- Enterprise.should_receive(:is_primary_producer)
+ let!(:distributor) { create(:distributor_enterprise) }
+
+ before do
+ Enterprise.stub(:distributors_with_active_order_cycles).and_return [distributor]
+ Enterprise.stub(:visible).and_return [distributor]
+ end
+
+ it "sets active distributors" do
get :index
+ assigns[:active_distributors].should == [distributor]
end
end
diff --git a/spec/features/consumer/shopping/shopping_spec.rb b/spec/features/consumer/shopping/shopping_spec.rb
index 304eff7d23..e219e970a2 100644
--- a/spec/features/consumer/shopping/shopping_spec.rb
+++ b/spec/features/consumer/shopping/shopping_spec.rb
@@ -77,7 +77,6 @@ feature "As a consumer I want to shop with a distributor", js: true do
page.should have_content "Next order closing in 2 days"
Spree::Order.last.order_cycle.should == oc1
page.should have_content product.name
- save_screenshot "/Users/willmarshall/Desktop/shop.png"
page.should have_content product.master.display_name
page.should have_content product.master.display_as
end
diff --git a/spec/javascripts/application_spec.js b/spec/javascripts/application_spec.js
index df629c1c81..4eacb45036 100644
--- a/spec/javascripts/application_spec.js
+++ b/spec/javascripts/application_spec.js
@@ -5,7 +5,10 @@
//= require angular-mocks
//= require angular-cookies
//= require angular-backstretch.js
+//= require lodash.underscore.js
//= require angular-flash.min.js
//= require moment
angular.module('templates', [])
+angular.module('google-maps', []);
+angular.module('duScroll', []);
diff --git a/spec/javascripts/mock_google_maps.js.coffee b/spec/javascripts/mock_google_maps.js.coffee
new file mode 100644
index 0000000000..02ef0aa81f
--- /dev/null
+++ b/spec/javascripts/mock_google_maps.js.coffee
@@ -0,0 +1,68 @@
+@google =
+ maps:
+ event:
+ addDomListener: ->
+ addDomListenerOnce: ->
+ addListener: ->
+ addListenerOnce: ->
+ bind: ->
+ clearInstanceListeners: ->
+ clearListeners: ->
+ forward: ->
+ removeListener: ->
+ trigger: ->
+ vf: ->
+
+class google.maps.LatLng
+ constructor: (lat, lng) ->
+ @latitude = parseFloat(lat)
+ @longitude = parseFloat(lng)
+
+ lat: -> @latitude
+ lng: -> @longitude
+
+class google.maps.LatLngBounds
+ constructor: (@ne, @sw) ->
+
+ getSouthWest: -> @sw
+ getNorthEast: -> @ne
+
+class google.maps.OverlayView
+
+class google.maps.Marker
+ getAnimation: ->
+ getClickable: ->
+ getCursor: ->
+ getDraggable: ->
+ getFlat: ->
+ getIcon: ->
+ getPosition: ->
+ getShadow: ->
+ getShape: ->
+ getTitle: ->
+ getVisible: ->
+ getZIndex: ->
+ setAnimation: ->
+ setClickable: ->
+ setCursor: ->
+ setDraggable: ->
+ setFlat: ->
+ setIcon: ->
+ setPosition: ->
+ setShadow: ->
+ setShape: ->
+ setTitle: ->
+ setVisible: ->
+ setZIndex: ->
+ setMap: ->
+ getMap: ->
+
+class google.maps.MarkerImage
+
+class google.maps.Map
+
+class google.maps.Point
+
+class google.maps.Size
+
+class google.maps.InfoWindow
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 8e59248806..9c2545b851 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
@@ -1,9 +1,14 @@
describe "AccordionCtrl", ->
ctrl = null
scope = null
+ CurrentHubMock =
+ id: 1
beforeEach ->
module "Darkswarm"
+ module ($provide)->
+ $provide.value "CurrentHub", CurrentHubMock
+ null
localStorage.clear()
describe "loading incomplete form", ->
diff --git a/spec/javascripts/unit/darkswarm/controllers/products_controller_spec.js.coffee b/spec/javascripts/unit/darkswarm/controllers/products_controller_spec.js.coffee
index 685d495039..47ad0ccbd4 100644
--- a/spec/javascripts/unit/darkswarm/controllers/products_controller_spec.js.coffee
+++ b/spec/javascripts/unit/darkswarm/controllers/products_controller_spec.js.coffee
@@ -9,7 +9,7 @@ describe 'ProductsCtrl', ->
Product =
all: ->
update: ->
- data: "testy mctest"
+ products: "testy mctest"
OrderCycle =
order_cycle: {}
@@ -18,4 +18,4 @@ describe 'ProductsCtrl', ->
ctrl = $controller 'ProductsCtrl', {$scope: scope, Product: Product, OrderCycle: OrderCycle}
it 'fetches products from Product', ->
- expect(scope.data).toEqual 'testy mctest'
+ expect(scope.Product.products).toEqual 'testy mctest'
diff --git a/spec/javascripts/unit/darkswarm/services/enterprise_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/enterprise_spec.js.coffee
new file mode 100644
index 0000000000..ec0475b93b
--- /dev/null
+++ b/spec/javascripts/unit/darkswarm/services/enterprise_spec.js.coffee
@@ -0,0 +1,27 @@
+describe "Enterprises service", ->
+ Enterprises = null
+ enterprises = [
+ {id: 1, type: "hub", producers: [{id: 2}]},
+ {id: 2, type: "producer", hubs: [{id: 1}]},
+ {id: 3, type: "producer", hubs: [{id: 1}]}
+ ]
+ beforeEach ->
+ module 'Darkswarm'
+ angular.module('Darkswarm').value('enterprises', enterprises)
+
+ inject ($injector)->
+ Enterprises = $injector.get("Enterprises")
+
+ it "stores enterprises as id/object pairs", ->
+ expect(Enterprises.enterprises_by_id["1"]).toBe enterprises[0]
+ expect(Enterprises.enterprises_by_id["2"]).toBe enterprises[1]
+
+ it "stores enterprises as an array", ->
+ expect(Enterprises.enterprises).toBe enterprises
+
+ it "puts the same objects in enterprises and enterprises_by_id", ->
+ expect(Enterprises.enterprises[0]).toBe Enterprises.enterprises_by_id["1"]
+
+ it "dereferences references to other enterprises", ->
+ expect(Enterprises.enterprises_by_id["1"].producers[0]).toBe enterprises[1]
+ expect(Enterprises.enterprises_by_id["3"].hubs[0]).toBe enterprises[0]
diff --git a/spec/javascripts/unit/darkswarm/services/hubs_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/hubs_spec.js.coffee
new file mode 100644
index 0000000000..41828242a8
--- /dev/null
+++ b/spec/javascripts/unit/darkswarm/services/hubs_spec.js.coffee
@@ -0,0 +1,39 @@
+describe "Hubs service", ->
+ Hubs = null
+ Enterprises = null
+ hubs = [
+ {
+ id: 2
+ active: false
+ orders_close_at: new Date()
+ is_distributor: true
+ }
+ {
+ id: 3
+ active: false
+ orders_close_at: new Date()
+ is_distributor: true
+ }
+ {
+ id: 1
+ active: true
+ orders_close_at: new Date()
+ is_distributor: true
+ }
+ ]
+
+
+ beforeEach ->
+ module 'Darkswarm'
+ angular.module('Darkswarm').value('enterprises', hubs)
+ inject ($injector)->
+ Enterprises = $injector.get("Enterprises")
+ Hubs = $injector.get("Hubs")
+
+ it "filters Enterprise.hubs into a new array", ->
+ expect(Hubs.hubs[0]).toBe Enterprises.enterprises[2]
+ # Because the $filter is a new sorted array
+ # We check to see the objects in both arrays are still the same
+ Enterprises.enterprises[2].active = false
+ expect(Hubs.hubs[0].active).toBe false
+
diff --git a/spec/javascripts/unit/darkswarm/services/map_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/map_spec.js.coffee
new file mode 100644
index 0000000000..67acef2770
--- /dev/null
+++ b/spec/javascripts/unit/darkswarm/services/map_spec.js.coffee
@@ -0,0 +1,19 @@
+describe "Hubs service", ->
+ OfnMap = null
+ enterprises = [
+ {
+ id: 2
+ active: false
+ orders_close_at: new Date()
+ type: "hub"
+ }
+ ]
+
+ beforeEach ->
+ module 'Darkswarm'
+ angular.module('Darkswarm').value('enterprises', enterprises)
+ inject ($injector)->
+ OfnMap = $injector.get("OfnMap")
+
+ it "builds MapMarkers from enterprises", ->
+ expect(OfnMap.enterprises[0].id).toBe enterprises[0].id
diff --git a/spec/javascripts/unit/darkswarm/services/order_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/order_spec.js.coffee
index f6a4112eef..58b2838ac4 100644
--- a/spec/javascripts/unit/darkswarm/services/order_spec.js.coffee
+++ b/spec/javascripts/unit/darkswarm/services/order_spec.js.coffee
@@ -6,6 +6,10 @@ describe 'Order service', ->
flash = null
storage = null
scope = null
+ CurrentHubMock =
+ id: 1
+ FlashLoaderMock =
+ loadFlash: (arg)->
beforeEach ->
orderData =
@@ -36,6 +40,10 @@ describe 'Order service', ->
angular.module('Darkswarm').value('order', orderData)
module 'Darkswarm'
+ module ($provide)->
+ $provide.value "CurrentHub", CurrentHubMock
+ $provide.value "RailsFlashLoader", FlashLoaderMock
+ null
inject ($injector, _$httpBackend_, _storage_, $rootScope)->
$httpBackend = _$httpBackend_
@@ -58,13 +66,13 @@ describe 'Order service', ->
spyOn(storage, "bind")
Order.fieldsToBind = ["testy"]
Order.bindFieldsToLocalStorage({})
- prefix = "order_#{Order.order.id}#{Order.order.user_id}"
+ prefix = "order_#{Order.order.id}#{Order.order.user_id}#{CurrentHubMock.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}"
+ prefix = "order_#{Order.order.id}#{Order.order.user_id}#{CurrentHubMock.id}"
expect(localStorage.getItem("#{prefix}_email")).toMatch "test@test.com"
it "does not store secrets in local storage", ->
@@ -100,10 +108,11 @@ describe 'Order service', ->
$httpBackend.flush()
it "sends flash messages to the flash service", ->
+ spyOn(FlashLoaderMock, "loadFlash") # Stubbing out writes to window.location
$httpBackend.expectPUT("/checkout").respond 400, {flash: {error: "frogs"}}
Order.submit()
$httpBackend.flush()
- expect(flash.error).toEqual "frogs"
+ expect(FlashLoaderMock.loadFlash).toHaveBeenCalledWith {error: "frogs"}
it "puts errors into the scope", ->
$httpBackend.expectPUT("/checkout").respond 400, {errors: {error: "frogs"}}
diff --git a/spec/javascripts/unit/darkswarm/services/producers_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/producers_spec.js.coffee
new file mode 100644
index 0000000000..282e4725de
--- /dev/null
+++ b/spec/javascripts/unit/darkswarm/services/producers_spec.js.coffee
@@ -0,0 +1,15 @@
+describe "Producers service", ->
+ Producers = null
+ Enterprises = null
+ enterprises = [
+ {is_primary_producer: true}
+ ]
+
+ beforeEach ->
+ module 'Darkswarm'
+ angular.module('Darkswarm').value('enterprises', enterprises)
+ inject ($injector)->
+ Producers = $injector.get("Producers")
+
+ it "delegates producers array to Enterprises", ->
+ expect(Producers.producers[0]).toBe enterprises[0]
diff --git a/spec/javascripts/unit/darkswarm/services/product_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/product_spec.js.coffee
index 260074a981..c053573565 100644
--- a/spec/javascripts/unit/darkswarm/services/product_spec.js.coffee
+++ b/spec/javascripts/unit/darkswarm/services/product_spec.js.coffee
@@ -11,4 +11,4 @@ describe 'Product service', ->
it "Fetches products from the backend on init", ->
$httpBackend.expectGET("/shop/products").respond([{test : "cats"}])
$httpBackend.flush()
- expect(Product.data.products[0].test).toEqual "cats"
+ expect(Product.products[0].test).toEqual "cats"