mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-18 04:39:14 +00:00
Count selected variants on an exchange
This commit is contained in:
@@ -3,6 +3,14 @@ function AdminCreateOrderCycleCtrl($scope, OrderCycle, Enterprise) {
|
||||
|
||||
$scope.order_cycle = OrderCycle.order_cycle;
|
||||
|
||||
$scope.exchangeVariantsSelected = function(exchange) {
|
||||
return OrderCycle.exchangeVariantsSelected(exchange);
|
||||
};
|
||||
|
||||
$scope.enterpriseVariantsTotal = function(enterprise) {
|
||||
return OrderCycle.enterpriseVariantsTotal(enterprise);
|
||||
};
|
||||
|
||||
$scope.toggleProducts = function($event, exchange) {
|
||||
$event.preventDefault();
|
||||
OrderCycle.toggleProducts(exchange);
|
||||
@@ -25,6 +33,14 @@ function AdminEditOrderCycleCtrl($scope, $location, OrderCycle, Enterprise) {
|
||||
var order_cycle_id = $location.absUrl().match(/\/admin\/order_cycles\/(\d+)/)[1];
|
||||
$scope.order_cycle = OrderCycle.load(order_cycle_id);
|
||||
|
||||
$scope.exchangeVariantsSelected = function(exchange) {
|
||||
return OrderCycle.exchangeVariantsSelected(exchange);
|
||||
};
|
||||
|
||||
$scope.enterpriseVariantsTotal = function(enterprise) {
|
||||
return OrderCycle.enterpriseVariantsTotal(enterprise);
|
||||
};
|
||||
|
||||
$scope.toggleProducts = function($event, exchange) {
|
||||
$event.preventDefault();
|
||||
OrderCycle.toggleProducts(exchange);
|
||||
@@ -56,6 +72,28 @@ angular.module('order_cycle', ['ngResource']).
|
||||
order_cycle: {incoming_exchanges: [],
|
||||
outgoing_exchanges: []},
|
||||
|
||||
exchangeVariantsSelected: function(exchange) {
|
||||
var numActiveVariants = 0;
|
||||
|
||||
angular.forEach(exchange.variants, function(active, id) {
|
||||
if(active) {
|
||||
numActiveVariants++;
|
||||
}
|
||||
});
|
||||
|
||||
return numActiveVariants;
|
||||
},
|
||||
|
||||
enterpriseVariantsTotal: function(enterprise) {
|
||||
var numVariants = 0;
|
||||
|
||||
angular.forEach(enterprise.supplied_products, function(product) {
|
||||
numVariants += product.variants.length == 0 ? 1 : product.variants.length;
|
||||
});
|
||||
|
||||
return numVariants;
|
||||
},
|
||||
|
||||
toggleProducts: function(exchange) {
|
||||
exchange.showProducts = !exchange.showProducts
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user