Recurring transactions support pagination.

This commit is contained in:
James Cole 2018-08-07 20:47:05 +02:00
parent 723abf44bd
commit 477788658b
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
2 changed files with 15 additions and 8 deletions

View File

@ -31,6 +31,8 @@ use FireflyIII\Models\Recurrence;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use FireflyIII\Transformers\RecurrenceTransformer;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Symfony\Component\HttpFoundation\ParameterBag;
/**
@ -77,19 +79,24 @@ class IndexController extends Controller
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
$collection = $this->recurring->get();
// split collection
$total = $collection->count();
/** @var Collection $recurrences */
$recurrences = $collection->slice(($page - 1) * $pageSize, $pageSize);
$transformer = new RecurrenceTransformer(new ParameterBag);
$recurring = [];
/** @var Recurrence $recurrence */
foreach ($collection as $recurrence) {
foreach ($recurrences as $recurrence) {
$array = $transformer->transform($recurrence);
$array['first_date'] = new Carbon($array['first_date']);
$array['repeat_until'] = null === $array['repeat_until'] ? null : new Carbon($array['repeat_until']);
$array['latest_date'] = null === $array['latest_date'] ? null : new Carbon($array['latest_date']);
$recurring[] = $array;
}
return view('recurring.index', compact('recurring', 'page', 'pageSize'));
$paginator = new LengthAwarePaginator($recurring, $total, $pageSize, $page);
$paginator->setPath(route('recurring.index'));
return view('recurring.index', compact('paginator', 'page', 'pageSize','total'));
}
/**

View File

@ -6,7 +6,7 @@
{% block content %}
<!-- block with list of recurring transaction -->
{% if recurring|length > 0 %}
{% if total > 0 %}
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="box">
@ -32,7 +32,7 @@
<!-- list of recurring here -->
<div style="padding-left:8px;">
{{ recurring.render|raw }}
{{ paginator.render|raw }}
</div>
<table class="table table-hover sortable">
<thead>
@ -44,7 +44,7 @@
</tr>
</thead>
<tbody>
{% for rt in recurring %}
{% for rt in paginator %}
<tr>
<td class="hidden-sm hidden-xs">
<div class="btn-group btn-group-xs edit_tr_buttons">
@ -122,7 +122,7 @@
</tbody>
</table>
<div style="padding-left:8px;">
{{ recurring.render|raw }}
{{ paginator.render|raw }}
</div>
</div>
<div class="box-footer">
@ -136,7 +136,7 @@
{% if recurring|length == 0 and page == 1 %}
{% if total == 0 and page == 1 %}
{% include 'partials.empty' with {what: 'default', type: 'recurring',route: route('recurring.create')} %}
{% endif %}
{% endblock %}