Move some stuff over to AJAX thing.

This commit is contained in:
James Cole 2016-10-25 18:53:54 +02:00
parent e2d187d74b
commit a7e5fcc806
20 changed files with 164 additions and 247 deletions

View File

@ -173,7 +173,10 @@ class ReportController extends Controller
/** @var CategoryRepositoryInterface $repository */
$repository = app(CategoryRepositoryInterface::class);
$category = $repository->find(intval($attributes['categoryId']));
$journals = $repository->journalsInPeriod(new Collection([$category]), $attributes['accounts'], [], $attributes['startDate'], $attributes['endDate']);
$types = [TransactionType::WITHDRAWAL, TransactionType::TRANSFER];
$journals = $repository->journalsInPeriod(
new Collection([$category]), $attributes['accounts'], $types, $attributes['startDate'], $attributes['endDate']
);
$view = view('popup.report.category-entry', compact('journals', 'category'))->render();
return $view;

View File

@ -0,0 +1,49 @@
<?php
/**
* InOutController.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Http\Controllers\Report;
use Carbon\Carbon;
use FireflyIII\Helpers\Report\ReportHelperInterface;
use FireflyIII\Http\Controllers\Controller;
use Illuminate\Support\Collection;
use Response;
/**
* Class InOutController
*
* @package FireflyIII\Http\Controllers\Report
*/
class InOutController extends Controller
{
public function inOutReport(ReportHelperInterface $helper, Carbon $start, Carbon $end, Collection $accounts)
{
$incomes = $helper->getIncomeReport($start, $end, $accounts);
$expenses = $helper->getExpenseReport($start, $end, $accounts);
$incomeTopLength = 8;
$expenseTopLength = 8;
return Response::json(
[
'income' => view('reports.partials.income', compact('incomes', 'incomeTopLength'))->render(),
'expenses' => view('reports.partials.expenses', compact('expenses', 'expenseTopLength'))->render(),
'incomes_expenses' => view('reports.partials.income-vs-expenses', compact('expenses', 'incomes'))->render(),
]
);
}
}

View File

