Skip to content

Firefly III: a personal finances manager

Some changes in the charts and range thing.

James Cole5e8cfb512b12
diff --git a/app/controllers/ChartController.php b/app/controllers/ChartController.php
index c3d412184c..b0d8ec7458 100644
--- a/app/controllers/ChartController.php
+++ b/app/controllers/ChartController.php
@@ -2,6 +2,7 @@
use Carbon\Carbon as Carbon;
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
+use Firefly\Helper\Toolkit\Toolkit as tk;
class ChartController extends BaseController
{
@@ -16,17 +17,16 @@ class ChartController extends BaseController
/**
* Show home charts.
*/
- public function home($account = null)
+ public function homeAccount($account = null)
{
+ list($start,$end) = tk::getDateRange();
+ $current = clone $start;
+
// chart
$chart = App::make('gchart');
$chart->addColumn('Day of the month', 'date');
- // date
- $today = new Carbon;
- $past = clone $today;
- $past->subMonth();
- $current = clone $past;
+
if (is_null($account)) {
// get accounts:
@@ -36,7 +36,7 @@ class ChartController extends BaseController
$chart->addColumn($account->name, 'number');
}
- while ($current <= $today) {
+ while ($current <= $end) {
$row = [clone $current];
// loop accounts:
@@ -52,7 +52,7 @@ class ChartController extends BaseController
return View::make('error')->with('message', 'No account found.');
}
$chart->addColumn($account->name, 'number');
- while ($current <= $today) {
+ while ($current <= $end) {
$row = [clone $current, $account->balance(clone $current)];
$current->addDay();
$chart->addRowArray($row);
diff --git a/app/controllers/HomeController.php b/app/controllers/HomeController.php
index 7a2ed4a2a7..4388491a9c 100644
--- a/app/controllers/HomeController.php
+++ b/app/controllers/HomeController.php
@@ -20,6 +20,10 @@ class HomeController extends BaseController
public function index()
{
+ // get preferred viewing range
+ $viewRange = $this->preferences->get('viewRange','week');
+
+
// get list setting:
$pref = $this->preferences->get('frontpageAccounts', []);
diff --git a/app/lib/Firefly/Helper/Toolkit/Toolkit.php b/app/lib/Firefly/Helper/Toolkit/Toolkit.php
new file mode 100644
index 0000000000..ecb54d5733
--- /dev/null
+++ b/app/lib/Firefly/Helper/Toolkit/Toolkit.php
@@ -0,0 +1,44 @@
+<?php
+
+namespace Firefly\Helper\Toolkit;
+
+
+class Toolkit
+{
+
+ /**
+ * Based on the preference 'viewRange' and other variables I have not yet thought of,
+ * this method will return a date range that defines the 'current' period of time.
+ *
+ * ie. the current week or month.
+ *
+ * $start is always the past, $end is 'now' or at least later.
+ */
+ public static function getDateRange()
+ {
+ $preferences = \App::make('Firefly\Helper\Preferences\PreferencesHelperInterface');
+ $viewRange = $preferences->get('viewRange', 'week');
+
+ // as you can see, this method now only supports "right now":
+ $now = new \Carbon\Carbon;
+ $start = clone $now;
+ $end = clone $now;
+
+
+ switch ($viewRange->data) {
+ case 'week':
+ $start->startOfWeek();
+ $end->endOfWeek();
+ break;
+ default:
+ case 'month':
+ $start->startOfMonth();
+ $end->endOfMonth();
+ break;
+ }
+ return [$start, $end];
+
+
+ }
+
+}
\ No newline at end of file
diff --git a/app/lib/Firefly/Helper/Toolkit/ToolkitInterface.php b/app/lib/Firefly/Helper/Toolkit/ToolkitInterface.php
new file mode 100644
index 0000000000..1b83643997
--- /dev/null
+++ b/app/lib/Firefly/Helper/Toolkit/ToolkitInterface.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace Firefly\Helper\Toolkit;
+
+
+class ToolkitInterface {
+
+}
\ No newline at end of file
diff --git a/app/routes.php b/app/routes.php
index c5fa5b13b6..2fdbab8556 100644
--- a/app/routes.php
+++ b/app/routes.php
@@ -6,7 +6,7 @@ Route::group(['before' => 'auth'], function () {
Route::get('/', ['uses' => 'HomeController@index', 'as' => 'index']);
// chart controller
- Route::get('/chart/home/{account?}', ['uses' => 'ChartController@home', 'as' => 'chart.home']);
+ Route::get('/chart/home/account/{account?}', ['uses' => 'ChartController@homeAccount', 'as' => 'chart.home']);
// preferences controller
Route::get('/preferences', ['uses' => 'PreferencesController@index', 'as' => 'preferences']);
diff --git a/app/views/index.blade.php b/app/views/index.blade.php
index a2596ab4b7..6bf48df680 100644
--- a/app/views/index.blade.php
+++ b/app/views/index.blade.php
@@ -32,8 +32,11 @@
</p>
</div>
@else
+
+
+
<!-- ACCOUNTS -->
- <div class="row" style="border-top:1px #eee solid;">
+ <div class="row">
@foreach($accounts as $index => $account)
<div class="col-lg-6">
<h4>{{{$account->name}}} chart</h4>
@@ -62,6 +65,32 @@
@endforeach
</div>
+
+ <!-- week / month / year navigation -->
+ <div class="row">
+ <div class="col-lg-2 col-sm-6 col-md-2">
+ <a href="#" class="btn btn-default btn-xs">Previous [period]</a>
+ </div>
+
+ <div class="col-lg-offset-8 col-lg-2 col-sm-6 col-md-offset-8 col-md-2" style="text-align: right;">
+ <a href="#" class="btn btn-default btn-xs">Next [period]</a>
+ </div>
+ </div>
+
+ <!-- Beneficiaries, categories and budget pie charts: -->
+ <div class="row">
+ <div class="col-lg-4 col-sm-6 col-md-6">
+ <h4>Beneficiaries</h4>
+ </div>
+ <div class="col-lg-4 col-sm-6 col-md-6">
+ <h4>Categories</h4>
+ </div>
+ <div class="col-lg-4 col-sm-6 col-md-6">
+ <h4>Budgets</h4>
+ </div>
+ </div>
+
+
@endif
@stop
diff --git a/public/assets/javascript/index.js b/public/assets/javascript/index.js
index a12e1ba816..0c3cad6185 100644
--- a/public/assets/javascript/index.js
+++ b/public/assets/javascript/index.js
@@ -13,7 +13,7 @@ function drawAccountChart() {
var accountID = obj.data('id').toString();
var holderID = $(v).attr('id').toString();
console.log('AccountID: ' + accountID + ', ' + 'holderID ' + holderID);
- var URL = 'chart/home/' + accountID;
+ var URL = 'chart/home/account/' + accountID;
console.log('URL: ' + URL);