mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-17 23:28:20 +00:00
Rebuild frontend, do not use store in components.
This commit is contained in:
@@ -20,10 +20,10 @@
|
||||
|
||||
<template>
|
||||
<!-- FOREIGN Currency -->
|
||||
<div class="form-group" v-if="selectIsVisible">
|
||||
<div class="form-group" v-if="isVisible">
|
||||
<div class="text-xs"> </div>
|
||||
<div class="input-group">
|
||||
<select name="foreign_currency_id[]" v-model="currencyId" class="form-control">
|
||||
<select name="foreign_currency_id[]" v-model="selectedCurrency" class="form-control">
|
||||
<option v-for="currency in selectableCurrencies" :label="currency.name" :value="currency.id">{{ currency.name }}</option>
|
||||
</select>
|
||||
</div>
|
||||
@@ -31,77 +31,48 @@
|
||||
</template>
|
||||
<script>
|
||||
|
||||
import {createNamespacedHelpers} from "vuex";
|
||||
|
||||
const {mapState, mapGetters, mapActions, mapMutations} = createNamespacedHelpers('transactions/create')
|
||||
|
||||
export default {
|
||||
name: "TransactionForeignCurrency",
|
||||
props: ['index'],
|
||||
props: [
|
||||
'index',
|
||||
'transactionType',
|
||||
'sourceCurrencyId',
|
||||
'destinationCurrencyId',
|
||||
'selectedCurrencyId'
|
||||
],
|
||||
data() {
|
||||
return {
|
||||
selectedCurrency: 0,
|
||||
allCurrencies: [],
|
||||
selectableCurrencies: [],
|
||||
dstCurrencyId: this.destinationCurrencyId,
|
||||
srcCurrencyId: this.sourceCurrencyId,
|
||||
lockedCurrency: 0,
|
||||
selectIsVisible: true
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
sourceCurrencyId: function (value) {
|
||||
this.srcCurrencyId = value;
|
||||
},
|
||||
destinationCurrencyId: function (value) {
|
||||
this.dstCurrencyId = value;
|
||||
},
|
||||
selectedCurrency: function(value) {
|
||||
this.$emit('set-foreign-currency-id', value);
|
||||
},
|
||||
transactionType: function (value) {
|
||||
this.lockedCurrency = 0;
|
||||
if ('Transfer' === value) {
|
||||
// take currency from destination:
|
||||
this.currencyId = this.transactions[this.index].destination_account.currency_id;
|
||||
this.currencySymbol = this.transactions[this.index].destination_account.currency_symbol;
|
||||
this.lockedCurrency = this.currencyId;
|
||||
this.lockedCurrency = this.dstCurrencyId;
|
||||
this.selectedCurrency = this.dstCurrencyId;
|
||||
}
|
||||
this.filterCurrencies();
|
||||
this.checkVisibility();
|
||||
},
|
||||
destinationAllowedTypes: function (value) {
|
||||
this.lockedCurrency = 0;
|
||||
if ('Transfer' === this.transactionType) {
|
||||
// take currency from destination:
|
||||
this.currencyId = this.transactions[this.index].destination_account.currency_id;
|
||||
this.currencySymbol = this.transactions[this.index].destination_account.currency_symbol;
|
||||
this.lockedCurrency = this.currencyId;
|
||||
}
|
||||
this.filterCurrencies();
|
||||
this.checkVisibility();
|
||||
},
|
||||
sourceAllowedTypes: function (value) {
|
||||
this.lockedCurrency = 0;
|
||||
if ('Transfer' === this.transactionType) {
|
||||
// take currency from destination:
|
||||
this.currencyId = this.transactions[this.index].destination_account.currency_id;
|
||||
this.currencySymbol = this.transactions[this.index].destination_account.currency_symbol;
|
||||
this.lockedCurrency = this.currencyId;
|
||||
}
|
||||
this.filterCurrencies();
|
||||
this.checkVisibility();
|
||||
},
|
||||
|
||||
},
|
||||
created: function () {
|
||||
this.getAllCurrencies();
|
||||
},
|
||||
methods: {
|
||||
...mapMutations(
|
||||
[
|
||||
'updateField',
|
||||
],
|
||||
),
|
||||
checkVisibility: function () {
|
||||
// have the same currency ID, but not zero, and is a transfer
|
||||
let sourceId = this.transactions[this.index].source_account.currency_id;
|
||||
let destId = this.transactions[this.index].destination_account.currency_id;
|
||||
this.selectIsVisible = true;
|
||||
if (sourceId === destId && 0 !== sourceId && 'Transfer' === this.transactionType) {
|
||||
this.selectIsVisible = false;
|
||||
this.currencyId = 0;
|
||||
}
|
||||
},
|
||||
|
||||
getAllCurrencies: function () {
|
||||
axios.get('./api/v1/autocomplete/currencies')
|
||||
.then(response => {
|
||||
@@ -119,14 +90,13 @@ export default {
|
||||
let current = this.allCurrencies[key];
|
||||
if (current.id === this.lockedCurrency) {
|
||||
this.selectableCurrencies = [current];
|
||||
this.currencyId = current.id;
|
||||
this.selectedCurrency = current.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.selectableCurrencies = [
|
||||
{
|
||||
"id": 0,
|
||||
@@ -136,62 +106,15 @@ export default {
|
||||
for (let key in this.allCurrencies) {
|
||||
if (this.allCurrencies.hasOwnProperty(key) && /^0$|^[1-9]\d*$/.test(key) && key <= 4294967294) {
|
||||
let current = this.allCurrencies[key];
|
||||
// add to array if not "locked" in place:
|
||||
if (this.transactions[this.index].currency_id !== current.id) {
|
||||
this.selectableCurrencies.push(current);
|
||||
}
|
||||
// deselect impossible currency.
|
||||
if (this.transactions[this.index].currency_id === current.id && this.currencyId === current.id) {
|
||||
this.currencyId = 0;
|
||||
}
|
||||
this.selectableCurrencies.push(current);
|
||||
}
|
||||
}
|
||||
//currency_id
|
||||
|
||||
// always add empty currency:
|
||||
// this.selectableCurrencies = this.allCurrencies;
|
||||
// this.selectableCurrencies.reverse();
|
||||
// this.selectableCurrencies.push(
|
||||
// ;
|
||||
// this.selectableCurrencies.reverse();
|
||||
|
||||
// remove
|
||||
|
||||
}
|
||||
|
||||
// updateCurrency: function () {
|
||||
// if (0 === this.currencyId) {
|
||||
// // use default currency from store.
|
||||
// this.currencySymbol = this.currencyPreference.symbol;
|
||||
// this.currencyId = this.currencyPreference.id;
|
||||
// }
|
||||
// }
|
||||
},
|
||||
computed: {
|
||||
currencyPreference: {
|
||||
get() {
|
||||
return this.$store.state.currencyPreference;
|
||||
}
|
||||
},
|
||||
...mapGetters([
|
||||
'transactionType',
|
||||
'transactions',
|
||||
'destinationAllowedTypes',
|
||||
'sourceAllowedTypes',
|
||||
]),
|
||||
currencyId: {
|
||||
get() {
|
||||
return this.transactions[this.index].foreign_currency_id;
|
||||
},
|
||||
set(value) {
|
||||
this.updateField({field: 'foreign_currency_id', index: this.index, value: value});
|
||||
}
|
||||
},
|
||||
normalCurrencyId: {
|
||||
get() {
|
||||
return this.transactions[this.index].currency_id;
|
||||
},
|
||||
},
|
||||
isVisible: function () {
|
||||
return !('Transfer' === this.transactionType && this.srcCurrencyId === this.dstCurrencyId);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user