@ -22,7 +22,6 @@ use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Transaction;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
use FireflyIII\Repositories\Account\AccountTaskerInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
@ -226,12 +225,7 @@ class ReportController extends Controller
*/
private function defaultMonth(string $reportType, Carbon $start, Carbon $end, Collection $accounts)
{
$incomeTopLength = 8;
$expenseTopLength = 8;
// get report stuff!
$incomes = $this->helper->getIncomeReport($start, $end, $accounts);
$expenses = $this->helper->getExpenseReport($start, $end, $accounts);
$budgets = $this->budgetHelper->getBudgetReport($start, $end, $accounts);
$categories = $this->helper->getCategoryReport($start, $end, $accounts);
$balance = $this->balanceHelper->getBalanceReport($start, $end, $accounts);
@ -247,8 +241,7 @@ class ReportController extends Controller
compact(
'start', 'end', 'reportType',
'tags',
'incomes', 'incomeTopLength',
'expenses', 'expenseTopLength',
'incomes',
'budgets', 'balance',
'categories',
'bills',
@ -268,13 +261,8 @@ class ReportController extends Controller
private function defaultMultiYear(string $reportType, Carbon $start, Carbon $end, Collection $accounts)
{
$incomeTopLength = 8;
$expenseTopLength = 8;
// list of users stuff:
$budgets = app(BudgetRepositoryInterface::class)->getActiveBudgets();
$categories = app(CategoryRepositoryInterface::class)->getCategories();
$incomes = $this->helper->getIncomeReport($start, $end, $accounts);
$expenses = $this->helper->getExpenseReport($start, $end, $accounts);
$tags = $this->helper->tagReport($start, $end, $accounts);
// and some id's, joined:
@ -288,9 +276,7 @@ class ReportController extends Controller
return view(
'reports.default.multi-year',
compact(
'budgets', 'accounts', 'categories', 'start', 'end', 'accountIds', 'reportType',
'incomes', 'expenses',
'incomeTopLength', 'expenseTopLength', 'tags'
'budgets', 'accounts', 'categories', 'start', 'end', 'accountIds', 'reportType', 'tags'
)
);
}
@ -305,11 +291,6 @@ class ReportController extends Controller
*/
private function defaultYear(string $reportType, Carbon $start, Carbon $end, Collection $accounts)
{
$incomeTopLength = 8;
$expenseTopLength = 8;
$incomes = $this->helper->getIncomeReport($start, $end, $accounts);
$expenses = $this->helper->getExpenseReport($start, $end, $accounts);
$tags = $this->helper->tagReport($start, $end, $accounts);
$budgets = $this->budgetHelper->budgetYearOverview($start, $end, $accounts);
@ -328,8 +309,7 @@ class ReportController extends Controller
return view(
'reports.default.year',
compact(
'start', 'incomes', 'reportType', 'accountIds', 'end',
'expenses', 'incomeTopLength', 'expenseTopLength', 'tags', 'budgets'
'start', 'reportType', 'accountIds', 'end', 'tags', 'budgets'
)
);
}

View File

@ -75,12 +75,24 @@ class Range
// set view variables.
$this->configureView();
// set more view variables:
$this->configureList();
}
return $theNext($request);
}
/**
*
*/
private function configureList()
{
$pref = Preferences::get('list-length', config('firefly.list_length', 10))->data;
View::share('listLength', $pref);
}
private function configureView()
{
$pref = Preferences::get('language', config('firefly.default_language', 'en_US'));

View File

@ -241,6 +241,7 @@ class CategoryRepository implements CategoryRepositoryInterface
if (count($types) > 0) {
$query->transactionTypes($types);
}
if ($accounts->count() > 0) {
$accountIds = $accounts->pluck('id')->toArray();
$query->leftJoin('transactions as t', 't.transaction_journal_id', '=', 'transaction_journals.id');
@ -275,7 +276,7 @@ class CategoryRepository implements CategoryRepositoryInterface
}
$second = $query->get(['transaction_journals.*']);
$second = $query->get(['transaction_journals.*','transaction_types.type as transaction_type_type']);
$complete = $complete->merge($first);
$complete = $complete->merge($second);

View File

@ -28,6 +28,7 @@ return [
'allowedMimes' => ['image/png', 'image/jpeg', 'application/pdf'],
'resend_confirmation' => 3600,
'confirmation_age' => 14400, // four hours
'list_length' => 10,
'export_formats' => [
'csv' => 'FireflyIII\Export\Exporter\CsvExporter',

View File

@ -8,11 +8,6 @@
/* globals hideable */
/**
* Created by sander on 01/04/16.
*/
$(function () {
"use strict";

View File

@ -1,4 +1,4 @@
/* globals startDate, endDate, reportType, accountIds */
/* globals startDate, showOnlyTop, showFullList, endDate, reportType, accountIds, inOutReportUrl, accountReportUrl */
/*
* all.js
* Copyright (C) 2016 thegrumpydictator@gmail.com
@ -7,10 +7,6 @@
* of the MIT license. See the LICENSE file for details.
*/
/**
* Created by sander on 01/04/16.
*/
$(function () {
"use strict";
@ -20,8 +16,62 @@ $(function () {
// load the account report, which this report shows:
loadAccountReport();
// load income / expense / difference:
loadInOutReport();
// trigger list length things:
listLengthInitial();
});
function listLengthInitial() {
"use strict";
$('.overListLength').hide();
$('.listLengthTrigger').unbind('click').click(triggerList)
}
function triggerList(e) {
"use strict";
var link = $(e.target);
var table = link.parent().parent().parent().parent();
console.log('data-hidden = ' + table.attr('data-hidden'));
if (table.attr('data-hidden') === 'no') {
// hide all elements, return false.
table.find('.overListLength').hide();
table.attr('data-hidden', 'yes');
link.text(showFullList);
return false;
}
// show all, return false
table.find('.overListLength').show();
table.attr('data-hidden', 'no');
link.text(showOnlyTop);
return false;
}
function loadInOutReport() {
"use strict";
console.log('Going to grab ' + inOutReportUrl);
$.get(inOutReportUrl).done(placeInOutReport).fail(failInOutReport);
}
function placeInOutReport(data) {
"use strict";
$('#incomeReport').removeClass('loading').html(data.income);
$('#expenseReport').removeClass('loading').html(data.expenses);
$('#incomeVsExpenseReport').removeClass('loading').html(data.incomes_expenses);
listLengthInitial();
}
function failInOutReport() {
"use strict";
console.log('Fail in/out report data!');
$('#incomeReport').removeClass('loading').addClass('general-chart-error');
$('#expenseReport').removeClass('loading').addClass('general-chart-error');
$('#incomeVsExpenseReport').removeClass('loading').addClass('general-chart-error');
}
function loadAccountReport() {
"use strict";
$.get(accountReportUrl).done(placeAccountReport).fail(failAccountReport);

View File

@ -1,14 +1,9 @@
/* globals google, startDate ,reportURL, endDate , reportType ,accountIds , picker:true, minDate, expenseRestShow:true, incomeRestShow:true, year, month, hideTheRest, showTheRest, showTheRestExpense, hideTheRestExpense, columnChart, lineChart, stackedColumnChart */
/* globals google, startDate ,reportURL, endDate , reportType ,accountIds , picker:true, minDate, year, month, columnChart, lineChart, stackedColumnChart */
$(function () {
"use strict";
drawChart();
// click open the top X income list:
$('#showIncomes').click(showIncomes);
// click open the top X expense list:
$('#showExpenses').click(showExpenses);
});
@ -18,47 +13,4 @@ function drawChart() {
// month view:
// draw account chart
lineChart('chart/account/report/' + reportType + '/' + startDate + '/' + endDate + '/' + accountIds, 'account-balances-chart');
}
function showIncomes() {
"use strict";
if (incomeRestShow) {
// hide everything, make button say "show"
$('#showIncomes').text(showTheRest);
$('.incomesCollapsed').removeClass('in').addClass('out');
// toggle:
incomeRestShow = false;
} else {
// show everything, make button say "hide".
$('#showIncomes').text(hideTheRest);
$('.incomesCollapsed').removeClass('out').addClass('in');
// toggle:
incomeRestShow = true;
}
return false;
}
function showExpenses() {
"use strict";
if (expenseRestShow) {
// hide everything, make button say "show"
$('#showExpenses').text(showTheRestExpense);
$('.expenseCollapsed').removeClass('in').addClass('out');
// toggle:
expenseRestShow = false;
} else {
// show everything, make button say "hide".
$('#showExpenses').text(hideTheRestExpense);
$('.expenseCollapsed').removeClass('out').addClass('in');
// toggle:
expenseRestShow = true;
}
return false;
}

View File

@ -1,15 +1,10 @@
/* globals google, startDate ,reportURL, endDate , reportType ,accountIds , picker:true, minDate, expenseRestShow:true, incomeRestShow:true, year, month, hideTheRest, showTheRest, showTheRestExpense, hideTheRestExpense, columnChart, lineChart, stackedColumnChart */
/* globals google, startDate ,reportURL, endDate , reportType ,accountIds , picker:true, minDate, year, month, columnChart, lineChart, stackedColumnChart */
$(function () {
"use strict";
drawChart();
// click open the top X income list:
$('#showIncomes').click(showIncomes);
// click open the top X expense list:
$('#showExpenses').click(showExpenses);
});
@ -158,48 +153,4 @@ function readCookie(name) {
function eraseCookie(name) {
createCookie(name, "", -1);
}
function showIncomes() {
"use strict";
if (incomeRestShow) {
// hide everything, make button say "show"
$('#showIncomes').text(showTheRest);
$('.incomesCollapsed').removeClass('in').addClass('out');
// toggle:
incomeRestShow = false;
} else {
// show everything, make button say "hide".
$('#showIncomes').text(hideTheRest);
$('.incomesCollapsed').removeClass('out').addClass('in');
// toggle:
incomeRestShow = true;
}
return false;
}
function showExpenses() {
"use strict";
if (expenseRestShow) {
// hide everything, make button say "show"
$('#showExpenses').text(showTheRestExpense);
$('.expenseCollapsed').removeClass('in').addClass('out');
// toggle:
expenseRestShow = false;
} else {
// show everything, make button say "hide".
$('#showExpenses').text(hideTheRestExpense);
$('.expenseCollapsed').removeClass('out').addClass('in');
// toggle:
expenseRestShow = true;
}
return false;
}

View File

@ -1,4 +1,4 @@
/* globals google, startDate ,reportURL, endDate , reportType ,accountIds , picker:true, minDate, expenseRestShow:true, incomeRestShow:true, year, month, hideTheRest, showTheRest, showTheRestExpense, hideTheRestExpense, columnChart, lineChart, stackedColumnChart */
/* globals google, startDate ,reportURL, endDate , reportType ,accountIds , picker:true, minDate, year, month, columnChart, lineChart, stackedColumnChart */
var chartDrawn;
var budgetChart;
@ -7,10 +7,6 @@ $(function () {
chartDrawn = false;
drawChart();
// click open the top X income list:
$('#showIncomes').click(showIncomes);
// click open the top X expense list:
$('#showExpenses').click(showExpenses);
});
@ -86,52 +82,5 @@ function clickBudgetChart(e) {
}
// if chart drawn is true, add new data to existing chart.
// console.log('Budget id is ' + budgetId);
// $('#budget_chart').empty();
// columnChart('chart/budget/period/' + budgetId + '/' + reportType + '/' + startDate + '/' + endDate + '/' + accountIds, 'budget_chart');
return false;
}
function showIncomes() {
"use strict";
if (incomeRestShow) {
// hide everything, make button say "show"
$('#showIncomes').text(showTheRest);
$('.incomesCollapsed').removeClass('in').addClass('out');
// toggle:
incomeRestShow = false;
} else {
// show everything, make button say "hide".
$('#showIncomes').text(hideTheRest);
$('.incomesCollapsed').removeClass('out').addClass('in');
// toggle:
incomeRestShow = true;
}
return false;
}
function showExpenses() {
"use strict";
if (expenseRestShow) {
// hide everything, make button say "show"
$('#showExpenses').text(showTheRestExpense);
$('.expenseCollapsed').removeClass('in').addClass('out');
// toggle:
expenseRestShow = false;
} else {
// show everything, make button say "hide".
$('#showExpenses').text(hideTheRestExpense);
$('.expenseCollapsed').removeClass('out').addClass('in');
// toggle:
expenseRestShow = true;
}
return false;
}

View File

@ -1,4 +1,4 @@
/* globals google, startDate ,reportURL, endDate , reportType ,accountIds , picker:true, minDate, expenseRestShow:true, incomeRestShow:true, year, month, hideTheRest, showTheRest, showTheRestExpense, hideTheRestExpense, columnChart, lineChart, stackedColumnChart */
/* globals google, startDate ,reportURL, endDate , reportType ,accountIds , picker:true, minDate, year, month, columnChart, lineChart, stackedColumnChart */
$(function () {

View File

@ -604,8 +604,8 @@ return [
'in' => 'In',
'out' => 'Out',
'topX' => 'top :number',
'showTheRest' => 'Show everything',
'hideTheRest' => 'Show only the top :number',
'show_full_list' => 'Show entire list',
'show_only_top' => 'Show only top :number',
'sum_of_year' => 'Sum of year',
'sum_of_years' => 'Sum of years',
'average_of_year' => 'Average of year',

View File

@ -192,6 +192,9 @@
var mon_thousands_sep = "{{ localeconv.mon_thousands_sep|escape('js') }}";
var frac_digits = {{ localeconv.frac_digits }};
var showFullList = '{{ trans('firefly.show_full_list') }}';
var showOnlyTop = '{{ trans('firefly.show_only_top',{number:listLength}) }}';
</script>

View File

@ -22,18 +22,13 @@
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 loading" id="accountReport">
</div>
<div class="col-lg-3 col-md-3 col-sm-3">
<!-- income -->
{% include 'reports/partials/income.twig' %}
<div class="col-lg-3 col-md-3 col-sm-3 loading" id="incomeReport">
</div>
<div class="col-lg-3 col-md-3 col-sm-3">
<!-- expenses -->
{% include 'reports/partials/expenses.twig' %}
<div class="col-lg-3 col-md-3 col-sm-3 loading" id="expenseReport">
</div>
</div>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6">
{% include 'reports/partials/income-vs-expenses.twig' %}
<div class="col-lg-6 col-md-6 col-sm-6 loading" id="incomeVsExpenseReport">
</div>
<div class="col-lg-6 col-md-6 col-sm-6">
{% include 'reports/partials/tags.twig' %}
@ -84,17 +79,9 @@
var reportType = '{{ reportType }}';
var accountIds = '{{ accountIds }}';
var incomeTopLength = {{ incomeTopLength }};
var expenseTopLength = {{ expenseTopLength }};
var incomeRestShow = false; // starts hidden.
var expenseRestShow = false; // starts hidden.
var showTheRest = '{{ trans('firefly.showTheRest',{number:incomeTopLength}) }}';
var hideTheRest = '{{ trans('firefly.hideTheRest',{number:incomeTopLength}) }}';
var showTheRestExpense = '{{ trans('firefly.showTheRest',{number:expenseTopLength}) }}';
var hideTheRestExpense = '{{ trans('firefly.hideTheRest',{number:expenseTopLength}) }}';
<!-- some URL's -->
var accountReportUrl = '{{ route('reports.data.accountReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}';
var inOutReportUrl = '{{ route('reports.data.inOutReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}';
</script>
<script type="text/javascript" src="js/ff/reports/default/all.js"></script>
<script type="text/javascript" src="js/ff/reports/default/month.js"></script>

View File

@ -33,18 +33,13 @@
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 loading" id="accountReport">
</div>
<div class="col-lg-3 col-md-3 col-sm-3">
<!-- income -->
{% include 'reports/partials/income.twig' %}
<div class="col-lg-3 col-md-3 col-sm-3 loading" id="incomeReport">
</div>
<div class="col-lg-3 col-md-3 col-sm-3">
<!-- expenses -->
{% include 'reports/partials/expenses.twig' %}
<div class="col-lg-3 col-md-3 col-sm-3 loading" id="expenseReport">
</div>
</div>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6">
{% include 'reports/partials/income-vs-expenses.twig' %}
<div class="col-lg-6 col-md-6 col-sm-6 loading" id="incomeVsExpenseReport">
</div>
<div class="col-lg-6 col-md-6 col-sm-6">
{% include 'reports/partials/tags.twig' %}
@ -165,17 +160,9 @@
var reportType = '{{ reportType }}';
var accountIds = '{{ accountIds }}';
var incomeTopLength = {{ incomeTopLength }};
var expenseTopLength = {{ expenseTopLength }};
var incomeRestShow = false; // starts hidden.
var expenseRestShow = false; // starts hidden.
var showTheRest = '{{ trans('firefly.showTheRest',{number:incomeTopLength}) }}';
var hideTheRest = '{{ trans('firefly.hideTheRest',{number:incomeTopLength}) }}';
var showTheRestExpense = '{{ trans('firefly.showTheRest',{number:expenseTopLength}) }}';
var hideTheRestExpense = '{{ trans('firefly.hideTheRest',{number:expenseTopLength}) }}';
<!-- some URL's -->
var accountReportUrl = '{{ route('reports.data.accountReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}';
var inOutReportUrl = '{{ route('reports.data.inOutReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}';
</script>
<script type="text/javascript" src="js/ff/reports/default/all.js"></script>

View File

@ -33,14 +33,12 @@
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="loading" id="accountReport">
</div>
{% include 'reports/partials/income-vs-expenses.twig' %}
<div class="loading" id="incomeVsExpenseReport">
</div>
<div class="col-lg-3 col-md-3 col-sm-3">
{% include 'reports/partials/income.twig' %}
</div>
<div class="col-lg-3 col-md-3 col-sm-3">
{% include 'reports/partials/expenses.twig' %}
<div class="col-lg-3 col-md-3 col-sm-3 loading" id="incomeReport">
</div>
<div class="col-lg-3 col-md-3 col-sm-3 loading" id="expenseReport">
</div>
</div>
<div class="row">
@ -125,18 +123,9 @@
var reportType = '{{ reportType }}';
var accountIds = '{{ accountIds }}';
var incomeTopLength = {{ incomeTopLength }};
var expenseTopLength = {{ expenseTopLength }};
var incomeRestShow = false; // starts hidden.
var expenseRestShow = false; // starts hidden.
var showTheRest = '{{ trans('firefly.showTheRest',{number:incomeTopLength}) }}';
var hideTheRest = '{{ trans('firefly.hideTheRest',{number:incomeTopLength}) }}';
var showTheRestExpense = '{{ trans('firefly.showTheRest',{number:expenseTopLength}) }}';
var hideTheRestExpense = '{{ trans('firefly.hideTheRest',{number:expenseTopLength}) }}';
<!-- some URL's -->
var accountReportUrl = '{{ route('reports.data.accountReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}';
var inOutReportUrl = '{{ route('reports.data.inOutReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}';
</script>
<script type="text/javascript" src="js/ff/reports/default/all.js"></script>

View File

@ -6,8 +6,8 @@
<table class="table table-hover">
<tbody>
{% for expense in expenses.getExpenses %}
{% if loop.index > expenseTopLength %}
<tr class="collapse out expenseCollapsed">
{% if loop.index > listLength %}
<tr class="overListLength">
{% else %}
<tr>
{% endif %}
@ -32,7 +32,7 @@
{% if expenses.getExpenses|length > expenseTopLength %}
<tr>
<td colspan="2" class="active">
<a href="#" id="showExpenses">{{ trans('firefly.showTheRest',{number:incomeTopLength}) }}</a>
<a href="#" class="listLengthTrigger">{{ trans('firefly.show_full_list',{number:incomeTopLength}) }}</a>
</td>
</tr>
{% endif %}

View File

@ -6,8 +6,8 @@
<table class="table table-hover">
<tbody>
{% for income in incomes.getIncomes %}
{% if loop.index > incomeTopLength %}
<tr class="collapse out incomesCollapsed">
{% if loop.index > listLength %}
<tr class="overListLength">
{% else %}
<tr>
{% endif %}
@ -23,15 +23,16 @@
{% endif %}
</td>
<td>{{ income.amount|formatAmount }}</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
{% if incomes.getIncomes|length > incomeTopLength %}
{% if incomes.getIncomes|length > listLength %}
<tr>
<td colspan="2" class="active">
<a href="#" id="showIncomes">{{ trans('firefly.showTheRest',{number:incomeTopLength}) }}</a>
<a href="#" class="listLengthTrigger">{{ trans('firefly.show_full_list',{ number:listLength } ) }}</a>
</td>
</tr>
{% endif %}

View File

@ -317,11 +317,18 @@ Route::group(
/**
* Report AJAX data Controller:
*/
// account report
Route::get(
'/reports/data/accountReport/{start_date}/{end_date}/{accountList}',
'/reports/data/account-report/{start_date}/{end_date}/{accountList}',
['uses' => 'Report\AccountController@accountReport', 'as' => 'reports.data.accountReport']
);
// income report
Route::get(
'/reports/data/in-out-report/{start_date}/{end_date}/{accountList}',
['uses' => 'Report\InOutController@inOutReport', 'as' => 'reports.data.inOutReport']
);
/**
* Rules Controller
*/