2022-03-29 14:55:51 +02:00
|
|
|
<!--
|
|
|
|
- App.vue
|
|
|
|
- Copyright (c) 2022 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/>.
|
|
|
|
-->
|
|
|
|
|
2022-02-27 10:12:54 +01:00
|
|
|
<template>
|
|
|
|
<router-view/>
|
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
import {defineComponent} from 'vue';
|
|
|
|
import Preferences from "./api/preferences";
|
2022-06-06 14:40:19 +02:00
|
|
|
import Prefs from "./api/v2/preferences";
|
2022-02-27 10:12:54 +01:00
|
|
|
import Currencies from "./api/currencies";
|
2022-05-02 18:54:43 +02:00
|
|
|
import {useFireflyIIIStore} from 'stores/fireflyiii'
|
|
|
|
|
2022-02-27 10:12:54 +01:00
|
|
|
|
|
|
|
export default defineComponent(
|
|
|
|
{
|
|
|
|
name: 'App',
|
|
|
|
preFetch({store}) {
|
2022-05-02 18:54:43 +02:00
|
|
|
const ffStore = useFireflyIIIStore(store);
|
2022-02-27 10:12:54 +01:00
|
|
|
|
2022-05-02 18:54:43 +02:00
|
|
|
ffStore.refreshCacheKey();
|
2022-02-27 10:12:54 +01:00
|
|
|
|
2022-05-02 18:54:43 +02:00
|
|
|
const getViewRange = function () {
|
2022-02-27 10:12:54 +01:00
|
|
|
let pref = new Preferences();
|
2022-05-02 18:54:43 +02:00
|
|
|
return pref.getByName('viewRange').then(data => {
|
2022-02-27 10:12:54 +01:00
|
|
|
|
|
|
|
const viewRange = data.data.data.attributes.data;
|
2022-05-02 18:54:43 +02:00
|
|
|
ffStore.updateViewRange(viewRange);
|
|
|
|
ffStore.setDatesFromViewRange();
|
2022-02-27 10:12:54 +01:00
|
|
|
}).catch((err) => {
|
|
|
|
console.error('Could not load view range.')
|
|
|
|
console.log(err);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-05-02 18:54:43 +02:00
|
|
|
const getListPageSize = function () {
|
2022-02-27 10:12:54 +01:00
|
|
|
let pref = new Preferences();
|
2022-05-02 18:54:43 +02:00
|
|
|
return pref.getByName('listPageSize').then(data => {
|
2022-02-27 10:12:54 +01:00
|
|
|
|
|
|
|
const listPageSize = data.data.data.attributes.data;
|
2022-05-02 18:54:43 +02:00
|
|
|
ffStore.updateListPageSize(listPageSize);
|
2022-02-27 10:12:54 +01:00
|
|
|
}).catch((err) => {
|
|
|
|
console.error('Could not load listPageSize.')
|
|
|
|
console.log(err);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-05-02 18:54:43 +02:00
|
|
|
const getDefaultCurrency = function () {
|
2022-02-27 10:12:54 +01:00
|
|
|
let curr = new Currencies();
|
2022-05-02 18:54:43 +02:00
|
|
|
return curr.default().then(data => {
|
2022-02-27 10:12:54 +01:00
|
|
|
let currencyId = parseInt(data.data.data.id);
|
|
|
|
let currencyCode = data.data.data.attributes.code;
|
2022-05-02 18:54:43 +02:00
|
|
|
ffStore.setCurrencyId(currencyId);
|
|
|
|
ffStore.setCurrencyCode(currencyCode);
|
2022-02-27 10:12:54 +01:00
|
|
|
}).catch((err) => {
|
|
|
|
console.error('Could not load preferences.');
|
|
|
|
console.log(err);
|
2023-04-10 14:21:10 +02:00
|
|
|
|
|
|
|
// redirect user if 401
|
|
|
|
if (err.response) {
|
|
|
|
if(401 === err.response.status) {
|
|
|
|
window.location.href = '/login';
|
|
|
|
}
|
|
|
|
}
|
2022-02-27 10:12:54 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-06-06 14:40:19 +02:00
|
|
|
const getLocale = function () {
|
|
|
|
return (new Prefs).get('locale').then(data => {
|
2022-12-29 19:43:43 +01:00
|
|
|
const locale = data.data.data.attributes.data.replace('_', '-');
|
2022-06-06 14:40:19 +02:00
|
|
|
|
|
|
|
ffStore.setLocale(locale);
|
|
|
|
}).catch((err) => {
|
|
|
|
console.error('Could not load locale.')
|
|
|
|
console.log(err);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-02-27 10:12:54 +01:00
|
|
|
|
|
|
|
getDefaultCurrency().then(() => {
|
|
|
|
getViewRange();
|
|
|
|
getListPageSize();
|
2022-06-06 14:40:19 +02:00
|
|
|
getLocale();
|
2022-02-27 10:12:54 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
})
|
|
|
|
</script>
|