Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix category sort.
James Cole48795d04c10b
diff --git a/resources/assets/v3/js/pages/accounts/index.js b/resources/assets/v3/js/pages/accounts/index.jsindex 39b9b68711..52154a4133 100644--- a/resources/assets/v3/js/pages/accounts/index.js+++ b/resources/assets/v3/js/pages/accounts/index.js@@ -39,8 +39,6 @@ let index = function () {listPageSize: 50,objectType: "invalid",accounts: [],- // page: 1, // TODO obsolete, must be per table.- // totalPages: 1, // TODO obsolete.i18next: null,anonymous: false,loadingPage: true,@@ -50,22 +48,16 @@ let index = function () {debts: {},differences: {},- // functions- formatMoney: formatMoney,-// default settings for sortable tables.storageKey: "",- defaultSortColumn: "order", // TODO obsolete?- defaultSortDirection: "asc", // TODO obsolete?defaultSortColumns: {"main": "order"},defaultSortDirections: {"main": "asc"},defaultPages: {"main": 1},-- // variables necessary for sortable tables.pageNavUrl: "./accounts/",- filter: {}, // TODO needs change when doing multiple tables.+ filter: {},// sort functions, imported+ formatMoney: formatMoney,updateHistory: updateHistory,initFromLocalStorage: initFromLocalStorage,initFromQueryParams: initFromQueryParams,@@ -166,7 +158,6 @@ let index = function () {return account;},downloadObjects() {-// since this function only downloads for table "main", it is safe to extract only "main" from the filter object.this.sortableTable.loadingNewSort = true;let sort = "asc" === this.sortableTable.sortDirections["main"] ? this.sortableTable.sortColumns["main"] : "-" + this.sortableTable.sortColumns["main"];diff --git a/resources/assets/v3/js/pages/categories/index.js b/resources/assets/v3/js/pages/categories/index.jsindex e5f47465c5..46b6f84b00 100644--- a/resources/assets/v3/js/pages/categories/index.js+++ b/resources/assets/v3/js/pages/categories/index.js@@ -25,7 +25,7 @@ import Alpine from "@alpinejs/csp";import formatMoney from "../../util/format-money.js";import formatDate from "../../util/format-date.js";import i18next from "i18next";-import {initFromLocalStorage, initFromQueryParams, sortableTable, storeFilterAndSort, updateHistory, respondToSortChange} from "../shared/sortable-tables.js";+import {initFromLocalStorage, initFromQueryParams, respondToSortChange, sortableTable, storeFilterAndSort, updateHistory} from "../shared/sortable-tables.js";import Get from "../../api/model/category/get.js";window.enableDates = false;@@ -33,25 +33,22 @@ window.enableDates = false;let index = function () {return {categories: [],- totalPages: 0,- page: 1,i18next: null,anonymous: false,loadingPage: true,convertToPrimary: false,- // functions- formatMoney: formatMoney,- formatDate: formatDate,-- // default settings for sorting- pageNavUrl: "./categories/",- storageKey: "categories-index",- defaultSortColumn: "name",- defaultSortDirection: "asc",+ // default settings for sortable tables.+ storageKey: "",+ defaultSortColumns: {"main": "name"},+ defaultSortDirections: {"main": "asc"},+ defaultPages: {"main": 1},filter: {},+ pageNavUrl: "./categories/",// sort functions, imported+ formatMoney: formatMoney,+ formatDate: formatDate,updateHistory: updateHistory,storeFilterAndSort: storeFilterAndSort,initFromLocalStorage: initFromLocalStorage,@@ -64,17 +61,22 @@ let index = function () {this.initFromQueryParams();// create sortable table.- this.sortableTable = new sortableTable("main");+ let tables = ["main"];+ for(let i = 0; i < tables.length; i++) {+ let table = tables[i];+ this.filter[table] = {};+ }+ this.sortableTable = new sortableTable(tables);// prepare some varsthis.i18next = i18next;this.anonymous = window.store.get("anonymous");// configure sortable table with final result (not filter).- this.sortableTable.sortColumn = this.defaultSortColumn;- this.sortableTable.sortDirection = this.defaultSortDirection;+ this.sortableTable.sortColumns = this.defaultSortColumns;+ this.sortableTable.sortDirections = this.defaultSortDirections;this.sortableTable.storageKey = this.storageKey;- this.sortableTable.page = this.page;+ this.sortableTable.pages = this.defaultPages;// initialize sortable table.this.sortableTable.init(this);@@ -84,20 +86,33 @@ let index = function () {this.downloadObjects();},downloadObjects() {+ // since this function only downloads for table "main", it is safe to extract only "main" from the filter object.this.sortableTable.loadingNewSort = true;- let sort = "asc" === this.sortableTable.sortDirection ? this.sortableTable.sortColumn : "-" + this.sortableTable.sortColumn;+ let sort = "asc" === this.sortableTable.sortDirections["main"] ? this.sortableTable.sortColumns["main"] : "-" + this.sortableTable.sortColumns["main"];++ // catch undefined stuff.+ if('-undefined' === sort) {+ sort = "asc" === this.defaultSortDirections["main"] ? this.defaultSortColumns["main"] : "-" + this.defaultSortColumns["main"];+ }+this.convertToPrimary = window.store.get("convert_to_primary");let locale = window.store.get("locale");new Get().list({active: this.active,sort: sort,- page: this.page,+ page: this.sortableTable.pages["main"],filter: JSON.parse(JSON.stringify(this.filter)),}).then((response) => {this.categories = [];- this.totalPages = parseInt(response.data.meta.pagination.total_pages);++ this.sortableTable.totalPages["main"] = parseInt(response.data.meta.pagination.total_pages);+ const length = response.data.data.length;+ if(this.sortableTable.totalPages["main"] <= this.sortableTable.pages["main"] && 0 === length) {+ this.sortableTable.pages["main"] = this.sortableTable.totalPages["main"];+ this.downloadObjects();+ }for (let i = 0; i < response.data.data.length; i++) {if (Object.hasOwn(response.data.data, i)) {@@ -107,7 +122,7 @@ let index = function () {if (null !== current.attributes.last_activity) {lastActivity = formatDate(current.attributes.last_activity,- i18next.t("config.date_time_fns", { lng: locale }),+ i18next.t("config.date_time_fns", {lng: locale}),locale,);noLastActivity = false;diff --git a/resources/views/categories/index.blade.php b/resources/views/categories/index.blade.phpindex 57d75c8b26..302ac7bbf4 100644--- a/resources/views/categories/index.blade.php+++ b/resources/views/categories/index.blade.php@@ -16,8 +16,8 @@:route="route('categories.create') . '?_from=' . urlencode($FF3_FROM)":linkTitle="__('firefly.create_new_category')"/><div class="card-body p-0">- <template x-if="totalPages > 1">- <x-elements.alpine.page-navigation/>+ <template x-if="sortableTable.totalPages.main > 1">+ <x-elements.alpine.page-navigation sort-identifier="main"/></template><table data-sort-identifier="main" class="table table-valign-middle table-sm table-hover sortable"><thead>@@ -53,8 +53,8 @@</tbody></table>- <template x-if="totalPages > 1">- <x-elements.alpine.page-navigation/>+ <template x-if="sortableTable.totalPages.main > 1">+ <x-elements.alpine.page-navigation sort-identifier="main"/></template><x-elements.card-footer-with-menu