Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
First version of a slightly more dynamic sort and filter table function.
James Coleac6b44f799bd
diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.phpindex c2cec98bce..f993052a8d 100644--- a/app/Repositories/Account/AccountRepository.php+++ b/app/Repositories/Account/AccountRepository.php@@ -44,7 +44,9 @@ use FireflyIII\Support\Repositories\UserGroup\UserGroupInterface;use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;use Illuminate\Database\Eloquent\Builder as EloquentBuilder;use Illuminate\Database\Eloquent\Relations\HasMany;+use Illuminate\Database\Query\JoinClause;use Illuminate\Support\Collection;+use Illuminate\Support\Facades\DB;use Illuminate\Support\Facades\Log;use Illuminate\Support\Facades\Storage;use Override;@@ -248,16 +250,30 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac$filter ??= [];if (0 !== count($sort)) {foreach ($sort as $param) {- if (in_array($param[0], $allowed, true)) {- $query->orderBy($param[0], $param[1]);- ++$sorted;- }+ // basic sort:+ if (in_array($param[0], $allowed, true)) {+ $query->orderBy($param[0], $param[1]);+ ++$sorted;+ }}}// add filter parameters.$allowed = config('firefly.allowed_filter_parameters.Account', []);if (0 !== count($filter)) {foreach ($filter as $field => $search) {+ if('account_number_and_iban' === $field) {+ $query->leftJoin('account_meta', function(JoinClause $join)+ {+ $join->on('accounts.id', '=', 'account_meta.account_id');+ $join->on('account_meta.name','=',DB::raw("'account_number'"));+ });++ $query->where(function(EloquentBuilder $q1) use ($search) {+ $q1->whereLike('account_meta.data', sprintf('%%%s%%', $search));+ $q1->orWhereLike('accounts.iban', sprintf('%%%s%%', $search));+ });+ continue;+ }if (in_array($field, $allowed, true)) {if ('' !== (string) $search) {$query->whereLike($field, sprintf('%%%s%%', $search));@@ -276,6 +292,8 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac$query->orderBy('accounts.id', 'ASC');}+ // add post-db filter:+return $query->get(['accounts.*']);}diff --git a/config/firefly.php b/config/firefly.phpindex c735ced6a9..9846f5cdf6 100644--- a/config/firefly.php+++ b/config/firefly.php@@ -851,6 +851,7 @@ return ['allowed_filter_parameters' => ['Account' => ['name',+ 'account_number_and_iban'],],'allowed_sort_parameters' => [diff --git a/resources/assets/v3/js/boot/bootstrap.js b/resources/assets/v3/js/boot/bootstrap.jsindex 4be4be9eb9..310d568eec 100644--- a/resources/assets/v3/js/boot/bootstrap.js+++ b/resources/assets/v3/js/boot/bootstrap.js@@ -28,10 +28,10 @@ import store from "../store/store.js";import axios from "axios";import Shepherd from "shepherd.js";import "cally";-import { getFreshVariable } from "../store/get-fresh-variable.js";-import { getVariables } from "../store/get-variables.js";-import { getViewRange } from "../support/get-viewrange.js";-import { loadTranslations } from "../support/load-translations.js";+import {getFreshVariable} from "../store/get-fresh-variable.js";+import {getVariables} from "../store/get-variables.js";+import {getViewRange} from "../support/get-viewrange.js";+import {loadTranslations} from "../support/load-translations.js";import i18next from "i18next";window.bootstrapped = false;@@ -42,127 +42,124 @@ window.axios = axios;window.axios.defaults.headers.common["X-Requested-With"] = "XMLHttpRequest";// always grab the preference "marker" from Firefly III.-getFreshVariable("lastActivity")- .then((serverValue) => {- if (null === serverValue) {- // console.log("Server value is null in getFreshVariable.");- throw new Error("401 in getFreshVariable.");- }- const localValue = store.get("lastActivity");- store.set("cacheValid", localValue === serverValue);- store.set("lastActivity", serverValue);- // console.log('Server value = ' + serverValue);- // console.log('Local value: ' + localValue);- // console.log('Cache valid: ' + (localValue === serverValue));- })- .then(() => {- Promise.resolve(- getVariables(["viewRange", "anonymous", "darkMode", "locale", "language", "convert_to_primary"]),- ).then((values) => {- const range = getViewRange(values.viewRange, new Date());- if (!store.get("start") || !store.get("end")) {- // calculate new start and end, and store them.- store.set("start", range.start);- store.set("end", range.end);- }- // always set defaultStart and defaultEnd- store.set("viewRange", values.viewRange);- store.set("defaultStart", range.start);- store.set("defaultEnd", range.end);- store.set("anonymous", values.anonymous);- //- if ("equal" === values.locale) {- values.locale = values.language;- }- const replacedLocale = values.locale.replace("_", "-");- const replacedLanguage = values.language.replace("_", "-");-- // save local in window.__ something- window.__localeId__ = replacedLocale;- store.set("language", replacedLanguage);- store.set("locale", replacedLocale);- console.log("Ready with bootstrap for this page.");- loadTranslations(replacedLanguage, replacedLocale).then(function () {- window.i18next = i18next;- const event = new Event("firefly-iii-bootstrapped");- document.dispatchEvent(event);- window.bootstrapped = true;- // console.log('Bootstrapped!');-- // page may have an introduction necessary to be played.- if (!window.showTour) {- return;- }- const url = "/";- let site = axios.create({- baseURL: url,- withCredentials: true,- });- axios.defaults.withCredentials = true;- axios.defaults.baseURL = url;-- site.get(window.routeStepsUrl).then(function (data) {- let hints = data.data;-- const tour = new Shepherd.Tour({- useModalOverlay: true,- defaultStepOptions: {- // classes: 'shadow-md bg-purple-dark',- scrollTo: true,- cancelIcon: {- enabled: true,- },- },+const serverValue = await getFreshVariable("lastActivity");+if (null === serverValue) {+ // console.log("Server value is null in getFreshVariable.");+ throw new Error("401 in getFreshVariable.");+}+const localValue = store.get("lastActivity");+store.set("cacheValid", localValue === serverValue);+store.set("lastActivity", serverValue);++// get a bunch of variables, and then use them to build the store+const preferences = await getVariables(["viewRange", "anonymous", "darkMode", "locale", "language", "convert_to_primary"]);++const range = getViewRange(preferences.viewRange, new Date());+if (!store.get("start") || !store.get("end")) {+ // calculate new start and end, and store them.+ store.set("start", range.start);+ store.set("end", range.end);+}+// always set defaultStart and defaultEnd+store.set("viewRange", preferences.viewRange);+store.set("defaultStart", range.start);+store.set("defaultEnd", range.end);+store.set("anonymous", preferences.anonymous);+//+if ("equal" === preferences.locale) {+ preferences.locale = preferences.language;+}+const replacedLocale = preferences.locale.replace("_", "-");+const replacedLanguage = preferences.language.replace("_", "-");++// save local in window.__ something+window.__localeId__ = replacedLocale;+store.set("language", replacedLanguage);+store.set("locale", replacedLocale);+console.log("Ready with bootstrap for this page.");++// need the language to be loaded first, so continue only once we have it.+await loadTranslations(replacedLanguage, replacedLocale)+const event = new Event("firefly-iii-bootstrapped");+document.dispatchEvent(event);+window.bootstrapped = true;++// page may have an introduction necessary to be played.+if (!window.showTour) {+ return;+}+loadTour();++++++function loadTour() {+ const url = "/";+ let site = axios.create({baseURL: url, withCredentials: true,});+ axios.defaults.withCredentials = true;+ axios.defaults.baseURL = url;++ site.get(window.routeStepsUrl).then(function (data) {+ let hints = data.data;++ const tour = new Shepherd.Tour({+ useModalOverlay: true,+ defaultStepOptions: {+ // classes: 'shadow-md bg-purple-dark',+ scrollTo: true,+ cancelIcon: {+ enabled: true,+ },+ },+ });+ // cancel or complete+ tour.on("cancel", () => {+ site.post(window.routeForFinishedTour);+ });+ tour.on("complete", () => {+ site.post(window.routeForFinishedTour);+ });++ for (let i = 0; i < hints.length; i++) {+ if (Object.hasOwn(hints, i)) {+ let hint = hints[i];++ let buttons = [];+ if (i > 0) {+ buttons.push({+ text: i18next.t("firefly.intro_prev_label"),+ action: tour.back,});- // cancel or complete- tour.on("cancel", () => {- site.post(window.routeForFinishedTour);+ }+ if (i < hints.length - 1) {+ buttons.push({+ text: i18next.t("firefly.intro_next_label"),+ action: tour.next,});- tour.on("complete", () => {- site.post(window.routeForFinishedTour);+ }+ if (i === hints.length - 1) {+ // console.log("Add complete");+ buttons.push({+ text: i18next.t("firefly.intro_done_label"),+ action: tour.complete,});+ }- for (let i = 0; i < hints.length; i++) {- if (Object.hasOwn(hints, i)) {- let hint = hints[i];-- let buttons = [];- if (i > 0) {- buttons.push({- text: i18next.t("firefly.intro_prev_label"),- action: tour.back,- });- }- if (i < hints.length - 1) {- buttons.push({- text: i18next.t("firefly.intro_next_label"),- action: tour.next,- });- }- if (i === hints.length - 1) {- // console.log("Add complete");- buttons.push({- text: i18next.t("firefly.intro_done_label"),- action: tour.complete,- });- }-- let step = {- // id: 'example-step',- text: hint.text,- buttons: buttons,- };- if (Object.hasOwn(hint, "element")) {- step.attachTo = {- element: hint.element,- on: hint.position,- };- }- tour.addStep(step);- }- }- tour.start();- });- });- });+ let step = {+ // id: 'example-step',+ text: hint.text,+ buttons: buttons,+ };+ if (Object.hasOwn(hint, "element")) {+ step.attachTo = {+ element: hint.element,+ on: hint.position,+ };+ }+ tour.addStep(step);+ }+ }+ tour.start();});+}diff --git a/resources/assets/v3/js/pages/accounts/create.js b/resources/assets/v3/js/pages/accounts/create.jsindex 2506f82818..5b82af2e1f 100644--- a/resources/assets/v3/js/pages/accounts/create.js+++ b/resources/assets/v3/js/pages/accounts/create.js@@ -37,11 +37,11 @@ let create = function () {let direction = event.target.value;if ("credit" === direction) {document.querySelector('label[for="ffInput_opening_balance"]').textContent =- window.i18next.t("firefly.i_am_owed_amount");+ i18next.t("firefly.i_am_owed_amount");}if ("debit" === direction) {document.querySelector('label[for="ffInput_opening_balance"]').textContent =- window.i18next.t("firefly.i_owe_amount");+ i18next.t("firefly.i_owe_amount");}});// also change it the first time arounddiff --git a/resources/assets/v3/js/pages/accounts/edit.js b/resources/assets/v3/js/pages/accounts/edit.jsindex 25b5b130d1..843f186277 100644--- a/resources/assets/v3/js/pages/accounts/edit.js+++ b/resources/assets/v3/js/pages/accounts/edit.js@@ -37,18 +37,18 @@ let edit = function () {let direction = event.target.value;if ("credit" === direction) {document.querySelector('label[for="ffInput_opening_balance"]').textContent =- window.i18next.t("firefly.i_am_owed_amount");+ i18next.t("firefly.i_am_owed_amount");}if ("debit" === direction) {document.querySelector('label[for="ffInput_opening_balance"]').textContent =- window.i18next.t("firefly.i_owe_amount");+ i18next.t("firefly.i_owe_amount");}});// also change it the first time aroundlet direction = el.value;if ("credit" === direction) {document.querySelector('label[for="ffInput_opening_balance"]').textContent =- window.i18next.t("firefly.i_am_owed_amount");+ i18next.t("firefly.i_am_owed_amount");}if ("debit" === direction) {document.querySelector('label[for="ffInput_opening_balance"]').textContent =diff --git a/resources/assets/v3/js/pages/accounts/index.js b/resources/assets/v3/js/pages/accounts/index.jsindex 94b1664e6d..87548f76a0 100644--- a/resources/assets/v3/js/pages/accounts/index.js+++ b/resources/assets/v3/js/pages/accounts/index.js@@ -29,6 +29,7 @@ import format from "../../util/format.js";import formatMoney from "../../util/format-money.js";import i18next from "i18next";import { addDrag } from "../shared/drag-and-droppable-rows.js";+import {sortableTable} from "../shared/sortable-tables.js";window.enableDates = true;@@ -36,28 +37,38 @@ let index = function () {return {listPageSize: 50,objectType: "invalid",- sortColumn: "order",accounts: [],- sortDirection: "asc",page: 1,i18next: null,anonymous: false,totalPages: 1,loadingPage: true,convertToPrimary: false,- loadingNewSort: true,active: true,- pageNavUrl: "./accounts/",- handleFunc: null,storageKey: "",sums: {},debts: {},differences: {},- isFiltering: false,- filter: {- name: "",- },++ // functionsformatMoney: formatMoney,++ // default settings for sorting+ defaultSortColumn: 'order',+ defaultSortDirection: 'asc',++ // variables necessary for sorting tables.+ handleFunc: null,+ pageNavUrl: "./accounts/",+ sortColumn: "order",+ sortDirection: "asc",+ loadingNewSort: true,+ isFiltering: false,+ filter: {},++ // sort functions+ sortableTable: null,+objectToQueryString(obj, prefix) {if (null === obj) {return "";@@ -108,112 +119,66 @@ let index = function () {},init() {- this.$watch("filter.name", (value) => this.updateFilterValue("name", value));-- this.i18next = i18next;- this.anonymous = window.store.get("anonymous");- this.handleFunc = this.handlePageClick.bind(this);const page = window.location.href.split("?")[0].split("/");- if ("inactive-accounts" === page[page.length - 2]) {- this.active = false;- }- let defaultSortColumn = "order";- let defaultSortDirection = "asc";this.objectType = page[page.length - 1].substring(0, 15);+ this.i18next = i18next;+ this.anonymous = window.store.get("anonymous");this.storageKey = "accounts-" + this.objectType + (this.active ? "-active" : "-inactive");+ this.handleFunc = this.handlePageClick.bind(this);this.pageNavUrl = "./accounts/" + this.objectType;- const params = new Proxy(new URLSearchParams(window.location.search), {- get: (searchParams, prop) => searchParams.get(prop),- });- // shitty solution but for now it works.- if ("" !== params["filter[name]"]) {- this.filter.name = params["filter[name]"];- this.isFiltering = true;- }+if ("expense" === this.objectType || "revenue" === this.objectType) {- defaultSortColumn = "name";+ this.defaultSortColumn = "name";}++ // sort and paging settings.+ if ("inactive-accounts" === page[page.length - 2]) {+ this.active = false;+ }+let fromStore = window.store.get(this.storageKey);console.log("from store", fromStore);if (fromStore) {- defaultSortColumn = fromStore.column;- defaultSortDirection = fromStore.direction;+ this.defaultSortColumn = fromStore.column;+ this.defaultSortDirection = fromStore.direction;}- this.sortColumn = params.column ?? defaultSortColumn;- this.sortDirection = params.direction ?? defaultSortDirection;- this.page = parseInt(params.page) || 1;+ // document.querySelectorAll('table[data-sort-identifier="main"] thead th[data-filter-column]').forEach((th) => {+ // let column = th.getAttribute('data-filter-column');+ // console.log('[index] Will watch filter for column "' + column + '"');+ // this.$watch('filter.' + column, (newValue, oldValue) => {+ // console.log('filter for column "' + column + '" changed from "' + oldValue + '" to "' + newValue + '"');+ // });+ // });- // grab the account list.- this.downloadAccounts();- // get accounts by initial sort.- document.addEventListener("alpine:initialized", () => {- // add sortable click events.- document.querySelectorAll("table.sortable th.sortable span.title").forEach((el) => {- el.addEventListener("click", (event) => {- let parent = event.currentTarget.parentNode;- let newColumn = parent.dataset.column;- if (newColumn === this.sortColumn) {- this.sortDirection = "asc" === this.sortDirection ? "desc" : "asc";- }- if (newColumn !== this.sortColumn) {- this.sortColumn = newColumn;- }- console.log("New sort instructions", this.sortColumn, this.sortDirection);- this.updateHistory();- this.downloadAccounts();- });- });- // hide search again- document.querySelectorAll("table.sortable .hide-button").forEach((el) => {- el.addEventListener("click", () => {- let column = el.dataset.column;- // show search input again- document.querySelector(`span.title[data-column="${column}"]`).classList.remove("d-none");- document- .querySelector(`span.search-spacer[data-column="${column}"]`)- .classList.remove("d-none");- document.querySelector(`em.search-button[data-column="${column}"]`).classList.remove("d-none");- document.querySelector(`div.search-filter[data-column="${column}"] input`).value = "";-- // remove class from parent if was used to sort- if (null !== document.querySelector(`th.sortable_sorted[data-column="${column}"]`)) {- document- .querySelector(`th.sortable_sorted[data-column="${column}"]`)- .classList.remove("is-searching");- }+ const params = new Proxy(new URLSearchParams(window.location.search), {+ get: (searchParams, prop) => searchParams.get(prop),+ });+ this.sortColumn = params.column ?? this.defaultSortColumn;+ this.sortDirection = params.direction ?? this.defaultSortDirection;+ this.page = parseInt(params.page) || 1;- let input = document.querySelector(`div.search-filter[data-column="${column}"]`);- input.classList.add("d-none");+ this.sortableTable = new sortableTable('main');+ this.sortableTable.sortColumn = params.column ?? this.defaultSortColumn;+ this.sortableTable.sortDirection = params.direction ?? this.defaultSortDirection;+ this.sortableTable.page = this.page;+ this.sortableTable.init(this);- // TODO hardcoded!!- this.filter.name = "";- });- });+ // watch for changes in the sortable table instructions.+ document.addEventListener('sortable-table-sort-change', (event) => {+ console.log('sortable-table-sort-change', event.detail);+ this.sortColumn = event.detail.sortColumn;+ this.sortDirection = event.detail.sortDirection;+ // this.page = event.detail.page;+ this.updateHistory();+ this.downloadAccounts();+ });++ // grab the account list.+ this.downloadAccounts();- // add filterable click events.- document.querySelectorAll("table.sortable .search-button").forEach((el) => {- el.addEventListener("click", () => {- let column = el.dataset.column;- // hide search buttons etc.- el.classList.add("d-none");- document.querySelector(`span.title[data-column="${column}"]`).classList.add("d-none");- document.querySelector(`span.search-spacer[data-column="${column}"]`).classList.add("d-none");- // add class to parent if it's used to sort- if (null !== document.querySelector(`th.sortable_sorted[data-column="${column}"]`)) {- document- .querySelector(`th.sortable_sorted[data-column="${column}"]`)- .classList.add("is-searching");- }- // show search input- let input = document.querySelector(`div.search-filter[data-column="${column}"]`);- input.classList.remove("d-none");- input.querySelector("input").focus();- });- });- });getVariable("listPageSize").then((listPageSize) => {this.listPageSize = listPageSize;diff --git a/resources/assets/v3/js/pages/exchange-rates/rates.js b/resources/assets/v3/js/pages/exchange-rates/rates.jsindex 3acfb53565..92b97bafa3 100644--- a/resources/assets/v3/js/pages/exchange-rates/rates.js+++ b/resources/assets/v3/js/pages/exchange-rates/rates.js@@ -257,9 +257,7 @@ let rates = function () {inverse_id: inverse_id,date_formatted: format(date,- window.i18next.t("config.date_time_fns", { lng: window.store.get("locale") }),- window.store.get("locale"),- ),+ i18next.t("config.date_time_fns", { lng: window.store.get("locale") }), window.store.get("locale"),),date_field: current.attributes.date.substring(0, 10),rate: rate,inverse: "",diff --git a/resources/assets/v3/js/pages/shared/dates.js b/resources/assets/v3/js/pages/shared/dates.jsindex 0ec7375c16..6ef2803c51 100644--- a/resources/assets/v3/js/pages/shared/dates.js+++ b/resources/assets/v3/js/pages/shared/dates.js@@ -113,7 +113,7 @@ export default () => ({// set the title:let locale = window.store.get("locale");- let formatString = this.i18next.t("config.month_and_day_fns", { lng: locale });+ let formatString = i18next.t("config.month_and_day_fns", { lng: locale });let element = document.getElementsByClassName("daterange-holder")[0];element.textContent = format(this.range.start, formatString) + " - " + format(this.range.end, formatString);element.setAttribute("data-start", format(this.range.start, this.preferredFormat, "en-US"));@@ -140,7 +140,7 @@ export default () => ({// generate the default range ("Today")element = document.getElementsByClassName("daterange-today")[0];- let todayString = this.i18next.t("firefly.today");+ let todayString = i18next.t("firefly.today");todayString = String(todayString).charAt(0).toUpperCase() + String(todayString).slice(1);element.textContent = todayString;element.setAttribute("data-start", format(todayRange.start, this.preferredFormat, "en-US"));diff --git a/resources/assets/v3/js/pages/shared/sortable-tables.js b/resources/assets/v3/js/pages/shared/sortable-tables.jsnew file mode 100644index 0000000000..478bcb4dac--- /dev/null+++ b/resources/assets/v3/js/pages/shared/sortable-tables.js@@ -0,0 +1,215 @@+/*+ * sortable-tables.js+ * Copyright (c) 2026 [email protected]+ *+ * This file is part of Firefly III (https://github.com/firefly-iii).+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ */++export class sortableTable {+ tableId = '';+ sortColumn = 'order';+ sortDirection = 'asc';+ isFiltering = false;++ constructor(tableId) {+ this.tableId = tableId;+ console.log('Now in constructor("' + tableId + '")');+ }++ init(parent) {+ const params = new Proxy(new URLSearchParams(window.location.search), {+ get: (searchParams, prop) => searchParams.get(prop),+ });+ // shitty solution but for now it works.+ // if ("" !== params["filter[name]"]) {+ // this.isFiltering = true;+ // }++ queueMicrotask(() => {+ this.updateHeaderClasses();+ this.addClickEvents();+ this.addWatch(parent);+ });+ }++ addWatch(parent) {+ // add a watch for sortColumn, sortDirection and page+ parent.$watch('sortColumn', (newValue, oldValue) => {+ console.log('sortColumn changed from "' + oldValue + '" to "' + newValue + '"');+ // this.updateHeaderClasses();++ });+ parent.$watch('sortDirection', (newValue, oldValue) => {+ console.log('sortDirection changed from "' + oldValue + '" to "' + newValue + '"');+ });+ parent.$watch('page', (newValue, oldValue) => {+ console.log('page changed from "' + oldValue + '" to "' + newValue + '"');+ });+ // loop all filtered columns and watch those values.+ document.querySelectorAll('table[data-sort-identifier="' + this.tableId + '"] thead th[data-filter-column]').forEach((th) => {+ let column = th.getAttribute('data-filter-column');+ console.log('[class] Will watch filter for column "' + column + '"');+ parent.$watch('filter.' + column, (newValue, oldValue) => {+ // parent.filter[column] = newValue;+ console.log('filter for column "' + column + '" changed from "' + oldValue + '" to "' + newValue + '"');+ this.fireSortChangeEvent();+ });+ });+ }++ clickColumnTitle(event) {+ let parent = event.currentTarget.parentNode;+ let newColumn = parent.dataset.sortColumn;+ this.sortDirection = typeof this.sortDirection !== 'undefined' ? this.sortDirection : 'asc';+ if (newColumn === this.sortColumn) {+ this.sortDirection = "asc" === this.sortDirection ? "desc" : "asc";+ }+ if (newColumn !== this.sortColumn) {+ this.sortColumn = newColumn;+ }+ this.fireSortChangeEvent();+ //this.updateHistory();+ //this.downloadAccounts();+ }+ fireSortChangeEvent() {+ this.updateHeaderClasses();+ let obj = {+ tableId: this.tableId,+ sortColumn: this.sortColumn,+ sortDirection: this.sortDirection,+ };+ console.log('Change sort instructions', obj);+ let event = new CustomEvent('sortable-table-sort-change', {+ detail: obj+ });+ document.dispatchEvent(event);+ }+ clickCloseButton(event) {+ let th = event.currentTarget.parentNode.parentNode.parentNode;+ let column = th.dataset.filterColumn;+ console.log('close again', column);+ th.querySelector('.search-filter').classList.add('d-none');+ th.querySelector('.title').classList.remove('d-none');+ th.querySelector('.search-button').classList.remove('d-none');+ th.querySelector('.form-control').value = '';++ this.fireSortChangeEvent();+ }++ addClickEvents() {+ // add sortable click events.+ document.querySelectorAll('table[data-sort-identifier="' + this.tableId + '"] th[data-sort-column] span.title').forEach((el) => {+ el.addEventListener("click", this.clickColumnTitle.bind(this));+ });++ // create search buttons and inputs.+ document.querySelectorAll('table[data-sort-identifier="' + this.tableId + '"] th[data-filter-column]').forEach((el) => {++ let column = el.dataset.filterColumn;+ // create filter inset.+ let inset = document.createElement('span');+ inset.classList.add('search-inset');++ // add spacer+ let searchSpacer = document.createElement('span');+ searchSpacer.classList.add('search-spacer');+ searchSpacer.innerHTML = ' ';+ inset.appendChild(searchSpacer);++ // make button.+ let searchButton = document.createElement('em');+ searchButton.classList.add('search-button', 'bi', 'bi-search');+ searchButton.setAttribute('data-filter-column', column);+ inset.appendChild(searchButton);++ // add hidden div+ let div = document.createElement('div');+ div.classList.add('d-none', 'input-group', 'search-filter');+ // append input to div.+ let input = document.createElement('input');+ input.classList.add('form-control', 'form-control-sm');+ input.setAttribute('type', 'search');+ input.setAttribute('placeholder', 'TODO placeholder');+ input.setAttribute('x-model', 'filter.' + column);+ div.appendChild(input);++ // create button+ let button = document.createElement('button');+ button.classList.add('btn', 'btn-outline-secondary', 'btn-sm', 'hide-button');+ button.setAttribute('type', 'button');+ button.addEventListener('click', this.clickCloseButton.bind(this));+ let icon = document.createElement('em');+ icon.classList.add('bi', 'bi-x', 'text-danger');+ // append icon to button+ button.appendChild(icon);+ // add button to div+ div.appendChild(button);++ // append div to element+ inset.appendChild(div);+ el.appendChild(inset);+ });++ document.querySelectorAll('table[data-sort-identifier="' + this.tableId + '"] th[data-filter-column] .search-button').forEach((el) => {+ el.addEventListener("click", () => {+ let column = el.dataset.filterColumn;++ // hide search buttons etc.+ el.classList.add("d-none");+ let th = el.parentNode.parentNode;+ th.querySelector('span.title').classList.add("d-none");+ th.querySelector('span.search-spacer').classList.add("d-none");+ // add class to parent if it's used to sort++ // if th has class sortable_sorted, add class is-searching+ if (th.classList.contains('sortable_sorted')) {+ th.classList.add("is-searching");+ }++ // show search input in div.search-filter+ let input = th.querySelector('div.search-filter');+ input.classList.remove("d-none");+ input.querySelector("input").focus();+ });+ });+ }+++ updateHeaderClasses(tableId, column, direction) {+ document.querySelectorAll('table[data-sort-identifier="' + this.tableId + '"] thead th[data-sort-column]').forEach((th) => {+ // console.log('th', th.dataset.sortColumn);+ if (this.sortColumn === th.dataset.sortColumn) {+ // th.classList.add('sortable');+ th.classList.add('sortable_sorted');+ if ('asc' === this.sortDirection) {+ th.classList.add('sortable_sorted_asc');+ th.classList.remove('sortable_sorted_desc');+ }+ if ('desc' === this.sortDirection) {+ th.classList.add('sortable_sorted_desc');+ th.classList.remove('sortable_sorted_asc');+ }+ }+ if (this.sortColumn !== th.dataset.sortColumn) {+ th.classList.remove('sortable_sorted_asc');+ th.classList.remove('sortable_sorted_desc');+ th.classList.remove('sortable_sorted');+ }+ });+ }+++}diff --git a/resources/assets/v3/js/pages/transactions/shared/create-link-autocomplete.js b/resources/assets/v3/js/pages/transactions/shared/create-link-autocomplete.jsindex cb511899b0..38988bad33 100644--- a/resources/assets/v3/js/pages/transactions/shared/create-link-autocomplete.js+++ b/resources/assets/v3/js/pages/transactions/shared/create-link-autocomplete.js@@ -33,7 +33,7 @@ export function createLinkAutocomplete(fieldIdentifier, url) {", " +formatMoney(item.amount, item.currency_code) +" @ " +- format(new Date(item.date), window.i18next.t("config.date_time_fns", { lng: locale }), locale) ++ format(new Date(item.date), i18next.t("config.date_time_fns", { lng: locale }), locale) +"</small>");};diff --git a/resources/assets/v3/js/pages/transactions/shared/parse-errors.js b/resources/assets/v3/js/pages/transactions/shared/parse-errors.jsindex 4f1b5a26a3..4c098fae1a 100644--- a/resources/assets/v3/js/pages/transactions/shared/parse-errors.js+++ b/resources/assets/v3/js/pages/transactions/shared/parse-errors.js@@ -26,7 +26,7 @@ export function parseErrors(data) {this.notifications.success.show = false;this.notifications.wait.show = false;this.formStates.isSubmitting = false;- this.notifications.error.text = this.i18next.t("firefly.errors_submission_v2", { errorMessage: data.message });+ this.notifications.error.text = i18next.t("firefly.errors_submission_v2", { errorMessage: data.message });if (Object.hasOwn(data, "errors")) {this.entries = spliceErrorsIntoTransactions(data.errors, this.entries);diff --git a/resources/assets/v3/js/pages/transactions/shared/process-upload-error.js b/resources/assets/v3/js/pages/transactions/shared/process-upload-error.jsindex 4e57eb823d..aed6ae376e 100644--- a/resources/assets/v3/js/pages/transactions/shared/process-upload-error.js+++ b/resources/assets/v3/js/pages/transactions/shared/process-upload-error.js@@ -25,10 +25,10 @@ export function processUploadError(event) {this.notifications.wait.show = false;this.notifications.error.show = true;this.formStates.isSubmitting = false;- this.notifications.error.text = this.i18next.t("firefly.errors_upload");+ this.notifications.error.text = i18next.t("firefly.errors_upload");// console.error(event.detail.error.response.status);if (413 === event.detail.error.response.status) {- this.notifications.error.text = this.i18next.t("firefly.upload_too_large");+ this.notifications.error.text = i18next.t("firefly.upload_too_large");}if ("create" === this.formBehaviour.formType) {// delete transaction and let user try again.diff --git a/resources/assets/v3/js/pages/transactions/show.js b/resources/assets/v3/js/pages/transactions/show.jsindex 2d8e1b6930..2aa9cfed34 100644--- a/resources/assets/v3/js/pages/transactions/show.js+++ b/resources/assets/v3/js/pages/transactions/show.js@@ -91,8 +91,7 @@ let show = function () {current.dateObject = new Date(current.date);current.dateFormatted = format(current.dateObject,- window.i18next.t("config.date_time_fns", { lng: locale }),- locale,+ i18next.t("config.date_time_fns", { lng: locale }), locale,);console.log("Date formatted is", current.dateFormatted);this.group.transactions.push(current);diff --git a/resources/assets/v3/js/support/load-translations.js b/resources/assets/v3/js/support/load-translations.jsindex 9b934aaf39..62ffb3e72f 100644--- a/resources/assets/v3/js/support/load-translations.js+++ b/resources/assets/v3/js/support/load-translations.js@@ -57,7 +57,7 @@ function loadTranslations(language, locale) {return i18next.use(ChainedBackend).init(options);}- return Promise.resolve();+ return Promise.resolve(null);}export { loadTranslations };diff --git a/resources/views/accounts/index.blade.php b/resources/views/accounts/index.blade.phpindex 72f48cb556..f97dbee3fc 100644--- a/resources/views/accounts/index.blade.php+++ b/resources/views/accounts/index.blade.php@@ -19,51 +19,35 @@<div class="card-body p-0"><x-elements.alpine.page-navigation/>- <table class="table table-valign-middle table-sm table-hover sortable">+ <table data-sort-identifier="main" class="table table-valign-middle table-sm table-hover sortable"><thead><tr>- <th data-column="order"- :class="{'w-5' : true,'sortable': true, 'sortable_sorted': 'order' === sortColumn, 'sortable_sorted_asc': 'asc' === sortDirection, 'sortable_sorted_desc': 'desc' === sortDirection }">- <span> </span>- </th>- <th data-column="name"- :class="{'w-20' : true,'sortable': true, 'sortable_sorted': 'name' === sortColumn, 'sortable_sorted_asc': 'asc' === sortDirection, 'sortable_sorted_desc': 'desc' === sortDirection }">- <span data-column="name" class="title">{{ trans('list.name') }}</span>- <span data-column="name" class="search-spacer"> </span><em data-column="name" class="search-button search-button-name bi bi-search"></em>- <div data-column="name" class="search-filter search-filter-name d-none input-group">- <input type="search" x-model="filter.name" class="filter-input form-control form-control-sm" placeholder="Filter name...">- <button class="btn btn-outline-secondary btn-sm hide-button" data-column="name" type="button"><em class="bi bi-x text-danger"></em></button>- </div>+ <th data-sort-column="order" class="w-5">+ <span class="title"> </span></th>+ <th data-sort-column="name" data-filter-column="name" class="w-20"><span class="title">{{ trans('list.name') }}</span></th><template x-if="'asset' === objectType">{{-- hide on LG and smaller. --}}- <th data-column="role"- :class="{'d-lg-table-cell': true, 'd-none': true,'sortable': true, 'sortable_sorted': 'role' === sortColumn, 'sortable_sorted_asc': 'asc' === sortDirection, 'sortable_sorted_desc': 'desc' === sortDirection }"><span class="title">{{ trans('list.role') }}</span></th>+ <th data-sort-column="role" class="d-lg-table-cell d-none"><span class="title">{{ trans('list.role') }}</span></th></template><template x-if="'liabilities' === objectType">- <th data-column="account_type_id"- :class="{'sortable': true, 'sortable_sorted': 'account_type_id' === sortColumn, 'sortable_sorted_asc': 'asc' === sortDirection, 'sortable_sorted_desc': 'desc' === sortDirection }"><span class="title">{{ trans('list.liability_type') }}</span></th>+ <th data-sort-column="account_type_id"><span class="title">{{ trans('list.liability_type') }}</span></th></template><template x-if="'liabilities' === objectType">- <th data-column="liability_direction"- :class="{'sortable': true, 'sortable_sorted': 'liability_direction' === sortColumn, 'sortable_sorted_asc': 'asc' === sortDirection, 'sortable_sorted_desc': 'desc' === sortDirection }"><span class="title">{{ trans('form.liability_direction') }}</span></th>+ <th data-sort-column="liability_direction"><span class="title">{{ trans('form.liability_direction') }}</span></th></template><template x-if="'liabilities' === objectType">- <th data-column="liability_interest"- :class="{'sortable': true, 'sortable_sorted': 'liability_interest' === sortColumn, 'sortable_sorted_asc': 'asc' === sortDirection, 'sortable_sorted_desc': 'desc' === sortDirection }"><span class="title">{{ trans('list.interest') }}</span>+ <th data-sort-column="liability_interest"><span class="title">{{ trans('list.interest') }}</span>({{ trans('list.interest_period') }})</th></template>- <th data-column="account_number_and_iban"- :class="{'sortable': true, 'sortable_sorted': 'account_number_and_iban' === sortColumn, 'sortable_sorted_asc': 'asc' === sortDirection, 'sortable_sorted_desc': 'desc' === sortDirection }"><span class="title">{{ trans('form.account_number') }}</span></th>+ <th data-sort-column="account_number_and_iban" data-filter-column="account_number_and_iban"><span class="title">{{ trans('form.account_number') }}</span></th><template x-if="'liabilities' !== objectType">- <th data-column="current_balance"- :class="{'text-end': true, 'sortable': true, 'sortable_sorted': 'current_balance' === sortColumn, 'sortable_sorted_asc': 'asc' === sortDirection, 'sortable_sorted_desc': 'desc' === sortDirection }"><span class="title">{{ trans('list.currentBalance') }}</span></th>+ <th data-sort-column="current_balance"><span class="title">{{ trans('list.currentBalance') }}</span></th></template><template x-if="'liabilities' === objectType">- <th data-column="debt_amount"- :class="{'text-end': true, 'sortable': true, 'sortable_sorted': 'debt_amount' === sortColumn, 'sortable_sorted_asc': 'asc' === sortDirection, 'sortable_sorted_desc': 'desc' === sortDirection }">+ <th data-sort-column="debt_amount"><span class="title">{{ trans('firefly.left_in_debt') }}</span></th></template>@@ -71,12 +55,10 @@{{-- hide last activity to make room for other stuff --}}<template x-if="'liabilities' !== objectType">{{-- hide on LG and smaller. --}}- <th data-column="last_activity"- :class="{'d-lg-table-cell': true, 'd-none': true, 'sortable': true, 'sortable_sorted': 'last_activity' === sortColumn, 'sortable_sorted_asc': 'asc' === sortDirection, 'sortable_sorted_desc': 'desc' === sortDirection }"><span class="title">{{ trans('list.lastActivity') }}</span></th>+ <th data-sort-column="last_activity" class="d-lg-table-cell d-none"><span class="title">{{ trans('list.lastActivity') }}</span></th></template>{{-- hide on SM --}}- <th data-column="balance_difference"- :class="{'w-15': true,'text-end': true, 'd-lg-table-cell': true, 'd-none': true, 'sortable': true, 'sortable_sorted': 'balance_difference' === sortColumn, 'sortable_sorted_asc': 'asc' === sortDirection, 'sortable_sorted_desc': 'desc' === sortDirection }"><span class="title">{{ trans('list.balanceDiff') }}</span></th>+ <th data-sort-column="balance_difference" class="w-15 text-end d-lg-table-cell d-none"><span class="title">{{ trans('list.balanceDiff') }}</span></th><th> </th></tr><tr x-show="true === loadingNewSort">