This commit is contained in:
James Cole
2017-12-28 09:53:21 +01:00
parent eda1673518
commit 986d7de906
10 changed files with 98 additions and 26 deletions

View File

@@ -31,6 +31,7 @@ use FireflyIII\Models\Note;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Bill\BillRepositoryInterface; use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Preferences; use Preferences;
use URL; use URL;
@@ -167,15 +168,19 @@ class BillController extends Controller
* *
* @return View * @return View
*/ */
public function index(BillRepositoryInterface $repository) public function index(Request $request, BillRepositoryInterface $repository)
{ {
/** @var Carbon $start */ /** @var Carbon $start */
$start = session('start'); $start = session('start');
/** @var Carbon $end */ /** @var Carbon $end */
$end = session('end'); $end = session('end');
$page = 0 === intval($request->get('page')) ? 1 : intval($request->get('page'));
$pageSize = intval(Preferences::get('listPageSize', 50)->data);
$collection = $repository->getBills();
$total = $collection->count();
$collection = $collection->slice(($page - 1) * $pageSize, $pageSize);
$bills = $repository->getBills(); $collection->each(
$bills->each(
function (Bill $bill) use ($repository, $start, $end) { function (Bill $bill) use ($repository, $start, $end) {
// paid in this period? // paid in this period?
$bill->paidDates = $repository->getPaidDatesInRange($bill, $start, $end); $bill->paidDates = $repository->getPaidDatesInRange($bill, $start, $end);
@@ -188,6 +193,9 @@ class BillController extends Controller
$bill->nextExpectedMatch = $repository->nextExpectedMatch($bill, $lastPaidDate); $bill->nextExpectedMatch = $repository->nextExpectedMatch($bill, $lastPaidDate);
} }
); );
// paginate bills
$bills= new LengthAwarePaginator($collection, $total, $pageSize, $page);
$bills->setPath(route('bills.index'));
return view('bills.index', compact('bills')); return view('bills.index', compact('bills'));
} }

View File

