Code to fix #964

This commit is contained in:
James Cole
2017-12-15 12:59:21 +01:00
parent 3d0ecaa8d2
commit 985cc100e2
2 changed files with 40 additions and 25 deletions

View File

@@ -27,8 +27,8 @@ use Carbon\Carbon;
use DB; use DB;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\JournalCollectorInterface; use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\AccountType;
use FireflyIII\Http\Middleware\IsLimitedUser; use FireflyIII\Http\Middleware\IsLimitedUser;
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Bill\BillRepositoryInterface; use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use Illuminate\Http\Request; use Illuminate\Http\Request;
@@ -38,8 +38,8 @@ use Log;
use Monolog\Handler\RotatingFileHandler; use Monolog\Handler\RotatingFileHandler;
use Preferences; use Preferences;
use ReflectionException; use ReflectionException;
use Response;
use Route as RouteFacade; use Route as RouteFacade;
use Session;
use View; use View;
/** /**
@@ -60,6 +60,8 @@ class HomeController extends Controller
/** /**
* @param Request $request * @param Request $request
*
* @return \Illuminate\Http\JsonResponse
*/ */
public function dateRange(Request $request) public function dateRange(Request $request)
{ {
@@ -80,12 +82,17 @@ class HomeController extends Controller
$diff = $start->diffInDays($end); $diff = $start->diffInDays($end);
if ($diff > 50) { if ($diff > 50) {
Session::flash('warning', strval(trans('firefly.warning_much_data', ['days' => $diff]))); $request->session()->flash('warning', strval(trans('firefly.warning_much_data', ['days' => $diff])));
} }
Session::put('is_custom_range', $isCustomRange); $request->session()->put('is_custom_range', $isCustomRange);
Session::put('start', $start); Log::debug(sprintf('Set is_custom_range to %s', var_export($isCustomRange, true)));
Session::put('end', $end); $request->session()->put('start', $start);
Log::debug(sprintf('Set start to %s', $start->format('Y-m-d H:i:s')));
$request->session()->put('end', $end);
Log::debug(sprintf('Set end to %s', $end->format('Y-m-d H:i:s')));
return Response::json(['ok' => 'ok']);
} }
/** /**
@@ -265,12 +272,12 @@ class HomeController extends Controller
/** /**
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/ */
public function testFlash() public function testFlash(Request $request)
{ {
Session::flash('success', 'This is a success message.'); $request->session()->flash('success', 'This is a success message.');
Session::flash('info', 'This is an info message.'); $request->session()->flash('info', 'This is an info message.');
Session::flash('warning', 'This is a warning.'); $request->session()->flash('warning', 'This is a warning.');
Session::flash('error', 'This is an error!'); $request->session()->flash('error', 'This is an error!');
return redirect(route('home')); return redirect(route('home'));
} }

View File

@@ -30,7 +30,6 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Log; use Log;
use Navigation;
use Preferences; use Preferences;
/** /**
@@ -140,6 +139,7 @@ class JavascriptController extends Controller
$first = session('first'); $first = session('first');
$title = sprintf('%s - %s', $start->formatLocalized($this->monthAndDayFormat), $end->formatLocalized($this->monthAndDayFormat)); $title = sprintf('%s - %s', $start->formatLocalized($this->monthAndDayFormat), $end->formatLocalized($this->monthAndDayFormat));
$isCustom = session('is_custom_range'); $isCustom = session('is_custom_range');
$today = new Carbon;
$ranges = [ $ranges = [
// first range is the current range: // first range is the current range:
$title => [$start, $end], $title => [$start, $end],
@@ -149,28 +149,36 @@ class JavascriptController extends Controller
// when current range is a custom range, add the current period as the next range. // when current range is a custom range, add the current period as the next range.
if ($isCustom) { if ($isCustom) {
Log::debug('Custom is true.'); Log::debug('Custom is true.');
$index = Navigation::periodShow($start, $viewRange); $index = app('navigation')->periodShow($start, $viewRange);
$customPeriodStart = Navigation::startOfPeriod($start, $viewRange); $customPeriodStart = app('navigation')->startOfPeriod($start, $viewRange);
$customPeriodEnd = Navigation::endOfPeriod($customPeriodStart, $viewRange); $customPeriodEnd = app('navigation')->endOfPeriod($customPeriodStart, $viewRange);
$ranges[$index] = [$customPeriodStart, $customPeriodEnd]; $ranges[$index] = [$customPeriodStart, $customPeriodEnd];
} }
// then add previous range and next range // then add previous range and next range
$previousDate = Navigation::subtractPeriod($start, $viewRange); $previousDate = app('navigation')->subtractPeriod($start, $viewRange);
$index = Navigation::periodShow($previousDate, $viewRange); $index = app('navigation')->periodShow($previousDate, $viewRange);
$previousStart = Navigation::startOfPeriod($previousDate, $viewRange); $previousStart = app('navigation')->startOfPeriod($previousDate, $viewRange);
$previousEnd = Navigation::endOfPeriod($previousStart, $viewRange); $previousEnd = app('navigation')->endOfPeriod($previousStart, $viewRange);
$ranges[$index] = [$previousStart, $previousEnd]; $ranges[$index] = [$previousStart, $previousEnd];
$nextDate = Navigation::addPeriod($start, $viewRange, 0); $nextDate = app('navigation')->addPeriod($start, $viewRange, 0);
$index = Navigation::periodShow($nextDate, $viewRange); $index = app('navigation')->periodShow($nextDate, $viewRange);
$nextStart = Navigation::startOfPeriod($nextDate, $viewRange); $nextStart = app('navigation')->startOfPeriod($nextDate, $viewRange);
$nextEnd = Navigation::endOfPeriod($nextStart, $viewRange); $nextEnd = app('navigation')->endOfPeriod($nextStart, $viewRange);
$ranges[$index] = [$nextStart, $nextEnd]; $ranges[$index] = [$nextStart, $nextEnd];
// today:
$todayStart = app('navigation')->startOfPeriod($today, $viewRange);
$todayEnd = app('navigation')->endOfPeriod($todayStart, $viewRange);
if ($todayStart->ne($start) || $todayEnd->ne($end)) {
$ranges[ucfirst(strval(trans('firefly.today')))] = [$todayStart, $todayEnd];
}
// everything // everything
$index = strval(trans('firefly.everything')); $index = strval(trans('firefly.everything'));
$ranges[$index] = [$first, new Carbon]; $ranges[$index] = [$first, new Carbon];
$return = [ $return = [
'title' => $title, 'title' => $title,
'configuration' => [ 'configuration' => [