mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-15 07:27:33 +08:00
reduce unnecessary network requesting
This commit is contained in:
+114
-16
@@ -18,6 +18,8 @@ import {
|
||||
UPDATE_ACCOUNT_LIST_INVALID_STATE,
|
||||
|
||||
LOAD_TRANSACTION_LIST,
|
||||
INIT_TRANSACTION_LIST_FILTER,
|
||||
UPDATE_TRANSACTION_LIST_FILTER,
|
||||
COLLAPSE_MONTH_IN_TRANSACTION_LIST,
|
||||
SAVE_TRANSACTION_IN_TRANSACTION_LIST,
|
||||
REMOVE_TRANSACTION_FROM_TRANSACTION_LIST,
|
||||
@@ -92,6 +94,8 @@ import {
|
||||
} from './account.js';
|
||||
|
||||
import {
|
||||
initTransactionListFilter,
|
||||
updateTransactionListFilter,
|
||||
getTransactions,
|
||||
getTransaction,
|
||||
saveTransaction,
|
||||
@@ -99,6 +103,7 @@ import {
|
||||
collapseMonthInTransactionList,
|
||||
noTransaction,
|
||||
hasMoreTransaction,
|
||||
fillTransactionObject,
|
||||
calculateMonthTotalAmount,
|
||||
} from './transaction.js';
|
||||
|
||||
@@ -131,6 +136,15 @@ const stores = {
|
||||
allAccountsMap: {},
|
||||
allCategorizedAccounts: {},
|
||||
accountListStateInvalid: true,
|
||||
transactionsFilter: {
|
||||
dateType: 0,
|
||||
maxTime: 0,
|
||||
minTime: 0,
|
||||
type: 0,
|
||||
categoryId: '0',
|
||||
accountId: '0',
|
||||
keyword: ''
|
||||
},
|
||||
transactions: [],
|
||||
transactionsNextTimeId: 0,
|
||||
transactionListStateInvalid: true,
|
||||
@@ -169,6 +183,13 @@ const stores = {
|
||||
state.allCategorizedAccounts = {};
|
||||
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.transactionsNextTimeId = 0;
|
||||
state.transactionListStateInvalid = true;
|
||||
@@ -340,7 +361,7 @@ const stores = {
|
||||
[UPDATE_ACCOUNT_LIST_INVALID_STATE] (state, invalidState) {
|
||||
state.accountListStateInvalid = invalidState;
|
||||
},
|
||||
[LOAD_TRANSACTION_LIST] (state, { transactions, reload, autoExpand, defaultCurrency, accountId }) {
|
||||
[LOAD_TRANSACTION_LIST] (state, { transactions, reload, autoExpand, defaultCurrency }) {
|
||||
if (reload) {
|
||||
state.transactions = [];
|
||||
}
|
||||
@@ -351,14 +372,9 @@ const stores = {
|
||||
|
||||
for (let i = 0; i < transactions.items.length; i++) {
|
||||
const item = transactions.items[i];
|
||||
fillTransactionObject(state, item);
|
||||
|
||||
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 transactionMonth = utils.getMonth(transactionTime);
|
||||
const transactionYearMonth = utils.getYearAndMonth(transactionTime);
|
||||
@@ -377,7 +393,7 @@ const stores = {
|
||||
}
|
||||
|
||||
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({
|
||||
year: transactionYear,
|
||||
@@ -392,23 +408,95 @@ const stores = {
|
||||
}
|
||||
|
||||
currentMonthList.items.push(Object.freeze(item));
|
||||
calculateMonthTotalAmount(state, currentMonthList, defaultCurrency, accountId, true);
|
||||
calculateMonthTotalAmount(state, currentMonthList, defaultCurrency, state.transactionsFilter.accountId, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (transactions.nextTimeSequenceId) {
|
||||
state.transactionsNextTimeId = transactions.nextTimeSequenceId;
|
||||
} 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;
|
||||
}
|
||||
},
|
||||
[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 }) {
|
||||
if (month) {
|
||||
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++) {
|
||||
const transactionMonthList = state.transactions[i];
|
||||
|
||||
@@ -420,14 +508,22 @@ const stores = {
|
||||
|
||||
for (let j = 0; j < transactionMonthList.items.length; j++) {
|
||||
if (transactionMonthList.items[j].id === transaction.id) {
|
||||
transactionMonthList.items.splice(j, 1, transaction);
|
||||
calculateMonthTotalAmount(state, transactionMonthList, defaultCurrency, accountId, i >= state.transactions.length - 1 && state.transactionsNextTimeId > 0);
|
||||
fillTransactionObject(state, transaction);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
[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++) {
|
||||
const transactionMonthList = state.transactions[i];
|
||||
|
||||
@@ -446,7 +542,7 @@ const stores = {
|
||||
if (transactionMonthList.items.length < 1) {
|
||||
state.transactions.splice(i, 1);
|
||||
} 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,
|
||||
|
||||
// transaction
|
||||
initTransactionListFilter,
|
||||
updateTransactionListFilter,
|
||||
getTransactions,
|
||||
getTransaction,
|
||||
saveTransaction,
|
||||
|
||||
@@ -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 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 SAVE_TRANSACTION_IN_TRANSACTION_LIST = 'SAVE_TRANSACTION_IN_TRANSACTION_LIST';
|
||||
export const REMOVE_TRANSACTION_FROM_TRANSACTION_LIST = 'REMOVE_TRANSACTION_FROM_TRANSACTION_LIST';
|
||||
|
||||
+56
-22
@@ -7,7 +7,10 @@ import { getExchangedAmount } from "./exchangeRates.js";
|
||||
|
||||
import {
|
||||
LOAD_TRANSACTION_LIST,
|
||||
INIT_TRANSACTION_LIST_FILTER,
|
||||
UPDATE_TRANSACTION_LIST_FILTER,
|
||||
COLLAPSE_MONTH_IN_TRANSACTION_LIST,
|
||||
SAVE_TRANSACTION_IN_TRANSACTION_LIST,
|
||||
REMOVE_TRANSACTION_FROM_TRANSACTION_LIST,
|
||||
UPDATE_TRANSACTION_LIST_INVALID_STATE,
|
||||
UPDATE_ACCOUNT_LIST_INVALID_STATE,
|
||||
@@ -18,23 +21,31 @@ const emptyTransactionResult = {
|
||||
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;
|
||||
|
||||
if (reload && maxTime > 0) {
|
||||
actualMaxTime = maxTime;
|
||||
} else if (reload && maxTime <= 0) {
|
||||
if (reload && context.state.transactionsFilter.maxTime > 0) {
|
||||
actualMaxTime = context.state.transactionsFilter.maxTime * 1000 + 999;
|
||||
} else if (reload && context.state.transactionsFilter.maxTime <= 0) {
|
||||
actualMaxTime = 0;
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
services.getTransactions({
|
||||
maxTime: actualMaxTime,
|
||||
minTime: minTime,
|
||||
type: type,
|
||||
categoryId: categoryId,
|
||||
accountId: accountId,
|
||||
keyword: keyword
|
||||
minTime: context.state.transactionsFilter.minTime * 1000,
|
||||
type: context.state.transactionsFilter.type,
|
||||
categoryId: context.state.transactionsFilter.categoryId,
|
||||
accountId: context.state.transactionsFilter.accountId,
|
||||
keyword: context.state.transactionsFilter.keyword
|
||||
}).then(response => {
|
||||
const data = response.data;
|
||||
|
||||
@@ -44,8 +55,7 @@ export function getTransactions(context, { reload, autoExpand, defaultCurrency,
|
||||
transactions: emptyTransactionResult,
|
||||
reload: reload,
|
||||
autoExpand: autoExpand,
|
||||
defaultCurrency: defaultCurrency,
|
||||
accountId: accountId
|
||||
defaultCurrency: defaultCurrency
|
||||
});
|
||||
context.commit(UPDATE_TRANSACTION_LIST_INVALID_STATE, true);
|
||||
}
|
||||
@@ -58,8 +68,7 @@ export function getTransactions(context, { reload, autoExpand, defaultCurrency,
|
||||
transactions: data.result,
|
||||
reload: reload,
|
||||
autoExpand: autoExpand,
|
||||
defaultCurrency: defaultCurrency,
|
||||
accountId: accountId
|
||||
defaultCurrency: defaultCurrency
|
||||
});
|
||||
|
||||
if (reload) {
|
||||
@@ -75,8 +84,7 @@ export function getTransactions(context, { reload, autoExpand, defaultCurrency,
|
||||
transactions: emptyTransactionResult,
|
||||
reload: reload,
|
||||
autoExpand: autoExpand,
|
||||
defaultCurrency: defaultCurrency,
|
||||
accountId: accountId
|
||||
defaultCurrency: defaultCurrency
|
||||
});
|
||||
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) => {
|
||||
let promise = null;
|
||||
|
||||
@@ -144,7 +152,10 @@ export function saveTransaction(context, { transaction }) {
|
||||
if (!transaction.id) {
|
||||
context.commit(UPDATE_TRANSACTION_LIST_INVALID_STATE, true);
|
||||
} 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);
|
||||
@@ -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) => {
|
||||
services.deleteTransaction({
|
||||
id: transaction.id
|
||||
@@ -184,15 +195,13 @@ export function deleteTransaction(context, { transaction, defaultCurrency, accou
|
||||
beforeResolve(() => {
|
||||
context.commit(REMOVE_TRANSACTION_FROM_TRANSACTION_LIST, {
|
||||
transaction: transaction,
|
||||
defaultCurrency: defaultCurrency,
|
||||
accountId: accountId
|
||||
defaultCurrency: defaultCurrency
|
||||
});
|
||||
});
|
||||
} else {
|
||||
context.commit(REMOVE_TRANSACTION_FROM_TRANSACTION_LIST, {
|
||||
transaction: transaction,
|
||||
defaultCurrency: defaultCurrency,
|
||||
accountId: accountId
|
||||
defaultCurrency: defaultCurrency
|
||||
});
|
||||
}
|
||||
|
||||
@@ -238,6 +247,31 @@ export function hasMoreTransaction(state) {
|
||||
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) {
|
||||
if (!transactionMonthList) {
|
||||
return;
|
||||
|
||||
@@ -673,7 +673,8 @@ export default {
|
||||
self.$showLoading(() => self.submitting);
|
||||
|
||||
self.$store.dispatch('saveTransaction', {
|
||||
transaction: submitTransaction
|
||||
transaction: submitTransaction,
|
||||
defaultCurrency: self.defaultCurrency
|
||||
}).then(() => {
|
||||
self.submitting = false;
|
||||
self.$hideLoading();
|
||||
|
||||
@@ -372,15 +372,6 @@
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
query: {
|
||||
dateType: 0,
|
||||
maxTime: 0,
|
||||
minTime: 0,
|
||||
type: 0,
|
||||
categoryId: '0',
|
||||
accountId: '0',
|
||||
keyword: ''
|
||||
},
|
||||
loading: true,
|
||||
loadingMore: false,
|
||||
transactionToDelete: null,
|
||||
@@ -396,6 +387,9 @@ export default {
|
||||
defaultCurrency() {
|
||||
return this.$store.getters.currentUserDefaultCurrency || this.$t('default.currency');
|
||||
},
|
||||
query() {
|
||||
return this.$store.state.transactionsFilter;
|
||||
},
|
||||
transactions() {
|
||||
if (this.loading) {
|
||||
return [];
|
||||
@@ -420,17 +414,11 @@ export default {
|
||||
const self = this;
|
||||
const query = self.$f7route.query;
|
||||
|
||||
if (query.type) {
|
||||
self.query.type = query.type;
|
||||
}
|
||||
|
||||
if (query.categoryId) {
|
||||
self.query.categoryId = query.categoryId;
|
||||
}
|
||||
|
||||
if (query.accountId) {
|
||||
self.query.accountId = query.accountId;
|
||||
}
|
||||
this.$store.dispatch('initTransactionListFilter', {
|
||||
type: query.type,
|
||||
categoryId: query.categoryId,
|
||||
accountId: query.accountId
|
||||
});
|
||||
|
||||
this.reload(null);
|
||||
},
|
||||
@@ -454,13 +442,7 @@ export default {
|
||||
self.$store.dispatch('getTransactions', {
|
||||
reload: true,
|
||||
autoExpand: true,
|
||||
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
|
||||
defaultCurrency: self.defaultCurrency
|
||||
})
|
||||
];
|
||||
|
||||
@@ -500,13 +482,9 @@ export default {
|
||||
self.loadingMore = true;
|
||||
|
||||
self.$store.dispatch('getTransactions', {
|
||||
reload: false,
|
||||
autoExpand: autoExpand,
|
||||
defaultCurrency: self.defaultCurrency,
|
||||
minTime: self.query.minTime * 1000,
|
||||
type: self.query.type,
|
||||
categoryId: self.query.categoryId,
|
||||
accountId: self.query.accountId,
|
||||
keyword: self.query.keyword
|
||||
defaultCurrency: self.defaultCurrency
|
||||
}).then(() => {
|
||||
self.loadingMore = false;
|
||||
}).catch(error => {
|
||||
@@ -532,44 +510,51 @@ export default {
|
||||
return;
|
||||
}
|
||||
|
||||
let maxTime = 0;
|
||||
let minTime = 0;
|
||||
|
||||
if (dateType === 0) { // All
|
||||
this.query.maxTime = 0;
|
||||
this.query.minTime = 0;
|
||||
maxTime = 0;
|
||||
minTime = 0;
|
||||
} else if (dateType === 1) { // Today
|
||||
this.query.maxTime = this.$utilities.getTodayLastUnixTime();
|
||||
this.query.minTime = this.$utilities.getTodayFirstUnixTime();
|
||||
maxTime = this.$utilities.getTodayLastUnixTime();
|
||||
minTime = this.$utilities.getTodayFirstUnixTime();
|
||||
} else if (dateType === 2) { // Yesterday
|
||||
this.query.maxTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getTodayLastUnixTime(), 1, 'days');
|
||||
this.query.minTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getTodayFirstUnixTime(), 1, 'days');
|
||||
maxTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getTodayLastUnixTime(), 1, 'days');
|
||||
minTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getTodayFirstUnixTime(), 1, 'days');
|
||||
} else if (dateType === 3) { // Last 7 days
|
||||
this.query.maxTime = this.$utilities.getUnixTime(new Date());
|
||||
this.query.minTime = this.$utilities.getUnixTimeBeforeUnixTime(this.query.maxTime, 7, 'days');
|
||||
maxTime = this.$utilities.getUnixTime(new Date());
|
||||
minTime = this.$utilities.getUnixTimeBeforeUnixTime(maxTime, 7, 'days');
|
||||
} else if (dateType === 4) { // Last 30 days
|
||||
this.query.maxTime = this.$utilities.getUnixTime(new Date());
|
||||
this.query.minTime = this.$utilities.getUnixTimeBeforeUnixTime(this.query.maxTime, 30, 'days');
|
||||
maxTime = this.$utilities.getUnixTime(new Date());
|
||||
minTime = this.$utilities.getUnixTimeBeforeUnixTime(maxTime, 30, 'days');
|
||||
} else if (dateType === 5) { // This week
|
||||
this.query.maxTime = this.$utilities.getThisWeekLastUnixTime();
|
||||
this.query.minTime = this.$utilities.getThisWeekFirstUnixTime();
|
||||
maxTime = this.$utilities.getThisWeekLastUnixTime();
|
||||
minTime = this.$utilities.getThisWeekFirstUnixTime();
|
||||
} else if (dateType === 6) { // Last week
|
||||
this.query.maxTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getThisWeekLastUnixTime(), 7, 'days');
|
||||
this.query.minTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getThisWeekFirstUnixTime(), 7, 'days');
|
||||
maxTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getThisWeekLastUnixTime(), 7, 'days');
|
||||
minTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getThisWeekFirstUnixTime(), 7, 'days');
|
||||
} else if (dateType === 7) { // This month
|
||||
this.query.maxTime = this.$utilities.getThisMonthLastUnixTime();
|
||||
this.query.minTime = this.$utilities.getThisMonthFirstUnixTime();
|
||||
maxTime = this.$utilities.getThisMonthLastUnixTime();
|
||||
minTime = this.$utilities.getThisMonthFirstUnixTime();
|
||||
} else if (dateType === 8) { // Last month
|
||||
this.query.maxTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getThisMonthLastUnixTime(), 1, 'months');
|
||||
this.query.minTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getThisMonthFirstUnixTime(), 1, 'months');
|
||||
maxTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getThisMonthLastUnixTime(), 1, 'months');
|
||||
minTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getThisMonthFirstUnixTime(), 1, 'months');
|
||||
} else if (dateType === 9) { // This year
|
||||
this.query.maxTime = this.$utilities.getThisYearLastUnixTime();
|
||||
this.query.minTime = this.$utilities.getThisYearFirstUnixTime();
|
||||
maxTime = this.$utilities.getThisYearLastUnixTime();
|
||||
minTime = this.$utilities.getThisYearFirstUnixTime();
|
||||
} else if (dateType === 10) { // Last year
|
||||
this.query.maxTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getThisYearLastUnixTime(), 1, 'years');
|
||||
this.query.minTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getThisYearFirstUnixTime(), 1, 'years');
|
||||
maxTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getThisYearLastUnixTime(), 1, 'years');
|
||||
minTime = this.$utilities.getUnixTimeBeforeUnixTime(this.$utilities.getThisYearFirstUnixTime(), 1, 'years');
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
this.query.dateType = dateType;
|
||||
this.$store.dispatch('updateTransactionListFilter', {
|
||||
dateType: dateType,
|
||||
maxTime: maxTime,
|
||||
minTime: minTime
|
||||
});
|
||||
|
||||
this.showDatePopover = false;
|
||||
this.reload(null);
|
||||
@@ -579,10 +564,11 @@ export default {
|
||||
return;
|
||||
}
|
||||
|
||||
this.query.maxTime = maxTime;
|
||||
this.query.minTime = minTime;
|
||||
|
||||
this.query.dateType = 11;
|
||||
this.$store.dispatch('updateTransactionListFilter', {
|
||||
dateType: 11,
|
||||
maxTime: maxTime,
|
||||
minTime: minTime
|
||||
});
|
||||
|
||||
this.showCustomDateRangeSheet = false;
|
||||
|
||||
@@ -593,15 +579,21 @@ export default {
|
||||
return;
|
||||
}
|
||||
|
||||
let removeCategoryFilter = false;
|
||||
|
||||
if (type && this.query.categoryId) {
|
||||
const category = this.allCategories[this.query.categoryId];
|
||||
|
||||
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.reload(null);
|
||||
},
|
||||
@@ -610,7 +602,10 @@ export default {
|
||||
return;
|
||||
}
|
||||
|
||||
this.query.categoryId = categoryId;
|
||||
this.$store.dispatch('updateTransactionListFilter', {
|
||||
categoryId: categoryId
|
||||
});
|
||||
|
||||
this.showCategoryPopover = false;
|
||||
this.reload(null);
|
||||
},
|
||||
@@ -619,7 +614,10 @@ export default {
|
||||
return;
|
||||
}
|
||||
|
||||
this.query.accountId = accountId;
|
||||
this.$store.dispatch('updateTransactionListFilter', {
|
||||
accountId: accountId
|
||||
});
|
||||
|
||||
this.showAccountPopover = false;
|
||||
this.reload(null);
|
||||
},
|
||||
@@ -628,7 +626,10 @@ export default {
|
||||
return;
|
||||
}
|
||||
|
||||
this.query.keyword = keyword;
|
||||
this.$store.dispatch('updateTransactionListFilter', {
|
||||
keyword: keyword
|
||||
});
|
||||
|
||||
this.reload(null);
|
||||
},
|
||||
duplicate(transaction) {
|
||||
@@ -660,7 +661,6 @@ export default {
|
||||
self.$store.dispatch('deleteTransaction', {
|
||||
transaction: transaction,
|
||||
defaultCurrency: self.defaultCurrency,
|
||||
accountId: self.query.accountId,
|
||||
beforeResolve: (done) => {
|
||||
app.swipeout.delete($$(`#${self.$options.filters.transactionDomId(transaction)}`), () => {
|
||||
done();
|
||||
|
||||
Reference in New Issue
Block a user