mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-14 01:13:37 -06:00
Recurring transactions support pagination.
This commit is contained in:
parent
723abf44bd
commit
477788658b
@ -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'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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 %}
|
||||
|
Loading…
Reference in New Issue
Block a user