This commit is contained in:
James Cole
2021-03-22 06:45:13 +01:00
parent 7f48a1b6ee
commit abb0f3d2be
15 changed files with 836 additions and 2098 deletions

View File

@@ -27,9 +27,7 @@
<div class="row">
<div class="col">
<p v-if="links.length === 0">
<button class="btn btn-default btn-xs" :data-target="'#linkModal' + index" @click="resetModal" data-toggle="modal"><i class="fas fa-plus"></i> Add transaction
link
</button>
<button class="btn btn-default btn-xs" data-target="#linkModal" @click="resetModal" data-toggle="modal"><i class="fas fa-plus"></i> Add transaction link</button>
</p>
<ul v-if="links.length > 0" class="list-group">
<li v-for="(transaction, index) in links" class="list-group-item" v-bind:key="index">
@@ -66,13 +64,13 @@
</li>
</ul>
<div v-if="links.length > 0" class="form-text">
<button class="btn btn-default" @click="resetModal" :data-target="'#linkModal' + index" data-toggle="modal"><i class="fas fa-plus"></i></button>
<button class="btn btn-default" @click="resetModal" data-target="#linkModal" data-toggle="modal"><i class="fas fa-plus"></i></button>
</div>
</div>
</div>
</div>
<!-- modal -->
<div :id="'linkModal' + index" class="modal" tabindex="-1" :ref="'linkModal' + index">
<div id="linkModal" class="modal" tabindex="-1" ref="linkModal">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
@@ -307,7 +305,7 @@ export default {
}
);
},
resetModal: function () {
resetModal: function() {
this.search();
},
parseLinkTypes: function (data) {
@@ -334,7 +332,7 @@ export default {
}
},
search: function () {
if ('' === this.query) {
if('' === this.query) {
this.searchResults = [];
return;
}
@@ -353,28 +351,11 @@ export default {
for (let ii in data.data[i].attributes.transactions) {
if (data.data[i].attributes.transactions.hasOwnProperty(ii) && /^0$|^[1-9]\d*$/.test(ii) && ii <= 4294967294) {
let current = data.data[i].attributes.transactions[ii];
let copied = {
transaction_journal_id: current.transaction_journal_id,
transaction_group_id: parseInt(data.data[i].id),
description: current.description,
type: current.type,
amount: current.amount,
currency_code: current.currency_code,
source_id: current.source_id,
source_name: current.source_name,
destination_id: current.destination_id,
destination_name: current.destination_name,
selected: this.isJournalSelected(current.transaction_journal_id),
link_type_id: this.getJournalLinkType(current.transaction_journal_id),
link_type_text: '',
};
// current.transaction_group_id = parseInt(data.data[i].id);
// current.selected = this.isJournalSelected(current.transaction_journal_id);
// current.link_type_id = this.getJournalLinkType(current.transaction_journal_id);
// current.link_type_text = '';
this.searchResults.push(copied);
current.transaction_group_id = parseInt(data.data[i].id);
current.selected = this.isJournalSelected(current.transaction_journal_id);
current.link_type_id = this.getJournalLinkType(current.transaction_journal_id);
current.link_type_text = '';
this.searchResults.push(current);
}
}
}

View File

@@ -43,6 +43,7 @@ export default {
return {
notes: this.value,
availableFields: this.customFields,
emitEvent: true
}
},
computed: {
@@ -55,13 +56,17 @@ export default {
},
watch: {
value: function (value) {
this.emitEvent = false;
this.notes = value;
},
customFields: function (value) {
this.availableFields = value;
},
notes: function (value) {
this.$emit('set-field', {field: 'notes', index: this.index, value: value});
if (true === this.emitEvent) {
this.$emit('set-field', {field: 'notes', index: this.index, value: value});
}
this.emitEvent = true;
}
}
}

View File

@@ -33,16 +33,9 @@
name="piggy_bank_id[]"
v-on:submit.prevent
>
<optgroup v-for="group in this.piggyGroups" v-bind:key="group.title" :label="group.title">
<option v-for="piggy in group.piggies" :label="piggy.name_with_balance" :value="piggy.id">{{ piggy.name_with_balance }}</option>
</optgroup>
<option v-for="piggy in this.piggyList" :label="piggy.name_with_balance" :value="piggy.id">{{ piggy.name_with_balance }}</option>
</select>
<!--
<span v-for="group in this.piggyList">"{{ group.title }}"<br>
</span>
-->
</div>
<span v-if="errors.length > 0">
<span v-for="error in errors" class="text-danger small">{{ error }}<br/></span>
@@ -57,8 +50,7 @@ export default {
name: "TransactionPiggyBank",
data() {
return {
piggyGroups: [],
piggyList: {},
piggyList: [],
piggy_bank_id: this.value,
emitEvent: true
}
@@ -68,33 +60,12 @@ export default {
},
methods: {
collectData() {
// add empty group:
this.piggyGroups.push(
this.piggyList.push(
{
id: 0,
title: this.$t('firefly.default_group_title_name'),
piggies: []
name_with_balance: this.$t('firefly.no_piggy_bank'),
}
);
// empty piggy list:
// this.piggyList['0'] = {
// title: this.$t('firefly.default_group_title_name'),
// piggies: [
// {
// id: 0,
// name_with_balance: this.$t('firefly.no_piggy_bank'),
// }
// ]
// };
// this.piggyList.push(
// {
// id: 0,
// name_with_balance: this.$t('firefly.no_piggy_bank'),
// }
// );
this.getPiggies();
},
getPiggies() {
@@ -104,67 +75,18 @@ export default {
}
);
},
groupExists: function (title) {
for (let i in this.piggyGroups) {
if (this.piggyGroups.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {
let current = this.piggyGroups[i];
if (current.title === title) {
return true;
}
}
}
return false;
},
getGroupIndex: function (groupId) {
for (let i in this.piggyGroups) {
if (this.piggyGroups.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {
let current = this.piggyGroups[i];
if (current.id === groupId) {
return i;
}
}
}
return 0;
},
parsePiggies(data) {
for (let key in data) {
if (data.hasOwnProperty(key) && /^0$|^[1-9]\d*$/.test(key) && key <= 4294967294) {
let current = data[key];
let groupId = current.object_group_id ?? '0';
if ('0' !== groupId) {
if (this.groupExists(current.object_group_title)) {
let currentGroup = this.getGroupIndex(parseInt(current.object_group_id));
this.piggyGroups[currentGroup].piggies.push(current);
}
if (!this.groupExists(current.object_group_title)) {
this.piggyGroups.push(
{
id: parseInt(current.object_group_id),
title: current.object_group_title,
piggies: [current]
}
);
}
}
if ('0' === groupId) {
this.piggyGroups[0].piggies.push(current);
}
// //console.log('group id is ' + groupId);
// if ('0' !== groupId) {
// this.piggyList[groupId] = this.piggyList[groupId] ? this.piggyList[groupId] : {title: current.object_group_title, piggies: []};
// }
// this.piggyList[groupId].piggies.push(
// {
// id: parseInt(current.id),
// name_with_balance: current.name_with_balance
// }
// );
this.piggyList.push(
{
id: parseInt(current.id),
name_with_balance: current.name_with_balance
}
);
}
}
//console.log(this.piggyList);
},
},
watch: {