Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Allow sort for accounts again.
James Coleffd1fce474ec
diff --git a/app/Http/Controllers/Budget/IndexController.php b/app/Http/Controllers/Budget/IndexController.phpindex da1a6c9244..9e43694d93 100644--- a/app/Http/Controllers/Budget/IndexController.php+++ b/app/Http/Controllers/Budget/IndexController.php@@ -273,7 +273,7 @@ final class IndexController extends Controllerif (array_key_exists($currency->id, $spentArr) && array_key_exists('sum', $spentArr[$currency->id])) {$array['spent'][$currency->id]['spent'] = $spentArr[$currency->id]['sum'];$array['spent'][$currency->id]['spent_outside'] = Steam::negative(bcsub($spentInLimits[$currency->id], $spentArr[$currency->id]['sum']));- $array['spent'][$currency->id]['currency_id'] = $currency->id;+ $array['spent'][$currency->id]['currency_id'] = $currency->id;$array['spent'][$currency->id]['currency_symbol'] = $currency->symbol;$array['spent'][$currency->id]['currency_decimal_places'] = $currency->decimal_places;}diff --git a/app/Listeners/Model/TransactionGroup/StoresAuditLogEntry.php b/app/Listeners/Model/TransactionGroup/StoresAuditLogEntry.phpindex 5edde2f69a..7afe187338 100644--- a/app/Listeners/Model/TransactionGroup/StoresAuditLogEntry.php+++ b/app/Listeners/Model/TransactionGroup/StoresAuditLogEntry.php@@ -34,6 +34,7 @@ class StoresAuditLogEntry implements ShouldQueue{public function handle(TransactionGroupRequestsAuditLogEntry $event): void{+ Log::debug('Now in StoresAuditLogEntry::handle()');$array = ['auditable' => $event->auditable,'changer' => $event->changer,@@ -69,7 +70,7 @@ class StoresAuditLogEntry implements ShouldQueueLog::debug(sprintf('Converted "before" to "%s".', $event->before));Log::debug(sprintf('Converted "after" to "%s".', $event->after));}-+ Log::debug(sprintf('Will now store event log for event "%s"', $array['action']));/** @var ALERepositoryInterface $repository */$repository = app(ALERepositoryInterface::class);$repository->store($array);diff --git a/app/View/Components/Lists/Accounts.php b/app/View/Components/Lists/Accounts.phpindex f450012d46..24428e97dc 100644--- a/app/View/Components/Lists/Accounts.php+++ b/app/View/Components/Lists/Accounts.php@@ -33,14 +33,16 @@ class Accounts extends Component{public LengthAwarePaginator $accounts;public string $objectType = '';+ public int $page = 1;/*** Create a new component instance.*/- public function __construct(LengthAwarePaginator $accounts, string $objectType)+ public function __construct(LengthAwarePaginator $accounts, string $objectType, int $page){$this->accounts = $accounts;$this->objectType = $objectType;+ $this->page = $page;}/**diff --git a/resources/assets/v3/js/api/model/account/put.js b/resources/assets/v3/js/api/model/account/put.jsnew file mode 100644index 0000000000..f36ffdf5fb--- /dev/null+++ b/resources/assets/v3/js/api/model/account/put.js@@ -0,0 +1,28 @@+/*+ * post.js+ * Copyright (c) 2023 [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/>.+ */++import { api } from "../../../boot/axios";++export default class Put {+ put(submission, params) {+ let url = "/api/v1/accounts/" + parseInt(params.id);+ return api.put(url, submission);+ }+}diff --git a/resources/assets/v3/js/pages/accounts/index.js b/resources/assets/v3/js/pages/accounts/index.jsnew file mode 100644index 0000000000..8b4f7963d6--- /dev/null+++ b/resources/assets/v3/js/pages/accounts/index.js@@ -0,0 +1,85 @@+/*+ * show.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/>.+ */+++import "../../boot/bootstrap.js";+import sidebar from "../shared/sidebar.js";+import dates from "../shared/dates.js";+import {addDrag} from "../shared/drag-and-droppable-rows.js";+import Alpine from "alpinejs";+import {getVariable} from "../../store/get-variable.js";+import Put from '../../api/model/account/put.js';++window.enableDates = false;++let index = function () {+ return {+ listPageSize: 50,+ init() {+ getVariable("listPageSize").then((listPageSize) => {+ console.log(listPageSize);+ this.listPageSize = listPageSize;+ 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});+ // save new order as current order in the row.+ document.querySelector(`tr[data-id="${item.id}"]`).setAttribute('data-current-order', item.order);+ }+ }+ }+ console.log(e.detail);+ });++ });+ },+ };+};++const comps = {+ index,+ sidebar,+ dates,+};++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/assets/v3/js/pages/shared/drag-and-droppable-rows.js b/resources/assets/v3/js/pages/shared/drag-and-droppable-rows.jsnew file mode 100644index 0000000000..600983eb4c--- /dev/null+++ b/resources/assets/v3/js/pages/shared/drag-and-droppable-rows.js@@ -0,0 +1,141 @@+/*+ * drag-and-droppable-rows.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 function addDrag() {+ const tbody = document.querySelector('.sortable tbody');+ let draggedRow = null;++ // animation Helper+ function getRowOffsets() {+ const map = new Map();+ tbody.querySelectorAll('tr').forEach(row => {+ map.set(row, row.getBoundingClientRect().top);+ });+ return map;+ }++ // swap logic+ function handleRowSwap(clientY, targetElement) {+ const targetRow = targetElement.closest('tr');++ if (targetRow && targetRow !== draggedRow && targetRow.parentNode === tbody) {+ const rect = targetRow.getBoundingClientRect();+ const next = (clientY - rect.top) / (rect.bottom - rect.top) > 0.5;+ const nextSibling = next ? targetRow.nextSibling : targetRow;++ if (draggedRow.nextSibling !== nextSibling) {+ const firstPositions = getRowOffsets();++ tbody.insertBefore(draggedRow, nextSibling);++ const lastPositions = getRowOffsets();++ tbody.querySelectorAll('tr').forEach(row => {+ const firstTop = firstPositions.get(row);+ const lastTop = lastPositions.get(row);+ const deltaY = firstTop - lastTop;++ if (deltaY !== 0) {+ row.style.transform = `translateY(${deltaY}px)`;+ row.style.transition = 'none';++ requestAnimationFrame(() => {+ row.style.transform = '';+ row.style.transition = 'transform 0.2s ease-out';+ });+ }+ });+ }+ }+ }++ function getRowOrder() {+ let index = 1;+ return Array.from(tbody.querySelectorAll('tr')).map(row => ({+ id: row.getAttribute('data-id'),+ order: index++,+ currentOrder: parseInt(row.getAttribute('data-current-order')),+ page: parseInt(row.getAttribute('data-page')),+ }));+ }++ // add events+ tbody.addEventListener('mousedown', (e) => {+ if (e.target.classList.contains('object-handle')) {+ e.target.closest('tr').setAttribute('draggable', 'true');+ }+ });++ tbody.addEventListener('dragstart', (e) => {+ draggedRow = e.target.closest('tr');+ setTimeout(() => draggedRow.classList.add('is-dragging'), 0);+ });++ tbody.addEventListener('dragend', (e) => {+ if (draggedRow) {+ draggedRow.removeAttribute('draggable');+ draggedRow.classList.remove('is-dragging');+ draggedRow = null;+ const currentOrder = getRowOrder();+ const event = new CustomEvent("firefly-iii-drag-complete", {+ detail: currentOrder,+ });+ document.dispatchEvent(event);+ }+ });++ tbody.addEventListener('dragover', (e) => {+ e.preventDefault();+ handleRowSwap(e.clientY, e.target);+ });++ tbody.addEventListener('touchstart', (e) => {+ if (e.target.classList.contains('object-handle')) {+ draggedRow = e.target.closest('tr');+ draggedRow.classList.add('is-dragging');+ }+ }, { passive: true });++ tbody.addEventListener('touchmove', (e) => {+ if (!draggedRow) return;++ // Get finger coordinates+ const touch = e.touches[0];++ // Find what element is currently underneath the user's finger+ const elementUnderFinger = document.elementFromPoint(touch.clientX, touch.clientY);++ if (elementUnderFinger) {+ handleRowSwap(touch.clientY, elementUnderFinger);+ }+ }, { passive: true });++ tbody.addEventListener('touchend', () => {+ if (draggedRow) {+ draggedRow.classList.remove('is-dragging');+ draggedRow = null;+ const currentOrder = getRowOrder();+ const event = new CustomEvent("firefly-iii-drag-complete", {+ detail: currentOrder,+ });+ document.dispatchEvent(event);+ }+ });+}diff --git a/resources/assets/v3/sass/app.scss b/resources/assets/v3/sass/app.scssindex d90bd78549..2222c63b14 100644--- a/resources/assets/v3/sass/app.scss+++ b/resources/assets/v3/sass/app.scss@@ -105,12 +105,15 @@ ul.nav:nth-child(1) > li:nth-child(2) .piggy-handle {}.object-handle {cursor: move;+ touch-action: none;}.rule-handle {cursor: move;+ touch-action: none;}.bill-handle {cursor: move;+ touch-action: none;}body.waiting * {diff --git a/resources/assets/v3/vite.config.js b/resources/assets/v3/vite.config.jsindex 63524afcc9..9a11009726 100644--- a/resources/assets/v3/vite.config.js+++ b/resources/assets/v3/vite.config.js@@ -57,6 +57,7 @@ export default defineConfig(({ command }) => {// accounts"js/pages/accounts/create.js","js/pages/accounts/edit.js",+ "js/pages/accounts/index.js",// administrations"js/pages/administrations/index.js",diff --git a/resources/views/accounts/index.blade.php b/resources/views/accounts/index.blade.phpindex 851d00f37c..5b748a3628 100644--- a/resources/views/accounts/index.blade.php+++ b/resources/views/accounts/index.blade.php@@ -1,12 +1,12 @@@extends('layout.v3.session')@section('content')@if(count($accounts) > 0)- <div class="row">+ <div class="row" x-data="index"><div class="col-lg-12 col-md-12 col-sm-12"><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">- <x-lists.accounts :accounts="$accounts" :objectType="$objectType" />+ <x-lists.accounts :accounts="$accounts" :objectType="$objectType" :page="$page ?? 1" /></div><x-elements.card-footer-with-menu :route="route('accounts.create', $objectType) . '?_from=' . urlencode($FF3_FROM)" :linkTitle="__('firefly.make_new_'. $objectType . '_account')" /></div>@@ -51,13 +51,7 @@@endif@endif-@endsection@section('scripts')- @vite(['js/pages/generic.js'])- <script type="text/javascript" nonce="{{ $JS_NONCE }}">- var objectType = '{{ e($objectType) }}';- </script>- <script src="v1/js/lib/jquery-ui.min.js?v={{ $FF_BUILD_TIME }}" type="text/javascript" nonce="{{ $JS_NONCE }}"></script>- <script type="text/javascript" nonce="{{ $JS_NONCE }}" src="v1/js/ff/accounts/index.js?v={{ $FF_BUILD_TIME }}"></script>+ @vite(['js/pages/accounts/index.js'])@endsectiondiff --git a/resources/views/components/lists/accounts.blade.php b/resources/views/components/lists/accounts.blade.phpindex 06ca431609..b5d798701b 100644--- a/resources/views/components/lists/accounts.blade.php+++ b/resources/views/components/lists/accounts.blade.php@@ -1,14 +1,14 @@<div class="m-2">{{ $accounts->links('pagination.bootstrap-4') }}</div>-<table class="table table-sm table-hover" id="sortable-table">++<table class="table table-sm table-hover sortable"><thead><tr><th class="w-5"> </th><th class="w-20">{{ trans('list.name') }}</th>@if('asset' === $objectType)-- <th {{-- hide on LG and smaller. --}} class="d-lg-table-cell d-none">{{ trans('list.role') }}</th>+ <th {{-- hide on LG and smaller. --}} class="d-lg-table-cell d-none">{{ trans('list.role') }}</th>@endif@if('liabilities' === $objectType)<th>{{ trans('list.liability_type') }}</th>@@ -35,9 +35,11 @@</thead><tbody>@foreach($accounts as $account)- <tr class="sortable-object" data-id="{{ $account->id }}" data-order="{{ $account->order }}" data-position="{{ $loop->index }}">+ <tr class="sortable-object" data-page="{{$page}}" data-current-order="{{ $account->order }}" data-id="{{ $account->id }}" data-order="{{ $account->order }}" data-position="{{ $loop->index }}"><td>- <span class="btn btn-sm bi bi-list object-handle"></span>+ @if(('asset' === $objectType || 'liabilities' === $objectType) && $accounts->count() > 1)+ <span class="btn btn-outline-secondary btn-sm bi bi-list object-handle"></span>+ @endif</td><td><a href="{{ route('accounts.show',$account->id) }}">{{ $account->name }}</a>