mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-17 08:14:25 +08:00
add parts of statistics ui
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import datetimeConstants from "../consts/datetime.js";
|
||||
import statisticsConstants from "../consts/statistics.js";
|
||||
import userState from "../lib/userstate.js";
|
||||
import utils from "../lib/utils.js";
|
||||
|
||||
@@ -44,6 +45,11 @@ import {
|
||||
|
||||
LOAD_TRANSACTION_OVERVIEW,
|
||||
UPDATE_TRANSACTION_OVERVIEW_INVALID_STATE,
|
||||
|
||||
LOAD_TRANSACTION_STATISTICS,
|
||||
INIT_TRANSACTION_STATISTICS_FILTER,
|
||||
UPDATE_TRANSACTION_STATISTICS_FILTER,
|
||||
UPDATE_TRANSACTION_STATISTICS_INVALID_STATE,
|
||||
} from './mutations.js';
|
||||
|
||||
import {
|
||||
@@ -88,6 +94,12 @@ import {
|
||||
loadTransactionOverview
|
||||
} from './overview.js';
|
||||
|
||||
import {
|
||||
loadTransactionStatistics,
|
||||
initTransactionStatisticsFilter,
|
||||
updateTransactionStatisticsFilter
|
||||
} from './statistics.js';
|
||||
|
||||
import {
|
||||
loadAllAccounts,
|
||||
getAccount,
|
||||
@@ -165,6 +177,15 @@ const stores = {
|
||||
transactionTagListStateInvalid: true,
|
||||
transactionOverview: {},
|
||||
transactionOverviewStateInvalid: true,
|
||||
transactionStatisticsFilter: {
|
||||
dateType: datetimeConstants.allDateRanges.ThisMonth.type,
|
||||
startTime: 0,
|
||||
endTime: 0,
|
||||
chartType: statisticsConstants.defaultChartType,
|
||||
chartLegendType: statisticsConstants.defaultChartLegendType,
|
||||
},
|
||||
transactionStatistics: [],
|
||||
transactionStatisticsStateInvalid: true,
|
||||
},
|
||||
getters: {
|
||||
// user
|
||||
@@ -216,6 +237,14 @@ const stores = {
|
||||
state.transactionOverview = {};
|
||||
state.transactionOverviewStateInvalid = true;
|
||||
|
||||
state.transactionStatisticsFilter.dateType = datetimeConstants.allDateRanges.ThisMonth.type;
|
||||
state.transactionStatisticsFilter.startTime = 0;
|
||||
state.transactionStatisticsFilter.endTime = 0;
|
||||
state.transactionStatisticsFilter.chartType = statisticsConstants.defaultChartType;
|
||||
state.transactionStatisticsFilter.chartLegendType = statisticsConstants.defaultChartLegendType;
|
||||
state.transactionStatistics = {};
|
||||
state.transactionStatisticsStateInvalid = true;
|
||||
|
||||
clearExchangeRatesFromLocalStorage();
|
||||
},
|
||||
[STORE_USER_INFO] (state, userInfo) {
|
||||
@@ -731,6 +760,86 @@ const stores = {
|
||||
[UPDATE_TRANSACTION_OVERVIEW_INVALID_STATE] (state, invalidState) {
|
||||
state.transactionOverviewStateInvalid = invalidState;
|
||||
},
|
||||
[LOAD_TRANSACTION_STATISTICS] (state, { statistics, defaultCurrency }) {
|
||||
if (statistics && statistics.items && statistics.items.length) {
|
||||
for (let i = 0; i < statistics.items.length; i++) {
|
||||
const item = statistics.items[i];
|
||||
|
||||
if (item.accountId) {
|
||||
item.account = state.allAccountsMap[item.accountId];
|
||||
}
|
||||
|
||||
if (item.categoryId) {
|
||||
item.category = state.allTransactionCategoriesMap[item.categoryId];
|
||||
}
|
||||
|
||||
if (item.account && item.account.currency !== defaultCurrency) {
|
||||
item.amountInDefaultCurrency = getExchangedAmount(state)(item.amount, item.account.currency, defaultCurrency);
|
||||
} else if (item.account && item.account.currency === defaultCurrency) {
|
||||
item.amountInDefaultCurrency = item.amount;
|
||||
} else {
|
||||
item.amountInDefaultCurrency = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
state.transactionStatistics = statistics;
|
||||
},
|
||||
[INIT_TRANSACTION_STATISTICS_FILTER] (state, filter) {
|
||||
if (filter && utils.isNumber(filter.dateType)) {
|
||||
state.transactionStatisticsFilter.dateType = filter.dateType;
|
||||
} else {
|
||||
state.transactionStatisticsFilter.dateType = datetimeConstants.allDateRanges.ThisMonth.type;
|
||||
}
|
||||
|
||||
if (filter && utils.isNumber(filter.startTime)) {
|
||||
state.transactionStatisticsFilter.startTime = filter.startTime;
|
||||
} else {
|
||||
state.transactionStatisticsFilter.startTime = 0;
|
||||
}
|
||||
|
||||
if (filter && utils.isNumber(filter.endTime)) {
|
||||
state.transactionStatisticsFilter.endTime = filter.endTime;
|
||||
} else {
|
||||
state.transactionStatisticsFilter.endTime = 0;
|
||||
}
|
||||
|
||||
if (filter && utils.isNumber(filter.chartType)) {
|
||||
state.transactionStatisticsFilter.chartType = filter.chartType;
|
||||
} else {
|
||||
state.transactionStatisticsFilter.chartType = statisticsConstants.defaultChartType;
|
||||
}
|
||||
|
||||
if (filter && utils.isNumber(filter.chartLegendType)) {
|
||||
state.transactionStatisticsFilter.chartLegendType = filter.chartLegendType;
|
||||
} else {
|
||||
state.transactionStatisticsFilter.chartLegendType = statisticsConstants.defaultChartLegendType;
|
||||
}
|
||||
},
|
||||
[UPDATE_TRANSACTION_STATISTICS_FILTER] (state, filter) {
|
||||
if (filter && utils.isNumber(filter.dateType)) {
|
||||
state.transactionStatisticsFilter.dateType = filter.dateType;
|
||||
}
|
||||
|
||||
if (filter && utils.isNumber(filter.startTime)) {
|
||||
state.transactionStatisticsFilter.startTime = filter.startTime;
|
||||
}
|
||||
|
||||
if (filter && utils.isNumber(filter.endTime)) {
|
||||
state.transactionStatisticsFilter.endTime = filter.endTime;
|
||||
}
|
||||
|
||||
if (filter && utils.isNumber(filter.chartType)) {
|
||||
state.transactionStatisticsFilter.chartType = filter.chartType;
|
||||
}
|
||||
|
||||
if (filter && utils.isNumber(filter.chartLegendType)) {
|
||||
state.transactionStatisticsFilter.chartLegendType = filter.chartLegendType;
|
||||
}
|
||||
},
|
||||
[UPDATE_TRANSACTION_STATISTICS_INVALID_STATE] (state, invalidState) {
|
||||
state.transactionStatisticsStateInvalid = invalidState;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
// user
|
||||
@@ -763,6 +872,11 @@ const stores = {
|
||||
// overview
|
||||
loadTransactionOverview,
|
||||
|
||||
// statistics
|
||||
loadTransactionStatistics,
|
||||
initTransactionStatisticsFilter,
|
||||
updateTransactionStatisticsFilter,
|
||||
|
||||
// account
|
||||
loadAllAccounts,
|
||||
saveAccount,
|
||||
|
||||
@@ -39,3 +39,8 @@ export const UPDATE_TRANSACTION_TAG_LIST_INVALID_STATE = 'UPDATE_TRANSACTION_TAG
|
||||
|
||||
export const LOAD_TRANSACTION_OVERVIEW = 'LOAD_TRANSACTION_OVERVIEW';
|
||||
export const UPDATE_TRANSACTION_OVERVIEW_INVALID_STATE = 'UPDATE_TRANSACTION_OVERVIEW_INVALID_STATE';
|
||||
|
||||
export const LOAD_TRANSACTION_STATISTICS = 'LOAD_TRANSACTION_STATISTICS';
|
||||
export const INIT_TRANSACTION_STATISTICS_FILTER = 'INIT_TRANSACTION_STATISTICS_FILTER';
|
||||
export const UPDATE_TRANSACTION_STATISTICS_FILTER = 'UPDATE_TRANSACTION_STATISTICS_FILTER';
|
||||
export const UPDATE_TRANSACTION_STATISTICS_INVALID_STATE = 'UPDATE_TRANSACTION_STATISTICS_INVALID_STATE';
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import services from '../lib/services.js';
|
||||
import logger from '../lib/logger.js';
|
||||
|
||||
import {
|
||||
LOAD_TRANSACTION_STATISTICS,
|
||||
INIT_TRANSACTION_STATISTICS_FILTER,
|
||||
UPDATE_TRANSACTION_STATISTICS_FILTER,
|
||||
UPDATE_TRANSACTION_STATISTICS_INVALID_STATE
|
||||
} from "./mutations.js";
|
||||
|
||||
export function loadTransactionStatistics(context, { defaultCurrency }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.getTransactionStatistics({
|
||||
startTime: context.state.transactionStatisticsFilter.startTime,
|
||||
endTime: context.state.transactionStatisticsFilter.endTime
|
||||
}).then(response => {
|
||||
const data = response.data;
|
||||
|
||||
if (!data || !data.success || !data.result) {
|
||||
reject({ message: 'Unable to get transaction statistics' });
|
||||
return;
|
||||
}
|
||||
|
||||
context.commit(LOAD_TRANSACTION_STATISTICS, {
|
||||
statistics: data.result,
|
||||
defaultCurrency: defaultCurrency
|
||||
});
|
||||
|
||||
if (context.state.transactionStatisticsStateInvalid) {
|
||||
context.commit(UPDATE_TRANSACTION_STATISTICS_INVALID_STATE, false);
|
||||
}
|
||||
|
||||
resolve(data.result);
|
||||
}).catch(error => {
|
||||
logger.error('failed to get transaction statistics', error);
|
||||
|
||||
if (error.response && error.response.data && error.response.data.errorMessage) {
|
||||
reject({ error: error.response.data });
|
||||
} else if (!error.processed) {
|
||||
reject({ message: 'Unable to get transaction statistics' });
|
||||
} else {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function initTransactionStatisticsFilter(context, filter) {
|
||||
context.commit(INIT_TRANSACTION_STATISTICS_FILTER, filter);
|
||||
}
|
||||
|
||||
export function updateTransactionStatisticsFilter(context, filter) {
|
||||
context.commit(UPDATE_TRANSACTION_STATISTICS_FILTER, filter);
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
UPDATE_TRANSACTION_LIST_INVALID_STATE,
|
||||
UPDATE_ACCOUNT_LIST_INVALID_STATE,
|
||||
UPDATE_TRANSACTION_OVERVIEW_INVALID_STATE,
|
||||
UPDATE_TRANSACTION_STATISTICS_INVALID_STATE,
|
||||
} from './mutations.js';
|
||||
|
||||
const emptyTransactionResult = {
|
||||
@@ -177,6 +178,10 @@ export function saveTransaction(context, { transaction, defaultCurrency }) {
|
||||
context.commit(UPDATE_TRANSACTION_OVERVIEW_INVALID_STATE, true);
|
||||
}
|
||||
|
||||
if (!context.state.transactionStatisticsStateInvalid) {
|
||||
context.commit(UPDATE_TRANSACTION_STATISTICS_INVALID_STATE, true);
|
||||
}
|
||||
|
||||
resolve(data.result);
|
||||
}).catch(error => {
|
||||
logger.error('failed to save transaction', error);
|
||||
@@ -230,6 +235,10 @@ export function deleteTransaction(context, { transaction, defaultCurrency, befor
|
||||
context.commit(UPDATE_TRANSACTION_OVERVIEW_INVALID_STATE, true);
|
||||
}
|
||||
|
||||
if (!context.state.transactionStatisticsStateInvalid) {
|
||||
context.commit(UPDATE_TRANSACTION_STATISTICS_INVALID_STATE, true);
|
||||
}
|
||||
|
||||
resolve(data.result);
|
||||
}).catch(error => {
|
||||
logger.error('failed to delete transaction', error);
|
||||
|
||||
+10
-1
@@ -13,7 +13,8 @@ import {
|
||||
UPDATE_ACCOUNT_LIST_INVALID_STATE,
|
||||
UPDATE_TRANSACTION_CATEGORY_LIST_INVALID_STATE,
|
||||
UPDATE_TRANSACTION_TAG_LIST_INVALID_STATE,
|
||||
UPDATE_TRANSACTION_OVERVIEW_INVALID_STATE
|
||||
UPDATE_TRANSACTION_OVERVIEW_INVALID_STATE,
|
||||
UPDATE_TRANSACTION_STATISTICS_INVALID_STATE
|
||||
} from './mutations.js';
|
||||
|
||||
export function authorize(context, { loginName, password }) {
|
||||
@@ -258,6 +259,10 @@ export function updateUserProfile(context, { profile, currentPassword }) {
|
||||
context.commit(UPDATE_TRANSACTION_OVERVIEW_INVALID_STATE, true);
|
||||
}
|
||||
|
||||
if (!context.state.transactionStatisticsStateInvalid) {
|
||||
context.commit(UPDATE_TRANSACTION_STATISTICS_INVALID_STATE, true);
|
||||
}
|
||||
|
||||
resolve(data.result);
|
||||
}).catch(error => {
|
||||
logger.error('failed to save user profile', error);
|
||||
@@ -301,6 +306,10 @@ export function clearUserData(context, { password }) {
|
||||
context.commit(UPDATE_TRANSACTION_OVERVIEW_INVALID_STATE, true);
|
||||
}
|
||||
|
||||
if (!context.state.transactionStatisticsStateInvalid) {
|
||||
context.commit(UPDATE_TRANSACTION_STATISTICS_INVALID_STATE, true);
|
||||
}
|
||||
|
||||
resolve(data.result);
|
||||
}).catch(error => {
|
||||
logger.error('failed to clear user data', error);
|
||||
|
||||
Reference in New Issue
Block a user