mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-28 09:51:21 -06:00
Organized some category charts. Still needs some translating
This commit is contained in:
parent
cdc0e3cfd8
commit
7e10641461
@ -31,7 +31,7 @@ interface CategoryChartGenerator
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function month(Collection $entries);
|
||||
public function period(Collection $entries);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -17,17 +17,12 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator
|
||||
|
||||
/**
|
||||
* @param Collection $entries
|
||||
* @param string $dateFormat
|
||||
*
|
||||
* @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 = [
|
||||
'count' => 2,
|
||||
@ -45,7 +40,7 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator
|
||||
];
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
$data['labels'][] = $entry[1];//$entry[0]->formatLocalized($format);
|
||||
$data['labels'][] = $entry[1];
|
||||
$spent = round($entry[2], 2);
|
||||
$earned = round($entry[3], 2);
|
||||
|
||||
@ -90,9 +85,9 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function month(Collection $entries)
|
||||
public function period(Collection $entries)
|
||||
{
|
||||
return $this->all($entries, 'monthAndDay');
|
||||
return $this->all($entries);
|
||||
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,7 @@ class CategoryController extends Controller
|
||||
$journals = new LengthAwarePaginator($set, $count, 50, $page);
|
||||
$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'));
|
||||
$set = $repository->getJournals($category, $page);
|
||||
$count = $repository->countJournals($category);
|
||||
$totalSum = $repository->journalsSum($category);
|
||||
$periodSum = $repository->journalsSum($category, Session::get('start'), Session::get('end'));
|
||||
$subTitle = $category->name;
|
||||
$journals = new LengthAwarePaginator($set, $count, 50, $page);
|
||||
$journals->setPath('categories/show/' . $category->id);
|
||||
@ -221,7 +219,7 @@ class CategoryController extends Controller
|
||||
$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'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -132,7 +132,7 @@ class CategoryController extends Controller
|
||||
*
|
||||
* @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());
|
||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||
@ -143,7 +143,7 @@ class CategoryController extends Controller
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($category->id);
|
||||
$cache->addProperty('category');
|
||||
$cache->addProperty('month');
|
||||
$cache->addProperty('currentPeriod');
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
@ -153,12 +153,55 @@ class CategoryController extends Controller
|
||||
while ($start <= $end) {
|
||||
$spent = $repository->spentOnDaySumCorrected($category, $start);
|
||||
$earned = $repository->earnedOnDaySumCorrected($category, $start);
|
||||
$date = Navigation::periodShow($start, '1D');
|
||||
$date = Navigation::periodShow($start, '1D');
|
||||
$entries->push([clone $start, $date, $spent, $earned]);
|
||||
$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);
|
||||
|
||||
return Response::json($data);
|
||||
|
@ -303,12 +303,13 @@ Route::group(
|
||||
// categories:
|
||||
Route::get('/chart/category/frontpage', ['uses' => 'Chart\CategoryController@frontpage']);
|
||||
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(
|
||||
['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']);
|
||||
|
||||
// piggy banks:
|
||||
|
@ -254,6 +254,7 @@ class TransactionJournal extends Model
|
||||
return $amount;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
|
@ -1,11 +1,19 @@
|
||||
/* globals $, categoryID, columnChart */
|
||||
/* globals $, categoryID, columnChart, categoryDate */
|
||||
$(function () {
|
||||
"use strict";
|
||||
if (typeof categoryID !== 'undefined') {
|
||||
columnChart('chart/category/' + categoryID + '/all', 'all');
|
||||
columnChart('chart/category/' + categoryID + '/month', 'month');
|
||||
// more splits:
|
||||
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');
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
@ -13,10 +13,10 @@
|
||||
</div>
|
||||
<div class="box-body">
|
||||
{% if Config.get('firefly.chart') == 'google' %}
|
||||
<div id="month"></div>
|
||||
<div id="period"></div>
|
||||
{% endif %}
|
||||
{% 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 %}
|
||||
</div>
|
||||
</div>
|
||||
@ -45,7 +45,7 @@
|
||||
<h3 class="box-title">{{ 'transactions'|_ }}</h3>
|
||||
</div>
|
||||
<div class="box-body no-padding">
|
||||
{% include 'list/journals' with {showPageSum: true, showTotalSum: true, showPeriodSum: true} %}
|
||||
{% include 'list/journals' %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -7,32 +7,17 @@
|
||||
{% block content %}
|
||||
|
||||
<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-header with-border">
|
||||
<h3 class="box-title">{{ 'overview'|_ }} (month)</h3>
|
||||
<h3 class="box-title">{{ 'overview'|_ }} (period)</h3>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
{% if Config.get('firefly.chart') == 'google' %}
|
||||
<div id="month"></div>
|
||||
<div id="period-specific-period"></div>
|
||||
{% endif %}
|
||||
{% if Config.get('firefly.chart') == 'chartjs' %}
|
||||
<canvas id="month" 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>
|
||||
<canvas id="period-specific-period" style="width:100%;height:350px;"></canvas>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
@ -61,6 +46,7 @@
|
||||
{% block scripts %}
|
||||
<script type="text/javascript">
|
||||
var categoryID = {{ category.id }};
|
||||
var categoryDate = "{{ carbon.format('Y-m-d') }}";
|
||||
</script>
|
||||
<!-- load the libraries and scripts necessary for Google Charts: -->
|
||||
{% if Config.get('firefly.chart') == 'google' %}
|
||||
|
Loading…
Reference in New Issue
Block a user