migrate to typescript

This commit is contained in:
MaysWind
2024-12-29 14:24:37 +08:00
parent b638a73e4d
commit 2560a70e5e
171 changed files with 3402 additions and 2557 deletions
+19 -19
View File
@@ -413,12 +413,12 @@
<v-divider v-if="query.tagIds && query.tagIds !== 'none'" />
<template :key="filterType.type"
v-for="filterType in allTransactionTagFilterTypes"
v-if="query.tagIds && query.tagIds !== 'none'">
<template v-if="query.tagIds && query.tagIds !== 'none'">
<v-list-item class="text-sm" density="compact"
:key="filterType.type"
:value="filterType.type"
:append-icon="(query.tagFilterType === filterType.type ? icons.check : null)">
:append-icon="(query.tagFilterType === filterType.type ? icons.check : null)"
v-for="filterType in allTransactionTagFilterTypes">
<v-list-item-title class="cursor-pointer"
@click="changeTagFilterType(filterType.type)">
<div class="d-flex align-center">
@@ -595,12 +595,12 @@ import { useTransactionTagsStore } from '@/stores/transactionTag.js';
import { useTransactionsStore } from '@/stores/transaction.js';
import { useTransactionTemplatesStore } from '@/stores/transactionTemplate.js';
import { AccountType } from '@/core/account.ts';
import { TransactionType, TransactionTagFilterType } from '@/core/transaction.ts';
import { TemplateType } from '@/core/template.ts';
import numeralConstants from '@/consts/numeral.js';
import datetimeConstants from '@/consts/datetime.js';
import accountConstants from '@/consts/account.js';
import transactionConstants from '@/consts/transaction.js';
import templateConstants from '@/consts/template.js';
import { isString, isNumber, getNameByKeyValue } from '@/lib/common.js';
import { isString, isNumber, getNameByKeyValue } from '@/lib/common.ts';
import logger from '@/lib/logger.js';
import {
getCurrentUnixTime,
@@ -629,8 +629,8 @@ import {
} from '@/lib/category.js';
import { getUnifiedSelectedAccountsCurrencyOrDefaultCurrency } from '@/lib/account.js';
import { getTransactionDisplayAmount } from '@/lib/transaction.js';
import { isDataImportingEnabled } from '@/lib/server_settings.js';
import { scrollToSelectedItem } from '@/lib/ui.desktop.js';
import { isDataImportingEnabled } from '@/lib/server_settings.ts';
import { scrollToSelectedItem } from '@/lib/ui/desktop.js';
import {
mdiMagnify,
@@ -729,7 +729,7 @@ export default {
if (this.query.accountIds && this.queryAllFilterAccountIdsCount === 1) {
const account = this.allAccounts[this.query.accountIds];
if (account && account.type === accountConstants.allAccountTypes.MultiSubAccounts) {
if (account && account.type === AccountType.MultiSubAccounts.type) {
return false;
}
}
@@ -980,16 +980,16 @@ export default {
return numeralConstants.allAmountFilterTypeArray;
},
allTransactionTypes() {
return transactionConstants.allTransactionTypes;
return TransactionType;
},
allTransactionTagFilterTypes() {
const allTagFilterTypes = this.$locale.getAllTransactionTagFilterTypes();
const allTagFilterTypesWithIcon = [];
const tagFilterIconMap = {
[transactionConstants.allTransactionTagFilterTypes.HasAny.type]: this.icons.withAnyTags,
[transactionConstants.allTransactionTagFilterTypes.HasAll.type]: this.icons.withAllTags,
[transactionConstants.allTransactionTagFilterTypes.NotHasAny.type]: this.icons.withoutAnyTags,
[transactionConstants.allTransactionTagFilterTypes.NotHasAll.type]: this.icons.withoutAllTags
[TransactionTagFilterType.HasAny.type]: this.icons.withAnyTags,
[TransactionTagFilterType.HasAll.type]: this.icons.withAllTags,
[TransactionTagFilterType.NotHasAny.type]: this.icons.withoutAnyTags,
[TransactionTagFilterType.NotHasAll.type]: this.icons.withoutAllTags
};
for (let i = 0; i < allTagFilterTypes.length; i++) {
@@ -1055,7 +1055,7 @@ export default {
},
allTransactionTemplates() {
const allVisibleTemplates = this.transactionTemplatesStore.allVisibleTemplates;
return allVisibleTemplates[templateConstants.allTemplateTypes.Normal] || [];
return allVisibleTemplates[TemplateType.Normal.type] || [];
},
recentMonthDateRanges() {
return this.$locale.getAllRecentMonthDateRanges(this.userStore, true, true);
@@ -1147,7 +1147,7 @@ export default {
this.reload(false);
this.transactionTemplatesStore.loadAllTemplates({
templateType: templateConstants.allTemplateTypes.Normal,
templateType: TemplateType.Normal.type,
force: false
});
},
@@ -1312,7 +1312,7 @@ export default {
if (type && this.query.categoryIds) {
newCategoryFilter = '';
for (let categoryId in this.queryAllFilterCategoryIds) {
for (const categoryId in this.queryAllFilterCategoryIds) {
if (!Object.prototype.hasOwnProperty.call(this.queryAllFilterCategoryIds, categoryId)) {
continue;
}
@@ -179,10 +179,10 @@ import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import { useTransactionTagsStore } from '@/stores/transactionTag.js';
import { useExchangeRatesStore } from '@/stores/exchangeRates.js';
import categoryConstants from '@/consts/category.js';
import { CategoryType } from '@/core/category.ts';
import {
getNameByKeyValue
} from '@/lib/common.js';
} from '@/lib/common.ts';
import {
getTransactionPrimaryCategoryName,
getTransactionSecondaryCategoryName,
@@ -219,7 +219,7 @@ export default {
return this.userStore.currentUserDefaultCurrency;
},
allCategoryTypes() {
return categoryConstants.allCategoryTypes;
return CategoryType;
},
allAccounts() {
return this.accountsStore.allPlainAccounts;
@@ -200,7 +200,7 @@
v-model="transaction.time"
@error="showDateTimeError" />
</v-col>
<v-col cols="12" md="6" v-if="type === 'template' && transaction.templateType === allTemplateTypes.Schedule">
<v-col cols="12" md="6" v-if="type === 'template' && transaction.templateType === allTemplateTypes.Schedule.type">
<schedule-frequency-select
:readonly="mode === 'view'"
:disabled="loading || submitting"
@@ -208,7 +208,7 @@
v-model:type="transaction.scheduledFrequencyType"
v-model="transaction.scheduledFrequency" />
</v-col>
<v-col cols="12" md="6" v-if="type === 'transaction' || (type === 'template' && transaction.templateType === allTemplateTypes.Schedule)">
<v-col cols="12" md="6" v-if="type === 'transaction' || (type === 'template' && transaction.templateType === allTemplateTypes.Schedule.type)">
<v-autocomplete
class="transaction-edit-timezone"
item-title="displayNameWithUtcOffset"
@@ -400,22 +400,23 @@ import { useTransactionsStore } from '@/stores/transaction.js';
import { useTransactionTemplatesStore } from '@/stores/transactionTemplate.js';
import { useExchangeRatesStore } from '@/stores/exchangeRates.js';
import fileConstants from '@/consts/file.js';
import categoryConstants from '@/consts/category.js';
import transactionConstants from '@/consts/transaction.js';
import templateConstants from '@/consts/template.js';
import apiConstants from '@/consts/api.js';
import { CategoryType } from '@/core/category.ts';
import { TransactionType, TransactionEditScopeType } from '@/core/transaction.ts';
import { TemplateType, ScheduledTemplateFrequencyType } from '@/core/template.ts';
import { TRANSACTION_MAX_PICTURE_COUNT } from '@/consts/transaction.ts';
import { KnownErrorCode } from '@/consts/api.ts';
import { SUPPORTED_IMAGE_EXTENSIONS } from '@/consts/file.ts';
import logger from '@/lib/logger.js';
import {
isArray,
getNameByKeyValue
} from '@/lib/common.js';
} from '@/lib/common.ts';
import {
getUtcOffsetByUtcOffsetMinutes,
getTimezoneOffsetMinutes,
getCurrentUnixTime
} from '@/lib/datetime.js';
import { generateRandomUUID } from '@/lib/misc.js';
import { generateRandomUUID } from '@/lib/misc.ts';
import {
getTransactionPrimaryCategoryName,
getTransactionSecondaryCategoryName,
@@ -425,7 +426,7 @@ import { setTransactionModelByTransaction } from '@/lib/transaction.js';
import {
isTransactionPicturesEnabled,
getMapProvider
} from '@/lib/server_settings.js';
} from '@/lib/server_settings.ts';
import {
mdiDotsVertical,
@@ -496,13 +497,13 @@ export default {
} else {
return 'Transaction Detail';
}
} else if (this.type === 'template' && this.transaction.templateType === templateConstants.allTemplateTypes.Normal) {
} else if (this.type === 'template' && this.transaction.templateType === TemplateType.Normal.type) {
if (this.mode === 'add') {
return 'Add Transaction Template';
} else if (this.mode === 'edit') {
return 'Edit Transaction Template';
}
} else if (this.type === 'template' && this.transaction.templateType === templateConstants.allTemplateTypes.Schedule) {
} else if (this.type === 'template' && this.transaction.templateType === TemplateType.Schedule.type) {
if (this.mode === 'add') {
return 'Add Scheduled Transaction';
} else if (this.mode === 'edit') {
@@ -571,13 +572,13 @@ export default {
return this.userStore.currentUserDefaultAccountId;
},
allTransactionTypes() {
return transactionConstants.allTransactionTypes;
return TransactionType;
},
allCategoryTypes() {
return categoryConstants.allCategoryTypes;
return CategoryType;
},
allTemplateTypes() {
return templateConstants.allTemplateTypes;
return TemplateType.all();
},
allTimezones() {
return this.$locale.getAllTimezones(true);
@@ -607,7 +608,7 @@ export default {
return this.transactionTagsStore.allTransactionTagsMap;
},
supportedImageExtensions() {
return fileConstants.supportedImageExtensions;
return SUPPORTED_IMAGE_EXTENSIONS;
},
hasAvailableExpenseCategories() {
if (!this.allCategories || !this.allCategories[this.allCategoryTypes.Expense] || !this.allCategories[this.allCategoryTypes.Expense].length) {
@@ -702,7 +703,7 @@ export default {
return false;
}
return !isArray(this.transaction.pictures) || this.transaction.pictures.length < transactionConstants.maxPictureCount;
return !isArray(this.transaction.pictures) || this.transaction.pictures.length < TRANSACTION_MAX_PICTURE_COUNT;
},
mapProvider() {
return getMapProvider();
@@ -839,8 +840,8 @@ export default {
self.transaction.templateType = options.templateType;
}
if (self.transaction.templateType === templateConstants.allTemplateTypes.Schedule) {
self.transaction.scheduledFrequencyType = templateConstants.allTemplateScheduledFrequencyTypes.Disabled.type;
if (self.transaction.templateType === TemplateType.Schedule.type) {
self.transaction.scheduledFrequencyType = ScheduledTemplateFrequencyType.Disabled.type;
self.transaction.scheduledFrequency = '';
}
@@ -850,7 +851,7 @@ export default {
self.transaction.templateType = options.currentTemplate.templateType;
self.transaction.name = options.currentTemplate.name;
if (self.transaction.templateType === templateConstants.allTemplateTypes.Schedule) {
if (self.transaction.templateType === TemplateType.Schedule.type) {
self.transaction.scheduledFrequencyType = options.currentTemplate.scheduledFrequencyType;
self.transaction.scheduledFrequency = options.currentTemplate.scheduledFrequency;
self.transaction.utcOffset = options.currentTemplate.utcOffset;
@@ -903,7 +904,7 @@ export default {
self.transaction.templateType = template.templateType;
self.transaction.name = template.name;
if (self.transaction.templateType === templateConstants.allTemplateTypes.Schedule) {
if (self.transaction.templateType === TemplateType.Schedule.type) {
self.transaction.scheduledFrequencyType = template.scheduledFrequencyType;
self.transaction.scheduledFrequency = template.scheduledFrequency;
self.transaction.utcOffset = template.utcOffset;
@@ -974,12 +975,12 @@ export default {
}).catch(error => {
self.submitting = false;
if (error.error && (error.error.errorCode === apiConstants.transactionCannotCreateInThisTimeErrorCode || error.error.errorCode === apiConstants.transactionCannotModifyInThisTimeErrorCode)) {
if (error.error && (error.error.errorCode === KnownErrorCode.TransactionCannotCreateInThisTime || error.error.errorCode === KnownErrorCode.TransactionCannotModifyInThisTime)) {
self.$refs.confirmDialog.open('You have set this time range to prevent editing transactions. Would you like to change the editable transaction range to All?').then(() => {
self.submitting = true;
self.userStore.updateUserTransactionEditScope({
transactionEditScope: transactionConstants.allTransactionEditScopeTypes.All.type
transactionEditScope: TransactionEditScopeType.All.type
}).then(() => {
self.submitting = false;
@@ -1272,7 +1273,7 @@ export default {
self.removingPictureId = '';
self.submitting = false;
}).catch(error => {
if (error.error && error.error.errorCode === apiConstants.transactionPictureNotFoundErrorCode) {
if (error.error && error.error.errorCode === KnownErrorCode.TransactionPictureNotFound) {
for (let i = 0; i < self.transaction.pictures.length; i++) {
if (self.transaction.pictures[i].pictureId === pictureInfo.pictureId) {
self.transaction.pictures.splice(i, 1);
@@ -606,16 +606,16 @@ import { useOverviewStore } from '@/stores/overview.js';
import { useStatisticsStore } from '@/stores/statistics.js';
import { useExchangeRatesStore } from '@/stores/exchangeRates.js';
import categoryConstants from '@/consts/category.js';
import transactionConstants from '@/consts/transaction.js';
import { CategoryType } from '@/core/category.ts';
import { TransactionType } from '@/core/transaction.ts';
import {
isString,
isNumber,
getNameByKeyValue,
objectFieldToArrayItem
} from '@/lib/common.js';
import { isFileExtensionSupported } from '@/lib/file.js';
import { generateRandomUUID } from '@/lib/misc.js';
} from '@/lib/common.ts';
import { isFileExtensionSupported } from '@/lib/file.ts';
import { generateRandomUUID } from '@/lib/misc.ts';
import logger from '@/lib/logger.js';
import {
parseDateFromUnixTime,
@@ -736,10 +736,10 @@ export default {
return getNameByKeyValue(this.allSupportedImportFileTypes, this.fileType, 'type', 'subTypes');
},
allTransactionTypes() {
return transactionConstants.allTransactionTypes;
return TransactionType;
},
allCategoryTypes() {
return categoryConstants.allCategoryTypes;
return CategoryType;
},
allAccounts() {
return this.accountsStore.allPlainAccounts;
@@ -1635,7 +1635,7 @@ export default {
}
}
for (let name in invalidCategoryNames) {
for (const name in invalidCategoryNames) {
if (!Object.prototype.hasOwnProperty.call(invalidCategoryNames, name)) {
continue;
}
@@ -1666,7 +1666,7 @@ export default {
}
}
for (let name in invalidAccountNames) {
for (const name in invalidAccountNames) {
if (!Object.prototype.hasOwnProperty.call(invalidAccountNames, name)) {
continue;
}
@@ -1700,7 +1700,7 @@ export default {
}
}
for (let name in invalidTagNames) {
for (const name in invalidTagNames) {
if (!Object.prototype.hasOwnProperty.call(invalidTagNames, name)) {
continue;
}