Paginated the account list.

This commit is contained in:
James Cole 2015-03-02 15:44:06 +01:00
parent 08ca3c89d3
commit 14c7ad201a
2 changed files with 20 additions and 5 deletions

View File

@ -8,11 +8,12 @@ use FireflyIII\Http\Requests;
use FireflyIII\Http\Requests\AccountFormRequest; use FireflyIII\Http\Requests\AccountFormRequest;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Pagination\LengthAwarePaginator;
use Input; use Input;
use Redirect; use Redirect;
use Session; use Session;
use View;
use Steam; use Steam;
use View;
/** /**
* Class AccountController * Class AccountController
@ -117,16 +118,21 @@ class AccountController extends Controller
$subTitle = Config::get('firefly.subTitlesByIdentifier.' . $what); $subTitle = Config::get('firefly.subTitlesByIdentifier.' . $what);
$subTitleIcon = Config::get('firefly.subIconsByIdentifier.' . $what); $subTitleIcon = Config::get('firefly.subIconsByIdentifier.' . $what);
$types = Config::get('firefly.accountTypesByIdentifier.' . $what); $types = Config::get('firefly.accountTypesByIdentifier.' . $what);
$size = 50;
$page = intval(Input::get('page')) == 0 ? 1 : intval(Input::get('page'));
$offset = ($page - 1) * $size;
// move to repository: // move to repository:
$accounts = Auth::user()->accounts()->with( $set = Auth::user()->accounts()->with(
['accountmeta' => function ($query) { ['accountmeta' => function ($query) {
$query->where('name', 'accountRole'); $query->where('name', 'accountRole');
}] }]
)->accountTypeIn($types)->get(['accounts.*']); )->accountTypeIn($types)->take($size)->offset($offset)->get(['accounts.*']);
$total = Auth::user()->accounts()->accountTypeIn($types)->count();
// last activity: // last activity:
$accounts->each( $set->each(
function (Account $account) { function (Account $account) {
$lastTransaction = $account->transactions()->leftJoin( $lastTransaction = $account->transactions()->leftJoin(
'transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id' 'transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id'
@ -137,10 +143,13 @@ class AccountController extends Controller
$account->lastActivityDate = null; $account->lastActivityDate = null;
} }
$account->startBalance = Steam::balance($account, Session::get('start')); $account->startBalance = Steam::balance($account, Session::get('start'));
$account->endBalance = Steam::balance($account, Session::get('end')); $account->endBalance = Steam::balance($account, Session::get('end'));
} }
); );
$accounts = new LengthAwarePaginator($set, $total, $size, $page);
$accounts->setPath(route('accounts.index',$what));
return view('accounts.index', compact('what', 'subTitleIcon', 'subTitle', 'accounts')); return view('accounts.index', compact('what', 'subTitleIcon', 'subTitle', 'accounts'));
} }

View File

@ -1,3 +1,6 @@
@if(is_object($accounts) && method_exists($accounts, 'render'))
{!! $accounts->render() !!}
@endif
<table class="table table-striped"> <table class="table table-striped">
<tr> <tr>
<th>&nbsp;</th> <th>&nbsp;</th>
@ -51,3 +54,6 @@
@endforeach @endforeach
</table> </table>
@if(is_object($accounts) && method_exists($accounts, 'render'))
{!! $accounts->render() !!}
@endif