Further patches to the damned RABL system, patching everything up to use our new Service structure

This commit is contained in:
Will Marshall
2014-06-18 17:54:13 +10:00
parent 224a70c11f
commit c02c7cf7ca
18 changed files with 40 additions and 37 deletions

View File

@@ -1,11 +1,12 @@
Darkswarm.controller "ProductsCtrl", ($scope, $rootScope, Product, OrderCycle) ->
$scope.data = Product.data
$scope.products = Product.products
$scope.loading = Product.loading
$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.products.length
$scope.limit = $scope.limit + 1
$scope.searchKeypress = (e)->

View File

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

View File

@@ -1,13 +1,17 @@
Darkswarm.factory "OfnMap", (enterprisesForMap, MapModal)->
Darkswarm.factory "OfnMap", (Enterprises, MapModal)->
new class OfnMap
constructor: ->
@enterprises = (@extend(enterprise) for enterprise in enterprisesForMap)
console.log @enterprises
@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
latitude: enterprise.latitude
longitude: enterprise.longitude
icon: enterprise.icon
id: enterprise.id
reveal: =>
MapModal.open @
MapModal.open enterprise

View File

@@ -2,7 +2,7 @@ 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?']
if enterprise.enterprise_type == "producer"
scope.producer = enterprise
$modal.open(templateUrl: "map_modal_producer.html", scope: scope)
else

View File

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

View File

@@ -5,11 +5,10 @@ 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
@products = $resource("/shop/products").query =>
@loading = false
@

View File

@@ -1,10 +1,10 @@
module SharedHelper
def inject_enterprises
inject_json "enterprises" , "enterprises", collection: @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)

View File

@@ -1,5 +1,4 @@
collection Enterprise.visible
attributes :name, :id, :description
extends 'json/partials/enterprise'
extends 'json/partials/producer'
extends 'json/partials/hub'

View File

@@ -1,2 +1,2 @@
collection @enterprises
extends 'json/partials/enterprise'
extends "json/partials/enterprise"

View File

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

View File

@@ -1,6 +1,6 @@
attributes :name, :id, :description, :latitude, :longitude, :long_description, :website, :instagram, :linkedin, :twitter, :facebook, :is_primary_producer?, :is_distributor?
attributes :name, :id, :description, :latitude, :longitude, :long_description, :website, :instagram, :linkedin, :twitter, :facebook
node :type do |enterprise|
node :enterprise_type do |enterprise|
if enterprise.is_primary_producer?
"producer"
elsif enterprise.is_distributor?

View File

@@ -1,4 +1,4 @@
= inject_json "enterprisesForMap" , "enterprises_for_map", collection: @enterprises
= inject_enterprises
.map-container{"fill-vertical" => true}
%map{"ng-controller" => "MapCtrl"}

View File

@@ -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 products | filter:query | orderBy:ordering.order | limitTo: limit track by product.id"}
%div
= render partial: "shop/products/summary"
%div{"bo-if" => "hasVariants"}
@@ -22,7 +22,7 @@
.variants.row{"bo-if" => "!hasVariants"}
= render partial: "shop/products/master"
%product{"ng-show" => "data.loading"}
%product{"ng-show" => "loading"}
.row.summary
.small-12.columns.text-center
Loading products

View File

@@ -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.products).toEqual 'testy mctest'

View File

@@ -6,19 +6,19 @@ describe "Hubs service", ->
id: 2
active: false
orders_close_at: new Date()
type: "hub"
enterprise_type: "hub"
}
{
id: 3
active: false
orders_close_at: new Date()
type: "hub"
enterprise_type: "hub"
}
{
id: 1
active: true
orders_close_at: new Date()
type: "hub"
enterprise_type: "hub"
}
]

View File

@@ -16,4 +16,4 @@ describe "Hubs service", ->
OfnMap = $injector.get("OfnMap")
it "builds MapMarkers from enterprises", ->
expect(OfnMap.enterprises[0].enterprise).toBe enterprises[0]
expect(OfnMap.enterprises[0].id).toBe enterprises[0].id

View File

@@ -2,7 +2,7 @@ describe "Producers service", ->
Producers = null
Enterprises = null
enterprises = [
{type: "producer"}
{enterprise_type: "producer"}
]
beforeEach ->

View File

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