Fix pagination of account lists for issue #1040

This commit is contained in:
James Cole
2017-12-21 21:18:30 +01:00
parent 4b869f0d9e
commit b0ecdfe01d
12 changed files with 45 additions and 27 deletions

View File

@@ -36,6 +36,7 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
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;
@@ -214,18 +215,24 @@ class AccountController extends Controller
} }
/** /**
* @param Request $request
* @param AccountRepositoryInterface $repository * @param AccountRepositoryInterface $repository
* @param string $what * @param string $what
* *
* @return View * @return View
*/ */
public function index(AccountRepositoryInterface $repository, string $what) public function index(Request $request, AccountRepositoryInterface $repository, string $what)
{ {
$what = $what ?? 'asset'; $what = $what ?? 'asset';
$subTitle = trans('firefly.' . $what . '_accounts'); $subTitle = trans('firefly.' . $what . '_accounts');
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $what); $subTitleIcon = config('firefly.subIconsByIdentifier.' . $what);
$types = config('firefly.accountTypesByIdentifier.' . $what); $types = config('firefly.accountTypesByIdentifier.' . $what);
$accounts = $repository->getAccountsByType($types); $collection = $repository->getAccountsByType($types);
$total = $collection->count();
$page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
$pageSize = intval(Preferences::get('listPageSize', 50)->data);
$accounts = $collection->slice(($page-1) * $pageSize, $pageSize);
unset($collection);
/** @var Carbon $start */ /** @var Carbon $start */
$start = clone session('start', Carbon::now()->startOfMonth()); $start = clone session('start', Carbon::now()->startOfMonth());
/** @var Carbon $end */ /** @var Carbon $end */
@@ -246,7 +253,11 @@ class AccountController extends Controller
} }
); );
return view('accounts.index', compact('what', 'subTitleIcon', 'subTitle', 'accounts')); // make paginator:
$accounts = new LengthAwarePaginator($accounts, $total, $pageSize, $page);
$accounts->setPath(route('accounts.index', [$what]));
return view('accounts.index', compact('what', 'subTitleIcon', 'subTitle', 'page', 'accounts'));
} }
/** /**
@@ -273,7 +284,7 @@ class AccountController extends Controller
$range = Preferences::get('viewRange', '1M')->data; $range = Preferences::get('viewRange', '1M')->data;
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $account->accountType->type); $subTitleIcon = config('firefly.subIconsByIdentifier.' . $account->accountType->type);
$page = intval($request->get('page')); $page = intval($request->get('page'));
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data); $pageSize = intval(Preferences::get('listPageSize', 50)->data);
$chartUri = route('chart.account.single', [$account->id]); $chartUri = route('chart.account.single', [$account->id]);
$start = null; $start = null;
$end = null; $end = null;

View File

@@ -234,7 +234,7 @@ class BillController extends Controller
$end = session('end'); $end = session('end');
$year = $date->year; $year = $date->year;
$page = intval($request->get('page')); $page = intval($request->get('page'));
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data); $pageSize = intval(Preferences::get('listPageSize', 50)->data);
$yearAverage = $repository->getYearAverage($bill, $date); $yearAverage = $repository->getYearAverage($bill, $date);
$overallAverage = $repository->getOverallAverage($bill); $overallAverage = $repository->getOverallAverage($bill);

View File

@@ -379,7 +379,7 @@ class BudgetController extends Controller
} }
$page = intval($request->get('page')); $page = intval($request->get('page'));
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data); $pageSize = intval(Preferences::get('listPageSize', 50)->data);
/** @var JournalCollectorInterface $collector */ /** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class); $collector = app(JournalCollectorInterface::class);
@@ -421,7 +421,7 @@ class BudgetController extends Controller
$start = session('first', Carbon::create()->startOfYear()); $start = session('first', Carbon::create()->startOfYear());
$end = new Carbon; $end = new Carbon;
$page = intval($request->get('page')); $page = intval($request->get('page'));
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data); $pageSize = intval(Preferences::get('listPageSize', 50)->data);
$limits = $this->getLimits($budget, $start, $end); $limits = $this->getLimits($budget, $start, $end);
$repetition = null; $repetition = null;
// collector: // collector:
@@ -452,7 +452,7 @@ class BudgetController extends Controller
} }
$page = intval($request->get('page')); $page = intval($request->get('page'));
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data); $pageSize = intval(Preferences::get('listPageSize', 50)->data);
$subTitle = trans( $subTitle = trans(
'firefly.budget_in_period', 'firefly.budget_in_period',
[ [

View File

@@ -164,7 +164,7 @@ class CategoryController extends Controller
$end = null; $end = null;
$periods = new Collection; $periods = new Collection;
$page = intval($request->get('page')); $page = intval($request->get('page'));
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data); $pageSize = intval(Preferences::get('listPageSize', 50)->data);
// prep for "all" view. // prep for "all" view.
if ('all' === $moment) { if ('all' === $moment) {
@@ -221,7 +221,7 @@ class CategoryController extends Controller
$subTitle = $category->name; $subTitle = $category->name;
$subTitleIcon = 'fa-bar-chart'; $subTitleIcon = 'fa-bar-chart';
$page = intval($request->get('page')); $page = intval($request->get('page'));
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data); $pageSize = intval(Preferences::get('listPageSize', 50)->data);
$range = Preferences::get('viewRange', '1M')->data; $range = Preferences::get('viewRange', '1M')->data;
$start = null; $start = null;
$end = null; $end = null;

View File

@@ -96,7 +96,7 @@ class PreferencesController extends Controller
$viewRange = $viewRangePref->data; $viewRange = $viewRangePref->data;
$frontPageAccounts = Preferences::get('frontPageAccounts', []); $frontPageAccounts = Preferences::get('frontPageAccounts', []);
$language = Preferences::get('language', config('firefly.default_language', 'en_US'))->data; $language = Preferences::get('language', config('firefly.default_language', 'en_US'))->data;
$transactionPageSize = Preferences::get('transactionPageSize', 50)->data; $listPageSize = Preferences::get('listPageSize', 50)->data;
$customFiscalYear = Preferences::get('customFiscalYear', 0)->data; $customFiscalYear = Preferences::get('customFiscalYear', 0)->data;
$showDeps = Preferences::get('showDepositsFrontpage', false)->data; $showDeps = Preferences::get('showDepositsFrontpage', false)->data;
$fiscalYearStartStr = Preferences::get('fiscalYearStart', '01-01')->data; $fiscalYearStartStr = Preferences::get('fiscalYearStart', '01-01')->data;
@@ -114,7 +114,7 @@ class PreferencesController extends Controller
'tjOptionalFields', 'tjOptionalFields',
'viewRange', 'viewRange',
'customFiscalYear', 'customFiscalYear',
'transactionPageSize', 'listPageSize',
'fiscalYearStart', 'fiscalYearStart',
'is2faEnabled', 'is2faEnabled',
'has2faSecret', 'has2faSecret',
@@ -175,10 +175,10 @@ class PreferencesController extends Controller
Preferences::set('showDepositsFrontpage', $showDepositsFrontpage); Preferences::set('showDepositsFrontpage', $showDepositsFrontpage);
// save page size: // save page size:
Preferences::set('transactionPageSize', 50); Preferences::set('listPageSize', 50);
$transactionPageSize = intval($request->get('transactionPageSize')); $listPageSize = intval($request->get('listPageSize'));
if ($transactionPageSize > 0 && $transactionPageSize < 1337) { if ($listPageSize > 0 && $listPageSize < 1337) {
Preferences::set('transactionPageSize', $transactionPageSize); Preferences::set('listPageSize', $listPageSize);
} }
$twoFactorAuthEnabled = false; $twoFactorAuthEnabled = false;

View File

@@ -196,7 +196,7 @@ class TagController extends Controller
$subTitle = $tag->tag; $subTitle = $tag->tag;
$subTitleIcon = 'fa-tag'; $subTitleIcon = 'fa-tag';
$page = intval($request->get('page')); $page = intval($request->get('page'));
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data); $pageSize = intval(Preferences::get('listPageSize', 50)->data);
$range = Preferences::get('viewRange', '1M')->data; $range = Preferences::get('viewRange', '1M')->data;
$start = null; $start = null;
$end = null; $end = null;

View File

@@ -77,7 +77,7 @@ class TransactionController extends Controller
$subTitleIcon = config('firefly.transactionIconsByWhat.' . $what); $subTitleIcon = config('firefly.transactionIconsByWhat.' . $what);
$types = config('firefly.transactionTypesByWhat.' . $what); $types = config('firefly.transactionTypesByWhat.' . $what);
$page = intval($request->get('page')); $page = intval($request->get('page'));
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data); $pageSize = intval(Preferences::get('listPageSize', 50)->data);
$range = Preferences::get('viewRange', '1M')->data; $range = Preferences::get('viewRange', '1M')->data;
$start = null; $start = null;
$end = null; $end = null;

View File

@@ -407,9 +407,9 @@ return [
'pref_home_show_deposits_info' => 'The home screen already shows your expense accounts. Should it also show your revenue accounts?', 'pref_home_show_deposits_info' => 'The home screen already shows your expense accounts. Should it also show your revenue accounts?',
'pref_home_do_show_deposits' => 'Yes, show them', 'pref_home_do_show_deposits' => 'Yes, show them',
'successful_count' => 'of which :count successful', 'successful_count' => 'of which :count successful',
'transaction_page_size_title' => 'Page size', 'list_page_size_title' => 'Page size',
'transaction_page_size_help' => 'Any list of transactions shows at most this many transactions', 'list_page_size_help' => 'Any list of things (accounts, transactions, etc) shows at most this many per page.',
'transaction_page_size_label' => 'Page size', 'list_page_size_label' => 'Page size',
'between_dates' => '(:start and :end)', 'between_dates' => '(:start and :end)',
'pref_optional_fields_transaction' => 'Optional fields for transactions', 'pref_optional_fields_transaction' => 'Optional fields for transactions',
'pref_optional_fields_transaction_help' => 'By default not all fields are enabled when creating a new transaction (because of the clutter). Below, you can enable these fields if you think they could be useful for you. Of course, any field that is disabled, but already filled in, will be visible regardless of the setting.', 'pref_optional_fields_transaction_help' => 'By default not all fields are enabled when creating a new transaction (because of the clutter). Below, you can enable these fields if you think they could be useful for you. Of course, any field that is disabled, but already filled in, will be visible regardless of the setting.',

View File

@@ -35,7 +35,7 @@ return [
'currentBalance' => 'Current balance', 'currentBalance' => 'Current balance',
'active' => 'Is active?', 'active' => 'Is active?',
'lastActivity' => 'Last activity', 'lastActivity' => 'Last activity',
'balanceDiff' => 'Balance difference between :start and :end', 'balanceDiff' => 'Balance difference',
'matchesOn' => 'Matched on', 'matchesOn' => 'Matched on',
'account_type' => 'Account type', 'account_type' => 'Account type',
'created_at' => 'Created at', 'created_at' => 'Created at',

View File

@@ -32,7 +32,8 @@
</div> </div>
</div> </div>
</div> </div>
{% else %} {% endif %}
{% if accounts.count == 0 and page == 0 %}
{% include 'partials.empty' with {what: what, type: 'accounts',route: route('accounts.create', [what])} %} {% include 'partials.empty' with {what: what, type: 'accounts',route: route('accounts.create', [what])} %}
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View File

@@ -1,3 +1,6 @@
<div style="padding-left:8px;">
{{ accounts.render|raw }}
</div>
<table class="table table-hover sortable"> <table class="table table-hover sortable">
<thead> <thead>
<tr> <tr>
@@ -11,7 +14,7 @@
<th class="hidden-sm hidden-xs">{{ trans('list.active') }}</th> <th class="hidden-sm hidden-xs">{{ trans('list.active') }}</th>
<th data-defaultsign="month" class="hidden-sm hidden-xs hidden-md">{{ trans('list.lastActivity') }}</th> <th data-defaultsign="month" class="hidden-sm hidden-xs hidden-md">{{ trans('list.lastActivity') }}</th>
<th data-defaultsign="_19" style="width:15%;" <th data-defaultsign="_19" style="width:15%;"
class="hidden-sm hidden-xs hidden-md">{{ trans('list.balanceDiff', {'start' : Session.get('start').formatLocalized(monthAndDayFormat),'end' : Session.get('end').formatLocalized(monthAndDayFormat)}) }}</th> class="hidden-sm hidden-xs hidden-md">{{ trans('list.balanceDiff') }}</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@@ -63,3 +66,6 @@
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
<div style="padding-left:8px;">
{{ accounts.render|raw }}
</div>

View File

@@ -245,9 +245,9 @@
<!-- layout settings column B --> <!-- layout settings column B -->
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12"> <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<div class="preferences-box"> <div class="preferences-box">
<h3>{{ 'transaction_page_size_title'|_ }}</h3> <h3>{{ 'list_page_size_title'|_ }}</h3>
<p class="text-info">{{ 'transaction_page_size_help'|_ }}</p> <p class="text-info">{{ 'list_page_size_help'|_ }}</p>
{{ ExpandedForm.integer('transactionPageSize',transactionPageSize,{'label' : 'transaction_page_size_label'|_}) }} {{ ExpandedForm.integer('listPageSize',listPageSize,{'label' : 'list_page_size_label'|_}) }}
</div> </div>
</div> </div>
</div> </div>