mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-08-26 13:17:30 -05:00
Fix default coordinates.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Generated
+1
-1
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "release",
|
||||
"name": "firefly-iii",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* basic.js
|
||||
* Copyright (c) 2021 james@firefly-iii.org
|
||||
*
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
@@ -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: '© <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: '© <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;
|
||||
|
||||
@@ -26,4 +26,5 @@ export function addSplit() {
|
||||
this.entries.push(createEmptySplit());
|
||||
this.disableSplitAccounts();
|
||||
this.addAllAutocompleteToForm();
|
||||
this.addTabListener();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* load-default-coordinates.js
|
||||
* Copyright (c) 2026 james@firefly-iii.org
|
||||
*
|
||||
* 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;
|
||||
});
|
||||
}
|
||||
@@ -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">
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user