Code for #4838 and some translations

This commit is contained in:
James Cole
2021-06-06 17:17:46 +02:00
parent 4d4290c234
commit eacaee9e47
10 changed files with 283 additions and 238 deletions

View File

@@ -45,7 +45,7 @@
:sort-desc.sync="sortDesc"
>
<template #table-busy>
<i class="fa fa-spinner"></i>
<i class="fas fa-spinner fa-spin"></i>
</template>
<template #cell(name)="data">
<a :class="false === data.item.active ? 'text-muted' : ''" :href="'./accounts/show/' + data.item.id" :title="data.value">{{ data.value }}</a>
@@ -232,7 +232,7 @@ export default {
}
},
computed: {
...mapGetters('root', ['listPageSize']),
...mapGetters('root', ['listPageSize', 'cacheKey']),
...mapGetters('accounts/index', ['orderMode', 'activeFilter']),
...mapGetters('dashboard/index', ['start', 'end',]),
'indexReady': function () {
@@ -373,16 +373,8 @@ export default {
},
downloadAccountList: function (page) {
console.log('downloadAccountList(' + page + ')');
// configure().then(async (api) => {
// const response = await api.get('/url')
//
// // Display something beautiful with `response.data` ;)
// })
configureAxios().then(async (api) => {
api.get('./api/v1/accounts?type=' + this.type + '&page=' + page)
api.get('./api/v1/accounts?type=' + this.type + '&page=' + page + '&key=' + this.cacheKey)
.then(response => {
let currentPage = parseInt(response.data.meta.pagination.current_page);
let totalPage = parseInt(response.data.meta.pagination.total_pages);
@@ -525,15 +517,15 @@ export default {
acctNr = current.attributes.account_number;
}
// only account nr
if(null === iban && null !== acctNr) {
if (null === iban && null !== acctNr) {
acct.acct_number = acctNr;
}
// only iban
if(null !== iban && null === acctNr) {
if (null !== iban && null === acctNr) {
acct.acct_number = iban;
}
// both:
if(null !== iban && null !== acctNr) {
if (null !== iban && null !== acctNr) {
acct.acct_number = iban + ' (' + acctNr + ')';
}
@@ -563,7 +555,7 @@ export default {
// console.log('getAccountLastActivity(' + index + ')');
// get single transaction for account:
// /api/v1/accounts/1/transactions?limit=1
axios.get('./api/v1/accounts/' + acct.id + '/transactions?limit=1').then(response => {
axios.get('./api/v1/accounts/' + acct.id + '/transactions?limit=1&key=' + this.cacheKey).then(response => {
if (0 === response.data.data.length) {
this.allAccounts[index].last_activity = 'none';
return;
@@ -588,8 +580,8 @@ export default {
}));
let startStr = format(this.start, 'y-MM-dd');
let endStr = format(this.end, 'y-MM-dd');
promises.push(axios.get('./api/v1/accounts/' + acct.id + '?date=' + startStr));
promises.push(axios.get('./api/v1/accounts/' + acct.id + '?date=' + endStr));
promises.push(axios.get('./api/v1/accounts/' + acct.id + '?date=' + startStr + '&key=' + this.cacheKey));
promises.push(axios.get('./api/v1/accounts/' + acct.id + '?date=' + endStr + '&key=' + this.cacheKey));
Promise.all(promises).then(responses => {
let index = responses[0].index;

View File

@@ -22,7 +22,11 @@
const state = () => (
{
listPageSize: 33,
timezone: ''
timezone: '',
cacheKey: {
age: 0,
value: 'empty',
},
}
)
@@ -36,11 +40,31 @@ const getters = {
// console.log('Wil return ' + state.listPageSize);
return state.timezone;
},
cacheKey: state => {
return state.cacheKey.value;
},
}
// actions
const actions = {
initialiseStore(context) {
// cache key auto refreshes every day
console.log('Now in initialize store.')
if (localStorage.cacheKey) {
console.log('Storage has cache key: ');
console.log(localStorage.cacheKey);
let object = JSON.parse(localStorage.cacheKey);
if (Date.now() - object.age > 86400000) {
console.log('Key is here but is old.');
context.commit('refreshCacheKey');
} else {
console.log('Cache key from local storage: ' + object.value);
context.commit('setCacheKey', object);
}
} else {
console.log('No key need new one.');
context.commit('refreshCacheKey');
}
if (localStorage.listPageSize) {
state.listPageSize = localStorage.listPageSize;
context.commit('setListPageSize', {length: localStorage.listPageSize});
@@ -69,6 +93,24 @@ const actions = {
// mutations
const mutations = {
refreshCacheKey(state) {
let age = Date.now();
let N = 8;
let cacheKey = Array(N+1).join((Math.random().toString(36)+'00000000000000000').slice(2, 18)).slice(0, N);
let object = {age: age, value: cacheKey};
console.log('Store new key in string JSON');
console.log(JSON.stringify(object));
localStorage.cacheKey = JSON.stringify(object);
state.cacheKey = {age: age, value: cacheKey};
console.log('Refresh: cachekey is now ' + cacheKey);
},
setCacheKey(state, payload) {
console.log('Stored cache key in localstorage.');
console.log(payload);
console.log(JSON.stringify(payload));
localStorage.cacheKey = JSON.stringify(payload);
state.cacheKey = payload;
},
setListPageSize(state, payload) {
// console.log('Got a payload in setListPageSize');
// console.log(payload);
@@ -76,7 +118,6 @@ const mutations = {
if (0 !== number) {
state.listPageSize = number;
localStorage.listPageSize = number;
}
},
setTimezone(state, payload) {