From e9969bdd5f6401a1ddf660fbd7d36872932d75b6 Mon Sep 17 00:00:00 2001 From: James Cole Date: Thu, 5 Mar 2015 21:13:38 +0100 Subject: [PATCH] Update the ranges to reflect the current dates. --- app/Http/Middleware/Range.php | 9 +++++++++ public/js/firefly.js | 19 +++++++++++++------ resources/views/layouts/default.blade.php | 3 +++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/app/Http/Middleware/Range.php b/app/Http/Middleware/Range.php index 36c68e019a..b37db6b6b4 100644 --- a/app/Http/Middleware/Range.php +++ b/app/Http/Middleware/Range.php @@ -9,6 +9,7 @@ use Illuminate\Contracts\Auth\Guard; use Navigation; use Preferences; use Session; +use View; /** * 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); + } diff --git a/public/js/firefly.js b/public/js/firefly.js index 0bf2c43a4f..e0a35830ea 100644 --- a/public/js/firefly.js +++ b/public/js/firefly.js @@ -2,14 +2,21 @@ $(function () { $('.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( { - ranges: { - 'This Month': [moment().startOf('month'), moment().endOf('month')], - 'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')], - 'Next Month': [moment().add(1, 'month').startOf('month'), moment().add(1, 'month').endOf('month')], - 'Everything': [firstDate, moment()] - }, + //View::share('currentMonthName', $current); + //View::share('previousMonthName', $prev); + //View::share('nextMonthName', $next); + + + ranges: ranges + , opens: 'left', format: 'DD-MM-YYYY', diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index d260d81dde..03f24a7048 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -132,6 +132,9 @@ var dateRangeURL = "{{route('daterange')}}"; var token = "{{csrf_token()}}"; var firstDate = moment("{{Session::get('first')->format('Y-m-d')}}"); + var currentMonthName = "{{$currentMonthName}}"; + var previousMonthName = "{{$previousMonthName}}"; + var nextMonthName = "{{$nextMonthName}}"; $('#daterange span').text(titleString);