mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-18 00:34:28 +08:00
migrate consts/statistics.js to ts
This commit is contained in:
+6
-80
@@ -12,16 +12,15 @@ import { AccountType, AccountCategory } from '@/core/account.ts';
|
||||
import { CategoryType } from '@/core/category.ts';
|
||||
import { TransactionEditScopeType, TransactionTagFilterType } from '@/core/transaction.ts';
|
||||
import { ScheduledTemplateFrequencyType } from '@/core/template.ts';
|
||||
import { CategoricalChartType, TrendChartType, ChartDataType, ChartSortingType, ChartDateAggregationType } from '@/core/statistics.ts';
|
||||
|
||||
import { UTC_TIMEZONE, ALL_TIMEZONES } from '@/consts/timezone.ts';
|
||||
import { ALL_CURRENCIES } from '@/consts/currency.ts';
|
||||
import { SUPPORTED_IMPORT_FILE_TYPES } from '@/consts/file.ts';
|
||||
import { DEFAULT_EXPENSE_CATEGORIES, DEFAULT_INCOME_CATEGORIES, DEFAULT_TRANSFER_CATEGORIES } from '@/consts/category.ts';
|
||||
import statisticsConstants from '@/consts/statistics.js';
|
||||
import { KnownErrorCode, SPECIFIED_API_NOT_FOUND_ERRORS, PARAMETERIZED_ERRORS } from '@/consts/api.ts';
|
||||
|
||||
import {
|
||||
isDefined,
|
||||
isString,
|
||||
isNumber,
|
||||
isBoolean,
|
||||
@@ -1109,96 +1108,23 @@ function getAllAccountTypes(translateFn) {
|
||||
}
|
||||
|
||||
function getAllCategoricalChartTypes(translateFn) {
|
||||
const allChartTypes = [];
|
||||
|
||||
for (let i = 0; i < statisticsConstants.allCategoricalChartTypesArray.length; i++) {
|
||||
const chartType = statisticsConstants.allCategoricalChartTypesArray[i];
|
||||
|
||||
allChartTypes.push({
|
||||
type: chartType.type,
|
||||
displayName: translateFn(chartType.name)
|
||||
});
|
||||
}
|
||||
|
||||
return allChartTypes;
|
||||
return getLocalizedDisplayNameAndType(CategoricalChartType.values(), translateFn);
|
||||
}
|
||||
|
||||
function getAllTrendChartTypes(translateFn) {
|
||||
const allChartTypes = [];
|
||||
|
||||
for (let i = 0; i < statisticsConstants.allTrendChartTypesArray.length; i++) {
|
||||
const chartType = statisticsConstants.allTrendChartTypesArray[i];
|
||||
|
||||
allChartTypes.push({
|
||||
type: chartType.type,
|
||||
displayName: translateFn(chartType.name)
|
||||
});
|
||||
}
|
||||
|
||||
return allChartTypes;
|
||||
return getLocalizedDisplayNameAndType(TrendChartType.values(), translateFn);
|
||||
}
|
||||
|
||||
function getAllStatisticsChartDataTypes(translateFn, analysisType) {
|
||||
const allChartDataTypes = [];
|
||||
|
||||
for (const dataTypeField in statisticsConstants.allChartDataTypes) {
|
||||
if (!Object.prototype.hasOwnProperty.call(statisticsConstants.allChartDataTypes, dataTypeField)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const chartDataType = statisticsConstants.allChartDataTypes[dataTypeField];
|
||||
|
||||
if (isDefined(analysisType) && !chartDataType.availableAnalysisTypes[analysisType]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
allChartDataTypes.push({
|
||||
type: chartDataType.type,
|
||||
displayName: translateFn(chartDataType.name),
|
||||
availableAnalysisTypes: chartDataType.availableAnalysisTypes
|
||||
});
|
||||
}
|
||||
|
||||
return allChartDataTypes;
|
||||
return getLocalizedDisplayNameAndType(ChartDataType.values(analysisType), translateFn);
|
||||
}
|
||||
|
||||
function getAllStatisticsSortingTypes(translateFn) {
|
||||
const allSortingTypes = [];
|
||||
|
||||
for (const sortingTypeField in statisticsConstants.allSortingTypes) {
|
||||
if (!Object.prototype.hasOwnProperty.call(statisticsConstants.allSortingTypes, sortingTypeField)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const sortingType = statisticsConstants.allSortingTypes[sortingTypeField];
|
||||
|
||||
allSortingTypes.push({
|
||||
type: sortingType.type,
|
||||
displayName: translateFn(sortingType.name),
|
||||
displayFullName: translateFn(sortingType.fullName)
|
||||
});
|
||||
}
|
||||
|
||||
return allSortingTypes;
|
||||
return getLocalizedDisplayNameAndType(ChartSortingType.values(), translateFn);
|
||||
}
|
||||
|
||||
function getAllStatisticsDateAggregationTypes(translateFn) {
|
||||
const aggregationTypes = [];
|
||||
|
||||
for (const aggregationTypeField in statisticsConstants.allDateAggregationTypes) {
|
||||
if (!Object.prototype.hasOwnProperty.call(statisticsConstants.allDateAggregationTypes, aggregationTypeField)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const aggregationType = statisticsConstants.allDateAggregationTypes[aggregationTypeField];
|
||||
|
||||
aggregationTypes.push({
|
||||
type: aggregationType.type,
|
||||
displayName: translateFn(aggregationType.name)
|
||||
});
|
||||
}
|
||||
|
||||
return aggregationTypes;
|
||||
return getLocalizedDisplayNameAndType(ChartDateAggregationType.values(), translateFn);
|
||||
}
|
||||
|
||||
function getAllTransactionEditScopeTypes(translateFn) {
|
||||
|
||||
+14
-7
@@ -1,6 +1,13 @@
|
||||
import { TimezoneTypeForStatistics } from '@/core/timezone.ts';
|
||||
import { CurrencySortingType } from '@/core/currency.ts';
|
||||
import statisticsConstants from '@/consts/statistics.js';
|
||||
import {
|
||||
CategoricalChartType,
|
||||
TrendChartType,
|
||||
ChartDataType,
|
||||
ChartSortingType,
|
||||
DEFAULT_CATEGORICAL_CHART_DATA_RANGE,
|
||||
DEFAULT_TREND_CHART_DATA_RANGE
|
||||
} from '@/core/statistics.ts';
|
||||
|
||||
const settingsLocalStorageKey = 'ebk_app_settings';
|
||||
|
||||
@@ -22,15 +29,15 @@ const defaultSettings = {
|
||||
showAccountBalance: true,
|
||||
currencySortByInExchangeRatesPage: CurrencySortingType.Default.type,
|
||||
statistics: {
|
||||
defaultChartDataType: statisticsConstants.defaultChartDataType,
|
||||
defaultChartDataType: ChartDataType.Default.type,
|
||||
defaultTimezoneType: TimezoneTypeForStatistics.Default.type,
|
||||
defaultAccountFilter: {},
|
||||
defaultTransactionCategoryFilter: {},
|
||||
defaultSortingType: statisticsConstants.defaultSortingType,
|
||||
defaultCategoricalChartType: statisticsConstants.defaultCategoricalChartType,
|
||||
defaultCategoricalChartDataRangeType: statisticsConstants.defaultCategoricalChartDataRangeType,
|
||||
defaultTrendChartType: statisticsConstants.defaultTrendChartType,
|
||||
defaultTrendChartDataRangeType: statisticsConstants.defaultTrendChartDataRangeType,
|
||||
defaultSortingType: ChartSortingType.Default.type,
|
||||
defaultCategoricalChartType: CategoricalChartType.Default.type,
|
||||
defaultCategoricalChartDataRangeType: DEFAULT_CATEGORICAL_CHART_DATA_RANGE.type,
|
||||
defaultTrendChartType: TrendChartType.Default.type,
|
||||
defaultTrendChartDataRangeType: DEFAULT_TREND_CHART_DATA_RANGE,
|
||||
},
|
||||
animate: true
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import statisticsConstants from '@/consts/statistics.js';
|
||||
import type { YearMonth, YearUnixTime, YearQuarterUnixTime, YearMonthUnixTime } from '@/core/datetime.ts';
|
||||
import { ChartSortingType, ChartDateAggregationType } from '@/core/statistics.ts';
|
||||
|
||||
import {
|
||||
getAllMonthsStartAndEndUnixTimes,
|
||||
@@ -6,26 +7,8 @@ import {
|
||||
getAllYearsStartAndEndUnixTimes
|
||||
} from '@/lib/datetime.ts';
|
||||
|
||||
export function isChartDataTypeAvailableForAnalysisType(chartDataType, analysisType) {
|
||||
for (const dataTypeField in statisticsConstants.allChartDataTypes) {
|
||||
if (!Object.prototype.hasOwnProperty.call(statisticsConstants.allChartDataTypes, dataTypeField)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const dataTypeItem = statisticsConstants.allChartDataTypes[dataTypeField];
|
||||
|
||||
if (dataTypeItem.type !== chartDataType) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return !!dataTypeItem.availableAnalysisTypes[analysisType];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function sortStatisticsItems(items, sortingType) {
|
||||
if (sortingType === statisticsConstants.allSortingTypes.DisplayOrder.type) {
|
||||
export function sortStatisticsItems(items: { name: string, totalAmount: number, displayOrders: number[] }[], sortingType: number): void {
|
||||
if (sortingType === ChartSortingType.DisplayOrder.type) {
|
||||
items.sort(function (data1, data2) {
|
||||
for (let i = 0; i < Math.min(data1.displayOrders.length, data2.displayOrders.length); i++) {
|
||||
if (data1.displayOrders[i] !== data2.displayOrders[i]) {
|
||||
@@ -38,7 +21,7 @@ export function sortStatisticsItems(items, sortingType) {
|
||||
sensitivity: 'base'
|
||||
});
|
||||
});
|
||||
} else if (sortingType === statisticsConstants.allSortingTypes.Name.type) {
|
||||
} else if (sortingType === ChartSortingType.Name.type) {
|
||||
items.sort(function (data1, data2) {
|
||||
return data1.name.localeCompare(data2.name, undefined, { // asc
|
||||
numeric: true,
|
||||
@@ -59,7 +42,7 @@ export function sortStatisticsItems(items, sortingType) {
|
||||
}
|
||||
}
|
||||
|
||||
export function getAllDateRanges(items, startYearMonth, endYearMonth, dateAggregationType) {
|
||||
export function getAllDateRanges(items: { items: YearMonth[] }[], startYearMonth: YearMonth | string, endYearMonth: YearMonth | string, dateAggregationType: number): YearUnixTime[] | YearQuarterUnixTime[] | YearMonthUnixTime[] {
|
||||
if ((!startYearMonth || !endYearMonth) && items && items.length) {
|
||||
let minYear = Number.MAX_SAFE_INTEGER, minMonth = Number.MAX_SAFE_INTEGER, maxYear = 0, maxMonth = 0;
|
||||
|
||||
@@ -88,11 +71,12 @@ export function getAllDateRanges(items, startYearMonth, endYearMonth, dateAggreg
|
||||
if (!startYearMonth || !endYearMonth) {
|
||||
return [];
|
||||
}
|
||||
if (dateAggregationType === statisticsConstants.allDateAggregationTypes.Year.type) {
|
||||
|
||||
if (dateAggregationType === ChartDateAggregationType.Year.type) {
|
||||
return getAllYearsStartAndEndUnixTimes(startYearMonth, endYearMonth);
|
||||
} else if (dateAggregationType === statisticsConstants.allDateAggregationTypes.Quarter.type) {
|
||||
} else if (dateAggregationType === ChartDateAggregationType.Quarter.type) {
|
||||
return getAllQuartersStartAndEndUnixTimes(startYearMonth, endYearMonth);
|
||||
} else { // if (dateAggregationType === statisticsConstants.allDateAggregationTypes.Month.type) {
|
||||
} else { // if (dateAggregationType === ChartDateAggregationType.Month.type) {
|
||||
return getAllMonthsStartAndEndUnixTimes(startYearMonth, endYearMonth);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user