@@ -35,6 +35,7 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Support\CacheProperties; use FireflyIII\Support\CacheProperties;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
use Preferences; use Preferences;
@@ -175,11 +176,13 @@ class BudgetController extends Controller
* @SuppressWarnings(PHPMD.CyclomaticComplexity) complex because of while loop * @SuppressWarnings(PHPMD.CyclomaticComplexity) complex because of while loop
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/ */
public function index(string $moment = null) public function index(Request $request, string $moment = null)
{ {
$range = Preferences::get('viewRange', '1M')->data; $range = Preferences::get('viewRange', '1M')->data;
$start = session('start', new Carbon); $start = session('start', new Carbon);
$end = session('end', new Carbon); $end = session('end', new Carbon);
$page = 0 === intval($request->get('page')) ? 1 : intval($request->get('page'));
$pageSize = intval(Preferences::get('listPageSize', 50)->data);
// make date if present: // make date if present:
if (null !== $moment || 0 !== strlen(strval($moment))) { if (null !== $moment || 0 !== strlen(strval($moment))) {
@@ -197,6 +200,8 @@ class BudgetController extends Controller
$prev = app('navigation')->startOfPeriod($prev, $range); $prev = app('navigation')->startOfPeriod($prev, $range);
$this->repository->cleanupBudgets(); $this->repository->cleanupBudgets();
$budgets = $this->repository->getActiveBudgets(); $budgets = $this->repository->getActiveBudgets();
$total = $budgets->count();
$budgets = $budgets->slice(($page - 1) * $pageSize, $pageSize);
$inactive = $this->repository->getInactiveBudgets(); $inactive = $this->repository->getInactiveBudgets();
$periodStart = $start->formatLocalized($this->monthAndDayFormat); $periodStart = $start->formatLocalized($this->monthAndDayFormat);
$periodEnd = $end->formatLocalized($this->monthAndDayFormat); $periodEnd = $end->formatLocalized($this->monthAndDayFormat);
@@ -206,6 +211,10 @@ class BudgetController extends Controller
$spent = array_sum(array_column($budgetInformation, 'spent')); $spent = array_sum(array_column($budgetInformation, 'spent'));
$budgeted = array_sum(array_column($budgetInformation, 'budgeted')); $budgeted = array_sum(array_column($budgetInformation, 'budgeted'));
// paginate budgets
$budgets = new LengthAwarePaginator($budgets, $total, $pageSize, $page);
$budgets->setPath(route('budgets.index'));
// select thing for last 12 periods: // select thing for last 12 periods:
$previousLoop = []; $previousLoop = [];
$previousDate = clone $start; $previousDate = clone $start;
@@ -248,6 +257,7 @@ class BudgetController extends Controller
'prevText', 'prevText',
'periodStart', 'periodStart',
'periodEnd', 'periodEnd',
'page',
'budgetInformation', 'budgetInformation',
'inactive', 'inactive',
'budgets', 'budgets',

View File

@@ -34,6 +34,7 @@ use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Support\CacheProperties; use FireflyIII\Support\CacheProperties;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
use Preferences; use Preferences;
@@ -136,16 +137,24 @@ class CategoryController extends Controller
* *
* @return View * @return View
*/ */
public function index(CategoryRepositoryInterface $repository) public function index(Request $request, CategoryRepositoryInterface $repository)
{ {
$categories = $repository->getCategories(); $page = 0 === intval($request->get('page')) ? 1 : intval($request->get('page'));
$pageSize = intval(Preferences::get('listPageSize', 50)->data);
$collection = $repository->getCategories();
$total = $collection->count();
$collection = $collection->slice(($page - 1) * $pageSize, $pageSize);
$categories->each( $collection->each(
function (Category $category) use ($repository) { function (Category $category) use ($repository) {
$category->lastActivity = $repository->lastUseDate($category, new Collection); $category->lastActivity = $repository->lastUseDate($category, new Collection);
} }
); );
// paginate categories
$categories = new LengthAwarePaginator($collection, $total, $pageSize, $page);
$categories->setPath(route('categories.index'));
return view('categories.index', compact('categories')); return view('categories.index', compact('categories'));
} }

View File

@@ -28,6 +28,7 @@ use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use Log; use Log;
use Preferences; use Preferences;
use View; use View;
@@ -198,12 +199,19 @@ class CurrencyController extends Controller
*/ */
public function index(Request $request) public function index(Request $request)
{ {
$currencies = $this->repository->get(); $page = 0 === intval($request->get('page')) ? 1 : intval($request->get('page'));
$currencies = $currencies->sortBy( $pageSize = intval(Preferences::get('listPageSize', 50)->data);
$collection = $this->repository->get();
$total = $collection->count();
$collection = $collection->sortBy(
function (TransactionCurrency $currency) { function (TransactionCurrency $currency) {
return $currency->name; return $currency->name;
} }
); );
$collection = $collection->slice(($page - 1) * $pageSize, $pageSize);
$currencies = new LengthAwarePaginator($collection, $total, $pageSize, $page);
$currencies->setPath(route('currencies.index'));
$defaultCurrency = $this->repository->getCurrencyByPreference(Preferences::get('currencyPreference', config('firefly.default_currency', 'EUR'))); $defaultCurrency = $this->repository->getCurrencyByPreference(Preferences::get('currencyPreference', config('firefly.default_currency', 'EUR')));
$isOwner = true; $isOwner = true;
if (!$this->userRepository->hasRole(auth()->user(), 'owner')) { if (!$this->userRepository->hasRole(auth()->user(), 'owner')) {

View File

@@ -30,7 +30,7 @@ use FireflyIII\Models\PiggyBank;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Collection; use Illuminate\Pagination\LengthAwarePaginator;
use Log; use Log;
use Preferences; use Preferences;
use Response; use Response;
@@ -199,17 +199,19 @@ class PiggyBankController extends Controller
* *
* @return View * @return View
*/ */
public function index(PiggyBankRepositoryInterface $piggyRepository) public function index(Request $request, PiggyBankRepositoryInterface $piggyRepository)
{ {
/** @var Collection $piggyBanks */ $collection = $piggyRepository->getPiggyBanks();
$piggyBanks = $piggyRepository->getPiggyBanks(); $total = $collection->count();
$page = 0 === intval($request->get('page')) ? 1 : intval($request->get('page'));
$pageSize = intval(Preferences::get('listPageSize', 50)->data);
/** @var Carbon $end */ /** @var Carbon $end */
$end = session('end', Carbon::now()->endOfMonth()); $end = session('end', Carbon::now()->endOfMonth());
$accounts = []; $accounts = [];
Log::debug('Looping piggues'); Log::debug('Looping piggues');
/** @var PiggyBank $piggyBank */ /** @var PiggyBank $piggyBank */
foreach ($piggyBanks as $piggyBank) { foreach ($collection as $piggyBank) {
$piggyBank->savedSoFar = $piggyBank->currentRelevantRep()->currentamount ?? '0'; $piggyBank->savedSoFar = $piggyBank->currentRelevantRep()->currentamount ?? '0';
$piggyBank->percentage = 0 !== bccomp('0', $piggyBank->savedSoFar) ? intval($piggyBank->savedSoFar / $piggyBank->targetamount * 100) : 0; $piggyBank->percentage = 0 !== bccomp('0', $piggyBank->savedSoFar) ? intval($piggyBank->savedSoFar / $piggyBank->targetamount * 100) : 0;
$piggyBank->leftToSave = bcsub($piggyBank->targetamount, strval($piggyBank->savedSoFar)); $piggyBank->leftToSave = bcsub($piggyBank->targetamount, strval($piggyBank->savedSoFar));
@@ -236,6 +238,11 @@ class PiggyBankController extends Controller
} }
} }
// paginate piggy banks
$collection = $collection->slice(($page - 1) * $pageSize, $pageSize);
$piggyBanks = new LengthAwarePaginator($collection, $total, $pageSize, $page);
$piggyBanks->setPath(route('piggy-banks.index'));
return view('piggy-banks.index', compact('piggyBanks', 'accounts')); return view('piggy-banks.index', compact('piggyBanks', 'accounts'));
} }

View File

@@ -83,7 +83,7 @@
{% endif %} {% endif %}
</div> </div>
</div> </div>
{% if budgets.count == 0 and inactive.count == 0 %} {% if budgets.count == 0 and inactive.count == 0 and page == 1 %}
{% include 'partials.empty' with {what: 'default', type: 'budgets',route: route('budgets.create')} %} {% include 'partials.empty' with {what: 'default', type: 'budgets',route: route('budgets.create')} %}
{# make FF ignore demo for now. #} {# make FF ignore demo for now. #}
{% set shownDemo = true %} {% set shownDemo = true %}
@@ -134,6 +134,9 @@
<h3 class="box-title">{{ 'budgets'|_ }}</h3> <h3 class="box-title">{{ 'budgets'|_ }}</h3>
</div> </div>
<div class="box-body no-padding"> <div class="box-body no-padding">
<div style="padding-left:8px;">
{{ budgets.render|raw }}
</div>
<table class="table table-bordered table-striped sortable" id="budgetList"> <table class="table table-bordered table-striped sortable" id="budgetList">
<thead> <thead>
<tr> <tr>
@@ -190,6 +193,9 @@
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
<div style="padding-left:8px;">
{{ budgets.render|raw }}
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -16,11 +16,14 @@
{{ 'currencies_intro'|_ }} {{ 'currencies_intro'|_ }}
</p> </p>
{% if currencies|length > 0 %} {% if currencies|length > 0 %}
<div style="padding-left:8px;">
{{ currencies.render|raw }}
</div>
<table class="table table-hover"> <table class="table table-hover">
<thead> <thead>
<tr> <tr>
{% if isOwner %} {% if isOwner %}
<th>&nbsp;</th> <th>&nbsp;</th>
{% endif %} {% endif %}
<th>{{ 'currency'|_ }}</th> <th>{{ 'currency'|_ }}</th>
<th>{{ 'number_of_decimals'|_ }}</th> <th>{{ 'number_of_decimals'|_ }}</th>
@@ -31,12 +34,12 @@
{% for currency in currencies %} {% for currency in currencies %}
<tr> <tr>
{% if isOwner %} {% if isOwner %}
<td> <td>
<div class="btn-group btn-group-xs"> <div class="btn-group btn-group-xs">
<a class="btn btn-default" href="{{ route('currencies.edit',currency.id) }}"><i class="fa fa-fw fa-pencil"></i></a> <a class="btn btn-default" href="{{ route('currencies.edit',currency.id) }}"><i class="fa fa-fw fa-pencil"></i></a>
<a class="btn btn-danger" href="{{ route('currencies.delete',currency.id) }}"><i class="fa fa-fw fa-trash"></i></a> <a class="btn btn-danger" href="{{ route('currencies.delete',currency.id) }}"><i class="fa fa-fw fa-trash"></i></a>
</div> </div>
</td> </td>
{% endif %} {% endif %}
<td>{{ currency.name }} ({{ currency.code }}) ({{ currency.symbol|raw }})</td> <td>{{ currency.name }} ({{ currency.code }}) ({{ currency.symbol|raw }})</td>
<td>{{ currency.decimal_places }}</td> <td>{{ currency.decimal_places }}</td>
@@ -52,6 +55,9 @@
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
<div style="padding-left:8px;">
{{ currencies.render|raw }}
</div>
{% endif %} {% endif %}
</div> </div>
<div class="box-footer"> <div class="box-footer">

View File

@@ -1,3 +1,6 @@
<div style="padding-left:8px;">
{{ bills.render|raw }}
</div>
<table class="table table-hover sortable"> <table class="table table-hover sortable">
<thead> <thead>
<tr> <tr>
@@ -126,3 +129,6 @@
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
<div style="padding-left:8px;">
{{ bills.render|raw }}
</div>

View File

@@ -1,3 +1,6 @@
<div style="padding-left:8px;">
{{ categories.render|raw }}
</div>
<table class="table table-hover sortable"> <table class="table table-hover sortable">
<thead> <thead>
<tr> <tr>
@@ -36,3 +39,6 @@
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
<div style="padding-left:8px;">
{{ categories.render|raw }}
</div>

View File

@@ -1,3 +1,6 @@
<div style="padding-left:8px;">
{{ piggyBanks.render|raw }}
</div>
<table class="table table-hover table-condensed" id="sortable-piggy"> <table class="table table-hover table-condensed" id="sortable-piggy">
<thead> <thead>
<tr> <tr>
@@ -80,3 +83,6 @@
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
<div style="padding-left:8px;">
{{ piggyBanks.render|raw }}
</div>