using monthly periods is just more simple

This commit is contained in:
Gwenhael Le Moine 2015-09-17 07:08:01 +02:00
parent b5c5c9822c
commit 06d8c5fcec

View file

@ -170,25 +170,22 @@ app.controller( 'DashboardCtrl',
} ); } );
}; };
$scope.dates_salaries = []; // $scope.dates_salaries = [];
$scope.period_offset = 0;
var retrieve_dates_salaries = function() { // var retrieve_dates_salaries = function() {
API.dates_salaries() // API.dates_salaries()
.then( function ( response ) { // .then( function ( response ) {
$scope.dates_salaries = response.data; // $scope.dates_salaries = response.data;
$scope.periods= []; // $scope.periods= [];
for ( var i = 0 ; i < ( $scope.dates_salaries.length - 1 ) ; i++ ) { // for ( var i = 0 ; i < ( $scope.dates_salaries.length - 1 ) ; i++ ) {
$scope.periods.push( 'from ' + $scope.dates_salaries[i] + ' to ' + $scope.dates_salaries[i+1] ); // $scope.periods.push( 'from ' + $scope.dates_salaries[i] + ' to ' + $scope.dates_salaries[i+1] );
} // }
$scope.periods.push( 'from ' + _($scope.dates_salaries).last() ); // $scope.periods.push( 'from ' + _($scope.dates_salaries).last() );
$scope.periods = _($scope.periods).reverse(); // $scope.periods = _($scope.periods).reverse();
$scope.period = _($scope.periods).first(); // $scope.period = _($scope.periods).first();
} ); // } );
}; // };
$scope.$watch( 'period', function () { //retrieve_dates_salaries();
retrieve_period_detailed_data();
} );
var retrieve_accounts = function() { var retrieve_accounts = function() {
API.accounts() API.accounts()
@ -201,6 +198,7 @@ app.controller( 'DashboardCtrl',
var retrieve_graph_values = function( params ) { var retrieve_graph_values = function( params ) {
API.graph_values( params ).then( function( response ) { API.graph_values( params ).then( function( response ) {
$scope.periods = [];
$scope.monthly_values = _.chain( response.data ) $scope.monthly_values = _.chain( response.data )
.keys() .keys()
.reverse() .reverse()
@ -209,11 +207,15 @@ app.controller( 'DashboardCtrl',
return { "key": key, return { "key": key,
"values": _(response.data[ key ]).map( function( value ) { "values": _(response.data[ key ]).map( function( value ) {
var date = new Date( value.date ); var date = new Date( value.date );
return [ date.getFullYear() + '-' + ( date.getMonth() < 9 ? '0' : '' ) + ( date.getMonth() + 1 ), var period = date.getFullYear() + '-' + ( date.getMonth() < 9 ? '0' : '' ) + ( date.getMonth() + 1 );
$scope.periods.push( period );
return [ period,
parseInt( value.amount ) * multiplicator ]; parseInt( value.amount ) * multiplicator ];
} ) }; } ) };
} ) } )
.value(); .value();
$scope.periods = _.chain($scope.periods).uniq().reverse().value();
$scope.period = _($scope.periods).first();
} ); } );
}; };
$scope.barGraphToolTipContentFunction = function () { $scope.barGraphToolTipContentFunction = function () {
@ -223,12 +225,19 @@ app.controller( 'DashboardCtrl',
}; };
$scope.graphed_accounts = [ 'Expenses', 'Income' ]; $scope.graphed_accounts = [ 'Expenses', 'Income' ];
$scope.$watch( 'period', function () {
retrieve_period_detailed_data();
} );
retrieve_accounts(); retrieve_accounts();
retrieve_dates_salaries();
$scope.$watch( 'graphed_accounts', function () { $scope.$watch( 'graphed_accounts', function () {
retrieve_graph_values( { period: '', retrieve_graph_values( { period: '',
categories: $scope.graphed_accounts.join(' ') } ); categories: $scope.graphed_accounts.join(' ') } );
} ); } );
$scope.$on( 'elementClick.directive', function( angularEvent, event ) {
$scope.period = event.point[ 0 ];
retrieve_period_detailed_data();
} );
} }
] ); ] );