From ff892ddadb9d621944a3a9730c9f0fd0ed4f4104 Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Sun, 24 May 2015 11:46:05 +0200 Subject: [PATCH] fixes #3 --- public/app/js/controllers/DashboardCtrl.js | 21 ++++++++++++++++++--- public/app/js/templates/dashboard.html | 2 +- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/public/app/js/controllers/DashboardCtrl.js b/public/app/js/controllers/DashboardCtrl.js index 933ef8d6..b57aa716 100644 --- a/public/app/js/controllers/DashboardCtrl.js +++ b/public/app/js/controllers/DashboardCtrl.js @@ -88,9 +88,24 @@ app.controller( 'DashboardCtrl', } ); } - bucket.total = _( bucket.data ).reduce( function ( memo, account ) { - return memo + account.amount; - }, 0 ); + bucket.total_detailed = _.chain( bucket.data ) + .groupBy( function( account ) { + return account.account.split(':')[0]; + } ) + .each( function( category ) { + category.total = _( category ).reduce( function ( memo, account ) { + return memo + account.amount; + }, 0 ); + } ) + .value(); + bucket.total_detailed = _.chain(bucket.total_detailed) + .keys() + .map( function( key ) { + return { account: key, + amount: bucket.total_detailed[key].total }; + } ) + .value(); + } ); }; diff --git a/public/app/js/templates/dashboard.html b/public/app/js/templates/dashboard.html index 22a96f5d..e1fbe511 100644 --- a/public/app/js/templates/dashboard.html +++ b/public/app/js/templates/dashboard.html @@ -19,7 +19,7 @@ -

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

+

{{account.account}}, total = {{account.amount | number:2}} €