Skip to content

Firefly III: a personal finances manager

Expand code.

James Colef5b5f1346e4a
diff --git a/public/v1/js/ff/firefly.js b/public/v1/js/ff/firefly.js
index c100fdf382..95e32eb8f4 100644
--- a/public/v1/js/ff/firefly.js
+++ b/public/v1/js/ff/firefly.js
@@ -165,7 +165,7 @@ function currencySelect(e) {
}
function configAccounting(customCurrency) {
- console.log('configAccounting');
+ // console.log('configAccounting');
// Settings object that controls default parameters for library methods:
accounting.settings = {
currency: {
diff --git a/resources/assets/v3/js/boot/bootstrap.js b/resources/assets/v3/js/boot/bootstrap.js
index cfbdbedc0a..69cae5ea74 100644
--- a/resources/assets/v3/js/boot/bootstrap.js
+++ b/resources/assets/v3/js/boot/bootstrap.js
@@ -55,7 +55,7 @@ getFreshVariable('lastActivity').then((serverValue) => {
Promise.resolve(
getVariables(['viewRange','darkMode','locale','language', 'convert_to_primary']),
).then((values) => {
- console.log(values);
+ //console.log(values);
if (!store.get('start') || !store.get('end')) {
// calculate new start and end, and store them.
const range = getViewRange(values.viewRange, new Date);
diff --git a/resources/assets/v3/js/pages/shared/dates.js b/resources/assets/v3/js/pages/shared/dates.js
index 1b6498839f..222a5d9172 100644
--- a/resources/assets/v3/js/pages/shared/dates.js
+++ b/resources/assets/v3/js/pages/shared/dates.js
@@ -57,7 +57,7 @@ export default () => ({
language: 'en_US',
init() {
- console.log('init on dates');
+ // console.log('init on dates');
this.range = {
start: new Date(window.store.get('start')),
end: new Date(window.store.get('end'))
@@ -83,7 +83,7 @@ export default () => ({
buildDateRange() {
- console.log('Dates buildDateRange');
+ //console.log('Dates buildDateRange');
// generate ranges
let nextRange = this.getNextRange();
diff --git a/resources/assets/v3/js/pages/shared/sidebar.js b/resources/assets/v3/js/pages/shared/sidebar.js
index 6b45c79005..18d7ab0ff5 100644
--- a/resources/assets/v3/js/pages/shared/sidebar.js
+++ b/resources/assets/v3/js/pages/shared/sidebar.js
@@ -21,7 +21,7 @@
export default () => ({
foo: 'bar',
init() {
- console.log('init op sidebar')
+ //console.log('init op sidebar')
},
logoutUser(e) {
e.preventDefault();
diff --git a/resources/assets/v3/js/pages/transactions/create.js b/resources/assets/v3/js/pages/transactions/create.js
index f9bd0576ac..fd9a5a0bca 100644
--- a/resources/assets/v3/js/pages/transactions/create.js
+++ b/resources/assets/v3/js/pages/transactions/create.js
@@ -24,7 +24,6 @@ import dates from '../shared/dates.js';
import {defaultErrorSet} from "./shared/create-empty-split.js";
import {parseFromEntries} from "./shared/parse-from-entries.js";
import Post from "../../api/model/transaction/post.js";
-import PostLink from '../../api/model/transaction-link/post.js';
import {loadCurrencies} from "./shared/load-currencies.js";
import {loadBudgets} from "./shared/load-budgets.js";
import {loadPiggyBanks} from "./shared/load-piggy-banks.js";
@@ -62,6 +61,7 @@ import {saveEditedLink} from "./shared/save-edited-link.js";
import {saveNewLink} from "./shared/save-new-link.js";
import {redirectAfterTransactionLinks} from './shared/redirect-after-transaction-links.js';
import {processTransactionLinks} from './shared/process-transaction-links.js';
+import {addTabListener} from "./shared/add-tab-listener.js";
let create = function () {
return {
@@ -92,9 +92,10 @@ let create = function () {
formStates: {
loadingCurrencies: true,
loadingBudgets: true,
- loadingLinks: true,
+ loadingLinks: null,
loadingPiggyBanks: true,
loadingSubscriptions: true,
+ loadingTransaction: true,
isSubmitting: false,
returnHereButton: false,
saveAsNewButton: false, // edit form only
@@ -194,6 +195,7 @@ let create = function () {
saveNewLink: saveNewLink,
processTransactionLinks: processTransactionLinks,
redirectAfterTransactionLinks: redirectAfterTransactionLinks,
+ addTabListener: addTabListener,
filterForeignCurrencies(code) {
let list = [];
@@ -228,6 +230,8 @@ let create = function () {
addedSplit() {
this.addAllAutocompleteToForm();
+ this.addTabListener();
+ this.formStates.loadingTransaction = false;
},
processUpload(event) {
@@ -252,19 +256,43 @@ let create = function () {
}
//console.log('Switched to new tab!', event.target.dataset.index);
},
- addTabListener() {
- // on switch tab (to re-render map if necessary).
- // this.maps[index].invalidateSize();
- setTimeout(() => {
- const tabEl = document.querySelectorAll('button[data-bs-toggle="tab"]')
- for (let i = 0; i < tabEl.length; i++) {
- tabEl[i].removeEventListener('shown.bs.tab', this.respondToTabSwitch);
- tabEl[i].addEventListener('shown.bs.tab', this.respondToTabSwitch.bind(this), true);
+
+ // this method automatically calls some
+ // "next steps", whenever the state of the form loads or changes.
+ // used during the init phase of the form.
+ autoStep() {
+ // check if custom field "links" is enabled and if so, load the link types and save them in formData.
+ if (null === this.formStates.loadingLinks && this.formBehaviour.customFields.hasOwnProperty('links') && true === this.formBehaviour.customFields.links) {
+ this.formStates.loadingLinks = true;
+ loadLinkTypes().then(data => {
+ for (let i = 0; i < data.length; i++) {
+ if (data.hasOwnProperty(i)) {
+ let current = data[i];
+ current.id = parseInt(current.id);
+ this.formData.linkTypes.push(current);
+ }
+ }
+ this.formStates.loadingLinks = false;
+ this.autoStep(); // yes, recurring.
+
+ });
+ }
+ if (this.formBehaviour.customFields.hasOwnProperty('links') && false === this.formBehaviour.customFields.links) {
+ this.formStates.storedLinks = true;
+ this.formStates.loadingLinks = false;
+ }
+ // check if the transaction is loaded and also the transaction links AND the field is enabled, then load the autocomplete for links.
+ if (false === this.formStates.loadingTransaction && false === this.formStates.loadingLinks && this.formBehaviour.customFields.hasOwnProperty('links') && true === this.formBehaviour.customFields.links) {
+ for(let i = 0; i < this.entries.length; i++) {
+ if(this.entries.hasOwnProperty(i)) {
+ this.createLinkAutocomplete('links_modal_search_' + i, 'api/v1/autocomplete/transactions-with-meta');
+ }
}
- // TODO don't do this on a timeout!
- }, 500);
+ }
+
},
+
init() {
this.i18next = i18next;
this.addSplit();
@@ -276,46 +304,30 @@ let create = function () {
this.formData.enabledCurrencies = data.enabledCurrencies;
this.formData.primaryCurrencies = data.primaryCurrencies;
this.formData.foreignCurrencies = data.foreignCurrencies;
+ this.autoStep();
});
loadBudgets(false).then(data => {
this.formData.budgets = data;
this.formStates.loadingBudgets = false;
+ this.autoStep();
});
loadPiggyBanks().then(data => {
this.formData.piggyBanks = data;
this.formStates.loadingPiggyBanks = false;
+ this.autoStep();
});
loadSubscriptions(false).then(data => {
this.formData.subscriptions = data;
this.formStates.loadingSubscriptions = false;
+ this.autoStep();
});
// load custom field preference and enable/disable those fields.
this.loadCustomFields().then(data => {
this.formBehaviour.customFields = data;
- // linked-transactions-search
- if (true === data.links) {
- loadLinkTypes().then(data => {
- //console.log(data);
- for (let i = 0; i < data.length; i++) {
- if (data.hasOwnProperty(i)) {
- let current = data[i];
- current.id = parseInt(current.id);
- this.formData.linkTypes.push(current);
- }
- }
- // TODO fix for all modals.
- //this.formData.linkTypes = data;
- this.formStates.loadingLinks = false;
- this.createLinkAutocomplete('links_modal_search_0', 'api/v1/autocomplete/transactions-with-meta');
-
- });
- }
- if (false === data.links) {
- this.formStates.storedLinks = true;
- }
+ this.autoStep();
});
diff --git a/resources/assets/v3/js/pages/transactions/edit.js b/resources/assets/v3/js/pages/transactions/edit.js
index b98f11159b..b2e65301e1 100644
--- a/resources/assets/v3/js/pages/transactions/edit.js
+++ b/resources/assets/v3/js/pages/transactions/edit.js
@@ -65,6 +65,7 @@ import {saveEditedLink} from "./shared/save-edited-link.js";
import {saveNewLink} from "./shared/save-new-link.js";
import {processTransactionLinks} from "./shared/process-transaction-links.js";
import {redirectAfterTransactionLinks} from "./shared/redirect-after-transaction-links.js";
+import {addTabListener} from "./shared/add-tab-listener.js";
const urls = getUrls();
@@ -180,7 +181,7 @@ let transactions = function () {
processTransactionLinks: processTransactionLinks,
redirectAfterTransactionLinks: redirectAfterTransactionLinks,
loadTransactionLinks: loadTransactionLinks,
-
+ addTabListener: addTabListener,
// part of the account selection auto-complete
@@ -252,6 +253,10 @@ let transactions = function () {
}
}
setTimeout(() => {
+ // send event that transaction group is loaded.
+ // document.dispatchEvent(new CustomEvent('transaction-group-loaded'));
+
+ // TODO should not be on a timeout.
// render tags:
Tags.init('select.ac-tags', {
allowClear: true,
@@ -274,6 +279,7 @@ let transactions = function () {
});
},
+
init() {
this.i18next = i18next;
@@ -318,10 +324,7 @@ let transactions = function () {
this.formData.linkTypes.push(current);
}
}
- //this.formData.linkTypes = data;
- // TODO fix for all mdodals.
this.formStates.loadingLinks = false;
- this.createLinkAutocomplete('links_modal_search_0', 'api/v1/autocomplete/transactions-with-meta');
for(let i = 0; i < this.entries.length; i++) {
this.links[i] = []; // empty set of links.
@@ -336,6 +339,14 @@ let transactions = function () {
}
});
+ // document.addEventListener('transaction-group-loaded', (event) => {
+ // this.createLinkAutocompletes();
+ // this.createLinkAutocomplete('links_modal_search_0', 'api/v1/autocomplete/transactions-with-meta');
+ // this.entries[event.detail.index].latitude = event.detail.latitude;
+ // this.entries[event.detail.index].longitude = event.detail.longitude;
+ // });
+
+
// add some event listeners
document.addEventListener('upload-success', (event) => {
this.processUpload(event);
@@ -345,10 +356,7 @@ let transactions = function () {
document.addEventListener('upload-error', (event) => {
this.processUploadError(event);
});
- // document.addEventListener('location-move', (event) => {
- // this.entries[event.detail.index].latitude = event.detail.latitude;
- // this.entries[event.detail.index].longitude = event.detail.longitude;
- // });
+
// document.addEventListener('location-set', (event) => {
// this.entries[event.detail.index].hasLocation = true;
@@ -449,6 +457,7 @@ let transactions = function () {
console.log('addedSplit()');
this.disableSplitAccounts();
this.addAllAutocompleteToForm();
+ this.addTabListener();
},
}
diff --git a/resources/assets/v3/js/pages/transactions/shared/add-autocomplete.js b/resources/assets/v3/js/pages/transactions/shared/add-autocomplete.js
index 77a2882ed5..5d4f4c6f30 100644
--- a/resources/assets/v3/js/pages/transactions/shared/add-autocomplete.js
+++ b/resources/assets/v3/js/pages/transactions/shared/add-autocomplete.js
@@ -39,7 +39,6 @@ export function getUrls() {
}
export function addAllAutocompleteToForm() {
- console.log('Now in addAllAutocompleteToForm()');
// filters are hard coded.
// part of the account selection auto-complete
let filters = {
diff --git a/resources/assets/v3/js/pages/transactions/shared/add-split.js b/resources/assets/v3/js/pages/transactions/shared/add-split.js
index 379ddd9996..651ba4a397 100644
--- a/resources/assets/v3/js/pages/transactions/shared/add-split.js
+++ b/resources/assets/v3/js/pages/transactions/shared/add-split.js
@@ -22,10 +22,7 @@ import {createEmptySplit} from "./create-empty-split.js";
import {addAllAutocompleteToForm} from "./add-autocomplete.js";
export function addSplit() {
- console.log('addSplit()');
this.entries.push(createEmptySplit());
this.links.push([]);
this.disableSplitAccounts();
- this.addAllAutocompleteToForm();
- this.addTabListener();
}
diff --git a/resources/assets/v3/js/pages/transactions/shared/add-tab-listener.js b/resources/assets/v3/js/pages/transactions/shared/add-tab-listener.js
new file mode 100644
index 0000000000..05a7508211
--- /dev/null
+++ b/resources/assets/v3/js/pages/transactions/shared/add-tab-listener.js
@@ -0,0 +1,29 @@
+/*
+ * add-tab-listener.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 addTabListener() {
+ // on switch tab (to re-render map if necessary).
+ const tabEl = document.querySelectorAll('button[data-bs-toggle="tab"]')
+ // console.log('tabEl length is now', tabEl.length);
+ for (let i = 0; i < tabEl.length; i++) {
+ tabEl[i].removeEventListener('shown.bs.tab', this.respondToTabSwitch);
+ tabEl[i].addEventListener('shown.bs.tab', this.respondToTabSwitch.bind(this), true);
+ }
+}
diff --git a/resources/assets/v3/js/pages/transactions/shared/disable-split-accounts.js b/resources/assets/v3/js/pages/transactions/shared/disable-split-accounts.js
index aaddaf9976..64ec8b52b0 100644
--- a/resources/assets/v3/js/pages/transactions/shared/disable-split-accounts.js
+++ b/resources/assets/v3/js/pages/transactions/shared/disable-split-accounts.js
@@ -21,20 +21,20 @@
// what happens when a user adds more than one split?
export function disableSplitAccounts() {
- console.log('Call disableSplitAccounts');
+ //console.log('Call disableSplitAccounts');
if(this.entries.length > 1) {
- console.log('Activate disableSplitAccounts');
+ //console.log('Activate disableSplitAccounts');
// disable source and/or destination, based on account type.
for(let i = 1;i<this.entries.length;i++) {
// disable source when withdrawal or transfer
if('transfer' === this.groupProperties.transactionType || 'withdrawal' === this.groupProperties.transactionType) {
this.entries[i].source_account.disabled = true;
- console.log('Disable source account #' + i + 1);
+ // console.log('Disable source account #' + i + 1);
}
// disable destination when deposit or transfer
if('transfer' === this.groupProperties.transactionType || 'deposit' === this.groupProperties.transactionType) {
this.entries[i].destination_account.disabled = true;
- console.log('Disable destination account #' + i + 1);
+ // console.log('Disable destination account #' + i + 1);
}
}
}
diff --git a/resources/assets/v3/js/pages/transactions/shared/load-currencies.js b/resources/assets/v3/js/pages/transactions/shared/load-currencies.js
index e80b74cbc4..abd034c7c3 100644
--- a/resources/assets/v3/js/pages/transactions/shared/load-currencies.js
+++ b/resources/assets/v3/js/pages/transactions/shared/load-currencies.js
@@ -52,9 +52,9 @@ export function loadCurrencies() {
};
if (obj.primary) {
- console.log('Made ' + obj.code + ' primary.');
+ //console.log('Made ' + obj.code + ' primary.');
returnData.primaryCurrency = obj;
- console.log(returnData.primaryCurrency);
+ //console.log(returnData.primaryCurrency);
}
returnData.enabledCurrencies.push(obj);
returnData.primaryCurrencies.push(obj);
@@ -62,7 +62,7 @@ export function loadCurrencies() {
}
}
}
- console.log(returnData);
+ //console.log(returnData);
return returnData;
});
}
diff --git a/resources/assets/v3/js/store/get-variables.js b/resources/assets/v3/js/store/get-variables.js
index 50b38d9b9d..adebb878c6 100644
--- a/resources/assets/v3/js/store/get-variables.js
+++ b/resources/assets/v3/js/store/get-variables.js
@@ -21,7 +21,7 @@
import Get from "../api/preferences/index.js";
export function getVariables(preferences) {
- console.log('Now in getVariables', preferences);
+ //console.log('Now in getVariables', preferences);
let chain = Promise.resolve();
let collectable = [];
let result = {};
@@ -69,7 +69,7 @@ export function getVariables(preferences) {
// console.log('Have something to collect');
chain = chain.then(() => {
let names = collectable.join(',');
- console.log('Will collect', names);
+ //console.log('Will collect', names);
return getter.getList(names).then((response) => {
let parsed = parseResponses(response);
// console.log('Returning "' + names + '" from server: ', parsed);
@@ -97,6 +97,6 @@ export function parseResponses(response) {
window.store.set(current.attributes.name, current.attributes.data);
}
}
- console.log('parseResponses', result);
+ // console.log('parseResponses', result);
return result;
}
diff --git a/resources/assets/v3/js/support/load-translations.js b/resources/assets/v3/js/support/load-translations.js
index 8d76f1d08a..92010ac616 100644
--- a/resources/assets/v3/js/support/load-translations.js
+++ b/resources/assets/v3/js/support/load-translations.js
@@ -27,12 +27,12 @@ import LocalStorageBackend from "i18next-localstorage-backend";
let loaded = false;
function loadTranslations(locale) {
- console.log('loadTranslations(' + locale + ')');
+ // console.log('loadTranslations(' + locale + ')');
if (false === loaded) {
const replacedLocale = locale.replace('-', '_');
loaded = true;
const expireTime = import.meta.env.MODE === 'development' ? 1 : 7 * 24 * 60 * 60 * 1000;
- console.log('Will load language "'+replacedLocale+'"');
+ // console.log('Will load language "'+replacedLocale+'"');
return i18next
.use(ChainedBackend)
.init({
@@ -54,7 +54,7 @@ function loadTranslations(locale) {
}
});
}
- console.warn('Loading translations skipped.');
+ console.warn( 'Loading translations skipped.');
return Promise.resolve();
}