reduce unnecessary network requesting

This commit is contained in:
MaysWind
2021-01-10 00:01:55 +08:00
parent 3bd91f2748
commit fb65402897
5 changed files with 240 additions and 105 deletions
+114 -16
View File
@@ -18,6 +18,8 @@ import {
UPDATE_ACCOUNT_LIST_INVALID_STATE, UPDATE_ACCOUNT_LIST_INVALID_STATE,
LOAD_TRANSACTION_LIST, LOAD_TRANSACTION_LIST,
INIT_TRANSACTION_LIST_FILTER,
UPDATE_TRANSACTION_LIST_FILTER,
COLLAPSE_MONTH_IN_TRANSACTION_LIST, COLLAPSE_MONTH_IN_TRANSACTION_LIST,
SAVE_TRANSACTION_IN_TRANSACTION_LIST, SAVE_TRANSACTION_IN_TRANSACTION_LIST,
REMOVE_TRANSACTION_FROM_TRANSACTION_LIST, REMOVE_TRANSACTION_FROM_TRANSACTION_LIST,
@@ -92,6 +94,8 @@ import {
} from './account.js'; } from './account.js';
import { import {
initTransactionListFilter,
updateTransactionListFilter,
getTransactions, getTransactions,
getTransaction, getTransaction,
saveTransaction, saveTransaction,
@@ -99,6 +103,7 @@ import {
collapseMonthInTransactionList, collapseMonthInTransactionList,
noTransaction, noTransaction,
hasMoreTransaction, hasMoreTransaction,
fillTransactionObject,
calculateMonthTotalAmount, calculateMonthTotalAmount,
} from './transaction.js'; } from './transaction.js';
@@ -131,6 +136,15 @@ const stores = {
allAccountsMap: {}, allAccountsMap: {},
allCategorizedAccounts: {}, allCategorizedAccounts: {},
accountListStateInvalid: true, accountListStateInvalid: true,
transactionsFilter: {
dateType: 0,
maxTime: 0,
minTime: 0,
type: 0,
categoryId: '0',
accountId: '0',
keyword: ''
},
transactions: [], transactions: [],
transactionsNextTimeId: 0, transactionsNextTimeId: 0,
transactionListStateInvalid: true, transactionListStateInvalid: true,
@@ -169,6 +183,13 @@ const stores = {
state.allCategorizedAccounts = {}; state.allCategorizedAccounts = {};
state.accountListStateInvalid = true; state.accountListStateInvalid = true;
state.transactionsFilter.dateType = 0;
state.transactionsFilter.maxTime = 0;
state.transactionsFilter.minTime = 0;
state.transactionsFilter.type = 0;
state.transactionsFilter.categoryId = '0';
state.transactionsFilter.accountId = '0';
state.transactionsFilter.keyword = '';
state.transactions = []; state.transactions = [];
state.transactionsNextTimeId = 0; state.transactionsNextTimeId = 0;
state.transactionListStateInvalid = true; state.transactionListStateInvalid = true;
@@ -340,7 +361,7 @@ const stores = {
[UPDATE_ACCOUNT_LIST_INVALID_STATE] (state, invalidState) { [UPDATE_ACCOUNT_LIST_INVALID_STATE] (state, invalidState) {
state.accountListStateInvalid = invalidState; state.accountListStateInvalid = invalidState;
}, },
[LOAD_TRANSACTION_LIST] (state, { transactions, reload, autoExpand, defaultCurrency, accountId }) { [LOAD_TRANSACTION_LIST] (state, { transactions, reload, autoExpand, defaultCurrency }) {
if (reload) { if (reload) {
state.transactions = []; state.transactions = [];
} }
@@ -351,14 +372,9 @@ const stores = {
for (let i = 0; i < transactions.items.length; i++) { for (let i = 0; i < transactions.items.length; i++) {
const item = transactions.items[i]; const item = transactions.items[i];
fillTransactionObject(state, item);
const transactionTime = utils.parseDateFromUnixTime(item.time); const transactionTime = utils.parseDateFromUnixTime(item.time);
item.day = utils.getDay(transactionTime);
item.dayOfWeek = utils.getDayOfWeek(transactionTime);
item.sourceAccount = state.allAccountsMap[item.sourceAccountId];
item.destinationAccount = state.allAccountsMap[item.destinationAccountId];
item.category = state.allTransactionCategoriesMap[item.categoryId];
const transactionYear = utils.getYear(transactionTime); const transactionYear = utils.getYear(transactionTime);
const transactionMonth = utils.getMonth(transactionTime); const transactionMonth = utils.getMonth(transactionTime);
const transactionYearMonth = utils.getYearAndMonth(transactionTime); const transactionYearMonth = utils.getYearAndMonth(transactionTime);
@@ -377,7 +393,7 @@ const stores = {
} }
if (!currentMonthList || currentMonthList.year !== transactionYear || currentMonthList.month !== transactionMonth) { if (!currentMonthList || currentMonthList.year !== transactionYear || currentMonthList.month !== transactionMonth) {
calculateMonthTotalAmount(state, currentMonthList, defaultCurrency, accountId, false); calculateMonthTotalAmount(state, currentMonthList, defaultCurrency, state.transactionsFilter.accountId, false);
state.transactions.push({ state.transactions.push({
year: transactionYear, year: transactionYear,
@@ -392,23 +408,95 @@ const stores = {
} }
currentMonthList.items.push(Object.freeze(item)); currentMonthList.items.push(Object.freeze(item));
calculateMonthTotalAmount(state, currentMonthList, defaultCurrency, accountId, true); calculateMonthTotalAmount(state, currentMonthList, defaultCurrency, state.transactionsFilter.accountId, true);
} }
} }
if (transactions.nextTimeSequenceId) { if (transactions.nextTimeSequenceId) {
state.transactionsNextTimeId = transactions.nextTimeSequenceId; state.transactionsNextTimeId = transactions.nextTimeSequenceId;
} else { } else {
calculateMonthTotalAmount(state, state.transactions[state.transactions.length - 1], defaultCurrency, accountId, false); calculateMonthTotalAmount(state, state.transactions[state.transactions.length - 1], defaultCurrency, state.transactionsFilter.accountId, false);
state.transactionsNextTimeId = -1; state.transactionsNextTimeId = -1;
} }
}, },
[INIT_TRANSACTION_LIST_FILTER] (state, filter) {
if (filter && utils.isNumber(filter.dateType)) {
state.transactionsFilter.dateType = filter.dateType;
} else {
state.transactionsFilter.dateType = 0;
}
if (filter && utils.isNumber(filter.maxTime)) {
state.transactionsFilter.maxTime = filter.maxTime;
} else {
state.transactionsFilter.maxTime = 0;
}
if (filter && utils.isNumber(filter.minTime)) {
state.transactionsFilter.minTime = filter.minTime;
} else {
state.transactionsFilter.minTime = 0;
}
if (filter && utils.isNumber(filter.type)) {
state.transactionsFilter.type = filter.type;
} else {
state.transactionsFilter.type = 0;
}
if (filter && utils.isString(filter.categoryId)) {
state.transactionsFilter.categoryId = filter.categoryId;
} else {
state.transactionsFilter.categoryId = '0';
}
if (filter && utils.isString(filter.accountId)) {
state.transactionsFilter.accountId = filter.accountId;
} else {
state.transactionsFilter.accountId = '0';
}
if (filter && utils.isString(filter.keyword)) {
state.transactionsFilter.keyword = filter.keyword;
} else {
state.transactionsFilter.keyword = '';
}
},
[UPDATE_TRANSACTION_LIST_FILTER] (state, filter) {
if (filter && utils.isNumber(filter.dateType)) {
state.transactionsFilter.dateType = filter.dateType;
}
if (filter && utils.isNumber(filter.maxTime)) {
state.transactionsFilter.maxTime = filter.maxTime;
}
if (filter && utils.isNumber(filter.minTime)) {
state.transactionsFilter.minTime = filter.minTime;
}
if (filter && utils.isNumber(filter.type)) {
state.transactionsFilter.type = filter.type;
}
if (filter && utils.isString(filter.categoryId)) {
state.transactionsFilter.categoryId = filter.categoryId;
}
if (filter && utils.isString(filter.accountId)) {
state.transactionsFilter.accountId = filter.accountId;
}
if (filter && utils.isString(filter.keyword)) {
state.transactionsFilter.keyword = filter.keyword;
}
},
[COLLAPSE_MONTH_IN_TRANSACTION_LIST] (state, { month, collapse }) { [COLLAPSE_MONTH_IN_TRANSACTION_LIST] (state, { month, collapse }) {
if (month) { if (month) {
month.opened = !collapse; month.opened = !collapse;
} }
}, },
[SAVE_TRANSACTION_IN_TRANSACTION_LIST] (state, { transaction, defaultCurrency, accountId }) { [SAVE_TRANSACTION_IN_TRANSACTION_LIST] (state, { transaction, defaultCurrency }) {
for (let i = 0; i < state.transactions.length; i++) { for (let i = 0; i < state.transactions.length; i++) {
const transactionMonthList = state.transactions[i]; const transactionMonthList = state.transactions[i];
@@ -420,14 +508,22 @@ const stores = {
for (let j = 0; j < transactionMonthList.items.length; j++) { for (let j = 0; j < transactionMonthList.items.length; j++) {
if (transactionMonthList.items[j].id === transaction.id) { if (transactionMonthList.items[j].id === transaction.id) {
transactionMonthList.items.splice(j, 1, transaction); fillTransactionObject(state, transaction);
calculateMonthTotalAmount(state, transactionMonthList, defaultCurrency, accountId, i >= state.transactions.length - 1 && state.transactionsNextTimeId > 0);
if ((state.transactionsFilter.categoryId && state.transactionsFilter.categoryId !== '0' && state.transactionsFilter.categoryId !== transaction.categoryId) ||
(state.transactionsFilter.accountId && state.transactionsFilter.accountId !== '0' && state.transactionsFilter.accountId !== transaction.sourceAccountId && state.transactionsFilter.accountId !== transaction.destinationAccountId)) {
transactionMonthList.items.splice(j, 1);
} else {
transactionMonthList.items.splice(j, 1, transaction);
}
calculateMonthTotalAmount(state, transactionMonthList, defaultCurrency, state.transactionsFilter.accountId, i >= state.transactions.length - 1 && state.transactionsNextTimeId > 0);
return; return;
} }
} }
} }
}, },
[REMOVE_TRANSACTION_FROM_TRANSACTION_LIST] (state, { transaction, defaultCurrency, accountId }) { [REMOVE_TRANSACTION_FROM_TRANSACTION_LIST] (state, { transaction, defaultCurrency }) {
for (let i = 0; i < state.transactions.length; i++) { for (let i = 0; i < state.transactions.length; i++) {
const transactionMonthList = state.transactions[i]; const transactionMonthList = state.transactions[i];
@@ -446,7 +542,7 @@ const stores = {
if (transactionMonthList.items.length < 1) { if (transactionMonthList.items.length < 1) {
state.transactions.splice(i, 1); state.transactions.splice(i, 1);
} else { } else {
calculateMonthTotalAmount(state, transactionMonthList, defaultCurrency, accountId, i >= state.transactions.length - 1 && state.transactionsNextTimeId > 0); calculateMonthTotalAmount(state, transactionMonthList, defaultCurrency, state.transactionsFilter.accountId, i >= state.transactions.length - 1 && state.transactionsNextTimeId > 0);
} }
} }
}, },
@@ -648,6 +744,8 @@ const stores = {
deleteAccount, deleteAccount,
// transaction // transaction
initTransactionListFilter,
updateTransactionListFilter,
getTransactions, getTransactions,
getTransaction, getTransaction,
saveTransaction, saveTransaction,
+2
View File
@@ -14,6 +14,8 @@ export const REMOVE_ACCOUNT_FROM_ACCOUNT_LIST = 'REMOVE_ACCOUNT_FROM_ACCOUNT_LIS
export const UPDATE_ACCOUNT_LIST_INVALID_STATE = 'UPDATE_ACCOUNT_LIST_INVALID_STATE'; export const UPDATE_ACCOUNT_LIST_INVALID_STATE = 'UPDATE_ACCOUNT_LIST_INVALID_STATE';
export const LOAD_TRANSACTION_LIST = 'LOAD_TRANSACTION_LIST'; export const LOAD_TRANSACTION_LIST = 'LOAD_TRANSACTION_LIST';
export const INIT_TRANSACTION_LIST_FILTER = 'INIT_TRANSACTION_LIST_FILTER';
export const UPDATE_TRANSACTION_LIST_FILTER = 'UPDATE_TRANSACTION_LIST_FILTER';
export const COLLAPSE_MONTH_IN_TRANSACTION_LIST = 'COLLAPSE_MONTH_IN_TRANSACTION_LIST'; export const COLLAPSE_MONTH_IN_TRANSACTION_LIST = 'COLLAPSE_MONTH_IN_TRANSACTION_LIST';
export const SAVE_TRANSACTION_IN_TRANSACTION_LIST = 'SAVE_TRANSACTION_IN_TRANSACTION_LIST'; export const SAVE_TRANSACTION_IN_TRANSACTION_LIST = 'SAVE_TRANSACTION_IN_TRANSACTION_LIST';
export const REMOVE_TRANSACTION_FROM_TRANSACTION_LIST = 'REMOVE_TRANSACTION_FROM_TRANSACTION_LIST'; export const REMOVE_TRANSACTION_FROM_TRANSACTION_LIST = 'REMOVE_TRANSACTION_FROM_TRANSACTION_LIST';
+56 -22
View File
@@ -7,7 +7,10 @@ import { getExchangedAmount } from "./exchangeRates.js";
import { import {
LOAD_TRANSACTION_LIST, LOAD_TRANSACTION_LIST,
INIT_TRANSACTION_LIST_FILTER,
UPDATE_TRANSACTION_LIST_FILTER,
COLLAPSE_MONTH_IN_TRANSACTION_LIST, COLLAPSE_MONTH_IN_TRANSACTION_LIST,
SAVE_TRANSACTION_IN_TRANSACTION_LIST,
REMOVE_TRANSACTION_FROM_TRANSACTION_LIST, REMOVE_TRANSACTION_FROM_TRANSACTION_LIST,
UPDATE_TRANSACTION_LIST_INVALID_STATE, UPDATE_TRANSACTION_LIST_INVALID_STATE,
UPDATE_ACCOUNT_LIST_INVALID_STATE, UPDATE_ACCOUNT_LIST_INVALID_STATE,
@@ -18,23 +21,31 @@ const emptyTransactionResult = {
transactionsNextTimeId: 0 transactionsNextTimeId: 0
}; };
export function getTransactions(context, { reload, autoExpand, defaultCurrency, maxTime, minTime, type, categoryId, accountId, keyword }) { export function initTransactionListFilter(context, filter) {
context.commit(INIT_TRANSACTION_LIST_FILTER, filter);
}
export function updateTransactionListFilter(context, filter) {
context.commit(UPDATE_TRANSACTION_LIST_FILTER, filter);
}
export function getTransactions(context, { reload, autoExpand, defaultCurrency }) {
let actualMaxTime = context.state.transactionsNextTimeId; let actualMaxTime = context.state.transactionsNextTimeId;
if (reload && maxTime > 0) { if (reload && context.state.transactionsFilter.maxTime > 0) {
actualMaxTime = maxTime; actualMaxTime = context.state.transactionsFilter.maxTime * 1000 + 999;
} else if (reload && maxTime <= 0) { } else if (reload && context.state.transactionsFilter.maxTime <= 0) {
actualMaxTime = 0; actualMaxTime = 0;
} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
services.getTransactions({ services.getTransactions({
maxTime: actualMaxTime, maxTime: actualMaxTime,
minTime: minTime, minTime: context.state.transactionsFilter.minTime * 1000,
type: type, type: context.state.transactionsFilter.type,
categoryId: categoryId, categoryId: context.state.transactionsFilter.categoryId,
accountId: accountId, accountId: context.state.transactionsFilter.accountId,
keyword: keyword keyword: context.state.transactionsFilter.keyword
}).then(response => { }).then(response => {
const data = response.data; const data = response.data;
@@ -44,8 +55,7 @@ export function getTransactions(context, { reload, autoExpand, defaultCurrency,
transactions: emptyTransactionResult, transactions: emptyTransactionResult,
reload: reload, reload: reload,
autoExpand: autoExpand, autoExpand: autoExpand,
defaultCurrency: defaultCurrency, defaultCurrency: defaultCurrency
accountId: accountId
}); });
context.commit(UPDATE_TRANSACTION_LIST_INVALID_STATE, true); context.commit(UPDATE_TRANSACTION_LIST_INVALID_STATE, true);
} }
@@ -58,8 +68,7 @@ export function getTransactions(context, { reload, autoExpand, defaultCurrency,
transactions: data.result, transactions: data.result,
reload: reload, reload: reload,
autoExpand: autoExpand, autoExpand: autoExpand,
defaultCurrency: defaultCurrency, defaultCurrency: defaultCurrency
accountId: accountId
}); });
if (reload) { if (reload) {
@@ -75,8 +84,7 @@ export function getTransactions(context, { reload, autoExpand, defaultCurrency,
transactions: emptyTransactionResult, transactions: emptyTransactionResult,
reload: reload, reload: reload,
autoExpand: autoExpand, autoExpand: autoExpand,
defaultCurrency: defaultCurrency, defaultCurrency: defaultCurrency
accountId: accountId
}); });
context.commit(UPDATE_TRANSACTION_LIST_INVALID_STATE, true); context.commit(UPDATE_TRANSACTION_LIST_INVALID_STATE, true);
} }
@@ -119,7 +127,7 @@ export function getTransaction(context, { transactionId }) {
}); });
} }
export function saveTransaction(context, { transaction }) { export function saveTransaction(context, { transaction, defaultCurrency }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let promise = null; let promise = null;
@@ -144,7 +152,10 @@ export function saveTransaction(context, { transaction }) {
if (!transaction.id) { if (!transaction.id) {
context.commit(UPDATE_TRANSACTION_LIST_INVALID_STATE, true); context.commit(UPDATE_TRANSACTION_LIST_INVALID_STATE, true);
} else { } else {
context.commit(UPDATE_TRANSACTION_LIST_INVALID_STATE, true); context.commit(SAVE_TRANSACTION_IN_TRANSACTION_LIST, {
transaction: data.result,
defaultCurrency: defaultCurrency
});
} }
context.commit(UPDATE_ACCOUNT_LIST_INVALID_STATE, true); context.commit(UPDATE_ACCOUNT_LIST_INVALID_STATE, true);
@@ -168,7 +179,7 @@ export function saveTransaction(context, { transaction }) {
}); });
} }
export function deleteTransaction(context, { transaction, defaultCurrency, accountId, beforeResolve }) { export function deleteTransaction(context, { transaction, defaultCurrency, beforeResolve }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
services.deleteTransaction({ services.deleteTransaction({
id: transaction.id id: transaction.id
@@ -184,15 +195,13 @@ export function deleteTransaction(context, { transaction, defaultCurrency, accou
beforeResolve(() => { beforeResolve(() => {
context.commit(REMOVE_TRANSACTION_FROM_TRANSACTION_LIST, { context.commit(REMOVE_TRANSACTION_FROM_TRANSACTION_LIST, {
transaction: transaction, transaction: transaction,
defaultCurrency: defaultCurrency, defaultCurrency: defaultCurrency
accountId: accountId
}); });
}); });
} else { } else {
context.commit(REMOVE_TRANSACTION_FROM_TRANSACTION_LIST, { context.commit(REMOVE_TRANSACTION_FROM_TRANSACTION_LIST, {
transaction: transaction, transaction: transaction,
defaultCurrency: defaultCurrency, defaultCurrency: defaultCurrency
accountId: accountId
}); });
} }
@@ -238,6 +247,31 @@ export function hasMoreTransaction(state) {
return state.transactionsNextTimeId > 0; return state.transactionsNextTimeId > 0;
} }
export function fillTransactionObject(state, transaction) {
if (!transaction) {
return;
}
const transactionTime = utils.parseDateFromUnixTime(transaction.time);
transaction.day = utils.getDay(transactionTime);
transaction.dayOfWeek = utils.getDayOfWeek(transactionTime);
if (transaction.sourceAccountId) {
transaction.sourceAccount = state.allAccountsMap[transaction.sourceAccountId];
}
if (transaction.destinationAccountId) {
transaction.destinationAccount = state.allAccountsMap[transaction.destinationAccountId];
}
if (transaction.categoryId) {
transaction.category = state.allTransactionCategoriesMap[transaction.categoryId];
}
return transaction;
}
export function calculateMonthTotalAmount(state, transactionMonthList, defaultCurrency, accountId, incomplete) { export function calculateMonthTotalAmount(state, transactionMonthList, defaultCurrency, accountId, incomplete) {
if (!transactionMonthList) { if (!transactionMonthList) {
return; return;
+2 -1
View File
@@ -673,7 +673,8 @@ export default {
self.$showLoading(() => self.submitting); self.$showLoading(() => self.submitting);
self.$store.dispatch('saveTransaction', { self.$store.dispatch('saveTransaction', {
transaction: submitTransaction transaction: submitTransaction,
defaultCurrency: self.defaultCurrency
}).then(() => { }).then(() => {
self.submitting = false; self.submitting = false;
self.$hideLoading(); self.$hideLoading();
+66 -66
View File
@@ -372,15 +372,6 @@
export default { export default {
data() { data() {
return { return {
query: {
dateType: 0,
maxTime: 0,
minTime: 0,
type: 0,
categoryId: '0',
accountId: '0',
keyword: ''
},
loading: true, loading: true,
loadingMore: false, loadingMore: false,
transactionToDelete: null, transactionToDelete: null,
@@ -396,6 +387,9 @@ export default {
defaultCurrency() { defaultCurrency() {
return this.$store.getters.currentUserDefaultCurrency || this.$t('default.currency'); return this.$store.getters.currentUserDefaultCurrency || this.$t('default.currency');
}, },
query() {
return this.$store.state.transactionsFilter;
},
transactions() { transactions() {
if (this.loading) { if (this.loading) {
return []; return [];
@@ -420,17 +414,11 @@ export default {
const self = this; const self = this;
const query = self.$f7route.query; const query = self.$f7route.query;
if (query.type) { this.$store.dispatch('initTransactionListFilter', {
self.query.type = query.type; type: query.type,
} categoryId: query.categoryId,
accountId: query.accountId
if (query.categoryId) { });
self.query.categoryId = query.categoryId;
}
if (query.accountId) {
self.query.accountId = query.accountId;
}
this.reload(null); this.reload(null);
}, },
@@ -454,13 +442,7 @@ export default {
self.$store.dispatch('getTransactions', { self.$store.dispatch('getTransactions', {
reload: true, reload: true,
autoExpand: true, autoExpand: true,
defaultCurrency: self.defaultCurrency, defaultCurrency: self.defaultCurrency
maxTime: self.query.maxTime > 0 ? self.query.maxTime * 1000 + 999 : 0,
minTime: self.query.minTime * 1000,
type: self.query.type,
categoryId: self.query.categoryId,
accountId: self.query.accountId,
keyword: self.query.keyword
}) })
]; ];
@@ -500,13 +482,9 @@ export default {
self.loadingMore = true; self.loadingMore = true;
self.$store.dispatch('getTransactions', { self.$store.dispatch('getTransactions', {
reload: false,
autoExpand: autoExpand, autoExpand: autoExpand,
defaultCurrency: self.defaultCurrency, defaultCurrency: self.defaultCurrency
minTime: self.query.minTime * 1000,
type: self.query.type,
categoryId: self.query.categoryId,
accountId: self.query.accountId,
keyword: self.query.keyword
}).then(() => { }).then(() => {
self.loadingMore = false; self.loadingMore = false;
}).catch(error => { }).catch(error => {
@@ -532,44 +510,51 @@ export default {
return; return;
} }
let maxTime = 0;
let minTime = 0;
if (dateType === 0) { // All if (dateType === 0) { // All
this.query.maxTime = 0; maxTime = 0;
this.query.minTime = 0; minTime = 0;
} else if (dateType === 1) { // Today } else if (dateType === 1) { // Today
this.query.maxTime = this.$utilities.getTodayLastUnixTime(); maxTime = this.$utilities.getTodayLastUnixTime();
this.query.minTime = this.$utilities.getTodayFirstUnixTime(); minTime = this.$utilities.getTodayFirstUnixTime();
} else if (dateType === 2) { // Yesterday } else if (dateType === 2) { // Yesterday
this.query.maxTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getTodayLastUnixTime(), 1, 'days'); maxTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getTodayLastUnixTime(), 1, 'days');
this.query.minTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getTodayFirstUnixTime(), 1, 'days'); minTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getTodayFirstUnixTime(), 1, 'days');
} else if (dateType === 3) { // Last 7 days } else if (dateType === 3) { // Last 7 days
this.query.maxTime = this.$utilities.getUnixTime(new Date()); maxTime = this.$utilities.getUnixTime(new Date());
this.query.minTime = this.$utilities.getUnixTimeBeforeUnixTime(this.query.maxTime, 7, 'days'); minTime = this.$utilities.getUnixTimeBeforeUnixTime(maxTime, 7, 'days');
} else if (dateType === 4) { // Last 30 days } else if (dateType === 4) { // Last 30 days
this.query.maxTime = this.$utilities.getUnixTime(new Date()); maxTime = this.$utilities.getUnixTime(new Date());
this.query.minTime = this.$utilities.getUnixTimeBeforeUnixTime(this.query.maxTime, 30, 'days'); minTime = this.$utilities.getUnixTimeBeforeUnixTime(maxTime, 30, 'days');
} else if (dateType === 5) { // This week } else if (dateType === 5) { // This week
this.query.maxTime = this.$utilities.getThisWeekLastUnixTime(); maxTime = this.$utilities.getThisWeekLastUnixTime();
this.query.minTime = this.$utilities.getThisWeekFirstUnixTime(); minTime = this.$utilities.getThisWeekFirstUnixTime();
} else if (dateType === 6) { // Last week } else if (dateType === 6) { // Last week
this.query.maxTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getThisWeekLastUnixTime(), 7, 'days'); maxTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getThisWeekLastUnixTime(), 7, 'days');
this.query.minTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getThisWeekFirstUnixTime(), 7, 'days'); minTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getThisWeekFirstUnixTime(), 7, 'days');
} else if (dateType === 7) { // This month } else if (dateType === 7) { // This month
this.query.maxTime = this.$utilities.getThisMonthLastUnixTime(); maxTime = this.$utilities.getThisMonthLastUnixTime();
this.query.minTime = this.$utilities.getThisMonthFirstUnixTime(); minTime = this.$utilities.getThisMonthFirstUnixTime();
} else if (dateType === 8) { // Last month } else if (dateType === 8) { // Last month
this.query.maxTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getThisMonthLastUnixTime(), 1, 'months'); maxTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getThisMonthLastUnixTime(), 1, 'months');
this.query.minTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getThisMonthFirstUnixTime(), 1, 'months'); minTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getThisMonthFirstUnixTime(), 1, 'months');
} else if (dateType === 9) { // This year } else if (dateType === 9) { // This year
this.query.maxTime = this.$utilities.getThisYearLastUnixTime(); maxTime = this.$utilities.getThisYearLastUnixTime();
this.query.minTime = this.$utilities.getThisYearFirstUnixTime(); minTime = this.$utilities.getThisYearFirstUnixTime();
} else if (dateType === 10) { // Last year } else if (dateType === 10) { // Last year
this.query.maxTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getThisYearLastUnixTime(), 1, 'years'); maxTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getThisYearLastUnixTime(), 1, 'years');
this.query.minTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getThisYearFirstUnixTime(), 1, 'years'); minTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getThisYearFirstUnixTime(), 1, 'years');
} else { } else {
return; return;
} }
this.query.dateType = dateType; this.$store.dispatch('updateTransactionListFilter', {
dateType: dateType,
maxTime: maxTime,
minTime: minTime
});
this.showDatePopover = false; this.showDatePopover = false;
this.reload(null); this.reload(null);
@@ -579,10 +564,11 @@ export default {
return; return;
} }
this.query.maxTime = maxTime; this.$store.dispatch('updateTransactionListFilter', {
this.query.minTime = minTime; dateType: 11,
maxTime: maxTime,
this.query.dateType = 11; minTime: minTime
});
this.showCustomDateRangeSheet = false; this.showCustomDateRangeSheet = false;
@@ -593,15 +579,21 @@ export default {
return; return;
} }
let removeCategoryFilter = false;
if (type && this.query.categoryId) { if (type && this.query.categoryId) {
const category = this.allCategories[this.query.categoryId]; const category = this.allCategories[this.query.categoryId];
if (category && category.type !== type - 1) { if (category && category.type !== type - 1) {
this.query.categoryId = 0; removeCategoryFilter = true;
} }
} }
this.query.type = type; this.$store.dispatch('updateTransactionListFilter', {
type: type,
categoryId: removeCategoryFilter ? '0' : undefined
});
this.showTypePopover = false; this.showTypePopover = false;
this.reload(null); this.reload(null);
}, },
@@ -610,7 +602,10 @@ export default {
return; return;
} }
this.query.categoryId = categoryId; this.$store.dispatch('updateTransactionListFilter', {
categoryId: categoryId
});
this.showCategoryPopover = false; this.showCategoryPopover = false;
this.reload(null); this.reload(null);
}, },
@@ -619,7 +614,10 @@ export default {
return; return;
} }
this.query.accountId = accountId; this.$store.dispatch('updateTransactionListFilter', {
accountId: accountId
});
this.showAccountPopover = false; this.showAccountPopover = false;
this.reload(null); this.reload(null);
}, },
@@ -628,7 +626,10 @@ export default {
return; return;
} }
this.query.keyword = keyword; this.$store.dispatch('updateTransactionListFilter', {
keyword: keyword
});
this.reload(null); this.reload(null);
}, },
duplicate(transaction) { duplicate(transaction) {
@@ -660,7 +661,6 @@ export default {
self.$store.dispatch('deleteTransaction', { self.$store.dispatch('deleteTransaction', {
transaction: transaction, transaction: transaction,
defaultCurrency: self.defaultCurrency, defaultCurrency: self.defaultCurrency,
accountId: self.query.accountId,
beforeResolve: (done) => { beforeResolve: (done) => {
app.swipeout.delete($$(`#${self.$options.filters.transactionDomId(transaction)}`), () => { app.swipeout.delete($$(`#${self.$options.filters.transactionDomId(transaction)}`), () => {
done(); done();