Skip to content

Firefly III: a personal finances manager

Fix default coordinates.

James Coled4ca3b3bebb6
diff --git a/app/Api/V1/Controllers/System/ConfigurationController.php b/app/Api/V1/Controllers/System/ConfigurationController.php
index e1ca4cdcf9..ee8457fecd 100644
--- a/app/Api/V1/Controllers/System/ConfigurationController.php
+++ b/app/Api/V1/Controllers/System/ConfigurationController.php
@@ -42,9 +42,6 @@ use Illuminate\Validation\ValidationException;
final class ConfigurationController extends Controller
{
/**
- * This endpoint is documented at:
- * https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/configuration/getConfiguration
- *
* @throws FireflyException
*/
public function index(): JsonResponse
diff --git a/app/Http/Controllers/Transaction/CreateController.php b/app/Http/Controllers/Transaction/CreateController.php
index a55afbc419..11a6536903 100644
--- a/app/Http/Controllers/Transaction/CreateController.php
+++ b/app/Http/Controllers/Transaction/CreateController.php
@@ -132,9 +132,9 @@ final class CreateController extends Controller
return view('transactions.create', [
'subTitleIcon' => $subTitleIcon,
'cash' => $cash,
- 'longitude' => $longitude,
- 'latitude' => $latitude,
- 'zoomLevel' => $zoomLevel,
+// 'longitude' => $longitude,
+// 'latitude' => $latitude,
+// 'zoomLevel' => $zoomLevel,
'objectType' => $objectType,
'subTitle' => $subTitle,
'previousUrl' => $previousUrl,
diff --git a/package-lock.json b/package-lock.json
index 8b13388015..4d7208d4dd 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,5 +1,5 @@
{
- "name": "release",
+ "name": "firefly-iii",
"lockfileVersion": 3,
"requires": true,
"packages": {
diff --git a/resources/assets/v3/js/api/configuration/get.js b/resources/assets/v3/js/api/configuration/get.js
new file mode 100644
index 0000000000..ab92676d1a
--- /dev/null
+++ b/resources/assets/v3/js/api/configuration/get.js
@@ -0,0 +1,27 @@
+/*
+ * basic.js
+ * Copyright (c) 2021 [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 Get {
+ getByName(name) {
+ return api.get('/api/v1/configuration/' + name);
+ }
+}
diff --git a/resources/assets/v3/js/pages/transactions/create.js b/resources/assets/v3/js/pages/transactions/create.js
index f0f2506e8d..fcc3d1eeba 100644
--- a/resources/assets/v3/js/pages/transactions/create.js
+++ b/resources/assets/v3/js/pages/transactions/create.js
@@ -52,6 +52,7 @@ import {determineAmountCurrency} from './shared/determine-amount-currency.js';
import {loadCustomFields} from './shared/load-custom-fields.js';
import L from 'leaflet';
import 'leaflet/dist/leaflet.css';
+import {loadDefaultCoordinates} from './shared/load-default-coordinates.js';
// TODO fix two maps, perhaps disconnect from entries entirely.
// TODO map location from preferences
@@ -67,6 +68,9 @@ let create = function () {
// transactions are stored in "entries":
entries: [],
+ // maps are stored in this array so they can be referred to.
+ maps: [],
+
// properties for the entire transaction group
groupProperties: {
transactionType: 'unknown',
@@ -96,6 +100,12 @@ let create = function () {
formType: 'create',
foreignCurrencyEnabled: true,
customFields: {},
+ defaultCoordinates: {
+ loaded: false,
+ latitude: 30,
+ longitude: 20,
+ zoom_level: 9,
+ },
},
// form data (except transactions) is stored in formData
@@ -108,7 +118,7 @@ let create = function () {
foreignCurrencies: [], // this is the select list for foreign currencies.
budgets: [],
piggyBanks: [],
- subscriptions: [],
+ subscriptions: []
},
@@ -159,6 +169,7 @@ let create = function () {
determineAmountCurrency: determineAmountCurrency,
addAllAutocompleteToForm: addAllAutocompleteToForm,
loadCustomFields: loadCustomFields,
+ loadDefaultCoordinates: loadDefaultCoordinates,
filterForeignCurrencies(code) {
@@ -209,31 +220,76 @@ let create = function () {
clearCategory(index) {
this.entries[index].category_name = '';
},
-
+ displayMap(index) {
+ index = parseInt(index);
+ if (true === this.formBehaviour.customFields.location) {
+
+ if (false === this.formBehaviour.defaultCoordinates.loaded) {
+ // load first, then show map.
+ this.loadDefaultCoordinates().then(data => {
+ this.formBehaviour.defaultCoordinates = data;
+ this.renderMap(index, true);
+ });
+ return;
+ }
+ this.renderMap(index, false);
+ }
+ },
+ renderMap(index, useDefault) {
+ const el = document.getElementById('location_map_' + index);
+ let latitude = parseFloat(this.formBehaviour.defaultCoordinates.latitude);
+ let longitude = parseFloat(this.formBehaviour.defaultCoordinates.longitude);
+ let zoomLevel = parseInt(this.formBehaviour.defaultCoordinates.zoom_level);
+ if(!useDefault) {
+ console.log('Using coordinates from data attributes');
+ latitude = parseFloat(el.dataset.latitude);
+ longitude = parseFloat(el.dataset.longitude);
+ zoomLevel = parseInt(el.dataset.zoomLevel);
+ }
+ console.log('lat', latitude);
+ console.log('long', longitude);
+ console.log('zoom', zoomLevel);
+
+ this.maps[index] = L.map(el).setView([latitude, longitude], zoomLevel);
+ L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
+ maxZoom: 19,
+ referrerPolicy: 'origin-when-cross-origin',
+ attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
+ }).addTo(this.maps[index]);
+ },
+ respondToTabSwitch(event) {
+ // event.target // newly activated tab
+ // event.relatedTarget // previous active tab
+ let index = parseInt(event.currentTarget.dataset.index);
+ console.log(this);
+ if(this.maps.hasOwnProperty(index)) {
+ this.maps[index].invalidateSize();
+ }
+ //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"]')
+ console.log('Found tab elements', tabEl.length);
+ for(let i = 0; i < tabEl.length; i++) {
+ console.log('Add to tab element', i);
+ tabEl[i].removeEventListener('shown.bs.tab', this.respondToTabSwitch);
+ tabEl[i].addEventListener('shown.bs.tab', this.respondToTabSwitch.bind(this), true);
+ }
+ // tabEl.addEventListener('shown.bs.tab', event => {
+ // // event.target // newly activated tab
+ // // event.relatedTarget // previous active tab
+ // console.log('Switched to new tab!');
+ // });
+ }, 500);
+ },
init() {
- console.log('init()');
this.i18next = i18next;
this.addSplit();
- // load custom field preference and enable/disable those fields.
- this.loadCustomFields().then(data => {
- console.log('Loaded custom fields', data);
- this.formBehaviour.customFields = data;
- if(true === data.location) {
- console.log('Need to add map.');
-
- setTimeout(() => {
- let map = L.map(document.getElementById('location_map_0')).setView([51.505, -0.09], 13);
- L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
- maxZoom: 19,
- referrerPolicy: 'origin-when-cross-origin',
- attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
- }).addTo(map);
- }, 2000);
- }
- });
-
// load currencies and save in form data.
loadCurrencies().then(data => {
this.formStates.loadingCurrencies = false;
@@ -256,6 +312,13 @@ let create = function () {
this.formStates.loadingSubscriptions = false;
});
+ // load custom field preference and enable/disable those fields.
+ this.loadCustomFields().then(data => {
+ console.log('Loaded custom fields', data);
+ this.formBehaviour.customFields = data;
+ });
+
+
document.addEventListener('upload-success', (event) => {
console.log('Now in event listener "upload-success"');
this.processUpload(event);
@@ -270,6 +333,10 @@ let create = function () {
console.log('Now in event listener "upload-failed"')
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;
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 5fd12e3e7d..8b74c2e7b7 100644
--- a/resources/assets/v3/js/pages/transactions/shared/add-split.js
+++ b/resources/assets/v3/js/pages/transactions/shared/add-split.js
@@ -26,4 +26,5 @@ export function addSplit() {
this.entries.push(createEmptySplit());
this.disableSplitAccounts();
this.addAllAutocompleteToForm();
+ this.addTabListener();
}
diff --git a/resources/assets/v3/js/pages/transactions/shared/load-default-coordinates.js b/resources/assets/v3/js/pages/transactions/shared/load-default-coordinates.js
new file mode 100644
index 0000000000..2924007634
--- /dev/null
+++ b/resources/assets/v3/js/pages/transactions/shared/load-default-coordinates.js
@@ -0,0 +1,27 @@
+/*
+ * load-default-coordinates.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 Configuration from "../../../api/configuration/get.js";
+
+export function loadDefaultCoordinates() {
+ return (new Configuration()).getByName('firefly.default_location').then(data => {
+ return data.data.data.value;
+ });
+}
diff --git a/resources/views/components/transaction/tab-list.blade.php b/resources/views/components/transaction/tab-list.blade.php
index b33e087be9..95fe544fbd 100644
--- a/resources/views/components/transaction/tab-list.blade.php
+++ b/resources/views/components/transaction/tab-list.blade.php
@@ -9,6 +9,7 @@
data-bs-toggle="tab"
:data-bs-target="'#split-'+index+'-pane'"
type="button" role="tab"
+ :data-index="index"
:aria-controls="'split-'+index+'-pane'"
aria-selected="true">
<template x-if="'' === transaction.description">
diff --git a/resources/views/partials/form/transaction/location.blade.php b/resources/views/partials/form/transaction/location.blade.php
index 7fa4cdff23..6e7af44419 100644
--- a/resources/views/partials/form/transaction/location.blade.php
+++ b/resources/views/partials/form/transaction/location.blade.php
@@ -4,17 +4,17 @@
<label :for="'map_' + index" class="col-sm-1 col-form-label d-none d-sm-block">
<em title="{{ __('firefly.location') }}" class="bi bi-globe-europe-africa"></em>
</label>
- <template x-if="index > 0">
+ <template x-if="false && index > 0">
<div class="col-sm-10">
<label class="custom-control-label small">{{ __('firefly.location_first_split') }}</label>
</div>
</template>
- <template x-if="0 === index">
+ <template x-if="true || 0 === index">
<div class="col-sm-10">
- <div
- data-latitude="{{ $latitude ?? '' }}"
- data-longitude="{{ $longitude ?? '' }}"
- data-zoom-level="{{ $zoomLevel ?? '' }}"
+ <div x-init="displayMap(index)"
+ :data-longitude="formBehaviour.defaultCoordinates.longitude"
+ :data-latitude="formBehaviour.defaultCoordinates.latitude"
+ :data-zoom-level="formBehaviour.defaultCoordinates.zoom_level"
:id="'location_map_' + index" class="map-size location-map" :data-index="index"></div>
<span class="muted small">
diff --git a/resources/views/transactions/create.blade.php b/resources/views/transactions/create.blade.php
index 45f1bae474..de55f0d2c8 100644
--- a/resources/views/transactions/create.blade.php
+++ b/resources/views/transactions/create.blade.php
@@ -6,9 +6,6 @@
<div class="tab-content" id="splitTabsContent">
<template x-for="transaction, index in entries">
<x-transaction.split
- :zoomLevel="$zoomLevel"
- :latitude="$latitude"
- :longitude="$longitude"
/>
</template>
</div>