mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 20:22:07 +00:00
Fix sorting and order for account lists.
This commit is contained in:
@@ -69,17 +69,26 @@ class IndexController extends Controller
|
||||
$accounts = $this->repository->getAccountsByType($types, $sorting, $filters);
|
||||
$pageSize = $this->parameters->get('limit');
|
||||
$count = $accounts->count();
|
||||
|
||||
// depending on the sort parameters, this list must not be split, because the
|
||||
// order is calculated in the account transformer and by that time it's too late.
|
||||
$first = array_key_first($sorting);
|
||||
$disablePagination = in_array($first, ['last_activity', 'balance_difference'], true);
|
||||
if (!$disablePagination) {
|
||||
$accounts = $accounts->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
|
||||
}
|
||||
$paginator = new LengthAwarePaginator($accounts, $count, $pageSize, $this->parameters->get('page'));
|
||||
$transformer = new AccountTransformer();
|
||||
|
||||
$this->parameters->set('disablePagination', $disablePagination);
|
||||
$this->parameters->set('pageSize', $pageSize);
|
||||
$this->parameters->set('sort', $sorting);
|
||||
|
||||
$this->parameters->set('filters', $filters);
|
||||
$transformer->setParameters($this->parameters); // give params to transformer
|
||||
|
||||
return response()
|
||||
->json($this->jsonApiList('accounts', $paginator, $transformer))
|
||||
->header('Content-Type', self::CONTENT_TYPE)
|
||||
;
|
||||
->header('Content-Type', self::CONTENT_TYPE);
|
||||
}
|
||||
}
|
||||
|
@@ -63,6 +63,10 @@ class AccountTransformer extends AbstractTransformer
|
||||
$this->convertedBalances = [];
|
||||
$this->balanceDifferences = [];
|
||||
|
||||
// first collect all the "heavy" stuff that relies on ALL data to be present.
|
||||
// get last activity:
|
||||
$this->getLastActivity($objects);
|
||||
|
||||
// get balances of all accounts
|
||||
$this->getMetaBalances($objects);
|
||||
|
||||
@@ -75,17 +79,21 @@ class AccountTransformer extends AbstractTransformer
|
||||
// get account types:
|
||||
$this->collectAccountTypes($objects);
|
||||
|
||||
// get last activity:
|
||||
$this->getLastActivity($objects);
|
||||
|
||||
// add balance difference
|
||||
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
|
||||
$this->getBalanceDifference($objects, $this->parameters->get('start'), $this->parameters->get('end'));
|
||||
}
|
||||
|
||||
// get object groups"
|
||||
// get object groups
|
||||
$this->getObjectGroups($objects);
|
||||
|
||||
// if pagination is disabled, do it now:
|
||||
if(true === $this->parameters->get('disablePagination')) {
|
||||
$page = (int) $this->parameters->get('page');
|
||||
$size = (int) $this->parameters->get('pageSize');
|
||||
$objects = $objects->slice(($page-1) * $size, $size);
|
||||
}
|
||||
|
||||
return $this->sortAccounts($objects);
|
||||
}
|
||||
|
||||
|
@@ -111,7 +111,7 @@ return [
|
||||
'error_ip' => 'The IP address related to this error is: :ip',
|
||||
'error_url' => 'URL is: :url',
|
||||
'error_user_agent' => 'User agent: :userAgent',
|
||||
'error_stacktrace' => 'The full stacktrace is below. If you think this is a bug in Firefly III, you can forward this message to <a href="mailto:james@firefly-iii.org?subject=BUG!">james@firefly-iii.org</a>. This can help fix the bug you just encountered.',
|
||||
'error_stacktrace' => 'The full stacktrace is below. If you think this is a bug in Firefly III, you can forward this message to <a href="mailto:james@firefly-iii.org?subject=I%20found%20a%20bug!">james@firefly-iii.org</a>. This can help fix the bug you just encountered.',
|
||||
'error_github_html' => 'If you prefer, you can also open a new issue on <a href="https://github.com/firefly-iii/firefly-iii/issues">GitHub</a>.',
|
||||
'error_github_text' => 'If you prefer, you can also open a new issue on https://github.com/firefly-iii/firefly-iii/issues.',
|
||||
'error_stacktrace_below' => 'The full stacktrace is below:',
|
||||
|
Reference in New Issue
Block a user