Files
firefly-iii/frontend/src/components/dashboard/MainAccount.vue

116 lines
3.5 KiB
Vue
Raw Normal View History

2020-07-03 05:59:36 +02:00
<!--
- MainAccount.vue
- Copyright (c) 2020 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/>.
-->
2020-06-17 07:06:45 +02:00
<template>
2020-11-22 07:50:55 +01:00
<div class="card">
<div class="card-header">
<h3 class="card-title">{{ $t('firefly.yourAccounts') }}</h3>
2020-06-17 07:06:45 +02:00
</div>
2020-11-22 07:50:55 +01:00
<div class="card-body">
2021-02-13 20:04:18 +01:00
<div v-if="!loading">
2021-02-14 07:53:20 +01:00
<MainAccountChart :chart-data="dataCollection" :options="chartOptions" v-if="!loading && !error"/>
2021-02-13 20:04:18 +01:00
</div>
<div v-if="loading && !error" class="text-center">
<i class="fas fa-spinner fa-spin"></i>
</div>
<div v-if="error" class="text-center">
<i class="fas fa-exclamation-triangle text-danger"></i>
2020-11-22 07:50:55 +01:00
</div>
</div>
<div class="card-footer">
<a href="./accounts/asset" class="btn btn-default button-sm"><i class="far fa-money-bill-alt"></i> {{ $t('firefly.go_to_asset_accounts') }}</a>
</div>
</div>
2020-06-17 07:06:45 +02:00
</template>
<script>
2021-02-14 07:53:20 +01:00
2020-11-22 07:50:55 +01:00
import DataConverter from "../charts/DataConverter";
import DefaultLineOptions from "../charts/DefaultLineOptions";
2020-06-17 07:06:45 +02:00
2021-02-13 20:04:18 +01:00
import {createNamespacedHelpers} from "vuex";
import MainAccountChart from "./MainAccountChart";
2021-02-14 07:53:20 +01:00
2021-02-13 20:04:18 +01:00
const {mapState, mapGetters, mapActions, mapMutations} = createNamespacedHelpers('dashboard/index')
2020-11-22 07:50:55 +01:00
export default {
name: "MainAccount",
2021-02-13 20:04:18 +01:00
components: {MainAccountChart},
data() {
return {
loading: true,
error: false,
ready: false,
dataCollection: {},
chartOptions: {}
}
},
2020-11-22 07:50:55 +01:00
created() {
2021-02-14 07:53:20 +01:00
this.ready = true;
2021-02-13 20:04:18 +01:00
this.chartOptions = DefaultLineOptions.methods.getDefaultOptions();
},
computed: {
...mapGetters([
'start',
'end'
]),
'datesReady': function () {
return null !== this.start && null !== this.end && this.ready;
}
},
watch: {
datesReady: function (value) {
if (true === value) {
// console.log(this.chartOptions);
this.initialiseChart();
}
2021-02-14 07:53:20 +01:00
},
start: function () {
this.initialiseChart();
},
end: function () {
this.initialiseChart();
},
2021-02-13 20:04:18 +01:00
},
methods: {
initialiseChart: function () {
2021-02-14 07:53:20 +01:00
this.loading = true;
2021-02-13 20:04:18 +01:00
let startStr = this.start.toISOString().split('T')[0];
let endStr = this.end.toISOString().split('T')[0];
let url = './api/v1/chart/account/overview?start=' + startStr + '&end=' + endStr;
// console.log('URL is ' + url);
axios.get(url)
.then(response => {
let chartData = DataConverter.methods.convertChart(response.data);
chartData = DataConverter.methods.colorizeLineData(chartData);
this.dataCollection = chartData;
this.loading = false;
})
.catch(error => {
// console.log('Has error!');
// console.log(error);
this.error = true;
// console.error(error);
2020-11-22 07:50:55 +01:00
});
2021-02-13 20:04:18 +01:00
}
2020-11-22 07:50:55 +01:00
},
}
2020-06-17 07:06:45 +02:00
</script>