Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Improve page nav for accounts.
James Cole6c5bd171ebc2
diff --git a/app/Http/Controllers/Account/IndexController.php b/app/Http/Controllers/Account/IndexController.phpindex d4fc06c978..ea6db0b9dd 100644--- a/app/Http/Controllers/Account/IndexController.php+++ b/app/Http/Controllers/Account/IndexController.php@@ -113,8 +113,7 @@ final class IndexController extends Controller// make paginator:$accounts = new LengthAwarePaginator($accounts, $total, $pageSize, $page);- $accounts->setPath(route('accounts.inactive.index', [$objectType]));-+ $accounts->setPath(route('accounts.index', [$objectType]));return view('accounts.index', ['objectType' => $objectType,'inactivePage' => $inactivePage,@@ -122,6 +121,7 @@ final class IndexController extends Controller'subTitleIcon' => $subTitleIcon,'subTitle' => $subTitle,'page' => $page,+ 'accounts' => [],// 'accounts' => $accounts,]);}diff --git a/config/translations.php b/config/translations.phpindex 5e2d293330..bacf8a686a 100644--- a/config/translations.php+++ b/config/translations.php@@ -123,6 +123,8 @@ return ['administration_role_mng_rules','administration_role_mng_recurring','administration_role_mng_webhooks',+ 'may_inactive_accounts_link',+ 'no_inactive_accounts','administration_role_mng_currencies','administration_role_view_reports','administration_role_full',diff --git a/resources/assets/v3/js/pages/accounts/index.js b/resources/assets/v3/js/pages/accounts/index.jsindex 2733bac047..c7dc61cd62 100644--- a/resources/assets/v3/js/pages/accounts/index.js+++ b/resources/assets/v3/js/pages/accounts/index.js@@ -40,9 +40,23 @@ let index = function () {sortDirection: "asc",page: 1,totalPages: 1,+ loading: true,+ active: true,pageNavUrl: "./accounts/",++ updateHistory() {+ if (history.pushState) {+ let newUrl = window.location.protocol + "//" + window.location.host + window.location.pathname + "?page="+this.page+"&column=" + this.sortColumn + "&direction=" + this.sortDirection;+ window.history.pushState({ path: newUrl }, "", newUrl);+ }+ },init() {const page = window.location.href.split("?")[0].split("/");+ if('inactive-accounts' === page[page.length -2]) {+ this.active = false;+ }++this.objectType = page[page.length - 1].substring(0, 15);this.pageNavUrl = "./accounts/" + this.objectType;const params = new Proxy(new URLSearchParams(window.location.search), {@@ -57,7 +71,6 @@ let index = function () {// get accounts by initial sort.document.querySelectorAll("table.sortable th").forEach((el) => {- // console.log('El', el);el.addEventListener("click", (event) => {let newColumn = event.currentTarget.dataset.column;if (newColumn === this.sortColumn) {@@ -66,19 +79,7 @@ let index = function () {if (newColumn !== this.sortColumn) {this.sortColumn = newColumn;}- console.log("Will now sort on column", newColumn, "direction", this.sortDirection);- if (history.pushState) {- let newurl =- window.location.protocol +- "//" +- window.location.host +- window.location.pathname +- "?column=" +- this.sortColumn +- "&direction=" +- this.sortDirection;- window.history.pushState({ path: newurl }, "", newurl);- }+ this.updateHistory();this.downloadAccounts();});});@@ -100,7 +101,6 @@ let index = function () {}}}- // console.log(e.detail);});});},@@ -108,10 +108,9 @@ let index = function () {let sort = "asc" === this.sortDirection ? this.sortColumn : "-" + this.sortColumn;let start = window.store.get("start");let end = window.store.get("end");- let active = true;new Get().list({- active: active,+ active: this.active,sort: sort,page: this.page,type: this.objectType,@@ -164,7 +163,6 @@ let index = function () {lastActivity = i18next.t("firefly.never");noLastActivity = true;}- //console.log(current);let account = {id: parseInt(current.id),name: current.attributes.name,@@ -194,6 +192,12 @@ let index = function () {this.accounts.push(account);}}+ this.loading = false;+ if(0 === this.accounts.length) {+ document.querySelectorAll('.data-holder').forEach((el) => {+ el.classList.add('d-none');+ })+ }});},addSpaces(iban) {@@ -208,6 +212,23 @@ let index = function () {}return format(new Date(date), i18next.t("config.date_time_fns_short", { lng: window.store.get("locale") }));},+ capturePageNavigation() {+ document.querySelectorAll('a.page-link').forEach((el) => {+ el.addEventListener('click', (e) => {+ let link = e.currentTarget;+ let page = parseInt(link.dataset.page);+ if (isNaN(page)) {+ e.preventDefault();+ return false;+ }+ this.page = page;+ this.updateHistory();+ this.downloadAccounts();+ e.preventDefault();+ return false;+ });+ });+ }};};@@ -218,22 +239,18 @@ const comps = {};function loadPage(comps) {- // console.log('loadPage');Object.keys(comps).forEach((comp) => {let data = comps[comp]();Alpine.data(comp, () => data);- // console.log(comp);});Alpine.start();}// wait for load until bootstrapped event is received.document.addEventListener("firefly-iii-bootstrapped", () => {- // console.log('Loaded through event listener.');loadPage(comps);});// or is bootstrapped before event is triggered.if (window.bootstrapped) {- // console.log('Loaded through window variable.');loadPage(comps);}diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.phpindex 2df0970055..bba34d0ebd 100644--- a/resources/lang/en_US/firefly.php+++ b/resources/lang/en_US/firefly.php@@ -1976,7 +1976,10 @@ return ['account_locked_currency' => 'The currency of this account must remain :name as long as piggy banks are linked to it.','i_am_owed_amount' => 'I am owed amount','i_owe_amount' => 'I owe amount',+ 'may_inactive_accounts_link' => 'If all your accounts are inactive, <a href="{{url}}">you can view them on this separate page</a>.',+ 'no_inactive_accounts' => 'You have no inactive (archived) accounts. <a href="{{url}}">Go back to your list of active accounts</a>.','inactive_account_link' => 'You have :count inactive (archived) account, which you can view on this separate page.|You have :count inactive (archived) accounts, which you can view on this separate page.',+ 'inactive_account_link_js' => 'You can view inactive accounts on this separate page.','all_accounts_inactive' => 'These are your inactive accounts.','active_account_link' => 'This link goes back to your active accounts.','account_missing_transaction' => 'Account #:id (":name") cannot be viewed directly, but Firefly is missing redirect information.',diff --git a/resources/views/accounts/index.blade.php b/resources/views/accounts/index.blade.phpindex 4f350455db..c3d41420a0 100644--- a/resources/views/accounts/index.blade.php+++ b/resources/views/accounts/index.blade.php@@ -1,8 +1,20 @@@extends('layout.v3.session')@section('content')- @if(count($accounts) > 0)<div class="row" x-data="index">- <div class="col-lg-12 col-md-12 col-sm-12">+ <template x-if="true === loading">+ <div class="col-lg-12 text-center">+ <div id="status-box" class="p-3 install-box-border">+ <div class="spinner-border spinner-border-sm" role="status">+ <span class="visually-hidden">{{ __('firefly.thinking') }}</span>+ </div>+ </div>+ </div>+ </template>+ <template x-if="true">+ <div class="blabla"></div>+ </template>++ <div class="col-lg-12 col-md-12 col-sm-12 data-holder"><div class="card" id="account-index-{{ $objectType }}"><x-elements.card-header-with-menu :cardTitle="trans('firefly.'.$objectType.'_accounts')" :route="route('accounts.create', $objectType) . '?_from=' . urlencode($FF3_FROM)" :linkTitle="__('firefly.make_new_'. $objectType . '_account')"/><div class="card-body p-0">@@ -164,53 +176,50 @@</template></tbody></table>+<template x-if="totalPages > 1"><x-elements.alpine.page-navigation /></template></div><x-elements.card-footer-with-menu :route="route('accounts.create', $objectType) . '?_from=' . urlencode($FF3_FROM)" :linkTitle="__('firefly.make_new_'. $objectType . '_account')" /></div>- @if($inactiveCount > 0 && !$inactivePage)- <p class="m-2"><small>- <em>- <a href="{{ route('accounts.inactive.index', $objectType) }}" class="text-muted">- {{ trans_choice('firefly.inactive_account_link', $inactiveCount) }}- </a>- </em>- </small>- </p>- @endif- @if($inactivePage)- <p class="m-2"><small class="text-muted">- <em>- {{ trans('firefly.all_accounts_inactive') }}- <a href="{{ route('accounts.index', $objectType) }}">- {{ trans('firefly.active_account_link', ['count' => $inactiveCount]) }}- </a>- </em>- </small>- </p>- @endif</div>+ <template x-if="0 === accounts.length && true === active && false === loading">+ <x-empty-page :route="route('accounts.create', [$objectType]) . '?_from=' . urlencode($FF3_FROM)" type="accounts" :object-type="$objectType" />+ </template>+ <template x-if="0 === accounts.length && true === active">+ <p class="text-center"><small>+ <em>+ <span x-text="i18next.t('firefly.may_inactive_accounts_link', {url: '{{ route('accounts.inactive.index', $objectType) }}'})"></span>+ </em>+ </small>+ </p>+ </template>+ <template x-if="0 !== accounts.length && true === active">+ <p class="text-center"><small>+ <em>+ <span x-text="i18next.t('firefly.inactive_account_link_js')"></span>+ </em>+ </small>+ </p>+ </template>+ <template x-if="0 !== accounts.length && false === active">+ <p class="text-center"><small>+ <em>+ <a href="{{ route('accounts.index', $objectType) }}"><span x-text="i18next.t('firefly.active_account_link')"></span></a>+ </em>+ </small>+ </p>+ </template>+ <template x-if="0 === accounts.length && false === active">+ <p class="text-center"><small>+ <em>+ <span x-text="i18next.t('firefly.no_inactive_accounts', {url: '{{ route('accounts.index', $objectType) }}'})"></span>+ </em>+ </small>+ </p>+ </template></div>- @endif- @if(0 === count($accounts) && 1 === $page)- @php- $shownDemo = true- @endphp- <x-empty-page :route="route('accounts.create', [$objectType]) . '?_from=' . urlencode($FF3_FROM)" type="accounts" :object-type="$objectType" />- @if($inactiveCount > 0)- <p class="text-center"><small>- <em>- <a href="{{ route('accounts.inactive.index', $objectType) }}" class="text-muted">- {{ trans_choice('firefly.inactive_account_link', $inactiveCount) }}- </a>- </em>- </small>- </p>- @endif-- @endif@endsection@section('scripts')@vite(['js/pages/accounts/index.js'])diff --git a/resources/views/components/elements/alpine/page-navigation.blade.php b/resources/views/components/elements/alpine/page-navigation.blade.phpindex 964362802a..a6c99c9680 100644--- a/resources/views/components/elements/alpine/page-navigation.blade.php+++ b/resources/views/components/elements/alpine/page-navigation.blade.php@@ -1,4 +1,4 @@-<template x-if="totalPages > 1">+<template x-if="totalPages > 1" x-effect="capturePageNavigation()"><div class="m-2"><nav><ul class="pagination">@@ -7,13 +7,13 @@<span class="page-link" aria-hidden="true">‹</span></template><template x-if="page > 1">- <a class="page-link" :href="pageNavUrl + '?page=' + (page - 1)" rel="prev" aria-label="{!! __('pagination.previous') !!}" title="{!! __('pagination.previous') !!}">‹</a>+ <a class="page-link" :data-page="(page-1)" :href="pageNavUrl + '?page=' + (page - 1)" rel="prev" aria-label="{!! __('pagination.previous') !!}" title="{!! __('pagination.previous') !!}">‹</a></template></li><template x-for="current in totalPages" :key="current"><li class="page-item" :class="{'page-item': true, 'active': current === page}"><template x-if="current !== page">- <a class="page-link" :href="pageNavUrl+'?page=' + current" x-text="current" :aria-label="current"></a>+ <a class="page-link" :data-page="(current)" :href="pageNavUrl+'?page=' + current" x-text="current" :aria-label="current"></a></template><template x-if="current === page"><span class="page-link" x-text="current"></span>@@ -22,7 +22,7 @@</template><li class="{'page-item': true, 'disabled': totalPages === page" :aria-disabled="totalPages === page ? 'true' : 'false'" aria-label="{!! __('pagination.next') !!}"><template x-if="totalPages > page">- <a class="page-link" :href="pageNavUrl+'?page=' + (page +1)" rel="next" aria-label="{!! __('pagination.next') !!}" title="{!! __('pagination.next') !!}">›</a>+ <a class="page-link" :data-page="(page+1)" :href="pageNavUrl+'?page=' + (page +1)" rel="next" aria-label="{!! __('pagination.next') !!}" title="{!! __('pagination.next') !!}">›</a></template><template x-if="totalPages === page"><span class="page-link" aria-hidden="true">›</span>