mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-20 03:10:57 +00:00
Recurring transactions support pagination.
This commit is contained in:
@@ -31,6 +31,8 @@ use FireflyIII\Models\Recurrence;
|
|||||||
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
||||||
use FireflyIII\Transformers\RecurrenceTransformer;
|
use FireflyIII\Transformers\RecurrenceTransformer;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -77,19 +79,24 @@ class IndexController extends Controller
|
|||||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||||
$collection = $this->recurring->get();
|
$collection = $this->recurring->get();
|
||||||
|
|
||||||
|
// split collection
|
||||||
|
$total = $collection->count();
|
||||||
|
/** @var Collection $recurrences */
|
||||||
|
$recurrences = $collection->slice(($page - 1) * $pageSize, $pageSize);
|
||||||
|
|
||||||
$transformer = new RecurrenceTransformer(new ParameterBag);
|
$transformer = new RecurrenceTransformer(new ParameterBag);
|
||||||
$recurring = [];
|
$recurring = [];
|
||||||
/** @var Recurrence $recurrence */
|
/** @var Recurrence $recurrence */
|
||||||
foreach ($collection as $recurrence) {
|
foreach ($recurrences as $recurrence) {
|
||||||
$array = $transformer->transform($recurrence);
|
$array = $transformer->transform($recurrence);
|
||||||
$array['first_date'] = new Carbon($array['first_date']);
|
$array['first_date'] = new Carbon($array['first_date']);
|
||||||
$array['repeat_until'] = null === $array['repeat_until'] ? null : new Carbon($array['repeat_until']);
|
$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']);
|
$array['latest_date'] = null === $array['latest_date'] ? null : new Carbon($array['latest_date']);
|
||||||
$recurring[] = $array;
|
$recurring[] = $array;
|
||||||
}
|
}
|
||||||
|
$paginator = new LengthAwarePaginator($recurring, $total, $pageSize, $page);
|
||||||
return view('recurring.index', compact('recurring', 'page', 'pageSize'));
|
$paginator->setPath(route('recurring.index'));
|
||||||
|
return view('recurring.index', compact('paginator', 'page', 'pageSize','total'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<!-- block with list of recurring transaction -->
|
<!-- block with list of recurring transaction -->
|
||||||
{% if recurring|length > 0 %}
|
{% if total > 0 %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||||
<div class="box">
|
<div class="box">
|
||||||
@@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
<!-- list of recurring here -->
|
<!-- list of recurring here -->
|
||||||
<div style="padding-left:8px;">
|
<div style="padding-left:8px;">
|
||||||
{{ recurring.render|raw }}
|
{{ paginator.render|raw }}
|
||||||
</div>
|
</div>
|
||||||
<table class="table table-hover sortable">
|
<table class="table table-hover sortable">
|
||||||
<thead>
|
<thead>
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for rt in recurring %}
|
{% for rt in paginator %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="hidden-sm hidden-xs">
|
<td class="hidden-sm hidden-xs">
|
||||||
<div class="btn-group btn-group-xs edit_tr_buttons">
|
<div class="btn-group btn-group-xs edit_tr_buttons">
|
||||||
@@ -122,7 +122,7 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<div style="padding-left:8px;">
|
<div style="padding-left:8px;">
|
||||||
{{ recurring.render|raw }}
|
{{ paginator.render|raw }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-footer">
|
<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')} %}
|
{% include 'partials.empty' with {what: 'default', type: 'recurring',route: route('recurring.create')} %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Reference in New Issue
Block a user