This commit is contained in:
James Cole
2021-06-06 17:25:38 +02:00
parent a8f4154a77
commit 26ad0d3bc3

View File

@@ -57,7 +57,9 @@
</template> </template>
<template #cell(description)="data"> <template #cell(description)="data">
<span><i class="fas fa-angle-right" v-if="data.item.split && data.item.split_parent !== null"></i></span> <span><i class="fas fa-angle-right" v-if="data.item.split && data.item.split_parent !== null"></i></span>
<a :class="false === data.item.active ? 'text-muted' : ''" :href="'./transactions/show/' + data.item.id" :title="data.value">{{ data.value }}</a> <a :class="false === data.item.active ? 'text-muted' : ''" :href="'./transactions/show/' + data.item.id" :title="data.value">{{
data.value
}}</a>
</template> </template>
<template #cell(amount)="data"> <template #cell(amount)="data">
<span class="text-success" v-if="'deposit' === data.item.type"> <span class="text-success" v-if="'deposit' === data.item.type">
@@ -76,10 +78,12 @@
{{ data.item.date_formatted }} {{ data.item.date_formatted }}
</template> </template>
<template #cell(source_account)="data"> <template #cell(source_account)="data">
<a :class="false === data.item.active ? 'text-muted' : ''" :href="'./accounts/show/' + data.item.source_id" :title="data.item.source_name">{{ data.item.source_name }}</a> <a :class="false === data.item.active ? 'text-muted' : ''" :href="'./accounts/show/' + data.item.source_id"
:title="data.item.source_name">{{ data.item.source_name }}</a>
</template> </template>
<template #cell(destination_account)="data"> <template #cell(destination_account)="data">
<a :class="false === data.item.active ? 'text-muted' : ''" :href="'./accounts/show/' + data.item.destination_id" :title="data.item.destination_name">{{ data.item.destination_name }}</a> <a :class="false === data.item.active ? 'text-muted' : ''" :href="'./accounts/show/' + data.item.destination_id"
:title="data.item.destination_name">{{ data.item.destination_name }}</a>
</template> </template>
<template #cell(menu)="data"> <template #cell(menu)="data">
<div class="btn-group btn-group-sm" v-if="! data.item.split || data.item.split_parent === null"> <div class="btn-group btn-group-sm" v-if="! data.item.split || data.item.split_parent === null">
@@ -95,12 +99,12 @@
</div> </div>
</div> </div>
<div class="btn btn-light btn-sm" v-if="data.item.split && data.item.split_parent === null && data.item.collapsed === true" <div class="btn btn-light btn-sm" v-if="data.item.split && data.item.split_parent === null && data.item.collapsed === true"
v-on:click="toggleCollapse(data.item)"> v-on:click="toggleCollapse(data.item)">
<i class="fa fa-caret-down"></i> <i class="fa fa-caret-down"></i>
Expand split Expand split
</div> </div>
<div class="btn btn-light btn-sm" v-else-if="data.item.split && data.item.split_parent === null && data.item.collapsed === false" <div class="btn btn-light btn-sm" v-else-if="data.item.split && data.item.split_parent === null && data.item.collapsed === false"
v-on:click="toggleCollapse(data.item)"> v-on:click="toggleCollapse(data.item)">
<i class="fa fa-caret-up"></i> <i class="fa fa-caret-up"></i>
Collapse split Collapse split
</div> </div>
@@ -111,7 +115,8 @@
</b-table> </b-table>
</div> </div>
<div class="card-footer"> <div class="card-footer">
<a :href="'./transactions/create/' + type" class="btn btn-success" :title="$t('firefly.create_new_transaction')">{{ $t('firefly.create_new_transaction') }}</a> <a :href="'./transactions/create/' + type" class="btn btn-success"
:title="$t('firefly.create_new_transaction')">{{ $t('firefly.create_new_transaction') }}</a>
<a href="#" class="btn btn-info"><i class="fas fa-sync"></i></a> <a href="#" class="btn btn-info"><i class="fas fa-sync"></i></a>
</div> </div>
</div> </div>
@@ -248,24 +253,27 @@ export default {
let endStr = format(this.end, 'y-MM-dd'); let endStr = format(this.end, 'y-MM-dd');
api.get('./api/v1/transactions?type=' + this.type + '&page=' + page + "&start=" + startStr + "&end=" + endStr) api.get('./api/v1/transactions?type=' + this.type + '&page=' + page + "&start=" + startStr + "&end=" + endStr)
.then(response => { .then(response => {
let currentPage = parseInt(response.data.meta.pagination.current_page); let currentPage = parseInt(response.data.meta.pagination.current_page);
let totalPage = parseInt(response.data.meta.pagination.total_pages); let totalPages = parseInt(response.data.meta.pagination.total_pages);
this.total = parseInt(response.data.meta.pagination.total); this.total = parseInt(response.data.meta.pagination.total);
console.log('total is ' + this.total);
this.transactions.push(...response.data.data); this.transactions.push(...response.data.data);
if (currentPage < totalPage) { // if (currentPage < totalPage) {
let nextPage = currentPage + 1; // let nextPage = currentPage + 1;
this.downloadTransactionList(nextPage); // this.downloadTransactionList(nextPage);
} // }
if (currentPage >= totalPage) { // if (currentPage >= totalPage) {
// console.log('Looks like all downloaded.'); // console.log('Looks like all downloaded.');
this.downloaded = true; this.downloaded = true;
this.createTransactionRows(); this.createTransactionRows();
} // }
} }
); );
}); });
}, },
createTransactionRows: function() { createTransactionRows: function () {
this.transactionRows = []; this.transactionRows = [];
for (let i in this.transactions) { for (let i in this.transactions) {
let transaction = this.transactions[i]; let transaction = this.transactions[i];
@@ -277,14 +285,14 @@ export default {
transactionRow.split = true; transactionRow.split = true;
transactionRow.collapsed = transaction.collapsed === true || transaction.collapsed === undefined; transactionRow.collapsed = transaction.collapsed === true || transaction.collapsed === undefined;
transactionRow.amount = transaction.attributes.transactions transactionRow.amount = transaction.attributes.transactions
.map(transaction => Number(transaction.amount)) .map(transaction => Number(transaction.amount))
.reduce((sum, n) => sum + n); .reduce((sum, n) => sum + n);
transactionRow.source_name = ''; transactionRow.source_name = '';
transactionRow.source_id = ''; transactionRow.source_id = '';
transactionRow.destination_name = ''; transactionRow.destination_name = '';
transactionRow.destination_id = ''; transactionRow.destination_id = '';
if (! transactionRow.collapsed) { if (!transactionRow.collapsed) {
for (let i = 0; i < transaction.attributes.transactions.length; i++) { for (let i = 0; i < transaction.attributes.transactions.length; i++) {
let splitTransactionRow = this.getTransactionRow(transaction, i); let splitTransactionRow = this.getTransactionRow(transaction, i);
splitTransactionRow.key = splitTransactionRow.id + "." + i splitTransactionRow.key = splitTransactionRow.id + "." + i
@@ -300,7 +308,7 @@ export default {
this.loading = false; this.loading = false;
}, },
getTransactionRow(transaction, index) { getTransactionRow(transaction, index) {
let transactionRow = { }; let transactionRow = {};
let currentTransaction = transaction.attributes.transactions[index]; let currentTransaction = transaction.attributes.transactions[index];
transactionRow.key = transaction.id; transactionRow.key = transaction.id;
@@ -323,16 +331,16 @@ export default {
return transactionRow; return transactionRow;
}, },
toggleCollapse: function(row) { toggleCollapse: function (row) {
let transaction = this.transactions.filter(transaction => transaction.id === row.id)[0]; let transaction = this.transactions.filter(transaction => transaction.id === row.id)[0];
if (transaction.collapsed === undefined) { if (transaction.collapsed === undefined) {
transaction.collapsed = false; transaction.collapsed = false;
} else { } else {
transaction.collapsed = ! transaction.collapsed; transaction.collapsed = !transaction.collapsed;
} }
this.createTransactionRows(); this.createTransactionRows();
}, },
tableSortCompare: function(aRow, bRow, key, sortDesc, formatter, compareOptions, compareLocale) { tableSortCompare: function (aRow, bRow, key, sortDesc, formatter, compareOptions, compareLocale) {
let a = aRow[key] let a = aRow[key]
let b = bRow[key] let b = bRow[key]
@@ -354,8 +362,8 @@ export default {
} }
if ( if (
(typeof a === 'number' && typeof b === 'number') || (typeof a === 'number' && typeof b === 'number') ||
(a instanceof Date && b instanceof Date) (a instanceof Date && b instanceof Date)
) { ) {
// If both compared fields are native numbers or both are native dates // If both compared fields are native numbers or both are native dates
return a < b ? -1 : a > b ? 1 : 0 return a < b ? -1 : a > b ? 1 : 0
@@ -369,9 +377,9 @@ export default {
return '' return ''
} else if (value instanceof Object) { } else if (value instanceof Object) {
return Object.keys(value) return Object.keys(value)
.sort() .sort()
.map(key => toString(value[key])) .map(key => toString(value[key]))
.join(' ') .join(' ')
} else { } else {
return String(value) return String(value)
} }