mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Performance improvements
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
%div.pad-top{bindonce: true}
|
||||
%product.animate-repeat{"ng-controller" => "ProductNodeCtrl",
|
||||
"ng-repeat" => "product in filteredProducts = (Product.products | products:query | taxons:activeTaxons | orderBy:ordering.order | limitTo:limit) track by product.id "}
|
||||
"ng-repeat" => "product in filteredProducts = (Product.products | products:query | taxons:activeTaxons | orderBy:ordering.order) track by product.id "}
|
||||
%div
|
||||
= render partial: "shop/products/summary"
|
||||
%div{"bo-if" => "hasVariants"}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
.row.summary
|
||||
.small-1.columns
|
||||
%product-modal
|
||||
%img{"bo-src" => "product.master.images[0].small_url"}
|
||||
%img{"bo-src" => "product.master.images[0].small_url", "ng-click" => "triggerProductModal()"}
|
||||
|
||||
.small-4.columns.summary-header
|
||||
%render-svg{path: "{{product.primary_taxon.icon}}"}
|
||||
%product-modal {{ product.name }}
|
||||
%a{"ng-click" => "triggerProductModal()"}{{ product.name }}
|
||||
|
||||
.small-5.columns
|
||||
%i.ofn-i_036-producers
|
||||
@@ -14,4 +13,4 @@
|
||||
.small-2.columns.summary-price.text-right.price
|
||||
%span{"ng-if" => "hasVariants"}
|
||||
%em from
|
||||
{{ price() | currency }}
|
||||
{{ product.price | currency }}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
.row.variants{bindonce: true,
|
||||
"ng-repeat" => "variant in product.variants"}
|
||||
"ng-repeat" => "variant in product.variants track by variant.id"}
|
||||
|
||||
.small-1.columns
|
||||
%i.ofn-i_056-bulk{"bo-if" => "product.group_buy"}
|
||||
|
||||
Reference in New Issue
Block a user