From e7e07a93db112653c323c90754beb4418edd05b3 Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Sun, 12 Oct 2014 10:42:53 +0200 Subject: [PATCH] filter an accounts --- public/app/js/controllers/BalanceCtrl.js | 46 +++++++++++++++--------- public/app/js/templates/balance.tpl.html | 12 ++++--- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/public/app/js/controllers/BalanceCtrl.js b/public/app/js/controllers/BalanceCtrl.js index 50ba5397..a9bd4b7a 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 ).map( function ( transaction ) { + return '

' + key + '

' + '
' + _( details ).map( function ( transaction ) { return ''; } ).join( '' ) + '' + '
' + transaction.date + '' + transaction.payee + '' + $filter( 'number' )( transaction.amount, 2 ) + ' ' + transaction.currency + '
Total :' + x + ' €
'; }; @@ -67,6 +67,12 @@ app.controller( 'BalanceCtrl', // } } ); + $scope.update_chart_data = function() { + _($scope.balance.buckets).each( function( bucket ) { + bucket.chart.data = $filter('filter')( bucket.data, bucket.account_selected, true ); + } ); + }; + var retrieve_data = function () { var from, to, period; @@ -91,11 +97,17 @@ app.controller( 'BalanceCtrl', buckets: [ { categories: 'Expenses', data: [], - total: 0 + total: 0, + chart: { + data: [] + } }, { categories: 'Income Equity', data: [], - total: 0 + total: 0, + chart: { + data: [] + } } ], details: {} }; @@ -122,6 +134,8 @@ app.controller( 'BalanceCtrl', bucket.total = _( response.data ).reduce( function ( memo, account ) { return memo + account.amount; }, 0 ); + + $scope.update_chart_data(); } ); } ); }; @@ -142,24 +156,24 @@ app.controller( 'BalanceCtrl', $scope.period_offset = $scope.dates_salaries.length - 1; }; - API.dates_salaries() - .then( function ( response ) { - $scope.dates_salaries = response.data; - - $scope.reset_offset(); - - // retrieve_data() when the value of week_offset changes - // n.b.: triggered when week_offset is initialized above - $scope.$watch( 'period_offset', function () { - retrieve_data(); - } ); - - } ); API.accounts() .then( function ( response ) { $scope.accounts = response.data.map( function( account_ary ) { return account_ary.join( ':' ); } ); + API.dates_salaries() + .then( function ( response ) { + $scope.dates_salaries = response.data; + + $scope.reset_offset(); + + // retrieve_data() when the value of week_offset changes + // n.b.: triggered when week_offset is initialized above + $scope.$watch( 'period_offset', function () { + retrieve_data(); + } ); + + } ); } ); } ] ); diff --git a/public/app/js/templates/balance.tpl.html b/public/app/js/templates/balance.tpl.html index 4d9af575..2413d6f2 100644 --- a/public/app/js/templates/balance.tpl.html +++ b/public/app/js/templates/balance.tpl.html @@ -15,9 +15,6 @@ next - - @@ -31,9 +28,14 @@

{{bucket.categories}}, total = {{bucket.total | number:2}} €

+
- -