Performance improvements

This commit is contained in:
Will Marshall
2014-07-11 15:09:20 +10:00
parent c852eefdbc
commit 7bd65d7854
6 changed files with 19 additions and 27 deletions

View File

@@ -1,11 +1,7 @@
Darkswarm.controller "ProductNodeCtrl", ($scope) ->
$scope.price = ->
if $scope.product.variants.length > 0
prices = (v.price for v in $scope.product.variants)
Math.min.apply(null, prices)
else
$scope.product.price
Darkswarm.controller "ProductNodeCtrl", ($scope, $modal) ->
$scope.enterprise = $scope.product.supplier # For the modal, so it's consistent
$scope.hasVariants = $scope.product.variants.length > 0
$scope.triggerProductModal = ->
$modal.open(templateUrl: "product_modal.html", scope: $scope)

View File

@@ -1,9 +0,0 @@
Darkswarm.directive "productModal", ($modal)->
restrict: 'E'
replace: true
template: "<a ng-transclude></a>"
transclude: true
link: (scope, elem, attrs, ctrl)->
elem.on "click", =>
scope.modalInstance = $modal.open(controller: ctrl, templateUrl: 'product_modal.html', scope: scope)

View File

@@ -1,5 +1,5 @@
Darkswarm.factory 'Product', ($resource, Enterprises, Dereferencer, Taxons) ->
new class Product
new class Products
constructor: ->
@update()
@@ -10,7 +10,8 @@ Darkswarm.factory 'Product', ($resource, Enterprises, Dereferencer, Taxons) ->
update: =>
@loading = true
@products = $resource("/shop/products").query =>
@products = $resource("/shop/products").query (products)=>
@extend()
@dereference()
@loading = false
@
@@ -19,4 +20,9 @@ Darkswarm.factory 'Product', ($resource, Enterprises, Dereferencer, Taxons) ->
for product in @products
product.supplier = Enterprises.enterprises_by_id[product.supplier.id]
Dereferencer.dereference product.taxons, Taxons.taxons_by_id
extend: ->
for product in @products
if product.variants.length > 0
prices = (v.price for v in product.variants)
product.price = Math.min.apply(null, prices)