mirror of
https://github.com/gwenhael-le-moine/ledgerrb.git
synced 2024-12-26 09:59:18 +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 ) {
|
||||
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: [ {
|
||||
categories: 'Expenses',
|
||||
data: [],
|
||||
total: 0,
|
||||
chart: {
|
||||
data: []
|
||||
}
|
||||
total: 0
|
||||
}, {
|
||||
categories: 'Income Equity',
|
||||
data: [],
|
||||
total: 0,
|
||||
chart: {
|
||||
data: []
|
||||
}
|
||||
total: 0
|
||||
} ],
|
||||
details: {}
|
||||
};
|
||||
|
@ -115,14 +121,14 @@ app.controller( 'BalanceCtrl',
|
|||
API.register( { period: period,
|
||||
categories: '' } )
|
||||
.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 ) {
|
||||
API.balance( { period: period,
|
||||
categories: bucket.categories } )
|
||||
.then( function ( response ) {
|
||||
bucket.data = _.chain( response.data )
|
||||
bucket.raw_data = _.chain( response.data )
|
||||
.map( function( account ) {
|
||||
account.amount = ( account.amount < 0 ) ? account.amount * -1 : account.amount;
|
||||
return account;
|
||||
|
@ -131,11 +137,9 @@ app.controller( 'BalanceCtrl',
|
|||
return 1 / account.amount;
|
||||
} )
|
||||
.value();
|
||||
bucket.total = _( response.data ).reduce( function ( memo, account ) {
|
||||
return memo + account.amount;
|
||||
}, 0 );
|
||||
bucket.accounts_selected = bucket.raw_data;
|
||||
|
||||
$scope.update_chart_data();
|
||||
$scope.filter_data();
|
||||
} );
|
||||
} );
|
||||
};
|
||||
|
|
|
@ -28,14 +28,15 @@
|
|||
<div flex data-ng-repeat="bucket in balance.buckets">
|
||||
<material-toolbar class="material-theme-light">
|
||||
<h3>{{bucket.categories}}, total = {{bucket.total | number:2}} €</h3>
|
||||
<select data-ng-model="bucket.account_selected"
|
||||
data-ng-options="account.account for account in bucket.data"
|
||||
data-ng-change="update_chart_data()">
|
||||
<select multiple
|
||||
data-ng-model="bucket.accounts_selected"
|
||||
data-ng-options="account.account for account in bucket.raw_data | orderBy:'account'"
|
||||
data-ng-change="filter_data()">
|
||||
<option value=''>...</option>
|
||||
</select>
|
||||
</material-toolbar>
|
||||
<material-content>
|
||||
<nvd3-pie-chart data="bucket.chart.data"
|
||||
<nvd3-pie-chart data="bucket.data"
|
||||
x="xFunction()"
|
||||
y="yFunction()"
|
||||
height="300"
|
||||
|
@ -50,7 +51,7 @@
|
|||
</material-content>
|
||||
<material-content>
|
||||
<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}"
|
||||
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'"
|
||||
|
|
Loading…
Reference in a new issue