Merge branch 'refactoring_services' into laura_and_will

This commit is contained in:
Will Marshall
2014-06-19 12:10:28 +10:00
38 changed files with 332 additions and 136 deletions

View File

@@ -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)->

View File

@@ -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]

View File

@@ -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'])

View File

@@ -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

View File

@@ -2,9 +2,10 @@ Darkswarm.factory "MapModal", ($modal, $rootScope)->
new class MapModal
open: (enterprise)->
scope = $rootScope.$new(true) # Spawn an isolate to contain the enterprise
if enterprise['is_primary_producer?']
scope.producer = enterprise
$modal.open(templateUrl: "map_modal_producer.html", scope: scope)
else
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)

View File

@@ -1,12 +1,6 @@
Darkswarm.factory 'Producers', (producers) ->
Darkswarm.factory 'Producers', (Enterprises) ->
new class Producers
constructor: ->
@producers = producers
# TODO: start adding functionality to producers like so
#@producers = (@extend(producer) for producer in producers)
@producers = Enterprises.enterprises.filter (enterprise)->
enterprise.is_primary_producer
#extend: (producer)->
#new class Producer
#constructor: ->
#@[k] = v for k, v of Producer

View File

@@ -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
@