mirror of
https://github.com/gwenhael-le-moine/ledgerrb.git
synced 2024-12-27 21:58:11 +01:00
filter on multiple accounts
This commit is contained in:
parent
e7e07a93db
commit
5056f6d9ac
2 changed files with 26 additions and 21 deletions
|
@ -67,9 +67,21 @@ app.controller( 'BalanceCtrl',
|
||||||
// }
|
// }
|
||||||
} );
|
} );
|
||||||
|
|
||||||
$scope.update_chart_data = function() {
|
$scope.filter_data = function() {
|
||||||
_($scope.balance.buckets).each( function( bucket ) {
|
_($scope.balance.buckets).each( function( bucket ) {
|
||||||
bucket.chart.data = $filter('filter')( bucket.data, bucket.account_selected, true );
|
bucket.data = [];
|
||||||
|
|
||||||
|
if ( _(bucket.accounts_selected).isEmpty() ) {
|
||||||
|
bucket.data = bucket.raw_data;
|
||||||
|
} else {
|
||||||
|
_(bucket.accounts_selected).each( function( account_selected ) {
|
||||||
|
bucket.data = bucket.data.concat( $filter('filter')( bucket.raw_data, account_selected, true ) );
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
bucket.total = _( bucket.data ).reduce( function ( memo, account ) {
|
||||||
|
return memo + account.amount;
|
||||||
|
}, 0 );
|
||||||
} );
|
} );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -97,17 +109,11 @@ app.controller( 'BalanceCtrl',
|
||||||
buckets: [ {
|
buckets: [ {
|
||||||
categories: 'Expenses',
|
categories: 'Expenses',
|
||||||
data: [],
|
data: [],
|
||||||
total: 0,
|
total: 0
|
||||||
chart: {
|
|
||||||
data: []
|
|
||||||
}
|
|
||||||
}, {
|
}, {
|
||||||
categories: 'Income Equity',
|
categories: 'Income Equity',
|
||||||
data: [],
|
data: [],
|
||||||
total: 0,
|
total: 0
|
||||||
chart: {
|
|
||||||
data: []
|
|
||||||
}
|
|
||||||
} ],
|
} ],
|
||||||
details: {}
|
details: {}
|
||||||
};
|
};
|
||||||
|
@ -115,14 +121,14 @@ app.controller( 'BalanceCtrl',
|
||||||
API.register( { period: period,
|
API.register( { period: period,
|
||||||
categories: '' } )
|
categories: '' } )
|
||||||
.then( function ( response ) {
|
.then( function ( response ) {
|
||||||
$scope.balance.details = _($scope.balance.details).extend( _(response.data.values).groupBy('account') );
|
$scope.balance.details = _($scope.balance.details).extend( _(response.data.values).groupBy( 'account' ) );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
_($scope.balance.buckets).each( function( bucket ) {
|
_($scope.balance.buckets).each( function( bucket ) {
|
||||||
API.balance( { period: period,
|
API.balance( { period: period,
|
||||||
categories: bucket.categories } )
|
categories: bucket.categories } )
|
||||||
.then( function ( response ) {
|
.then( function ( response ) {
|
||||||
bucket.data = _.chain( response.data )
|
bucket.raw_data = _.chain( response.data )
|
||||||
.map( function( account ) {
|
.map( function( account ) {
|
||||||
account.amount = ( account.amount < 0 ) ? account.amount * -1 : account.amount;
|
account.amount = ( account.amount < 0 ) ? account.amount * -1 : account.amount;
|
||||||
return account;
|
return account;
|
||||||
|
@ -131,11 +137,9 @@ app.controller( 'BalanceCtrl',
|
||||||
return 1 / account.amount;
|
return 1 / account.amount;
|
||||||
} )
|
} )
|
||||||
.value();
|
.value();
|
||||||
bucket.total = _( response.data ).reduce( function ( memo, account ) {
|
bucket.accounts_selected = bucket.raw_data;
|
||||||
return memo + account.amount;
|
|
||||||
}, 0 );
|
|
||||||
|
|
||||||
$scope.update_chart_data();
|
$scope.filter_data();
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,14 +28,15 @@
|
||||||
<div flex data-ng-repeat="bucket in balance.buckets">
|
<div flex data-ng-repeat="bucket in balance.buckets">
|
||||||
<material-toolbar class="material-theme-light">
|
<material-toolbar class="material-theme-light">
|
||||||
<h3>{{bucket.categories}}, total = {{bucket.total | number:2}} €</h3>
|
<h3>{{bucket.categories}}, total = {{bucket.total | number:2}} €</h3>
|
||||||
<select data-ng-model="bucket.account_selected"
|
<select multiple
|
||||||
data-ng-options="account.account for account in bucket.data"
|
data-ng-model="bucket.accounts_selected"
|
||||||
data-ng-change="update_chart_data()">
|
data-ng-options="account.account for account in bucket.raw_data | orderBy:'account'"
|
||||||
|
data-ng-change="filter_data()">
|
||||||
<option value=''>...</option>
|
<option value=''>...</option>
|
||||||
</select>
|
</select>
|
||||||
</material-toolbar>
|
</material-toolbar>
|
||||||
<material-content>
|
<material-content>
|
||||||
<nvd3-pie-chart data="bucket.chart.data"
|
<nvd3-pie-chart data="bucket.data"
|
||||||
x="xFunction()"
|
x="xFunction()"
|
||||||
y="yFunction()"
|
y="yFunction()"
|
||||||
height="300"
|
height="300"
|
||||||
|
@ -50,7 +51,7 @@
|
||||||
</material-content>
|
</material-content>
|
||||||
<material-content>
|
<material-content>
|
||||||
<table data-ng-table="tableParams" class="table">
|
<table data-ng-table="tableParams" class="table">
|
||||||
<tr data-ng-repeat="account in bucket.data | filter:bucket.account_selected"
|
<tr data-ng-repeat="account in bucket.data"
|
||||||
data-ng-class="{'even': $even, 'odd': $odd}"
|
data-ng-class="{'even': $even, 'odd': $odd}"
|
||||||
style="border-left:10px solid {{coloring_score( score_account( account.account ) )}};border-right:10px solid {{coloring_score( score_account( account.account ) )}}">
|
style="border-left:10px solid {{coloring_score( score_account( account.account ) )}};border-right:10px solid {{coloring_score( score_account( account.account ) )}}">
|
||||||
<td data-title="'Account'"
|
<td data-title="'Account'"
|
||||||
|
|
Loading…
Reference in a new issue