Code fixes.

This commit is contained in:
James Cole
2021-05-24 08:06:56 +02:00
parent 3b1b353b79
commit 2bff7750b4
45 changed files with 331 additions and 248 deletions

View File

@@ -36,8 +36,8 @@
<div class="card-header">
</div>
<div class="card-body p-0">
<b-table id="my-table" striped hover responsive="md" primary-key="id"
:items="accounts" :fields="fields"
<b-table id="my-table" striped hover responsive="md" primary-key="id" :no-local-sorting="true"
:items="itemsProvider" :fields="fields"
:per-page="perPage"
sort-icon-left
ref="table"
@@ -46,7 +46,7 @@
:sort-by.sync="sortBy"
:sort-desc.sync="sortDesc"
>
<template #cell(title)="data">
<template #cell(name)="data">
<a :class="false === data.item.active ? 'text-muted' : ''" :href="'./accounts/show/' + data.item.id" :title="data.value">{{ data.value }}</a>
</template>
<template #cell(number)="data">
@@ -162,6 +162,10 @@
import {mapGetters} from "vuex";
import Sortable from "sortablejs";
import format from "date-fns/format";
import {setup} from 'axios-cache-adapter'
// import {cacheAdapterEnhancer} from 'axios-extensions';
// pas wat teruggeven als die pagina ook gevraagd wordt, anders een empty array
// van X lang?
export default {
name: "Index",
@@ -179,9 +183,10 @@ export default {
fields: [],
currentPage: 1,
perPage: 5,
total: 0,
total: 1,
sortBy: 'order',
sortDesc: false,
api: null,
sortableOptions: {
disabled: false,
chosenClass: 'is-selected',
@@ -192,13 +197,13 @@ export default {
},
watch: {
storeReady: function () {
this.getAccountList();
//this.getAccountList();
},
start: function () {
this.getAccountList();
//this.getAccountList();
},
end: function () {
this.getAccountList();
//this.getAccountList();
},
orderMode: function (value) {
// update the table headers
@@ -229,14 +234,55 @@ export default {
let pathName = window.location.pathname;
let parts = pathName.split('/');
this.type = parts[parts.length - 1];
this.perPage = this.listPageSize ?? 51;
console.log('Per page: ' + this.perPage);
let params = new URLSearchParams(window.location.search);
this.currentPage = params.get('page') ? parseInt(params.get('page')) : 1;
this.updateFieldList();
this.ready = true;
// make object thing:
let token = document.head.querySelector('meta[name="csrf-token"]');
this.api = setup(
{
// `axios` options
//baseURL: './',
headers: {'X-CSRF-TOKEN': token.content, 'X-James': 'yes'},
// `axios-cache-adapter` options
cache: {
maxAge: 15 * 60 * 1000,
readHeaders: false,
exclude: {
query: false,
},
debug: true
}
});
},
methods: {
itemsProvider: function (ctx, callback) {
console.log('itemsProvider()');
console.log('ctx.currentPage = ' + ctx.currentPage);
console.log('this.currentPage = ' + this.currentPage);
if (ctx.currentPage === this.currentPage) {
let direction = this.sortDesc ? '-' : '+';
let url = 'api/v1/accounts?type=' + this.type + '&page=' + ctx.currentPage + '&sort=' + direction + this.sortBy;
this.api.get(url)
.then(async (response) => {
this.total = parseInt(response.data.meta.pagination.total);
let items = this.parseAccountsAndReturn(response.data.data);
items = this.filterAccountListAndReturn(items);
callback(items);
}
);
return null;
}
return [];
},
saveAccountSort: function (event) {
let oldIndex = parseInt(event.oldIndex);
let newIndex = parseInt(event.newIndex);
@@ -277,7 +323,7 @@ export default {
updateFieldList: function () {
this.fields = [];
this.fields = [{key: 'title', label: this.$t('list.name'), sortable: !this.orderMode}];
this.fields = [{key: 'name', label: this.$t('list.name'), sortable: !this.orderMode}];
if ('asset' === this.type) {
this.fields.push({key: 'role', label: this.$t('list.role'), sortable: !this.orderMode});
}
@@ -305,7 +351,7 @@ export default {
this.perPage = this.listPageSize ?? 51;
this.accounts = [];
this.allAccounts = [];
this.downloadAccountList(1);
//this.downloadAccountList(1);
}
if (this.indexReady && !this.loading && this.downloaded) {
// console.log('Index ready, not loading and not downloaded.');
@@ -314,8 +360,13 @@ export default {
}
},
downloadAccountList: function (page) {
const http = axios.create({
baseURL: './',
headers: {'Cache-Control': 'no-cache'},
});
// console.log('downloadAccountList(' + page + ')');
axios.get('./api/v1/accounts?type=' + this.type + '&page=' + page)
http.get('./api/v1/accounts?type=' + this.type + '&page=' + page)
.then(response => {
let currentPage = parseInt(response.data.meta.pagination.current_page);
let totalPage = parseInt(response.data.meta.pagination.total_pages);
@@ -333,6 +384,29 @@ export default {
}
);
},
filterAccountListAndReturn: function (allAccounts) {
console.log('filterAccountListAndReturn()');
let accounts = [];
for (let i in allAccounts) {
if (allAccounts.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {
// 1 = active only
// 2 = inactive only
// 3 = both
if (1 === this.activeFilter && false === allAccounts[i].active) {
// console.log('Skip account #' + this.allAccounts[i].id + ' because not active.');
continue;
}
if (2 === this.activeFilter && true === allAccounts[i].active) {
// console.log('Skip account #' + this.allAccounts[i].id + ' because active.');
continue;
}
// console.log('Include account #' + this.allAccounts[i].id + '.');
accounts.push(allAccounts[i]);
}
}
return accounts;
},
filterAccountList: function () {
// console.log('filterAccountList()');
this.accounts = [];
@@ -367,6 +441,49 @@ export default {
this.total = parseInt(data.pagination.total);
//console.log('Total is now ' + this.total);
},
parseAccountsAndReturn: function (data) {
console.log('In parseAccountsAndReturn()');
let allAccounts = [];
for (let key in data) {
if (data.hasOwnProperty(key) && /^0$|^[1-9]\d*$/.test(key) && key <= 4294967294) {
let current = data[key];
let acct = {};
acct.id = parseInt(current.id);
acct.order = current.attributes.order;
acct.name = current.attributes.name;
acct.active = current.attributes.active;
acct.role = this.roleTranslate(current.attributes.account_role);
acct.account_number = current.attributes.account_number;
acct.current_balance = current.attributes.current_balance;
acct.currency_code = current.attributes.currency_code;
if ('liabilities' === this.type) {
acct.liability_type = this.$t('firefly.account_type_' + current.attributes.liability_type);
acct.liability_direction = this.$t('firefly.liability_direction_' + current.attributes.liability_direction + '_short');
acct.interest = current.attributes.interest;
acct.interest_period = this.$t('firefly.interest_calc_' + current.attributes.interest_period);
acct.amount_due = current.attributes.current_debt;
}
acct.balance_diff = 'loading';
acct.last_activity = 'loading';
if (null !== current.attributes.iban) {
acct.iban = current.attributes.iban.match(/.{1,4}/g).join(' ');
}
if (null === current.attributes.iban) {
acct.iban = null;
}
allAccounts.push(acct);
if ('asset' === this.type) {
// TODO
//this.getAccountBalanceDifference(this.allAccounts.length - 1, current);
//this.getAccountLastActivity(this.allAccounts.length - 1, current);
}
}
}
return allAccounts;
},
parseAccounts: function (data) {
// console.log('In parseAccounts()');
for (let key in data) {
@@ -375,7 +492,7 @@ export default {
let acct = {};
acct.id = parseInt(current.id);
acct.order = current.attributes.order;
acct.title = current.attributes.name;
acct.name = current.attributes.name;
acct.active = current.attributes.active;
acct.role = this.roleTranslate(current.attributes.account_role);
acct.account_number = current.attributes.account_number;

View File

@@ -65,8 +65,6 @@ export default {
liability_direction: function (value) {
this.$emit('set-field', {field: 'liability_direction', value: value});
},
},
created() {
}
}
</script>

View File

@@ -71,10 +71,7 @@
<script>
export default {
name: "Index",
created() {
}
name: "Index"
}
</script>

View File

@@ -74,8 +74,9 @@ export default {
//let strokePointHighColors = [];
for (let i = 0; i < colourSet.length; i++) {
fillColors.push("rgba(" + colourSet[i][0] + ", " + colourSet[i][1] + ", " + colourSet[i][2] + ", 0.5)");
//for (let i = 0; i < colourSet.length; i++) {
for (let value of colourSet) {
fillColors.push("rgba(" + value[0] + ", " + value[1] + ", " + value[2] + ", 0.5)");
//strokePointHighColors.push("rgba(" + colourSet[i][0] + ", " + colourSet[i][1] + ", " + colourSet[i][2] + ", 0.9)");
}
this.newDataSet.labels = this.dataSet.labels;
@@ -123,8 +124,9 @@ export default {
//let strokePointHighColors = [];
for (let i = 0; i < colourSet.length; i++) {
fillColors.push("rgba(" + colourSet[i][0] + ", " + colourSet[i][1] + ", " + colourSet[i][2] + ", 0.5)");
//for (let i = 0; i < colourSet.length; i++) {
for (let value of colourSet) {
fillColors.push("rgba(" + value[0] + ", " + value[1] + ", " + value[2] + ", 0.5)");
//strokePointHighColors.push("rgba(" + colourSet[i][0] + ", " + colourSet[i][1] + ", " + colourSet[i][2] + ", 0.9)");
}
this.newDataSet.labels = this.dataSet.labels;

View File

@@ -327,7 +327,6 @@ export default {
let title = 'todo';
let half = 1;
// its currently first half of year:
if (today.getMonth() <= 5) {
// previous year, last half:
@@ -398,7 +397,6 @@ export default {
end.setMonth(5);
end.setDate(30);
end = endOfDay(end);
half = 1;
title = format(start, this.$t('config.half_year_fns', {half: half}));
this.periods.push(
{
@@ -450,7 +448,6 @@ export default {
let today = new Date(this.range.start);
let start;
let end;
let title;
// last year
start = new Date(today);

View File

@@ -22,9 +22,6 @@
//import {Line, mixins} from 'vue-chartjs'
import { Chart, LineController, LineElement, PointElement, LinearScale, Title } from 'chart.js'
const {reactiveProp} = mixins
export default {

View File

@@ -141,9 +141,9 @@ export default {
});
},
parseIncome(data) {
for (let mainKey in data) {
if (data.hasOwnProperty(mainKey)) {
mainKey = parseInt(mainKey);
for (let i in data) {
if (data.hasOwnProperty(i)) {
let mainKey = parseInt(i);
// contains currency info and entries.
let current = data[mainKey];
current.pct = 0;

View File

@@ -25,8 +25,6 @@
<form @submit="submitTransaction" autocomplete="off">
<SplitPills :transactions="transactions"/>
<div class="tab-content">
<!-- v-on:switch-accounts="switchAccounts($event)" -->
<!-- :allowed-opposing-types="allowedOpposingTypes" -->
<SplitForm
v-for="(transaction, index) in this.transactions"
v-bind:key="index"
@@ -119,8 +117,6 @@ import SplitPills from "./SplitPills";
import TransactionGroupTitle from "./TransactionGroupTitle";
import SplitForm from "./SplitForm";
import {mapGetters, mapMutations} from "vuex";
import {getDefaultErrors} from "../../shared/transactions";
export default {
name: "Create",

View File

@@ -386,23 +386,23 @@ export default {
},
sourceAccount: function () {
//console.log('computed::sourceAccount(' + this.index + ')');
let value = {
return {
id: this.transaction.source_account_id,
name: this.transaction.source_account_name,
type: this.transaction.source_account_type,
};
//console.log(JSON.stringify(value));
return value;
//return value;
},
destinationAccount: function () {
//console.log('computed::destinationAccount(' + this.index + ')');
let value = {
return {
id: this.transaction.destination_account_id,
name: this.transaction.destination_account_name,
type: this.transaction.destination_account_type,
};
//console.log(JSON.stringify(value));
return value;
//return value;
},
hasMetaFields: function () {
let requiredFields = [

View File

@@ -26,11 +26,6 @@
</span>
<span v-if="'any' === this.transactionType" class="text-muted">&nbsp;</span>
</div>
<!--
<div class="btn-group d-flex">
<button class="btn btn-light" @click="switchAccounts">&harr;</button>
</div>
-->
</div>
</template>

View File

@@ -23,7 +23,6 @@
<div v-if="visible" class="text-xs d-none d-lg-block d-xl-block">
<span v-if="0 === this.index">{{ $t('firefly.' + this.direction + '_account') }}</span>
<span v-if="this.index > 0" class="text-warning">{{ $t('firefly.first_split_overrules_' + this.direction) }}</span>
<!--<br><span>{{ selectedAccount }}</span>-->
</div>
<div v-if="!visible" class="text-xs d-none d-lg-block d-xl-block">
&nbsp;