mirror of
https://github.com/gwenhael-le-moine/ledgerrb.git
synced 2024-12-27 21:58:11 +01:00
predefined filters
This commit is contained in:
parent
5056f6d9ac
commit
596972b459
2 changed files with 24 additions and 6 deletions
|
@ -21,7 +21,7 @@ app.controller( 'BalanceCtrl',
|
||||||
};
|
};
|
||||||
|
|
||||||
// compute an account's score: from 1 (good) to 10 (bad), 0 is neutral/undecided
|
// 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)$/ ) ) {
|
if ( account.match( /^Income:(salaire|Sécu|Mutuelle)$/ ) ) {
|
||||||
return 1;
|
return 1;
|
||||||
} else if ( account.match( /^Income:(Gift|Remboursement)$/ ) ) {
|
} else if ( account.match( /^Income:(Gift|Remboursement)$/ ) ) {
|
||||||
|
@ -52,7 +52,7 @@ app.controller( 'BalanceCtrl',
|
||||||
|
|
||||||
$scope.color = function () {
|
$scope.color = function () {
|
||||||
return function ( d, i ) {
|
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 );
|
}, 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 retrieve_data = function () {
|
||||||
var from, to, period;
|
var from, to, period;
|
||||||
|
@ -131,12 +139,16 @@ app.controller( 'BalanceCtrl',
|
||||||
bucket.raw_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;
|
||||||
|
account.score = score_account( account.account );
|
||||||
return account;
|
return account;
|
||||||
} )
|
} )
|
||||||
.sortBy( function ( account ) {
|
.sortBy( function ( account ) {
|
||||||
return 1 / account.amount;
|
return 1 / account.amount;
|
||||||
} )
|
} )
|
||||||
.value();
|
.value();
|
||||||
|
bucket.raw_total = _( response.data ).reduce( function ( memo, account ) {
|
||||||
|
return memo + account.amount;
|
||||||
|
}, 0 );
|
||||||
bucket.accounts_selected = bucket.raw_data;
|
bucket.accounts_selected = bucket.raw_data;
|
||||||
|
|
||||||
$scope.filter_data();
|
$scope.filter_data();
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
</material-toolbar>
|
</material-toolbar>
|
||||||
<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}">
|
<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>
|
</h2>
|
||||||
</material-toolbar>
|
</material-toolbar>
|
||||||
</div>
|
</div>
|
||||||
|
@ -27,13 +27,19 @@
|
||||||
<div layout="vertical" layout-md="horizontal" layout-padding>
|
<div layout="vertical" layout-md="horizontal" layout-padding>
|
||||||
<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 flex="100">{{bucket.categories}}, total = {{bucket.total | number:2}} €</h3>
|
||||||
<select multiple
|
<select multiple flex="100"
|
||||||
data-ng-model="bucket.accounts_selected"
|
data-ng-model="bucket.accounts_selected"
|
||||||
data-ng-options="account.account for account in bucket.raw_data | orderBy:'account'"
|
data-ng-options="account.account for account in bucket.raw_data | orderBy:'account'"
|
||||||
data-ng-change="filter_data()">
|
data-ng-change="filter_data()">
|
||||||
<option value=''>...</option>
|
<option value=''>...</option>
|
||||||
</select>
|
</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-toolbar>
|
||||||
<material-content>
|
<material-content>
|
||||||
<nvd3-pie-chart data="bucket.data"
|
<nvd3-pie-chart data="bucket.data"
|
||||||
|
@ -53,7 +59,7 @@
|
||||||
<table data-ng-table="tableParams" class="table">
|
<table data-ng-table="tableParams" class="table">
|
||||||
<tr data-ng-repeat="account in bucket.data"
|
<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( account.score )}};border-right:10px solid {{coloring_score( account.score )}}">
|
||||||
<td data-title="'Account'"
|
<td data-title="'Account'"
|
||||||
style="border-bottom:1px solid {{coloring_score( score_account( account.account ) )}}">
|
style="border-bottom:1px solid {{coloring_score( score_account( account.account ) )}}">
|
||||||
{{account.account}}
|
{{account.account}}
|
||||||
|
|
Loading…
Reference in a new issue