Skip to content

Firefly III: a personal finances manager

Time-based navigation and some feedback for the user as to his import.

James Cole4f3493f9ff21
diff --git a/app/controllers/HomeController.php b/app/controllers/HomeController.php
index d1f09bdc05..4570ee1635 100644
--- a/app/controllers/HomeController.php
+++ b/app/controllers/HomeController.php
@@ -30,6 +30,33 @@ class HomeController extends BaseController
$this->_reminders = $reminders;
}
+ public function jobDev() {
+ $fullName = storage_path().DIRECTORY_SEPARATOR.'firefly-export-2014-07-23.json';
+ \Log::notice('Pushed start job.');
+ Queue::push('Firefly\Queue\Import@start', ['file' => $fullName, 'user' => 1]);
+
+ }
+
+ /*
+ *
+ */
+ public function sessionPrev() {
+ /** @var \Firefly\Helper\Toolkit\ToolkitInterface $toolkit */
+ $toolkit = App::make('Firefly\Helper\Toolkit\ToolkitInterface');
+ $toolkit->prev();
+ return Redirect::route('index');
+ }
+
+ /*
+ *
+ */
+ public function sessionNext() {
+ /** @var \Firefly\Helper\Toolkit\ToolkitInterface $toolkit */
+ $toolkit = App::make('Firefly\Helper\Toolkit\ToolkitInterface');
+ $toolkit->next();
+ return Redirect::route('index');
+ }
+
/**
* @return \Illuminate\Http\RedirectResponse
*/
diff --git a/app/filters.php b/app/filters.php
index b784c9bb3d..9a1c96aebc 100644
--- a/app/filters.php
+++ b/app/filters.php
@@ -6,8 +6,10 @@ App::before(
function ($request) {
if (Auth::check()) {
+ /** @var \Firefly\Helper\Toolkit\ToolkitInterface $toolkit */
$toolkit = App::make('Firefly\Helper\Toolkit\ToolkitInterface');
$toolkit->getDateRange();
+ $toolkit->checkImportJobs();
}
}
diff --git a/app/lib/Firefly/Helper/Toolkit/Toolkit.php b/app/lib/Firefly/Helper/Toolkit/Toolkit.php
index 5d7bfeef54..f8ba8dbb3e 100644
--- a/app/lib/Firefly/Helper/Toolkit/Toolkit.php
+++ b/app/lib/Firefly/Helper/Toolkit/Toolkit.php
@@ -3,6 +3,7 @@
namespace Firefly\Helper\Toolkit;
use Carbon\Carbon;
+use Firefly\Exception\FireflyException;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
@@ -30,25 +31,81 @@ class Toolkit implements ToolkitInterface
*/
public function getDateRange()
{
+ /*
+ * Get all data from the session:
+ */
$range = $this->_getRange();
- // start and end are always "now", and get edited later.
- $start = new Carbon;
- $end = new Carbon;
+ #\Log::debug('Range is: ' . $range);
+ $start = \Session::has('start') ? \Session::get('start') : new Carbon;
- // update start only:
+ #\Log::debug('Session start is: ' . $start->format('Y-m-d'));
+ $end = \Session::has('end') ? \Session::get('end') : new Carbon;
+ #\Log::debug('Session end is : ' . $end->format('Y-m-d'));
+
+ /*
+ * Force start date to at the start of the $range.
+ * Ie. the start of the week, month, year.
+ */
$start = $this->_updateStartDate($range, $start);
+ #\Log::debug('After update, session start is: ' . $start->format('Y-m-d'));
+
+ /*
+ * Force end date to at the END of the $range. Always based on $start.
+ * Ie. the END of the week, month, year.
+ */
+ $end = $this->_updateEndDate($range, $start);
+ #\Log::debug('After update, session end is : ' . $end->format('Y-m-d'));
+
+ /*
+ * get the name of the month, depending on the range. Purely for astetics
+ */
+ $period = $this->_periodName($range, $start);
- // update end only:
- $end = $this->_updateEndDate($range, $start, $end);
+ /*
+ * Get the date for the previous and next period.
+ * Ie. next week, next month, etc.
+ */
+ $prev = $this->_previous($range, clone $start);
+ $next = $this->_next($range, clone $start);
- // save in session:
+ /*
+ * Save everything in the session:
+ */
\Session::put('start', $start);
\Session::put('end', $end);
\Session::put('range', $range);
+ \Session::put('period', $period);
+ \Session::put('prev', $this->_periodName($range, $prev));
+ \Session::put('next', $this->_periodName($range, $next));
return null;
}
+ /**
+ *
+ */
+ public function checkImportJobs() {
+ /*
+ * Get all jobs.
+ */
+ /** @var \Importmap $importJob */
+ $importJob = \Importmap::where('user_id',\Auth::user()->id)
+ ->where('totaljobs','>',\DB::Raw('`jobsdone`'))
+ ->orderBy('created_at','DESC')
+ ->first();
+ if(!is_null($importJob)) {
+ $diff = intval($importJob->totaljobs) - intval($importJob->jobsdone);
+ $date = new Carbon;
+ $today = new Carbon;
+ $date->addSeconds($diff);
+ \Session::put('job_pct',$importJob->pct());
+ \Session::put('job_text',$date->diffForHumans());
+ } else {
+ \Session::forget('job_pct');
+ \Session::forget('job_text');
+ }
+ }
+
/**
* @return mixed
*/
@@ -63,6 +120,7 @@ class Toolkit implements ToolkitInterface
// default range:
$range = $viewRange->data;
+ \Session::put('range', $range);
}
return $range;
@@ -110,9 +168,8 @@ class Toolkit implements ToolkitInterface
*
* @return Carbon
*/
- protected function _updateEndDate($range, Carbon $start, Carbon $end)
+ protected function _updateEndDate($range, Carbon $start)
{
- $today = new Carbon;
switch ($range) {
case '1D':
$end = clone $start;
@@ -132,17 +189,132 @@ class Toolkit implements ToolkitInterface
break;
case '6M':
$end = clone $start;
- if (intval($today->format('m')) >= 7) {
+ if (intval($start->format('m')) >= 7) {
$end->endOfYear();
} else {
$end->startOfYear()->addMonths(6);
}
break;
+ default:
+ throw new FireflyException('Nothing happened with $end!');
+ break;
}
return $end;
}
+ protected function _periodName($range, Carbon $date)
+ {
+ switch ($range) {
+ default:
+ throw new FireflyException('No _periodName() for range "' . $range . '"');
+ break;
+ case '1M':
+ return $date->format('F Y');
+ break;
+ }
+ }
+
+ protected function _previous($range, Carbon $date)
+ {
+ switch ($range) {
+ case '1D':
+ $date->startOfDay()->subDay();
+ break;
+ case '1W':
+ $date->startOfWeek()->subWeek();
+ break;
+ case '1M':
+ $date->startOfMonth()->subMonth();
+ break;
+ case '3M':
+ $date->firstOfQuarter()->subMonths(3)->firstOfQuarter();
+ break;
+ case '6M':
+ if (intval($date->format('m')) >= 7) {
+ $date->startOfYear();
+ } else {
+ $date->startOfYear()->subMonths(6);
+ }
+ break;
+ }
+ return $date;
+ }
+
+ protected function _next($range, Carbon $date)
+ {
+ switch ($range) {
+ case '1D':
+ $date->endOfDay()->addDay();
+ break;
+ case '1W':
+ $date->endOfWeek()->addDay()->startOfWeek();
+ break;
+ case '1M':
+ $date->endOfMonth()->addDay()->startOfMonth();
+ break;
+ case '3M':
+ $date->lastOfQuarter();
+ break;
+ case '6M':
+ if (intval($date->format('m')) >= 7) {
+ $date->startOfYear()->addYear();
+ } else {
+ $date->startOfYear()->addMonths(6);
+ }
+ break;
+ }
+ return $date;
+ }
+
+ public function next()
+ {
+ /*
+ * Get the start date and the range from the session
+ */
+ $range = $this->_getRange();
+ $start = \Session::get('start');
+
+ /*
+ * Add some period to $start.
+ */
+ $next = $this->_next($range, clone $start);
+
+ /*
+ * Save in session:
+ */
+ \Session::put('start', $next);
+ return true;
+ }
+
+ public function prev()
+ {
+ /*
+ * Get the start date and the range from the session
+ */
+ $range = $this->_getRange();
+ $start = \Session::get('start');
+
+ /*
+ * Substract some period to $start.
+ */
+ $prev = $this->_previous($range, clone $start);
+
+ /*
+ * Save in session:
+ */
+ \Session::put('start', $prev);
+ return true;
+ }
+
+ /**
+ * This method checks and
+ */
+ public function bootstrapDaterange()
+ {
+
+ }
+
/**
* Takes any collection and tries to make a sensible select list compatible array of it.
*
diff --git a/app/lib/Firefly/Helper/Toolkit/ToolkitInterface.php b/app/lib/Firefly/Helper/Toolkit/ToolkitInterface.php
index e496c17997..e03700a9ce 100644
--- a/app/lib/Firefly/Helper/Toolkit/ToolkitInterface.php
+++ b/app/lib/Firefly/Helper/Toolkit/ToolkitInterface.php
@@ -28,4 +28,11 @@ interface ToolkitInterface
*/
public function makeSelectList(Collection $set, $titleField = null);
+ public function bootstrapDaterange();
+
+ public function next();
+ public function prev();
+
+public function checkImportJobs();
+
}
\ No newline at end of file
diff --git a/app/routes.php b/app/routes.php
index abed193f70..f1f5e282c1 100644
--- a/app/routes.php
+++ b/app/routes.php
@@ -120,9 +120,20 @@ Route::bind('piggybank', function($value, $route)
});
+
+// a development route:
+Route::get('/dev', ['uses' => 'HomeController@jobDev']);
+
// protected routes:
Route::group(['before' => 'auth'], function () {
+
+
+
+ // some date routes:
+ Route::get('/prev',['uses' => 'HomeController@sessionPrev', 'as' => 'sessionPrev']);
+ Route::get('/next',['uses' => 'HomeController@sessionNext', 'as' => 'sessionNext']);
+
// account controller:
Route::get('/accounts', ['uses' => 'AccountController@index', 'as' => 'accounts.index']);
diff --git a/app/views/index.blade.php b/app/views/index.blade.php
index 2eb0f12500..7bb3d15b16 100644
--- a/app/views/index.blade.php
+++ b/app/views/index.blade.php
@@ -61,6 +61,20 @@
</div>
<div class="col-lg-4 col-md-6 col-sm-12">
+ <!-- time based navigation -->
+ <div class="panel panel-default">
+ <div class="panel-heading">
+ <i class="fa fa-clock-o fa-fw"></i>
+ {{{\Session::get('period')}}}
+ </div>
+ <div class="panel-body">
+ <div class="btn-group btn-group-sm btn-group-justified">
+ <a class="btn btn-default" href="{{route('sessionPrev')}}"><i class="fa fa-arrow-left"></i> {{{\Session::get('prev')}}}</a>
+ <a class="btn btn-default" href="{{route('sessionNext')}}">{{{\Session::get('next')}}} <i class="fa fa-arrow-right"></i></a>
+ </div>
+ </div>
+ </div>
+
<!-- TRANSACTIONS -->
@foreach($transactions as $data)
<div class="panel panel-default">
diff --git a/app/views/partials/menu.blade.php b/app/views/partials/menu.blade.php
index ea8c3e8c71..0862571342 100644
--- a/app/views/partials/menu.blade.php
+++ b/app/views/partials/menu.blade.php
@@ -12,7 +12,40 @@
<!-- /.navbar-header -->
<ul class="nav navbar-top-links navbar-right">
-<li class="dropdown">
+ <!-- /.dropdown -->
+ <li class="dropdown">
+ <a class="dropdown-toggle" data-toggle="dropdown" href="#">
+ <i class="fa fa-tasks fa-fw"></i> <i class="fa fa-caret-down"></i>
+ </a>
+ <!-- display for import tasks, possibly others -->
+ @if(Session::has('job_pct'))
+ <ul class="dropdown-menu dropdown-tasks">
+ <li>
+ <a href="#">
+ <div>
+ <p>
+ <strong>Import from Firefly II</strong>
+ <span class="pull-right text-muted">{{Session::get('job_pct')}}% Complete</span>
+ </p>
+ <div class="progress progress-striped active">
+ <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="{{Session::get('job_pct')}}" aria-valuemin="0" aria-valuemax="100" style="width: {{Session::get('job_pct')}}%">
+ <span class="sr-only">{{Session::get('job_pct')}}% Complete (success)</span>
+ </div>
+ </div>
+ <p>
+ <small>Finished ~ {{Session::get('job_text')}}</small>
+ </p>
+ </div>
+ </a>
+ </li>
+ </ul>
+ <!-- /.dropdown-tasks -->
+ </li>
+ @endif
+
+
+
+ <li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-user fa-fw"></i> <i class="fa fa-caret-down"></i>
</a>
diff --git a/app/views/user/login.blade.php b/app/views/user/login.blade.php
index 1c45345465..3458043cdf 100644
--- a/app/views/user/login.blade.php
+++ b/app/views/user/login.blade.php
@@ -1,6 +1,5 @@
@extends('layouts.guest')
@section('content')
-
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="login-panel panel panel-default">