diff --git a/app/assets/javascripts/darkswarm/controllers/products_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/products_controller.js.coffee index 323df2fc4e..3fdb58cf8e 100644 --- a/app/assets/javascripts/darkswarm/controllers/products_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/products_controller.js.coffee @@ -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)-> diff --git a/app/assets/javascripts/darkswarm/services/hubs.js.coffee b/app/assets/javascripts/darkswarm/services/hubs.js.coffee index 65940c5708..70df62e888 100644 --- a/app/assets/javascripts/darkswarm/services/hubs.js.coffee +++ b/app/assets/javascripts/darkswarm/services/hubs.js.coffee @@ -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']) diff --git a/app/assets/javascripts/darkswarm/services/map.js.coffee b/app/assets/javascripts/darkswarm/services/map.js.coffee index f2050a6f25..fd76eeff91 100644 --- a/app/assets/javascripts/darkswarm/services/map.js.coffee +++ b/app/assets/javascripts/darkswarm/services/map.js.coffee @@ -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 diff --git a/app/assets/javascripts/darkswarm/services/map_modal.js.coffee b/app/assets/javascripts/darkswarm/services/map_modal.js.coffee index f5c8d3d065..2f1bd832b4 100644 --- a/app/assets/javascripts/darkswarm/services/map_modal.js.coffee +++ b/app/assets/javascripts/darkswarm/services/map_modal.js.coffee @@ -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 diff --git a/app/assets/javascripts/darkswarm/services/producers.js.coffee b/app/assets/javascripts/darkswarm/services/producers.js.coffee index 8ca9752d28..6483ef35eb 100644 --- a/app/assets/javascripts/darkswarm/services/producers.js.coffee +++ b/app/assets/javascripts/darkswarm/services/producers.js.coffee @@ -2,5 +2,5 @@ Darkswarm.factory 'Producers', (Enterprises) -> new class Producers constructor: -> @producers = Enterprises.enterprises.filter (enterprise)-> - enterprise.type == "producer" + enterprise.enterprise_type == "producer" diff --git a/app/assets/javascripts/darkswarm/services/product.js.coffee b/app/assets/javascripts/darkswarm/services/product.js.coffee index 406e122de1..5fae2314a8 100644 --- a/app/assets/javascripts/darkswarm/services/product.js.coffee +++ b/app/assets/javascripts/darkswarm/services/product.js.coffee @@ -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 + @ diff --git a/app/helpers/shared_helper.rb b/app/helpers/shared_helper.rb index f421107994..b552ccd554 100644 --- a/app/helpers/shared_helper.rb +++ b/app/helpers/shared_helper.rb @@ -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) diff --git a/app/views/json/_enterprises.rabl b/app/views/json/_enterprises.rabl index 40065ff03f..9b4988b83f 100644 --- a/app/views/json/_enterprises.rabl +++ b/app/views/json/_enterprises.rabl @@ -1,5 +1,4 @@ collection Enterprise.visible -attributes :name, :id, :description extends 'json/partials/enterprise' extends 'json/partials/producer' extends 'json/partials/hub' diff --git a/app/views/json/_enterprises_for_map.rabl b/app/views/json/_enterprises_for_map.rabl index 641cb34a82..9ce100ab65 100644 --- a/app/views/json/_enterprises_for_map.rabl +++ b/app/views/json/_enterprises_for_map.rabl @@ -1,2 +1,2 @@ collection @enterprises -extends 'json/partials/enterprise' +extends "json/partials/enterprise" 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/partials/_enterprise.rabl b/app/views/json/partials/_enterprise.rabl index 32c2ccf4ab..86cd9f08aa 100644 --- a/app/views/json/partials/_enterprise.rabl +++ b/app/views/json/partials/_enterprise.rabl @@ -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? 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/shop/products/_form.html.haml b/app/views/shop/products/_form.html.haml index 95bfdac31d..d948f18f60 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 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 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..3a1b5fb399 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.products).toEqual 'testy mctest' diff --git a/spec/javascripts/unit/darkswarm/services/hubs_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/hubs_spec.js.coffee index 6247c7a713..9d4513af35 100644 --- a/spec/javascripts/unit/darkswarm/services/hubs_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/hubs_spec.js.coffee @@ -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" } ] diff --git a/spec/javascripts/unit/darkswarm/services/map_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/map_spec.js.coffee index 19ee666e19..67acef2770 100644 --- a/spec/javascripts/unit/darkswarm/services/map_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/map_spec.js.coffee @@ -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 diff --git a/spec/javascripts/unit/darkswarm/services/producers_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/producers_spec.js.coffee index ab2cc04cac..403bf186ba 100644 --- a/spec/javascripts/unit/darkswarm/services/producers_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/producers_spec.js.coffee @@ -2,7 +2,7 @@ describe "Producers service", -> Producers = null Enterprises = null enterprises = [ - {type: "producer"} + {enterprise_type: "producer"} ] beforeEach -> 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"