Organized some category charts. Still needs some translating

This commit is contained in:
James Cole
2015-09-26 07:18:12 +02:00
parent cdc0e3cfd8
commit 7e10641461
9 changed files with 78 additions and 46 deletions

View File

@@ -31,7 +31,7 @@ interface CategoryChartGenerator
* *
* @return array * @return array
*/ */
public function month(Collection $entries); public function period(Collection $entries);
/** /**

View File

@@ -17,17 +17,12 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator
/** /**
* @param Collection $entries * @param Collection $entries
* @param string $dateFormat
* *
* @return array * @return array
*/ */
public function all(Collection $entries, $dateFormat = 'month') public function all(Collection $entries)
{ {
// language:
//$language = Preferences::get('language', 'en')->data;
//$format = Config::get('firefly.' . $dateFormat . '.' . $language);
$data = [ $data = [
'count' => 2, 'count' => 2,
@@ -45,7 +40,7 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator
]; ];
foreach ($entries as $entry) { foreach ($entries as $entry) {
$data['labels'][] = $entry[1];//$entry[0]->formatLocalized($format); $data['labels'][] = $entry[1];
$spent = round($entry[2], 2); $spent = round($entry[2], 2);
$earned = round($entry[3], 2); $earned = round($entry[3], 2);
@@ -90,9 +85,9 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator
* *
* @return array * @return array
*/ */
public function month(Collection $entries) public function period(Collection $entries)
{ {
return $this->all($entries, 'monthAndDay'); return $this->all($entries);
} }

View File

@@ -164,7 +164,7 @@ class CategoryController extends Controller
$journals = new LengthAwarePaginator($set, $count, 50, $page); $journals = new LengthAwarePaginator($set, $count, 50, $page);
$journals->setPath('categories/show/' . $category->id . '/' . $date); $journals->setPath('categories/show/' . $category->id . '/' . $date);
return view('categories.show_with_date', compact('category', 'journals', 'hideCategory', 'subTitle','carbon')); return view('categories.show_with_date', compact('category', 'journals', 'hideCategory', 'subTitle', 'carbon'));
} }
/** /**
@@ -179,8 +179,6 @@ class CategoryController extends Controller
$page = intval(Input::get('page')); $page = intval(Input::get('page'));
$set = $repository->getJournals($category, $page); $set = $repository->getJournals($category, $page);
$count = $repository->countJournals($category); $count = $repository->countJournals($category);
$totalSum = $repository->journalsSum($category);
$periodSum = $repository->journalsSum($category, Session::get('start'), Session::get('end'));
$subTitle = $category->name; $subTitle = $category->name;
$journals = new LengthAwarePaginator($set, $count, 50, $page); $journals = new LengthAwarePaginator($set, $count, 50, $page);
$journals->setPath('categories/show/' . $category->id); $journals->setPath('categories/show/' . $category->id);
@@ -221,7 +219,7 @@ class CategoryController extends Controller
$cache->store($entries); $cache->store($entries);
} }
return view('categories.show', compact('category', 'journals', 'entries', 'hideCategory', 'totalSum', 'periodSum', 'subTitle')); return view('categories.show', compact('category', 'journals', 'entries', 'hideCategory', 'subTitle'));
} }
/** /**

View File

@@ -132,7 +132,7 @@ class CategoryController extends Controller
* *
* @return \Symfony\Component\HttpFoundation\Response * @return \Symfony\Component\HttpFoundation\Response
*/ */
public function month(CategoryRepositoryInterface $repository, Category $category) public function currentPeriod(CategoryRepositoryInterface $repository, Category $category)
{ {
$start = clone Session::get('start', Carbon::now()->startOfMonth()); $start = clone Session::get('start', Carbon::now()->startOfMonth());
$end = Session::get('end', Carbon::now()->endOfMonth()); $end = Session::get('end', Carbon::now()->endOfMonth());
@@ -143,7 +143,7 @@ class CategoryController extends Controller
$cache->addProperty($end); $cache->addProperty($end);
$cache->addProperty($category->id); $cache->addProperty($category->id);
$cache->addProperty('category'); $cache->addProperty('category');
$cache->addProperty('month'); $cache->addProperty('currentPeriod');
if ($cache->has()) { if ($cache->has()) {
return Response::json($cache->get()); // @codeCoverageIgnore return Response::json($cache->get()); // @codeCoverageIgnore
} }
@@ -153,12 +153,55 @@ class CategoryController extends Controller
while ($start <= $end) { while ($start <= $end) {
$spent = $repository->spentOnDaySumCorrected($category, $start); $spent = $repository->spentOnDaySumCorrected($category, $start);
$earned = $repository->earnedOnDaySumCorrected($category, $start); $earned = $repository->earnedOnDaySumCorrected($category, $start);
$date = Navigation::periodShow($start, '1D'); $date = Navigation::periodShow($start, '1D');
$entries->push([clone $start, $date, $spent, $earned]); $entries->push([clone $start, $date, $spent, $earned]);
$start->addDay(); $start->addDay();
} }
$data = $this->generator->month($entries); $data = $this->generator->period($entries);
$cache->store($data);
return Response::json($data);
}
/**
* @param CategoryRepositoryInterface $repository
* @param Category $category
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function specificPeriod(CategoryRepositoryInterface $repository, Category $category, $date)
{
$carbon = new Carbon($date);
$range = Preferences::get('viewRange', '1M')->data;
$start = Navigation::startOfPeriod($carbon, $range);
$end = Navigation::endOfPeriod($carbon, $range);
// chart properties for cache:
$cache = new CacheProperties;
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($category->id);
$cache->addProperty('category');
$cache->addProperty('specificPeriod');
$cache->addProperty($date);
if ($cache->has()) {
return Response::json($cache->get()); // @codeCoverageIgnore
}
$entries = new Collection;
while ($start <= $end) {
$spent = $repository->spentOnDaySumCorrected($category, $start);
$earned = $repository->earnedOnDaySumCorrected($category, $start);
$theDate = Navigation::periodShow($start, '1D');
$entries->push([clone $start, $theDate, $spent, $earned]);
$start->addDay();
}
$data = $this->generator->period($entries);
$cache->store($data); $cache->store($data);
return Response::json($data); return Response::json($data);

View File

@@ -303,12 +303,13 @@ Route::group(
// categories: // categories:
Route::get('/chart/category/frontpage', ['uses' => 'Chart\CategoryController@frontpage']); Route::get('/chart/category/frontpage', ['uses' => 'Chart\CategoryController@frontpage']);
Route::get('/chart/category/spent-in-year/{year}/{shared?}', ['uses' => 'Chart\CategoryController@spentInYear'])->where( Route::get('/chart/category/spent-in-year/{year}/{shared?}', ['uses' => 'Chart\CategoryController@spentInYear'])->where(
['year' => '[0-9]{4}', 'shared' => 'shared'] ['year' => '[0-9]{4}', 'shared' => 'shared']
); );
Route::get('/chart/category/earned-in-year/{year}/{shared?}', ['uses' => 'Chart\CategoryController@earnedInYear'])->where( Route::get('/chart/category/earned-in-year/{year}/{shared?}', ['uses' => 'Chart\CategoryController@earnedInYear'])->where(
['year' => '[0-9]{4}', 'shared' => 'shared'] ['year' => '[0-9]{4}', 'shared' => 'shared']
); );
Route::get('/chart/category/{category}/month', ['uses' => 'Chart\CategoryController@month']); // should be period. Route::get('/chart/category/{category}/period', ['uses' => 'Chart\CategoryController@currentPeriod']);
Route::get('/chart/category/{category}/period/{date}', ['uses' => 'Chart\CategoryController@specificPeriod']);
Route::get('/chart/category/{category}/all', ['uses' => 'Chart\CategoryController@all']); Route::get('/chart/category/{category}/all', ['uses' => 'Chart\CategoryController@all']);
// piggy banks: // piggy banks:

View File

@@ -254,6 +254,7 @@ class TransactionJournal extends Model
return $amount; return $amount;
} }
/** /**
* @codeCoverageIgnore * @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\HasMany * @return \Illuminate\Database\Eloquent\Relations\HasMany

View File

@@ -1,11 +1,19 @@
/* globals $, categoryID, columnChart */ /* globals $, categoryID, columnChart, categoryDate */
$(function () { $(function () {
"use strict"; "use strict";
if (typeof categoryID !== 'undefined') { if (typeof categoryID !== 'undefined') {
columnChart('chart/category/' + categoryID + '/all', 'all'); // more splits:
columnChart('chart/category/' + categoryID + '/month', 'month'); if ($('#all').length > 0) {
columnChart('chart/category/' + categoryID + '/all', 'all');
}
if ($('#period').length > 0) {
columnChart('chart/category/' + categoryID + '/period', 'period');
}
}
if (typeof categoryID !== 'undefined' && typeof categoryDate !== undefined) {
columnChart('chart/category/' + categoryID + '/period/' + categoryDate, 'period-specific-period');
} }
}); });

View File

@@ -13,10 +13,10 @@
</div> </div>
<div class="box-body"> <div class="box-body">
{% if Config.get('firefly.chart') == 'google' %} {% if Config.get('firefly.chart') == 'google' %}
<div id="month"></div> <div id="period"></div>
{% endif %} {% endif %}
{% if Config.get('firefly.chart') == 'chartjs' %} {% if Config.get('firefly.chart') == 'chartjs' %}
<canvas id="month" style="width:100%;height:350px;"></canvas> <canvas id="period" style="width:100%;height:350px;"></canvas>
{% endif %} {% endif %}
</div> </div>
</div> </div>
@@ -45,7 +45,7 @@
<h3 class="box-title">{{ 'transactions'|_ }}</h3> <h3 class="box-title">{{ 'transactions'|_ }}</h3>
</div> </div>
<div class="box-body no-padding"> <div class="box-body no-padding">
{% include 'list/journals' with {showPageSum: true, showTotalSum: true, showPeriodSum: true} %} {% include 'list/journals' %}
</div> </div>
</div> </div>
</div> </div>

View File

@@ -7,32 +7,17 @@
{% block content %} {% block content %}
<div class="row"> <div class="row">
<div class="col-lg-6 col-md-6 col-sm-12"> <div class="col-lg-12 col-md-12 col-sm-12">
<div class="box"> <div class="box">
<div class="box-header with-border"> <div class="box-header with-border">
<h3 class="box-title">{{ 'overview'|_ }} (month)</h3> <h3 class="box-title">{{ 'overview'|_ }} (period)</h3>
</div> </div>
<div class="box-body"> <div class="box-body">
{% if Config.get('firefly.chart') == 'google' %} {% if Config.get('firefly.chart') == 'google' %}
<div id="month"></div> <div id="period-specific-period"></div>
{% endif %} {% endif %}
{% if Config.get('firefly.chart') == 'chartjs' %} {% if Config.get('firefly.chart') == 'chartjs' %}
<canvas id="month" style="width:100%;height:350px;"></canvas> <canvas id="period-specific-period" style="width:100%;height:350px;"></canvas>
{% endif %}
</div>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ 'overview'|_ }} (all)</h3>
</div>
<div class="box-body">
{% if Config.get('firefly.chart') == 'google' %}
<div id="all"></div>
{% endif %}
{% if Config.get('firefly.chart') == 'chartjs' %}
<canvas id="all" style="width:100%;height:350px;"></canvas>
{% endif %} {% endif %}
</div> </div>
</div> </div>
@@ -61,6 +46,7 @@
{% block scripts %} {% block scripts %}
<script type="text/javascript"> <script type="text/javascript">
var categoryID = {{ category.id }}; var categoryID = {{ category.id }};
var categoryDate = "{{ carbon.format('Y-m-d') }}";
</script> </script>
<!-- load the libraries and scripts necessary for Google Charts: --> <!-- load the libraries and scripts necessary for Google Charts: -->
{% if Config.get('firefly.chart') == 'google' %} {% if Config.get('firefly.chart') == 'google' %}