Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix sort and nav.
James Cole94ce2301ba1f
diff --git a/resources/assets/v3/js/pages/accounts/index.js b/resources/assets/v3/js/pages/accounts/index.jsindex c7dc61cd62..07b1f10346 100644--- a/resources/assets/v3/js/pages/accounts/index.js+++ b/resources/assets/v3/js/pages/accounts/index.js@@ -22,12 +22,14 @@ import "../../boot/bootstrap.js";import sidebar from "../shared/sidebar.js";import dates from "../shared/dates.js";import Alpine from "alpinejs";-import { getVariable } from "../../store/get-variable.js";+import {getVariable} from "../../store/get-variable.js";import Put from "../../api/model/account/put.js";import Get from "../../api/model/account/get.js";-import { format } from "date-fns";+import {format} from "date-fns";import formatMoney from "../../util/format-money.js";import i18next from "i18next";+import {addDrag} from "../shared/drag-and-droppable-rows.js";+import {nextTick} from "alpinejs/src/nextTick.js";window.enableDates = false;@@ -43,16 +45,19 @@ let index = function () {loading: true,active: true,pageNavUrl: "./accounts/",+ handleFunc: null,+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);+ 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() {+ this.handleFunc = this.handlePageClick.bind(this);const page = window.location.href.split("?")[0].split("/");- if('inactive-accounts' === page[page.length -2]) {+ if ('inactive-accounts' === page[page.length - 2]) {this.active = false;}@@ -68,7 +73,6 @@ let index = function () {// grab the account list.this.downloadAccounts();-// get accounts by initial sort.document.querySelectorAll("table.sortable th").forEach((el) => {el.addEventListener("click", (event) => {@@ -83,17 +87,16 @@ let index = function () {this.downloadAccounts();});});-getVariable("listPageSize").then((listPageSize) => {this.listPageSize = listPageSize;- //addDrag();+ addDrag();document.addEventListener("firefly-iii-drag-complete", (e) => {for (let i = 0; i < e.detail.length; i++) {if (Object.hasOwn(e.detail, i)) {let item = e.detail[i];if (item.order !== item.currentOrder) {// PUT new order to system.- new Put().put({ order: item.order }, { id: item.id });+ new Put().put({order: item.order}, {id: item.id});// save new order as current order in the row.document.querySelector(`tr[data-id="${item.id}"]`)@@ -120,7 +123,7 @@ let index = function () {.then((response) => {this.accounts = [];this.totalPages = parseInt(response.data.meta.pagination.total_pages);- for (let i = 1; i < response.data.data.length; i++) {+ for (let i = 0; i < response.data.data.length; i++) {if (Object.hasOwn(response.data.data, i)) {let current = response.data.data[i];let balanceDifference = formatMoney(@@ -192,8 +195,9 @@ let index = function () {this.accounts.push(account);}}+ console.log('Count of accounts', this.accounts.length);this.loading = false;- if(0 === this.accounts.length) {+ if (0 === this.accounts.length) {document.querySelectorAll('.data-holder').forEach((el) => {el.classList.add('d-none');})@@ -210,23 +214,31 @@ let index = function () {if (null === date) {return "";}- return format(new Date(date), i18next.t("config.date_time_fns_short", { lng: window.store.get("locale") }));+ return format(new Date(date), i18next.t("config.date_time_fns_short", {lng: window.store.get("locale")}));+ },+ handlePageClick(e) {+ let link = e.currentTarget;++ let page = parseInt(link.dataset.page);+ console.log('Click detected requested page ', page);+ if (isNaN(page)) {+ e.preventDefault();+ return false;+ }+ this.page = page;+ console.log('Page set to ', this.page);+ this.updateHistory();+ this.downloadAccounts();+ e.preventDefault();+ nextTick(() => {+ this.capturePageNavigation();+ });+ return false;},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;- });+ el.removeEventListener('click', this.handleFunc);+ el.addEventListener('click', this.handleFunc);});}};diff --git a/resources/views/accounts/index.blade.php b/resources/views/accounts/index.blade.phpindex c3d41420a0..deb8451021 100644--- a/resources/views/accounts/index.blade.php+++ b/resources/views/accounts/index.blade.php@@ -10,9 +10,6 @@</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 }}">@@ -56,7 +53,7 @@</thead><tbody><template x-for="account in accounts" :key="account.id">- <tr>+ <tr :data-id="account.id"><td><template x-if="('asset' === objectType || 'liabilities' === objectType) && 'asc' === sortDirection && 'order' === sortColumn && accounts.length > 1"><span class="btn btn-outline-secondary btn-sm bi bi-list object-handle"></span>diff --git a/resources/views/components/elements/alpine/page-navigation.blade.php b/resources/views/components/elements/alpine/page-navigation.blade.phpindex a6c99c9680..4bd2a514d6 100644--- a/resources/views/components/elements/alpine/page-navigation.blade.php+++ b/resources/views/components/elements/alpine/page-navigation.blade.php@@ -13,7 +13,7 @@<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" :data-page="(current)" :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,8 @@</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" :data-page="(page+1)" :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>