Refactoring the RABL injection and the Hubs/Producers/Enterprises services

This commit is contained in:
Will Marshall
2014-06-18 15:40:02 +10:00
parent c8384f1a71
commit a2965696da
14 changed files with 103 additions and 15 deletions

View File

@@ -1,5 +1,7 @@
Darkswarm.factory 'Enterprises', (enterprises)->
new class Enterprises
enterprises_by_id: {} # id/object pairs for lookup
constructor: ->
@enterprises = enterprises
@dereference()
for enterprise in enterprises
@enterprises_by_id[enterprise.id] = enterprise

View File

@@ -1,4 +1,9 @@
Darkswarm.factory 'Hubs', (hubs, $filter) ->
Darkswarm.factory 'Hubs', ($filter, Enterprises) ->
new class Hubs
constructor: ->
@hubs = $filter('orderBy')(hubs, ['-active', '+orders_close_at'])
@hubs = @filter Enterprises.enterprises.filter (hub)->
hub.type == "hub"
filter: (hubs)->
$filter('orderBy')(hubs, ['-active', '+orders_close_at'])

View File

@@ -1,5 +1,6 @@
Darkswarm.factory 'Producers', (producers) ->
Darkswarm.factory 'Producers', (Enterprises) ->
new class Producers
constructor: ->
@producers = producers
@producers = Enterprises.enterprises.filter (enterprise)->
enterprise.type == "producer"