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

133 lines
4.5 KiB
Vue
Raw Normal View History

2020-07-03 05:59:36 +02:00
<!--
- MainPiggyList.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-12-22 19:29:44 +01:00
<div class="card">
<div class="card-header">
<h3 class="card-title">{{ $t('firefly.piggy_banks') }}</h3>
</div>
2021-02-14 07:53:20 +01:00
<!-- body if loading -->
2021-02-26 06:39:20 +01:00
<div v-if="loading && !error" class="card-body">
2021-02-14 07:53:20 +01:00
<div class="text-center">
<span class="fas fa-spinner fa-spin"></span>
2021-02-14 07:53:20 +01:00
</div>
</div>
<!-- body if error -->
2021-02-26 06:39:20 +01:00
<div v-if="error" class="card-body">
2021-02-14 07:53:20 +01:00
<div class="text-center">
<span class="fas fa-exclamation-triangle text-danger"></span>
2021-02-14 07:53:20 +01:00
</div>
</div>
<!-- body if normal -->
2021-02-26 06:39:20 +01:00
<div v-if="!loading && !error" class="card-body table-responsive p-0">
2020-12-22 19:29:44 +01:00
<table class="table table-striped">
<caption style="display:none;">{{ $t('firefly.piggy_banks') }}</caption>
<thead>
<tr>
<th scope="col" style="width:35%;">{{ $t('list.piggy_bank') }}</th>
<th scope="col" style="width:40%;">{{ $t('list.percentage') }} <small>/ {{ $t('list.amount') }}</small></th>
</tr>
</thead>
<tbody>
<tr v-for="piggy in this.piggy_banks">
2021-02-05 06:45:27 +01:00
<td>
<a :href="'./piggy-banks/show/' + piggy.id" :title="piggy.attributes.name">{{ piggy.attributes.name }}</a>
2020-12-22 19:29:44 +01:00
<small v-if="piggy.attributes.object_group_title" class="text-muted">
<br/>
{{ piggy.attributes.object_group_title }}
</small>
</td>
<td>
<div class="progress-group">
<div class="progress progress-sm">
2021-05-08 21:26:50 +02:00
<div v-if="piggy.attributes.pct < 100" :style="{'width': piggy.attributes.pct + '%'}" class="progress-bar primary"></div>
2021-02-26 06:39:20 +01:00
<div v-if="100 === piggy.attributes.pct" :style="{'width': piggy.attributes.pct + '%'}"
class="progress-bar progress-bar-striped bg-success"></div>
2020-12-22 19:29:44 +01:00
</div>
</div>
<span class="text-success">
{{
Intl.NumberFormat(locale, {style: 'currency', currency: piggy.attributes.currency_code}).format(piggy.attributes.current_amount)
}}
2020-07-05 18:29:58 +02:00
</span>
2020-12-22 19:29:44 +01:00
of
<span class="text-success">{{
Intl.NumberFormat(locale, {
style: 'currency',
currency: piggy.attributes.currency_code
}).format(piggy.attributes.target_amount)
}}</span>
</td>
</tr>
</tbody>
</table>
</div>
<div class="card-footer">
<a class="btn btn-default button-sm" href="./piggy-banks"><span class="far fa-money-bill-alt"></span> {{ $t('firefly.go_to_piggies') }}</a>
2020-06-17 07:06:45 +02:00
</div>
2020-12-22 19:29:44 +01:00
</div>
2020-06-17 07:06:45 +02:00
</template>
<script>
2020-12-22 19:29:44 +01:00
export default {
name: "MainPiggyList",
2021-02-14 07:53:20 +01:00
data() {
return {
piggy_banks: [],
loading: true,
error: false,
locale: 'en-US'
}
},
2020-12-22 19:29:44 +01:00
created() {
2021-02-14 07:53:20 +01:00
this.locale = localStorage.locale ?? 'en-US';
2020-12-22 19:29:44 +01:00
axios.get('./api/v1/piggy_banks')
.then(response => {
this.loadPiggyBanks(response.data.data);
2021-02-14 07:53:20 +01:00
this.loading = false;
2020-12-22 19:29:44 +01:00
}
2021-02-14 07:53:20 +01:00
).catch(error => {
this.error = true
});
2020-12-22 19:29:44 +01:00
},
methods: {
loadPiggyBanks(data) {
for (let key in data) {
if (data.hasOwnProperty(key) && /^0$|^[1-9]\d*$/.test(key) && key <= 4294967294) {
let piggy = data[key];
if (0.0 !== parseFloat(piggy.attributes.left_to_save)) {
piggy.attributes.pct = (parseFloat(piggy.attributes.current_amount) / parseFloat(piggy.attributes.target_amount)) * 100;
this.piggy_banks.push(piggy);
}
2020-07-05 18:29:58 +02:00
}
2020-12-22 19:29:44 +01:00
}
this.piggy_banks.sort(function (a, b) {
return b.attributes.pct - a.attributes.pct;
});
}
}
}
2020-06-17 07:06:45 +02:00
</script>
<style scoped>
</style>