From 7f8f1652798b99c288b6a65b44dd503684adab87 Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Sun, 5 Oct 2014 09:49:42 +0200 Subject: [PATCH] add 'future' period --- public/app/js/controllers/BalanceCtrl.js | 22 ++++++++++++++++------ public/app/js/templates/balance.tpl.html | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/public/app/js/controllers/BalanceCtrl.js b/public/app/js/controllers/BalanceCtrl.js index 3b368d5a..480bd7e1 100644 --- a/public/app/js/controllers/BalanceCtrl.js +++ b/public/app/js/controllers/BalanceCtrl.js @@ -68,14 +68,24 @@ app.controller( 'BalanceCtrl', } ); var retrieve_data = function () { - $scope.from_date = new Date( $scope.dates_salaries[ $scope.period_offset ] ); - $scope.to_date = ( $scope.period_offset < $scope.dates_salaries.length - 1 ) ? new Date( $scope.dates_salaries[ $scope.period_offset + 1 ] ) : moment( $scope.from_date ).add( 1, 'month' ).toDate(); + var from, to, period; - var from = moment( $scope.from_date ); - var to = moment( $scope.to_date ); + if ( $scope.period_offset === $scope.dates_salaries.length ) { + $scope.from_date = moment( _($scope.dates_salaries).last() ).add( 1, 'month' ).toDate(); - var period = 'from ' + from.year() + '-' + ( from.month() + 1 ) + '-' + from.date(); - period += ' to ' + to.year() + '-' + ( to.month() + 1 ) + '-' + to.date(); + from = moment( $scope.from_date ); + + period = 'from ' + from.year() + '-' + ( from.month() + 1 ) + '-' + from.date(); + } else { + $scope.from_date = new Date( $scope.dates_salaries[ $scope.period_offset ] ); + $scope.to_date = ( $scope.period_offset < $scope.dates_salaries.length - 1 ) ? new Date( $scope.dates_salaries[ $scope.period_offset + 1 ] ) : moment( $scope.from_date ).add( 1, 'month' ).toDate(); + + from = moment( $scope.from_date ); + to = moment( $scope.to_date ); + + period = 'from ' + from.year() + '-' + ( from.month() + 1 ) + '-' + from.date(); + period += ' to ' + to.year() + '-' + ( to.month() + 1 ) + '-' + to.date(); + } $scope.balance = { buckets: [ { diff --git a/public/app/js/templates/balance.tpl.html b/public/app/js/templates/balance.tpl.html index 61cc0674..01f183dd 100644 --- a/public/app/js/templates/balance.tpl.html +++ b/public/app/js/templates/balance.tpl.html @@ -15,7 +15,7 @@ data-ng-class="{'disabled': period_offset == dates_salaries.length - 1}">Now next + data-ng-class="{'disabled': period_offset == dates_salaries.length}">next