Update the ranges to reflect the current dates.

This commit is contained in:
James Cole
2015-03-05 21:13:38 +01:00
parent 1139f950ed
commit e9969bdd5f
3 changed files with 25 additions and 6 deletions

View File

@@ -9,6 +9,7 @@ use Illuminate\Contracts\Auth\Guard;
use Navigation; use Navigation;
use Preferences; use Preferences;
use Session; use Session;
use View;
/** /**
* Class SessionFilter * Class SessionFilter
@@ -68,6 +69,14 @@ class Range
} }
} }
// set current / next / prev month.
$current = Carbon::now()->format('F Y');
$next = Carbon::now()->endOfMonth()->addDay()->format('F Y');
$prev = Carbon::now()->startOfMonth()->subDay()->format('F Y');
View::share('currentMonthName', $current);
View::share('previousMonthName', $prev);
View::share('nextMonthName', $next);
} }

View File

@@ -2,14 +2,21 @@ $(function () {
$('.currencySelect').click(currencySelect); $('.currencySelect').click(currencySelect);
ranges = {};
ranges[currentMonthName] = [moment().startOf('month'), moment().endOf('month')];
ranges[previousMonthName] = [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')];
ranges[nextMonthName] = [moment().add(1, 'month').startOf('month'), moment().add(1, 'month').endOf('month')];
ranges['Everything'] = [firstDate, moment()];
$('#daterange').daterangepicker( $('#daterange').daterangepicker(
{ {
ranges: { //View::share('currentMonthName', $current);
'This Month': [moment().startOf('month'), moment().endOf('month')], //View::share('previousMonthName', $prev);
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')], //View::share('nextMonthName', $next);
'Next Month': [moment().add(1, 'month').startOf('month'), moment().add(1, 'month').endOf('month')],
'Everything': [firstDate, moment()]
}, ranges: ranges
,
opens: 'left', opens: 'left',
format: 'DD-MM-YYYY', format: 'DD-MM-YYYY',

View File

@@ -132,6 +132,9 @@
var dateRangeURL = "{{route('daterange')}}"; var dateRangeURL = "{{route('daterange')}}";
var token = "{{csrf_token()}}"; var token = "{{csrf_token()}}";
var firstDate = moment("{{Session::get('first')->format('Y-m-d')}}"); var firstDate = moment("{{Session::get('first')->format('Y-m-d')}}");
var currentMonthName = "{{$currentMonthName}}";
var previousMonthName = "{{$previousMonthName}}";
var nextMonthName = "{{$nextMonthName}}";
$('#daterange span').text(titleString); $('#daterange span').text(titleString);
</script> </script>