From f73a3d20efa797a68413ba22407f30dfe8fcd529 Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Sun, 12 Oct 2014 08:34:47 +0200 Subject: [PATCH] reduce API calls for details --- public/app/js/controllers/BalanceCtrl.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/public/app/js/controllers/BalanceCtrl.js b/public/app/js/controllers/BalanceCtrl.js index d913c47c..ea956ce4 100644 --- a/public/app/js/controllers/BalanceCtrl.js +++ b/public/app/js/controllers/BalanceCtrl.js @@ -14,7 +14,7 @@ app.controller( 'BalanceCtrl', $scope.toolTipContentFunction = function () { return function ( key, x, y, e, graph ) { var details = $scope.balance.details[ key ]; - return '

' + details.key + '

' + '' + _( details.values ).map( function ( transaction ) { + return '

' + details.key + '

' + '
' + _( details ).map( function ( transaction ) { return ''; } ).join( '' ) + '' + '
' + transaction.date + '' + transaction.payee + '' + $filter( 'number' )( transaction.amount, 2 ) + ' ' + transaction.currency + '
Total :' + x + ' €
'; }; @@ -113,18 +113,15 @@ app.controller( 'BalanceCtrl', return 1 / account.amount; } ) .value(); - _( bucket.data ).each( - function ( account ) { - API.register( { period: period, - categories: account.account } ) - .then( function ( response ) { - $scope.balance.details[ account.account ] = response.data; - } ); - } ); bucket.total = _( response.data ).reduce( function ( memo, account ) { return memo + account.amount; }, 0 ); } ); + API.register( { period: period, + categories: bucket.categories } ) + .then( function ( response ) { + $scope.balance.details = _($scope.balance.details).extend( _(response.data.values).groupBy('account') ); + } ); } ); };