use the preset name if custom date range matches a preset item

This commit is contained in:
MaysWind
2024-06-03 00:47:39 +08:00
parent 809172bf34
commit 72f6a9e9a3
5 changed files with 31 additions and 11 deletions
+12 -6
View File
@@ -366,6 +366,16 @@ export function getShiftedDateRange(minTime, maxTime, scale) {
export function getShiftedDateRangeAndDateType(minTime, maxTime, scale, firstDayOfWeek, scene) { export function getShiftedDateRangeAndDateType(minTime, maxTime, scale, firstDayOfWeek, scene) {
const newDateRange = getShiftedDateRange(minTime, maxTime, scale); const newDateRange = getShiftedDateRange(minTime, maxTime, scale);
const newDateType = getDateTypeByDateRange(newDateRange.minTime, newDateRange.maxTime, firstDayOfWeek, scene);
return {
dateType: newDateType,
minTime: newDateRange.minTime,
maxTime: newDateRange.maxTime
};
}
export function getDateTypeByDateRange(minTime, maxTime, firstDayOfWeek, scene) {
let newDateType = dateTimeConstants.allDateRanges.Custom.type; let newDateType = dateTimeConstants.allDateRanges.Custom.type;
for (let dateRangeField in dateTimeConstants.allDateRanges) { for (let dateRangeField in dateTimeConstants.allDateRanges) {
@@ -381,17 +391,13 @@ export function getShiftedDateRangeAndDateType(minTime, maxTime, scale, firstDay
const dateRange = getDateRangeByDateType(dateRangeType.type, firstDayOfWeek); const dateRange = getDateRangeByDateType(dateRangeType.type, firstDayOfWeek);
if (dateRange && dateRange.minTime === newDateRange.minTime && dateRange.maxTime === newDateRange.maxTime) { if (dateRange && dateRange.minTime === minTime && dateRange.maxTime === maxTime) {
newDateType = dateRangeType.type; newDateType = dateRangeType.type;
break; break;
} }
} }
return { return newDateType;
dateType: newDateType,
minTime: newDateRange.minTime,
maxTime: newDateRange.maxTime
};
} }
export function getDateRangeByDateType(dateType, firstDayOfWeek) { export function getDateRangeByDateType(dateType, firstDayOfWeek) {
@@ -274,6 +274,7 @@ import {
getYearMonthFirstUnixTime, getYearMonthFirstUnixTime,
getYearMonthLastUnixTime, getYearMonthLastUnixTime,
getShiftedDateRangeAndDateType, getShiftedDateRangeAndDateType,
getDateTypeByDateRange,
getDateRangeByDateType getDateRangeByDateType
} from '@/lib/datetime.js'; } from '@/lib/datetime.js';
import { isChartDataTypeAvailableForAnalysisType } from '@/lib/statistics.js'; import { isChartDataTypeAvailableForAnalysisType } from '@/lib/statistics.js';
@@ -648,16 +649,20 @@ export default {
} }
if (this.analysisType === statisticsConstants.allAnalysisTypes.CategoricalAnalysis) { if (this.analysisType === statisticsConstants.allAnalysisTypes.CategoricalAnalysis) {
const chartDateType = getDateTypeByDateRange(startTime, endTime, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal);
this.statisticsStore.updateTransactionStatisticsFilter({ this.statisticsStore.updateTransactionStatisticsFilter({
categoricalChartDateType: this.allDateRanges.Custom.type, categoricalChartDateType: chartDateType,
categoricalChartStartTime: startTime, categoricalChartStartTime: startTime,
categoricalChartEndTime: endTime categoricalChartEndTime: endTime
}); });
this.showCustomDateRangeDialog = false; this.showCustomDateRangeDialog = false;
} else if (this.analysisType === statisticsConstants.allAnalysisTypes.TrendAnalysis) { } else if (this.analysisType === statisticsConstants.allAnalysisTypes.TrendAnalysis) {
const chartDateType = getDateTypeByDateRange(getYearMonthFirstUnixTime(startTime), getYearMonthLastUnixTime(endTime), this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.TrendAnalysis);
this.statisticsStore.updateTransactionStatisticsFilter({ this.statisticsStore.updateTransactionStatisticsFilter({
trendChartDateType: this.allDateRanges.Custom.type, trendChartDateType: chartDateType,
trendChartStartYearMonth: startTime, trendChartStartYearMonth: startTime,
trendChartEndYearMonth: endTime trendChartEndYearMonth: endTime
}); });
+4 -1
View File
@@ -371,6 +371,7 @@ import {
getBrowserTimezoneOffsetMinutes, getBrowserTimezoneOffsetMinutes,
getActualUnixTimeForStore, getActualUnixTimeForStore,
getShiftedDateRangeAndDateType, getShiftedDateRangeAndDateType,
getDateTypeByDateRange,
getDateRangeByDateType, getDateRangeByDateType,
getRecentDateRangeType, getRecentDateRangeType,
isDateRangeMatchOneMonth isDateRangeMatchOneMonth
@@ -797,8 +798,10 @@ export default {
return; return;
} }
const dateType = getDateTypeByDateRange(minTime, maxTime, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal);
this.transactionsStore.updateTransactionListFilter({ this.transactionsStore.updateTransactionListFilter({
dateType: datetimeConstants.allDateRanges.Custom.type, dateType: dateType,
maxTime: maxTime, maxTime: maxTime,
minTime: minTime minTime: minTime
}); });
@@ -261,6 +261,7 @@ import statisticsConstants from '@/consts/statistics.js';
import { getNameByKeyValue, limitText, formatPercent } from '@/lib/common.js' import { getNameByKeyValue, limitText, formatPercent } from '@/lib/common.js'
import { import {
getShiftedDateRangeAndDateType, getShiftedDateRangeAndDateType,
getDateTypeByDateRange,
getDateRangeByDateType getDateRangeByDateType
} from '@/lib/datetime.js'; } from '@/lib/datetime.js';
import { scrollToSelectedItem } from '@/lib/ui.mobile.js'; import { scrollToSelectedItem } from '@/lib/ui.mobile.js';
@@ -492,8 +493,10 @@ export default {
return; return;
} }
const chartDateType = getDateTypeByDateRange(startTime, endTime, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal);
this.statisticsStore.updateTransactionStatisticsFilter({ this.statisticsStore.updateTransactionStatisticsFilter({
categoricalChartDateType: this.allDateRanges.Custom.type, categoricalChartDateType: chartDateType,
categoricalChartStartTime: startTime, categoricalChartStartTime: startTime,
categoricalChartEndTime: endTime categoricalChartEndTime: endTime
}); });
+4 -1
View File
@@ -439,6 +439,7 @@ import {
getBrowserTimezoneOffsetMinutes, getBrowserTimezoneOffsetMinutes,
getActualUnixTimeForStore, getActualUnixTimeForStore,
getShiftedDateRangeAndDateType, getShiftedDateRangeAndDateType,
getDateTypeByDateRange,
getDateRangeByDateType getDateRangeByDateType
} from '@/lib/datetime.js'; } from '@/lib/datetime.js';
import { categoryTypeToTransactionType, transactionTypeToCategoryType } from '@/lib/category.js'; import { categoryTypeToTransactionType, transactionTypeToCategoryType } from '@/lib/category.js';
@@ -720,8 +721,10 @@ export default {
return; return;
} }
const dateType = getDateTypeByDateRange(minTime, maxTime, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal);
this.transactionsStore.updateTransactionListFilter({ this.transactionsStore.updateTransactionListFilter({
dateType: this.allDateRanges.Custom.type, dateType: dateType,
maxTime: maxTime, maxTime: maxTime,
minTime: minTime minTime: minTime
}); });