From 5e8cfb512b129c984f9bf0e46081e2bb955e6b0f Mon Sep 17 00:00:00 2001
From: James Cole
Date: Tue, 8 Jul 2014 07:51:25 +0200
Subject: [PATCH] Some changes in the charts and range thing.
---
app/controllers/ChartController.php | 16 +++----
app/controllers/HomeController.php | 4 ++
app/lib/Firefly/Helper/Toolkit/Toolkit.php | 44 +++++++++++++++++++
.../Helper/Toolkit/ToolkitInterface.php | 8 ++++
app/routes.php | 2 +-
app/views/index.blade.php | 31 ++++++++++++-
public/assets/javascript/index.js | 2 +-
7 files changed, 96 insertions(+), 11 deletions(-)
create mode 100644 app/lib/Firefly/Helper/Toolkit/Toolkit.php
create mode 100644 app/lib/Firefly/Helper/Toolkit/ToolkitInterface.php
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 @@
+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 @@
+ '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 @@
@else
+
+
+
-
+
@foreach($accounts as $index => $account)
{{{$account->name}}} chart
@@ -62,6 +65,32 @@
@endforeach
+
+
+
+
+
+
+
+
Beneficiaries
+
+
+
Categories
+
+
+
Budgets
+
+
+
+
@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);