predefined filters

This commit is contained in:
Gwenhael Le Moine 2014-10-12 12:28:20 +02:00
parent 5056f6d9ac
commit 596972b459
2 changed files with 24 additions and 6 deletions

View file

@ -21,7 +21,7 @@ app.controller( 'BalanceCtrl',
};
// compute an account's score: from 1 (good) to 10 (bad), 0 is neutral/undecided
$scope.score_account = function ( account ) {
var score_account = function ( account ) {
if ( account.match( /^Income:(salaire|Sécu|Mutuelle)$/ ) ) {
return 1;
} else if ( account.match( /^Income:(Gift|Remboursement)$/ ) ) {
@ -52,7 +52,7 @@ app.controller( 'BalanceCtrl',
$scope.color = function () {
return function ( d, i ) {
return $scope.coloring_score( $scope.score_account( d.data.account ) );
return $scope.coloring_score( score_account( d.data.account ) );
};
};
@ -84,6 +84,14 @@ app.controller( 'BalanceCtrl',
}, 0 );
} );
};
$scope.select = { all: function( bucket ) {
bucket.accounts_selected = bucket.raw_data;
},
score_higher_than: function( bucket, score ) {
bucket.accounts_selected = _(bucket.raw_data).filter( function( account ) {
return account.score > score;
} );
}};
var retrieve_data = function () {
var from, to, period;
@ -131,12 +139,16 @@ app.controller( 'BalanceCtrl',
bucket.raw_data = _.chain( response.data )
.map( function( account ) {
account.amount = ( account.amount < 0 ) ? account.amount * -1 : account.amount;
account.score = score_account( account.account );
return account;
} )
.sortBy( function ( account ) {
return 1 / account.amount;
} )
.value();
bucket.raw_total = _( response.data ).reduce( function ( memo, account ) {
return memo + account.amount;
}, 0 );
bucket.accounts_selected = bucket.raw_data;
$scope.filter_data();

View file

@ -19,7 +19,7 @@
</material-toolbar>
<material-toolbar>
<h2 class="balance" data-ng-class="{'negative': balance.buckets[1].total - balance.buckets[0].total < 0, 'positive': balance.buckets[1].total - balance.buckets[0].total > 0}">
Balance: {{( balance.buckets[1].total - balance.buckets[0].total ) | number:2}} €
Balance: {{( balance.buckets[1].raw_total - balance.buckets[0].raw_total ) | number:2}} €
</h2>
</material-toolbar>
</div>
@ -27,13 +27,19 @@
<div layout="vertical" layout-md="horizontal" layout-padding>
<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 multiple
<h3 flex="100">{{bucket.categories}}, total = {{bucket.total | number:2}} €</h3>
<select multiple flex="100"
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-button flex="50"
class="material-theme-light-blue"
data-ng-click="select.all( bucket ); filter_data()">All</material-button>
<material-button flex="50"
class="material-theme-light-blue"
data-ng-click="select.score_higher_than( bucket, 5 ); filter_data()">Superfluous</material-button>
</material-toolbar>
<material-content>
<nvd3-pie-chart data="bucket.data"
@ -53,7 +59,7 @@
<table data-ng-table="tableParams" class="table">
<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 ) )}}">
style="border-left:10px solid {{coloring_score( account.score )}};border-right:10px solid {{coloring_score( account.score )}}">
<td data-title="'Account'"
style="border-bottom:1px solid {{coloring_score( score_account( account.account ) )}}">
{{account.account}}