Skip to content

Firefly III: a personal finances manager

new stuff

Sander Dorigoe3268165f21d
diff --git a/app/Models/TransactionGroup.php b/app/Models/TransactionGroup.php
index c2c6f23aa3..4ee22788c4 100644
--- a/app/Models/TransactionGroup.php
+++ b/app/Models/TransactionGroup.php
@@ -81,6 +81,7 @@ class TransactionGroup extends Model
return $group;
}
+ throw new NotFoundHttpException();
}
Log::debug('Found no group.');
diff --git a/config/translations.php b/config/translations.php
index 147f8bf886..86fa751c83 100644
--- a/config/translations.php
+++ b/config/translations.php
@@ -59,6 +59,7 @@ return [
'interest_calc_yearly',
'loading',
'errors_upload',
+ 'upload_too_large',
'interest_calc_',
'wait_attachments',
'interest_calc_null',
diff --git a/public/v3/i18n/.gitignore b/public/v3/i18n/.gitignore
new file mode 100644
index 0000000000..94a2dd146a
--- /dev/null
+++ b/public/v3/i18n/.gitignore
@@ -0,0 +1 @@
+*.json
\ No newline at end of file
diff --git a/resources/assets/v3/js/api/model/transaction/delete.js b/resources/assets/v3/js/api/model/transaction/delete.js
new file mode 100644
index 0000000000..1a491ead3b
--- /dev/null
+++ b/resources/assets/v3/js/api/model/transaction/delete.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 Delete {
+ delete(id) {
+ let url = '/api/v1/transactions/' + parseInt(id);
+ return api.delete(url);
+ }
+}
diff --git a/resources/assets/v3/js/boot/bootstrap.js b/resources/assets/v3/js/boot/bootstrap.js
index 4168f4de55..6d8dc2f812 100644
--- a/resources/assets/v3/js/boot/bootstrap.js
+++ b/resources/assets/v3/js/boot/bootstrap.js
@@ -26,10 +26,10 @@ import store from "../store/store.js";
import axios from 'axios';
import Shepherd from 'shepherd.js';
import "cally";
-import {getFreshVariable} from "v2/src/store/get-fresh-variable.js";
-import {getVariable} from "v2/src/store/get-variable.js";
-import {getViewRange} from "v2/src/support/get-viewrange.js";
-import {loadTranslations} from "v2/src/support/load-translations.js";
+import {getFreshVariable} from "../store/get-fresh-variable.js";
+import {getVariable} from "../store/get-variable.js";
+import {getViewRange} from "../support/get-viewrange.js";
+import {loadTranslations} from "../support/load-translations.js";
window.bootstrapped = false;
window.store = store;
diff --git a/resources/assets/v3/js/pages/transactions/create.js b/resources/assets/v3/js/pages/transactions/create.js
index 46ec6086d9..dda8e6c515 100644
--- a/resources/assets/v3/js/pages/transactions/create.js
+++ b/resources/assets/v3/js/pages/transactions/create.js
@@ -25,6 +25,7 @@ import {createEmptySplit, defaultErrorSet} from "./shared/create-empty-split.js"
import {parseFromEntries} from "./shared/parse-from-entries.js";
import formatMoney from "../../util/format-money.js";
import Post from "../../api/model/transaction/post.js";
+import Delete from "../../api/model/transaction/delete.js";
import {loadCurrencies} from "./shared/load-currencies.js";
import {loadBudgets} from "./shared/load-budgets.js";
import {loadPiggyBanks} from "./shared/load-piggy-banks.js";
@@ -289,6 +290,13 @@ let create = function () {
this.notifications.error.show = true;
this.formStates.isSubmitting = false;
this.notifications.error.text = i18next.t('firefly.errors_upload');
+ console.log(event.detail.error.response.status);
+ if(413 === event.detail.error.response.status) {
+ this.notifications.error.text = i18next.t('firefly.upload_too_large');
+ }
+ // delete transaction and let user try again.
+ let del = new Delete();
+ del.delete(this.groupProperties.id);
// console.error(event);
},
diff --git a/resources/assets/v3/js/pages/transactions/shared/process-attachments.js b/resources/assets/v3/js/pages/transactions/shared/process-attachments.js
index 8245bdabf4..7b8fc4b15d 100644
--- a/resources/assets/v3/js/pages/transactions/shared/process-attachments.js
+++ b/resources/assets/v3/js/pages/transactions/shared/process-attachments.js
@@ -33,7 +33,7 @@ let uploadFiles = function (fileData) {
poster.upload(attachmentId, fileData[key].content).then(attachmentResponse => {
uploads++;
if (uploads === count) {
- const event = new CustomEvent('upload-success', {some: 'details'});
+ const event = new CustomEvent('upload-success', {detail: {some: 'details'}});
document.dispatchEvent(event);
}
}).catch(error => {
@@ -41,7 +41,7 @@ let uploadFiles = function (fileData) {
// console.error(error);
uploads++;
// break right away
- const event = new CustomEvent('upload-failed', {error: error});
+ const event = new CustomEvent('upload-failed', {detail: {error: error}});
document.dispatchEvent(event);
hasError = true;
});
@@ -49,7 +49,7 @@ let uploadFiles = function (fileData) {
console.error('Could not create upload.');
console.error(error);
uploads++;
- const event = new CustomEvent('upload-failed', {error: error});
+ const event = new CustomEvent('upload-failed', {detail: {error: error}});
document.dispatchEvent(event);
hasError = true;
});
diff --git a/resources/assets/v3/js/store/get-fresh-variable.js b/resources/assets/v3/js/store/get-fresh-variable.js
new file mode 100644
index 0000000000..f469a3fe73
--- /dev/null
+++ b/resources/assets/v3/js/store/get-fresh-variable.js
@@ -0,0 +1,46 @@
+/*
+ * get-variable.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 Get from "../api/preferences/index.js";
+import Post from "../api/preferences/post.js";
+
+export function getFreshVariable(name, defaultValue = null) {
+ let getter = (new Get);
+ return getter.getByName(name).then((response) => {
+ // console.log('Get from API');
+ return Promise.resolve(parseResponse(name, response));
+ }).catch((response) => {
+ if(response.status === 404) {
+ // preference does not exist (yet).
+ // POST it and then return it anyway.
+ let poster = (new Post);
+ poster.post(name, defaultValue).then((response) => {
+ return Promise.resolve(parseResponse(name, response));
+ });
+ return;
+ }
+ return Promise.resolve(null);
+ });
+}
+
+function parseResponse(name, response) {
+ return response.data.data.attributes.data;
+}
+
diff --git a/resources/assets/v3/js/support/get-viewrange.js b/resources/assets/v3/js/support/get-viewrange.js
new file mode 100644
index 0000000000..45084cfa61
--- /dev/null
+++ b/resources/assets/v3/js/support/get-viewrange.js
@@ -0,0 +1,126 @@
+/*
+ * get-viewrange.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 {
+ endOfDay, endOfMonth, endOfQuarter,
+ endOfWeek,
+ startOfDay,
+ startOfMonth,
+ startOfQuarter,
+ startOfWeek,
+ startOfYear,
+ subDays
+} from "date-fns";
+
+function getViewRange(viewRange, today) {
+ let start;
+ let end;
+
+ // console.log('getViewRange: ' + viewRange);
+
+ switch (viewRange) {
+ case 'last365':
+ start = startOfDay(subDays(today, 365));
+ end = endOfDay(today);
+ break;
+ case 'last90':
+ start = startOfDay(subDays(today, 90));
+ end = endOfDay(today);
+ break;
+ case 'last30':
+ start = startOfDay(subDays(today, 30));
+ end = endOfDay(today);
+ break;
+ case 'last7':
+ start = startOfDay(subDays(today, 7));
+ end = endOfDay(today);
+ break;
+ case 'YTD':
+ start = startOfYear(today);
+ end = endOfDay(today);
+ break;
+ case 'QTD':
+ start = startOfQuarter(today);
+ end = endOfDay(today);
+ break;
+ case 'MTD':
+ start = startOfMonth(today);
+ end = endOfDay(today);
+ break;
+ case '1D':
+ // today:
+ start = startOfDay(today);
+ end = endOfDay(today);
+ break;
+ case '1W':
+ // this week:
+ start = startOfDay(startOfWeek(today, {weekStartsOn: 1}));
+ end = endOfDay(endOfWeek(today, {weekStartsOn: 1}));
+ break;
+ case '1M':
+ // this month:
+ start = startOfDay(startOfMonth(today));
+ end = endOfDay(endOfMonth(today));
+ break;
+ case '3M':
+ // this quarter
+ start = startOfDay(startOfQuarter(today));
+ end = endOfDay(endOfQuarter(today));
+ break;
+ case '6M':
+ // this half-year
+ if (today.getMonth() <= 5) {
+ start = new Date(today);
+ start.setMonth(0);
+ start.setDate(1);
+ start = startOfDay(start);
+ end = new Date(today);
+ end.setMonth(5);
+ end.setDate(30);
+ end = endOfDay(start);
+ }
+ if (today.getMonth() > 5) {
+ start = new Date(today);
+ start.setMonth(6);
+ start.setDate(1);
+ start = startOfDay(start);
+ end = new Date(today);
+ end.setMonth(11);
+ end.setDate(31);
+ end = endOfDay(start);
+ }
+ break;
+ case '1Y':
+ // this year
+ start = new Date(today);
+ start.setMonth(0);
+ start.setDate(1);
+ start = startOfDay(start);
+
+ end = new Date(today);
+ end.setMonth(11);
+ end.setDate(31);
+ end = endOfDay(end);
+ break;
+ }
+ return {start: start, end: end};
+}
+
+export {getViewRange};
diff --git a/resources/assets/v3/js/support/load-translations.js b/resources/assets/v3/js/support/load-translations.js
new file mode 100644
index 0000000000..8d76f1d08a
--- /dev/null
+++ b/resources/assets/v3/js/support/load-translations.js
@@ -0,0 +1,61 @@
+/*
+ * load-translations.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 i18next from "i18next";
+import ChainedBackend from "i18next-chained-backend";
+import HttpBackend from "i18next-http-backend";
+import LocalStorageBackend from "i18next-localstorage-backend";
+
+let loaded = false;
+
+function 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+'"');
+ return i18next
+ .use(ChainedBackend)
+ .init({
+ load: 'languageOnly',
+ fallbackLng: "en",
+ lng: replacedLocale,
+ debug: import.meta.env.MODE === 'development',
+ backend: {
+ backends: [
+ LocalStorageBackend,
+ HttpBackend
+ ],
+ backendOptions: [{
+ load: 'languageOnly',
+ expirationTime: expireTime
+ }, {
+ loadPath: './v3/i18n/{{lng}}.json'
+ }]
+ }
+ });
+ }
+ console.warn('Loading translations skipped.');
+ return Promise.resolve();
+}
+
+export {loadTranslations};
diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php
index 7e82db265a..d9075d9cc2 100644
--- a/resources/lang/en_US/firefly.php
+++ b/resources/lang/en_US/firefly.php
@@ -2118,6 +2118,7 @@ return [
'wait_loading_data' => 'Please wait for your information to load...',
'wait_attachments' => 'Please wait for the attachments to upload.',
'errors_upload' => 'The upload has failed. Please check your browser console for the error.',
+ 'upload_too_large' => 'The upload has failed, the file is too large. Please try again.',
'amount_foreign_if' => 'Amount in foreign currency, if any',
'amount_destination_account' => 'Amount in the currency of the destination account',
'edit_transaction_title' => 'Edit transaction ":description"',