Rebuild front

This commit is contained in:
James Cole
2021-06-30 06:48:49 +02:00
parent 27c90bd217
commit 8bf0eaf969
32 changed files with 227 additions and 216 deletions

View File

@@ -66,7 +66,7 @@ export default new Vuex.Store(
state.currencyPreference = payload.payload;
},
initialiseStore(state) {
console.log('Now in initialiseStore()')
// console.log('Now in initialiseStore()')
// if locale in local storage:
if (localStorage.locale) {
state.locale = localStorage.locale;
@@ -98,7 +98,7 @@ export default new Vuex.Store(
actions: {
updateCurrencyPreference(context) {
console.log('Now in updateCurrencyPreference');
// console.log('Now in updateCurrencyPreference');
if (localStorage.currencyPreference) {
context.commit('setCurrencyPreference', {payload: JSON.parse(localStorage.currencyPreference)});
return;

View File

@@ -61,7 +61,7 @@ const getters = {
// actions
const actions = {
initialiseStore(context) {
console.log('initialiseStore for dashboard.');
// console.log('initialiseStore for dashboard.');
// restore from local storage:
context.dispatch('restoreViewRange');

View File

@@ -49,20 +49,20 @@ const getters = {
const actions = {
initialiseStore(context) {
// cache key auto refreshes every day
console.log('Now in initialize store.')
// console.log('Now in initialize store.')
if (localStorage.cacheKey) {
console.log('Storage has cache key: ');
console.log(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.');
// console.log('Key is here but is old.');
context.commit('refreshCacheKey');
} else {
console.log('Cache key from local storage: ' + object.value);
// console.log('Cache key from local storage: ' + object.value);
context.commit('setCacheKey', object);
}
} else {
console.log('No key need new one.');
// console.log('No key need new one.');
context.commit('refreshCacheKey');
}
if (localStorage.listPageSize) {
@@ -98,16 +98,16 @@ const mutations = {
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));
// 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);
// 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));
// console.log('Stored cache key in localstorage.');
// console.log(payload);
// console.log(JSON.stringify(payload));
localStorage.cacheKey = JSON.stringify(payload);
state.cacheKey = payload;
},

View File

@@ -234,7 +234,7 @@ export default {
return axios.post(url, data);
},
handleSubmissionResponse: function (response) {
console.log('In handleSubmissionResponse()');
// console.log('In handleSubmissionResponse()');
// save some meta data:
this.returnedGroupId = parseInt(response.data.data.id);
this.returnedGroupTitle = null === response.data.data.attributes.group_title ? response.data.data.attributes.transactions[0].description : response.data.data.attributes.group_title;
@@ -282,10 +282,10 @@ export default {
if (response.journals.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {
let journalId = response.journals[i];
let hasAttachments = submission.transactions[i].attachments;
console.log('Decided that ' + journalId);
console.log(hasAttachments);
// console.log('Decided that ' + journalId);
// console.log(hasAttachments);
if (hasAttachments) {
console.log('upload!');
// console.log('upload!');
this.updateField({index: i, field: 'transaction_journal_id', value: journalId});
// set upload trigger?
this.updateField({index: i, field: 'uploadTrigger', value: true});
@@ -305,12 +305,12 @@ export default {
this.updateField({index: payload.index, field: 'attachments', value: true});
},
finaliseSubmission: function () {
console.log('finaliseSubmission');
// console.log('finaliseSubmission');
if (0 === this.submittedAttachments) {
console.log('submittedAttachments = ' + this.submittedAttachments);
// console.log('submittedAttachments = ' + this.submittedAttachments);
return;
}
console.log('In finaliseSubmission');
// console.log('In finaliseSubmission');
if (false === this.createAnother) {
window.location.href = (window.previousURL ?? '/') + '?transaction_group_id=' + this.returnedGroupId + '&message=created';
return;
@@ -322,7 +322,7 @@ export default {
this.errorMessage = '';
this.successMessage = this.$t('firefly.transaction_stored_link', {ID: this.returnedGroupId, title: this.returnedGroupTitle});
}
console.log('here we are');
// console.log('here we are');
// enable flags:
this.enableSubmit = true;
this.submittedTransaction = false;
@@ -363,7 +363,7 @@ export default {
*/
submitTransaction: function (event) {
event.preventDefault();
console.log('submitTransaction()');
// console.log('submitTransaction()');
// disable the submit button:
this.enableSubmit = false;
@@ -717,20 +717,20 @@ export default {
let current = array.tags[i];
if (typeof current === 'object' && null !== current) {
currentSplit.tags.push(current.text);
console.log('Add tag "' + current.text + '" from object.');
// console.log('Add tag "' + current.text + '" from object.');
continue;
}
if (typeof current === 'string') {
currentSplit.tags.push(current);
console.log('Add tag "' + current + '" from string.');
// console.log('Add tag "' + current + '" from string.');
continue;
}
console.log('Is neither.');
// console.log('Is neither.');
}
}
}
console.log('Current split tags is now: ');
console.log(currentSplit.tags);
// console.log('Current split tags is now: ');
// console.log(currentSplit.tags);
// bills and piggy banks
if (0 !== array.piggy_bank_id) {

View File

@@ -533,7 +533,7 @@ export default {
this.transactions.push(newTransaction);
},
submitTransaction: function (event) {
console.log('submitTransaction()');
// console.log('submitTransaction()');
event.preventDefault();
this.enableSubmit = false;
let submission = {transactions: []};
@@ -559,7 +559,7 @@ export default {
// loop each transaction (edited by the user):
// console.log('Start of loop submitTransaction');
for (let i in this.transactions) {
console.log('Index ' + i);
// console.log('Index ' + i);
if (this.transactions.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {
// console.log('Has index ' + i);
// original transaction present:
@@ -573,21 +573,21 @@ export default {
// source and destination are overruled in some cases:
if (i > 0) {
console.log('i > 0');
// console.log('i > 0');
diff.type = this.transactionType.toLowerCase();
if ('deposit' === this.transactionType.toLowerCase() || 'transfer' === this.transactionType.toLowerCase()) {
// set destination to be whatever is in transaction zero:
// of the edited transaction
currentTransaction.destination_account_name = this.transactions[0].destination_account_name;
currentTransaction.destination_account_id = this.transactions[0].destination_account_id;
console.log('Destination is now: #' + currentTransaction.destination_account_id + ': ' + currentTransaction.destination_account_name);
// console.log('Destination is now: #' + currentTransaction.destination_account_id + ': ' + currentTransaction.destination_account_name);
}
if ('withdrawal' === this.transactionType.toLowerCase() || 'transfer' === this.transactionType.toLowerCase()) {
// set source to be whatever is in transaction zero:
currentTransaction.source_account_name = this.transactions[0].source_account_name;
currentTransaction.source_account_id = this.transactions[0].source_account_id;
console.log('Source is now: #' + currentTransaction.source_account_id + ': ' + currentTransaction.source_account_name);
// console.log('Source is now: #' + currentTransaction.source_account_id + ': ' + currentTransaction.source_account_name);
}
}
@@ -699,8 +699,8 @@ export default {
},
submitData: function (shouldSubmit, submission) {
console.log('submitData');
console.log(submission);
// console.log('submitData');
// console.log(submission);
if (!shouldSubmit) {
// console.log('No need to submit transaction.');
return Promise.resolve({});

View File

@@ -228,7 +228,7 @@ export default {
let parts = pathName.split('/');
this.type = parts[parts.length - 1];
this.perPage = this.listPageSize ?? 51;
console.log('Per page: ' + this.perPage);
// console.log('Per page: ' + this.perPage);
let params = new URLSearchParams(window.location.search);
this.currentPage = params.get('page') ? parseInt(params.get('page')) : 1;
@@ -275,9 +275,9 @@ export default {
this.getTransactionList();
},
getTransactionList: function () {
console.log('getTransactionList()');
// console.log('getTransactionList()');
if (this.indexReady && !this.loading && !this.downloaded) {
console.log('Index ready, not loading and not already downloaded. Reset.');
// console.log('Index ready, not loading and not already downloaded. Reset.');
this.loading = true;
this.perPage = this.listPageSize ?? 51;
this.transactions = [];
@@ -286,7 +286,7 @@ export default {
}
},
downloadTransactionList: function (page) {
console.log('downloadTransactionList(' + page + ')');
// console.log('downloadTransactionList(' + page + ')');
configureAxios().then(async (api) => {
let startStr = format(this.start, 'y-MM-dd');
let endStr = format(this.end, 'y-MM-dd');

View File

@@ -53,15 +53,15 @@ export default {
this.availableFields = value;
},
uploadTrigger: function () {
//console.log('uploadTrigger(' + this.transaction_journal_id + ',' + this.index + ')');
// console.log('uploadTrigger(' + this.transaction_journal_id + ',' + this.index + ')');
this.doUpload();
},
clearTrigger: function () {
//console.log('clearTrigger(' + this.transaction_journal_id + ',' + this.index + ')');
// console.log('clearTrigger(' + this.transaction_journal_id + ',' + this.index + ')');
this.$refs.att.value = null;
},
transaction_journal_id: function (value) {
//console.log('watch transaction_journal_id: ' + value + ' (index ' + this.index + ')');
// console.log('watch transaction_journal_id: ' + value + ' (index ' + this.index + ')');
}
},
computed: {
@@ -95,9 +95,9 @@ export default {
},
countAttachment: function () {
this.uploaded++;
//console.log('Uploaded ' + this.uploaded + ' / ' + this.uploads);
// console.log('Uploaded ' + this.uploaded + ' / ' + this.uploads);
if (this.uploaded >= this.uploads) {
//console.log('All files uploaded. Emit event for ' + this.transaction_journal_id + '(' + this.index + ')');
// console.log('All files uploaded. Emit event for ' + this.transaction_journal_id + '(' + this.index + ')');
this.$emit('uploaded-attachments', this.transaction_journal_id);
}
},

View File

@@ -87,7 +87,7 @@ export default {
computed: {
isVisible: {
get() {
return !('Transfer' === this.transactionType && this.sourceCurrencyId === this.destinationCurrencyId);
return !('transfer' === this.transactionType.toLowerCase() && parseInt(this.sourceCurrencyId) === parseInt(this.destinationCurrencyId));
}
},
}

View File

@@ -57,27 +57,37 @@ export default {
this.selectedCurrency = value;
},
sourceCurrencyId: function (value) {
// console.log('Watch sourceCurrencyId');
this.srcCurrencyId = value;
this.lockCurrency();
},
destinationCurrencyId: function (value) {
// console.log('Watch destinationCurrencyId');
this.dstCurrencyId = value;
this.lockCurrency();
},
selectedCurrency: function (value) {
this.$emit('set-field', {field: 'foreign_currency_id', index: this.index, value: value});
},
transactionType: function (value) {
this.lockedCurrency = 0;
if ('Transfer' === value) {
this.lockedCurrency = this.dstCurrencyId;
this.selectedCurrency = this.dstCurrencyId;
}
this.filterCurrencies();
this.lockCurrency();
},
},
created: function () {
// console.log('Created TransactionForeignCurrency');
this.getAllCurrencies();
},
methods: {
lockCurrency: function () {
// console.log('Lock currency (' + this.transactionType + ')');
this.lockedCurrency = 0;
if ('transfer' === this.transactionType.toLowerCase()) {
// console.log('IS a transfer!');
this.lockedCurrency = parseInt(this.dstCurrencyId);
this.selectedCurrency = parseInt(this.dstCurrencyId);
}
this.filterCurrencies();
},
getAllCurrencies: function () {
axios.get('./api/v1/autocomplete/currencies')
.then(response => {
@@ -88,17 +98,22 @@ export default {
},
filterCurrencies() {
// console.log('filterCurrencies');
// console.log(this.lockedCurrency);
// if a currency is locked only that currency can (and must) be selected:
if (0 !== this.lockedCurrency) {
// console.log('Here we are');
for (let key in this.allCurrencies) {
if (this.allCurrencies.hasOwnProperty(key) && /^0$|^[1-9]\d*$/.test(key) && key <= 4294967294) {
let current = this.allCurrencies[key];
if (current.id === this.lockedCurrency) {
if (parseInt(current.id) === this.lockedCurrency) {
this.selectableCurrencies = [current];
this.selectedCurrency = current.id;
}
}
}
// if source + dest ID are the same, skip the whole field.
return;
}
@@ -118,7 +133,7 @@ export default {
},
computed: {
isVisible: function () {
return !('Transfer' === this.transactionType && this.srcCurrencyId === this.dstCurrencyId);
return !('transfer' === this.transactionType.toLowerCase() && parseInt(this.srcCurrencyId) === parseInt(this.dstCurrencyId));
}
}
}