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
+41 -47
View File
@@ -1,5 +1,5 @@
import currencyConstants from '@/consts/currency.js';
import accountConstants from '@/consts/account.js';
import { AccountType, AccountCategory } from '@/core/account.ts';
import { PARENT_ACCOUNT_CURRENCY_PLACEHOLDER } from '@/consts/currency.ts';
export function setAccountModelByAnotherAccount(account, account2) {
account.id = account2.id;
@@ -16,22 +16,12 @@ export function setAccountModelByAnotherAccount(account, account2) {
account.visible = !account2.hidden;
}
export function getAccountCategoryInfo(categoryId) {
for (let i = 0; i < accountConstants.allCategories.length; i++) {
if (accountConstants.allCategories[i].id === categoryId) {
return accountConstants.allCategories[i];
}
}
return null;
}
export function getAccountOrSubAccountId(account, subAccountId) {
if (account.type === accountConstants.allAccountTypes.SingleAccount) {
if (account.type === AccountType.SingleAccount.type) {
return account.id;
} else if (account.type === accountConstants.allAccountTypes.MultiSubAccounts && !subAccountId) {
} else if (account.type === AccountType.MultiSubAccounts.type && !subAccountId) {
return account.id;
} else if (account.type === accountConstants.allAccountTypes.MultiSubAccounts && subAccountId) {
} else if (account.type === AccountType.MultiSubAccounts.type && subAccountId) {
if (!account.subAccounts || !account.subAccounts.length) {
return null;
}
@@ -51,11 +41,11 @@ export function getAccountOrSubAccountId(account, subAccountId) {
}
export function getAccountOrSubAccountComment(account, subAccountId) {
if (account.type === accountConstants.allAccountTypes.SingleAccount) {
if (account.type === AccountType.SingleAccount.type) {
return account.comment;
} else if (account.type === accountConstants.allAccountTypes.MultiSubAccounts && !subAccountId) {
} else if (account.type === AccountType.MultiSubAccounts.type && !subAccountId) {
return account.comment;
} else if (account.type === accountConstants.allAccountTypes.MultiSubAccounts && subAccountId) {
} else if (account.type === AccountType.MultiSubAccounts.type && subAccountId) {
if (!account.subAccounts || !account.subAccounts.length) {
return null;
}
@@ -109,7 +99,7 @@ export function getCategorizedAccountsMap(allAccounts) {
const account = allAccounts[i];
if (!ret[account.category]) {
const categoryInfo = getAccountCategoryInfo(account.category);
const categoryInfo = AccountCategory.valueOf(account.category);
if (categoryInfo) {
ret[account.category] = {
@@ -132,16 +122,17 @@ export function getCategorizedAccountsMap(allAccounts) {
export function getCategorizedAccounts(allAccounts) {
const ret = [];
const allCategories = AccountCategory.values();
const categorizedAccounts = getCategorizedAccountsMap(allAccounts);
for (let i = 0; i < accountConstants.allCategories.length; i++) {
const category = accountConstants.allCategories[i];
for (let i = 0; i < allCategories.length; i++) {
const category = allCategories[i];
if (!categorizedAccounts[category.id]) {
if (!categorizedAccounts[category.type]) {
continue;
}
const accountCategory = categorizedAccounts[category.id];
const accountCategory = categorizedAccounts[category.type];
ret.push(accountCategory);
}
@@ -150,15 +141,16 @@ export function getCategorizedAccounts(allAccounts) {
export function getCategorizedAccountsWithVisibleCount(categorizedAccountsMap) {
const ret = [];
const allCategories = AccountCategory.values();
for (let i = 0; i < accountConstants.allCategories.length; i++) {
const accountCategory = accountConstants.allCategories[i];
for (let i = 0; i < allCategories.length; i++) {
const accountCategory = allCategories[i];
if (!categorizedAccountsMap[accountCategory.id] || !categorizedAccountsMap[accountCategory.id].accounts) {
if (!categorizedAccountsMap[accountCategory.type] || !categorizedAccountsMap[accountCategory.type].accounts) {
continue;
}
const allAccounts = categorizedAccountsMap[accountCategory.id].accounts;
const allAccounts = categorizedAccountsMap[accountCategory.type].accounts;
const allSubAccounts = {};
const allVisibleSubAccountCounts = {};
const allFirstVisibleSubAccountIndexes = {};
@@ -176,7 +168,7 @@ export function getCategorizedAccountsWithVisibleCount(categorizedAccountsMap) {
}
}
if (account.type === accountConstants.allAccountTypes.MultiSubAccounts && account.subAccounts) {
if (account.type === AccountType.MultiSubAccounts.type && account.subAccounts) {
let visibleSubAccountCount = 0;
let firstVisibleSubAccountIndex = -1;
@@ -202,7 +194,7 @@ export function getCategorizedAccountsWithVisibleCount(categorizedAccountsMap) {
if (allAccounts.length > 0) {
ret.push({
category: accountCategory.id,
category: accountCategory.type,
name: accountCategory.name,
icon: accountCategory.defaultAccountIconId,
allAccounts: allAccounts,
@@ -219,31 +211,31 @@ export function getCategorizedAccountsWithVisibleCount(categorizedAccountsMap) {
}
export function getAllFilteredAccountsBalance(categorizedAccounts, accountFilter) {
const allAccountCategories = accountConstants.allCategories;
const allAccountCategories = AccountCategory.values();
const ret = [];
for (let categoryIdx = 0; categoryIdx < allAccountCategories.length; categoryIdx++) {
const accountCategory = allAccountCategories[categoryIdx];
if (!categorizedAccounts[accountCategory.id] || !categorizedAccounts[accountCategory.id].accounts) {
if (!categorizedAccounts[accountCategory.type] || !categorizedAccounts[accountCategory.type].accounts) {
continue;
}
for (let accountIdx = 0; accountIdx < categorizedAccounts[accountCategory.id].accounts.length; accountIdx++) {
const account = categorizedAccounts[accountCategory.id].accounts[accountIdx];
for (let accountIdx = 0; accountIdx < categorizedAccounts[accountCategory.type].accounts.length; accountIdx++) {
const account = categorizedAccounts[accountCategory.type].accounts[accountIdx];
if (account.hidden || !accountFilter(account)) {
continue;
}
if (account.type === accountConstants.allAccountTypes.SingleAccount) {
if (account.type === AccountType.SingleAccount.type) {
ret.push({
balance: account.balance,
isAsset: account.isAsset,
isLiability: account.isLiability,
currency: account.currency
});
} else if (account.type === accountConstants.allAccountTypes.MultiSubAccounts && account.subAccounts) {
} else if (account.type === AccountType.MultiSubAccounts.type && account.subAccounts) {
for (let subAccountIdx = 0; subAccountIdx < account.subAccounts.length; subAccountIdx++) {
const subAccount = account.subAccounts[subAccountIdx];
@@ -307,7 +299,7 @@ export function getUnifiedSelectedAccountsCurrencyOrDefaultCurrency(allAccounts,
const account = allAccounts[accountId];
if (account.currency === currencyConstants.parentAccountCurrencyPlaceholder) {
if (account.currency === PARENT_ACCOUNT_CURRENCY_PLACEHOLDER) {
continue;
}
@@ -326,9 +318,9 @@ export function getUnifiedSelectedAccountsCurrencyOrDefaultCurrency(allAccounts,
}
export function selectAccountOrSubAccounts(filterAccountIds, account, value) {
if (account.type === accountConstants.allAccountTypes.SingleAccount) {
if (account.type === AccountType.SingleAccount.type) {
filterAccountIds[account.id] = value;
} else if (account.type === accountConstants.allAccountTypes.MultiSubAccounts) {
} else if (account.type === AccountType.MultiSubAccounts.type) {
if (!account.subAccounts || !account.subAccounts.length) {
return;
}
@@ -348,7 +340,7 @@ export function selectAll(filterAccountIds, allAccountsMap) {
const account = allAccountsMap[accountId];
if (account && account.type === accountConstants.allAccountTypes.SingleAccount) {
if (account && account.type === AccountType.SingleAccount.type) {
filterAccountIds[account.id] = false;
}
}
@@ -362,7 +354,7 @@ export function selectNone(filterAccountIds, allAccountsMap) {
const account = allAccountsMap[accountId];
if (account && account.type === accountConstants.allAccountTypes.SingleAccount) {
if (account && account.type === AccountType.SingleAccount.type) {
filterAccountIds[account.id] = true;
}
}
@@ -376,7 +368,7 @@ export function selectInvert(filterAccountIds, allAccountsMap) {
const account = allAccountsMap[accountId];
if (account && account.type === accountConstants.allAccountTypes.SingleAccount) {
if (account && account.type === AccountType.SingleAccount.type) {
filterAccountIds[account.id] = !filterAccountIds[account.id];
}
}
@@ -415,9 +407,11 @@ export function isAccountOrSubAccountsHasButNotAllChecked(account, filterAccount
}
export function setAccountSuitableIcon(account, oldCategory, newCategory) {
for (let i = 0; i < accountConstants.allCategories.length; i++) {
if (accountConstants.allCategories[i].id === oldCategory) {
if (account.icon !== accountConstants.allCategories[i].defaultAccountIconId) {
const allCategories = AccountCategory.values();
for (let i = 0; i < allCategories.length; i++) {
if (allCategories[i].type === oldCategory) {
if (account.icon !== allCategories[i].defaultAccountIconId) {
return;
} else {
break;
@@ -425,9 +419,9 @@ export function setAccountSuitableIcon(account, oldCategory, newCategory) {
}
}
for (let i = 0; i < accountConstants.allCategories.length; i++) {
if (accountConstants.allCategories[i].id === newCategory) {
account.icon = accountConstants.allCategories[i].defaultAccountIconId;
for (let i = 0; i < allCategories.length; i++) {
if (allCategories[i].type === newCategory) {
account.icon = allCategories[i].defaultAccountIconId;
}
}
}
+20 -20
View File
@@ -1,5 +1,5 @@
import categoryConstants from '@/consts/category.js';
import transactionConstants from '@/consts/transaction.js';
import { CategoryType } from '@/core/category.ts';
import { TransactionType } from '@/core/transaction.ts';
export function setCategoryModelByAnotherCategory(category, category2) {
category.id = category2.id;
@@ -13,24 +13,24 @@ export function setCategoryModelByAnotherCategory(category, category2) {
}
export function transactionTypeToCategoryType(transactionType) {
if (transactionType === transactionConstants.allTransactionTypes.Income) {
return categoryConstants.allCategoryTypes.Income;
} else if (transactionType === transactionConstants.allTransactionTypes.Expense) {
return categoryConstants.allCategoryTypes.Expense;
} else if (transactionType === transactionConstants.allTransactionTypes.Transfer) {
return categoryConstants.allCategoryTypes.Transfer;
if (transactionType === TransactionType.Income) {
return CategoryType.Income;
} else if (transactionType === TransactionType.Expense) {
return CategoryType.Expense;
} else if (transactionType === TransactionType.Transfer) {
return CategoryType.Transfer;
} else {
return null;
}
}
export function categoryTypeToTransactionType(categoryType) {
if (categoryType === categoryConstants.allCategoryTypes.Income) {
return transactionConstants.allTransactionTypes.Income;
} else if (categoryType === categoryConstants.allCategoryTypes.Expense) {
return transactionConstants.allTransactionTypes.Expense;
} else if (categoryType === categoryConstants.allCategoryTypes.Transfer) {
return transactionConstants.allTransactionTypes.Transfer;
if (categoryType === CategoryType.Income) {
return TransactionType.Income;
} else if (categoryType === CategoryType.Expense) {
return TransactionType.Expense;
} else if (categoryType === CategoryType.Transfer) {
return TransactionType.Transfer;
} else {
return null;
}
@@ -73,16 +73,16 @@ export function getTransactionSecondaryCategoryName(categoryId, allCategories) {
export function allTransactionCategoriesWithVisibleCount(allTransactionCategories, allowCategoryTypes) {
const ret = {};
const hasAllowCategoryTypes = allowCategoryTypes
&& (allowCategoryTypes[categoryConstants.allCategoryTypes.Income.toString()]
|| allowCategoryTypes[categoryConstants.allCategoryTypes.Expense.toString()]
|| allowCategoryTypes[categoryConstants.allCategoryTypes.Transfer.toString()]);
&& (allowCategoryTypes[CategoryType.Income.toString()]
|| allowCategoryTypes[CategoryType.Expense.toString()]
|| allowCategoryTypes[CategoryType.Transfer.toString()]);
for (let key in categoryConstants.allCategoryTypes) {
if (!Object.prototype.hasOwnProperty.call(categoryConstants.allCategoryTypes, key)) {
for (let key in CategoryType) {
if (!Object.prototype.hasOwnProperty.call(CategoryType, key)) {
continue;
}
const categoryType = categoryConstants.allCategoryTypes[key];
const categoryType = CategoryType[key];
if (!allTransactionCategories[categoryType]) {
continue;
+76
View File
@@ -0,0 +1,76 @@
import Clipboard from 'clipboard';
export interface ClipboardCreateContext {
readonly el: string | Element;
readonly text: string;
readonly successCallback?: (e: ClipboardEvent) => void;
readonly errorCallback?: (e: ClipboardEvent) => void;
}
export interface ClipboardEvent {
readonly text: string;
readonly action: string;
}
export class ClipboardTextHolder {
private text: string;
constructor(text: string) {
this.text = text;
}
public getText(): string {
return this.text;
}
public setText(text: string): void {
this.text = text;
}
}
export class ClipboardHolder {
private readonly textHolder: ClipboardTextHolder;
private readonly clipboard: Clipboard;
private constructor(textHolder: ClipboardTextHolder, clipboard: Clipboard) {
this.textHolder = textHolder;
this.clipboard = clipboard;
}
public setClipboardText(text: string): void {
this.textHolder.setText(text);
}
public destroy(): void {
this.clipboard.destroy();
}
public static create({ el, text, successCallback, errorCallback }: ClipboardCreateContext): ClipboardHolder {
const textHolder = new ClipboardTextHolder(text);
const clipboard = new Clipboard(el, {
text: function () {
return textHolder.getText();
}
});
clipboard.on('success', (e) => {
if (successCallback) {
successCallback({
text: e.text,
action: e.action
});
}
});
clipboard.on('error', (e) => {
if (errorCallback) {
errorCallback({
text: e.text,
action: e.action
});
}
});
return new ClipboardHolder(textHolder, clipboard);
}
}
-16
View File
@@ -1,16 +0,0 @@
export function getColorsInRows(allColorInfos, itemPerRow) {
const ret = [];
let rowCount = -1;
for (let i = 0; i < allColorInfos.length; i++) {
if (i % itemPerRow === 0) {
ret[++rowCount] = [];
}
ret[rowCount].push({
color: allColorInfos[i]
});
}
return ret;
}
+18
View File
@@ -0,0 +1,18 @@
import type { ColorValue, ColorInfo } from '@/core/color.ts';
export function getColorsInRows(allColorValues: ColorValue[], itemPerRow: number): ColorInfo[][] {
const ret: ColorInfo[][] = [];
let rowCount = -1;
for (let i = 0; i < allColorValues.length; i++) {
if (i % itemPerRow === 0) {
ret[++rowCount] = [];
}
ret[rowCount].push({
color: allColorValues[i]
});
}
return ret;
}
+120 -97
View File
@@ -1,16 +1,16 @@
export function isFunction(val) {
export function isFunction(val: unknown): boolean {
return typeof(val) === 'function';
}
export function isDefined(val) {
export function isDefined(val: unknown): boolean {
return typeof val !== 'undefined';
}
export function isObject(val) {
export function isObject(val: unknown): boolean {
return val != null && typeof(val) === 'object' && !isArray(val);
}
export function isArray(val) {
export function isArray(val: unknown): boolean {
if (isFunction(Array.isArray)) {
return Array.isArray(val);
}
@@ -18,23 +18,23 @@ export function isArray(val) {
return Object.prototype.toString.call(val) === '[object Array]';
}
export function isString(val) {
export function isString(val: unknown): boolean {
return typeof(val) === 'string';
}
export function isNumber(val) {
export function isNumber(val: unknown): boolean {
return typeof(val) === 'number';
}
export function isInteger(val) {
export function isInteger(val: unknown): boolean {
return Number.isInteger(val);
}
export function isBoolean(val) {
export function isBoolean(val: unknown): boolean {
return typeof(val) === 'boolean';
}
export function isYearMonth(val) {
export function isYearMonth(val: unknown): boolean {
if (typeof(val) !== 'string') {
return false;
}
@@ -45,50 +45,53 @@ export function isYearMonth(val) {
return false;
}
return parseInt(items[0]) && parseInt(items[1]);
return !!parseInt(items[0]) && !!parseInt(items[1]);
}
export function isEquals(obj1, obj2) {
export function isEquals(obj1: unknown, obj2: unknown): boolean {
if (obj1 === obj2) {
return true;
}
if (isArray(obj1) && isArray(obj2)) {
if (obj1.length !== obj2.length) {
const arr1 = obj1 as unknown[];
const arr2 = obj2 as unknown[];
if (arr1.length !== arr2.length) {
return false;
}
for (let i = 0; i < obj1.length; i++) {
if (!isEquals(obj1[i], obj2[i])) {
for (let i = 0; i < arr1.length; i++) {
if (!isEquals(arr1[i], arr2[i])) {
return false;
}
}
return true;
} else if (isObject(obj1) && isObject(obj2)) {
const keys1 = Object.keys(obj1);
const keys2 = Object.keys(obj2);
const keys1 = Object.keys(obj1 as Record<string, unknown>);
const keys2 = Object.keys(obj2 as Record<string, unknown>);
if (keys1.length !== keys2.length) {
return false;
}
const keyExistsMap2 = {};
const keyExistsMap2 = new Map<string, boolean>();
for (let i = 0; i < keys2.length; i++) {
const key = keys2[i];
keyExistsMap2[key] = true;
keyExistsMap2.set(key, true);
}
for (let i = 0; i < keys1.length; i++) {
const key = keys1[i];
if (!keyExistsMap2[key]) {
if (!keyExistsMap2.get(key)) {
return false;
}
if (!isEquals(obj1[key], obj2[key])) {
if (!isEquals((obj1 as Record<string, unknown>)[key], (obj2 as Record<string, unknown>)[key])) {
return false;
}
}
@@ -99,7 +102,7 @@ export function isEquals(obj1, obj2) {
}
}
export function isYearMonthEquals(val1, val2) {
export function isYearMonthEquals(val1: unknown, val2: unknown): boolean {
if (typeof(val1) !== 'string' || typeof(val2) !== 'string') {
return false;
}
@@ -111,15 +114,15 @@ export function isYearMonthEquals(val1, val2) {
return false;
}
return (parseInt(items1[0]) && parseInt(items1[1])) && (parseInt(items1[0]) === parseInt(items2[0])) && (parseInt(items1[1]) === parseInt(items2[1]));
return (!!parseInt(items1[0]) && !!parseInt(items1[1])) && (parseInt(items1[0]) === parseInt(items2[0])) && (parseInt(items1[1]) === parseInt(items2[1]));
}
export function isObjectEmpty(obj) {
export function isObjectEmpty(obj: object): boolean {
if (!obj) {
return true;
}
for (let field in obj) {
for (const field in obj) {
if (!Object.prototype.hasOwnProperty.call(obj, field)) {
continue;
}
@@ -130,20 +133,20 @@ export function isObjectEmpty(obj) {
return true;
}
export function sortNumbersArray(array) {
export function sortNumbersArray(array: number[]): number[] {
return array.sort(function (num1, num2) {
return num1 - num2;
});
}
export function getObjectOwnFieldCount(object) {
export function getObjectOwnFieldCount(object: object): number {
let count = 0;
if (!object || !isObject(object)) {
return count;
}
for (let field in object) {
for (const field in object) {
if (!Object.prototype.hasOwnProperty.call(object, field)) {
continue;
}
@@ -154,20 +157,20 @@ export function getObjectOwnFieldCount(object) {
return count;
}
export function replaceAll(value, originalValue, targetValue) {
export function replaceAll(value: string, originalValue: string, targetValue: string): string {
// Escape special characters in originalValue to safely use it in a regex pattern.
// This ensures that characters like . (dot), * (asterisk), +, ?, etc. are treated literally,
// rather than as special regex symbols.
const escapedOriginalValue = originalValue.replace(/([.*+?^=!:${}()|\-/\\])/g, '\\$1');
return value.replaceAll(new RegExp(escapedOriginalValue, 'g'), targetValue);
}
export function removeAll(value, originalValue) {
export function removeAll(value: string, originalValue: string): string {
return replaceAll(value, originalValue, '');
}
export function limitText(value, maxLength) {
export function limitText(value: string, maxLength: number): string {
let length = 0;
for (let i = 0; i < value.length; i++) {
@@ -187,7 +190,7 @@ export function limitText(value, maxLength) {
return value.substring(0, maxLength - 3) + '...';
}
export function getTextBefore(fullText, text) {
export function getTextBefore(fullText: string, text: string): string {
if (!text) {
return fullText;
}
@@ -201,7 +204,7 @@ export function getTextBefore(fullText, text) {
return '';
}
export function getTextAfter(fullText, text) {
export function getTextAfter(fullText: string, text: string): string {
if (!text) {
return fullText;
}
@@ -216,15 +219,15 @@ export function getTextAfter(fullText, text) {
return '';
}
export function base64encode(arrayBuffer) {
if (!arrayBuffer || arrayBuffer.length === 0) {
export function base64encode(arrayBuffer: ArrayBuffer): string | null {
if (!arrayBuffer) {
return null;
}
return btoa(String.fromCharCode.apply(null, new Uint8Array(arrayBuffer)));
return btoa(String.fromCharCode.apply(null, Array.from(new Uint8Array(arrayBuffer))));
}
export function base64decode(str) {
export function base64decode(str: string): string | null {
if (!str) {
return '';
}
@@ -232,56 +235,64 @@ export function base64decode(str) {
return atob(str);
}
export function arrayBufferToString(arrayBuffer) {
return String.fromCharCode.apply(null, new Uint8Array(arrayBuffer));
export function arrayBufferToString(arrayBuffer: ArrayBuffer): string {
return String.fromCharCode.apply(null, Array.from(new Uint8Array(arrayBuffer)));
}
export function stringToArrayBuffer(str){
export function stringToArrayBuffer(str: string): ArrayBuffer {
return Uint8Array.from(str, c => c.charCodeAt(0)).buffer;
}
export function getFirstVisibleItem(items, hiddenField) {
if (isArray(items) && items.length > 0) {
for (let i = 0; i < items.length; i++) {
if (hiddenField && items[i][hiddenField]) {
export function getFirstVisibleItem(items: Record<string, unknown>[] | Record<string, Record<string, unknown>>, hiddenField: string): unknown {
if (isArray(items) && (items as Record<string, unknown>[]).length > 0) {
const arr = items as Record<string, unknown>[];
for (let i = 0; i < arr.length; i++) {
if (hiddenField && arr[i][hiddenField]) {
continue;
}
return items[i];
return arr[i];
}
} else if (isObject(items)) {
for (let field in items) {
if (!Object.prototype.hasOwnProperty.call(items, field)) {
const obj = items as Record<string, Record<string, unknown>>;
for (const field in obj) {
if (!Object.prototype.hasOwnProperty.call(obj, field)) {
continue;
}
if (hiddenField && items[field][hiddenField]) {
if (hiddenField && obj[field][hiddenField]) {
continue;
}
return items[field];
return obj[field];
}
}
return null;
}
export function getItemByKeyValue(src, value, keyField) {
export function getItemByKeyValue(src: Record<string, unknown>[] | Record<string, Record<string, unknown>>, value: unknown, keyField: string) {
if (isArray(src)) {
for (let i = 0; i < src.length; i++) {
const item = src[i];
const arr = src as Record<string, unknown>[];
for (let i = 0; i < arr.length; i++) {
const item = arr[i];
if (item[keyField] === value) {
return item;
}
}
} else if (isObject(src)) {
for (let field in src) {
const obj = src as Record<string, Record<string, unknown>>;
for (const field in obj) {
if (!Object.prototype.hasOwnProperty.call(src, field)) {
continue;
}
const item = src[field];
const item = obj[field];
if (item[keyField] === value) {
return item;
@@ -292,39 +303,47 @@ export function getItemByKeyValue(src, value, keyField) {
return null;
}
export function getNameByKeyValue(src, value, keyField, nameField, defaultName) {
export function getNameByKeyValue(src: Record<string, unknown>[] | Record<string, Record<string, unknown>>, value: unknown, keyField: string, nameField: string, defaultName: string): unknown {
if (isArray(src)) {
const arr = src as Record<string, unknown>[];
if (keyField) {
for (let i = 0; i < src.length; i++) {
const option = src[i];
for (let i = 0; i < arr.length; i++) {
const option = arr[i];
if (option[keyField] === value) {
return option[nameField];
}
}
} else {
if (src[value]) {
const option = src[value];
} else if (isNumber(value)) {
const index = value as number;
if (arr[index]) {
const option = arr[index];
return option[nameField];
}
}
} else if (isObject(src)) {
const obj = src as Record<string, Record<string, unknown>>;
if (keyField) {
for (let key in src) {
for (const key in obj) {
if (!Object.prototype.hasOwnProperty.call(src, key)) {
continue;
}
const option = src[key];
const option = obj[key];
if (option[keyField] === value) {
return option[nameField];
}
}
} else {
if (src[value]) {
const option = src[value];
} else if (isNumber(value)) {
const index = value as number;
if (obj[index]) {
const option = obj[index];
return option[nameField];
}
@@ -334,7 +353,7 @@ export function getNameByKeyValue(src, value, keyField, nameField, defaultName)
return defaultName;
}
export function copyObjectTo(fromObject, toObject) {
export function copyObjectTo(fromObject: Record<string, unknown>, toObject: Record<string, unknown>): object {
if (!isObject(fromObject)) {
return toObject;
}
@@ -343,7 +362,7 @@ export function copyObjectTo(fromObject, toObject) {
toObject = {};
}
for (let key in fromObject) {
for (const key in fromObject) {
if (!Object.prototype.hasOwnProperty.call(fromObject, key)) {
continue;
}
@@ -352,9 +371,9 @@ export function copyObjectTo(fromObject, toObject) {
const toValue = toObject[key];
if (isArray(fromValue)) {
toObject[key] = copyArrayTo(fromValue, toValue);
toObject[key] = copyArrayTo(fromValue as unknown[], toValue as unknown[]);
} else if (isObject(fromValue)) {
toObject[key] = copyObjectTo(fromValue, toValue);
toObject[key] = copyObjectTo(fromValue as Record<string, unknown>, toValue as Record<string, unknown>);
} else {
if (fromValue !== toValue) {
toObject[key] = fromValue;
@@ -365,7 +384,7 @@ export function copyObjectTo(fromObject, toObject) {
return toObject;
}
export function copyArrayTo(fromArray, toArray) {
export function copyArrayTo(fromArray: unknown[], toArray: unknown[]) {
if (!isArray(fromArray)) {
return toArray;
}
@@ -381,9 +400,9 @@ export function copyArrayTo(fromArray, toArray) {
const toValue = toArray[i];
if (isArray(fromValue)) {
toArray[i] = copyArrayTo(fromValue, toValue);
toArray[i] = copyArrayTo(fromValue as unknown[], toValue as unknown[]);
} else if (isObject(fromValue)) {
toArray[i] = copyObjectTo(fromValue, toValue);
toArray[i] = copyObjectTo(fromValue as Record<string, unknown>, toValue as Record<string, unknown>);
} else {
if (fromValue !== toValue) {
toArray[i] = fromValue;
@@ -391,9 +410,9 @@ export function copyArrayTo(fromArray, toArray) {
}
} else {
if (isArray(fromValue)) {
toArray.push(copyArrayTo(fromValue, []));
toArray.push(copyArrayTo(fromValue as unknown[], []));
} else if (isObject(fromValue)) {
toArray.push(copyObjectTo(fromValue, {}));
toArray.push(copyObjectTo(fromValue as Record<string, unknown>, {}));
} else {
toArray.push(fromValue);
}
@@ -403,7 +422,7 @@ export function copyArrayTo(fromArray, toArray) {
return toArray;
}
export function arrayContainsFieldValue(array, fieldName, value) {
export function arrayContainsFieldValue(array: Record<string, unknown>[], fieldName: string, value: unknown): boolean {
if (!value || !array || !array.length) {
return false;
}
@@ -417,10 +436,10 @@ export function arrayContainsFieldValue(array, fieldName, value) {
return false;
}
export function objectFieldToArrayItem(object) {
const ret = [];
export function objectFieldToArrayItem(object: object): string[] {
const ret: string[] = [];
for (let field in object) {
for (const field in object) {
if (!Object.prototype.hasOwnProperty.call(object, field)) {
continue;
}
@@ -431,8 +450,8 @@ export function objectFieldToArrayItem(object) {
return ret;
}
export function arrayItemToObjectField(array, value) {
const ret = {};
export function arrayItemToObjectField(array: string[], value: unknown): Record<string, unknown> {
const ret: Record<string, unknown> = {};
for (let i = 0; i < array.length; i++) {
ret[array[i]] = value;
@@ -441,10 +460,10 @@ export function arrayItemToObjectField(array, value) {
return ret;
}
export function categorizedArrayToPlainArray(object) {
const ret = [];
export function categorizedArrayToPlainArray(object: Record<string, unknown[]>): unknown[] {
const ret: unknown[] = [];
for (let field in object) {
for (const field in object) {
if (!Object.prototype.hasOwnProperty.call(object, field)) {
continue;
}
@@ -459,8 +478,8 @@ export function categorizedArrayToPlainArray(object) {
return ret;
}
export function selectAll(filterItemIds, allItemsMap) {
for (let itemId in filterItemIds) {
export function selectAll(filterItemIds: Record<string, boolean>, allItemsMap: { [key: string]: { id: string } }): void {
for (const itemId in filterItemIds) {
if (!Object.prototype.hasOwnProperty.call(filterItemIds, itemId)) {
continue;
}
@@ -473,8 +492,8 @@ export function selectAll(filterItemIds, allItemsMap) {
}
}
export function selectNone(filterItemIds, allItemsMap) {
for (let itemId in filterItemIds) {
export function selectNone(filterItemIds: Record<string, boolean>, allItemsMap: { [key: string]: { id: string } }): void {
for (const itemId in filterItemIds) {
if (!Object.prototype.hasOwnProperty.call(filterItemIds, itemId)) {
continue;
}
@@ -487,8 +506,8 @@ export function selectNone(filterItemIds, allItemsMap) {
}
}
export function selectInvert(filterItemIds, allItemsMap) {
for (let itemId in filterItemIds) {
export function selectInvert(filterItemIds: Record<string, boolean>, allItemsMap: { [key: string]: { id: string } }): void {
for (const itemId in filterItemIds) {
if (!Object.prototype.hasOwnProperty.call(filterItemIds, itemId)) {
continue;
}
@@ -501,7 +520,7 @@ export function selectInvert(filterItemIds, allItemsMap) {
}
}
export function isPrimaryItemHasSecondaryValue(primaryItem, primarySubItemsField, secondaryValueField, secondaryHiddenField, secondaryValue) {
export function isPrimaryItemHasSecondaryValue(primaryItem: Record<string, Record<string, unknown>[]>, primarySubItemsField: string, secondaryValueField: string, secondaryHiddenField: string, secondaryValue: unknown): boolean {
for (let i = 0; i < primaryItem[primarySubItemsField].length; i++) {
const secondaryItem = primaryItem[primarySubItemsField][i];
@@ -519,11 +538,13 @@ export function isPrimaryItemHasSecondaryValue(primaryItem, primarySubItemsField
return false;
}
export function getPrimaryValueBySecondaryValue(items, primarySubItemsField, primaryValueField, primaryHiddenField, secondaryValueField, secondaryHiddenField, secondaryValue) {
export function getPrimaryValueBySecondaryValue(items: Record<string, Record<string, unknown>[]>[] | Record<string, Record<string, Record<string, unknown>[]>>, primarySubItemsField: string, primaryValueField: string, primaryHiddenField: string, secondaryValueField: string, secondaryHiddenField: string, secondaryValue: unknown): unknown {
if (primarySubItemsField) {
if (isArray(items)) {
for (let i = 0; i < items.length; i++) {
const primaryItem = items[i];
const arr = items as Record<string, Record<string, unknown>[]>[];
for (let i = 0; i < arr.length; i++) {
const primaryItem = arr[i];
if (primaryHiddenField && primaryItem[primaryHiddenField]) {
continue;
@@ -538,12 +559,14 @@ export function getPrimaryValueBySecondaryValue(items, primarySubItemsField, pri
}
}
} else {
for (let field in items) {
if (!Object.prototype.hasOwnProperty.call(items, field)) {
const obj = items as Record<string, Record<string, Record<string, unknown>[]>>;
for (const field in obj) {
if (!Object.prototype.hasOwnProperty.call(obj, field)) {
continue;
}
const primaryItem = items[field];
const primaryItem = obj[field];
if (primaryHiddenField && primaryItem[primaryHiddenField]) {
continue;
@@ -563,7 +586,7 @@ export function getPrimaryValueBySecondaryValue(items, primarySubItemsField, pri
return null;
}
export function arrangeArrayWithNewStartIndex(array, startIndex) {
export function arrangeArrayWithNewStartIndex(array: unknown[], startIndex: number): unknown[] {
if (startIndex <= 0 || startIndex >= array.length) {
return array;
}
-83
View File
@@ -1,83 +0,0 @@
import currencyConstants from '@/consts/currency.js';
import { isString, isNumber } from './common.js';
export function getCurrencyFraction(currencyCode) {
const currencyInfo = currencyConstants.all[currencyCode];
if (currencyInfo) {
return currencyInfo.fraction;
}
return null;
}
export function appendCurrencySymbol(value, currencyDisplayType, currencyCode, currencyUnit, currencyName, isPlural) {
if (isNumber(value)) {
value = value.toString();
}
if (!isString(value)) {
return value;
}
const symbol = getAmountPrependAndAppendCurrencySymbol(currencyDisplayType, currencyCode, currencyUnit, currencyName, isPlural);
if (!symbol) {
return value;
}
const separator = currencyDisplayType.separator || '';
if (symbol.prependText) {
value = symbol.prependText + separator + value;
}
if (symbol.appendText) {
value = value + separator + symbol.appendText;
}
return value;
}
export function getAmountPrependAndAppendCurrencySymbol(currencyDisplayType, currencyCode, currencyUnit, currencyName, isPlural) {
if (!currencyDisplayType) {
return null;
}
let symbol = '';
if (currencyDisplayType.symbol === currencyConstants.allCurrencyDisplaySymbol.Symbol) {
const currencyInfo = currencyConstants.all[currencyCode];
if (currencyInfo && currencyInfo.symbol && currencyInfo.symbol.normal) {
symbol = currencyInfo.symbol.normal;
if (isPlural && currencyInfo.symbol.plural) {
symbol = currencyInfo.symbol.plural;
}
}
if (!symbol) {
symbol = currencyConstants.defaultCurrencySymbol;
}
} else if (currencyDisplayType.symbol === currencyConstants.allCurrencyDisplaySymbol.Code) {
symbol = currencyCode;
} else if (currencyDisplayType.symbol === currencyConstants.allCurrencyDisplaySymbol.Unit) {
symbol = currencyUnit;
} else if (currencyDisplayType.symbol === currencyConstants.allCurrencyDisplaySymbol.Name) {
symbol = currencyName;
}
if (currencyDisplayType.location === currencyConstants.allCurrencyDisplayLocation.BeforeAmount) {
return {
prependText: symbol
};
} else if (currencyDisplayType.location === currencyConstants.allCurrencyDisplayLocation.AfterAmount) {
return {
appendText: symbol
};
} else {
return null;
}
}
+80
View File
@@ -0,0 +1,80 @@
import { CurrencyDisplaySymbol, CurrencyDisplayLocation, type CurrencyPrependAndAppendText, CurrencyDisplayType } from '@/core/currency.ts';
import { ALL_CURRENCIES, DEFAULT_CURRENCY_SYMBOL } from '@/consts/currency.ts';
import { isString, isNumber } from './common.ts';
export function getCurrencyFraction(currencyCode: string): number | undefined {
const currencyInfo = ALL_CURRENCIES[currencyCode];
return currencyInfo?.fraction;
}
export function appendCurrencySymbol(value: unknown, currencyDisplayType: CurrencyDisplayType, currencyCode: string, currencyUnit: string, currencyName: string, isPlural: boolean): string | null {
if (isNumber(value)) {
value = (value as number).toString();
}
if (!isString(value)) {
return null;
}
const symbol = getAmountPrependAndAppendCurrencySymbol(currencyDisplayType, currencyCode, currencyUnit, currencyName, isPlural);
if (!symbol) {
return value as string;
}
const separator = currencyDisplayType.separator || '';
let ret = value as string;
if (symbol.prependText) {
ret = symbol.prependText + separator + ret;
}
if (symbol.appendText) {
ret = ret + separator + symbol.appendText;
}
return ret;
}
export function getAmountPrependAndAppendCurrencySymbol(currencyDisplayType: CurrencyDisplayType, currencyCode: string, currencyUnit: string, currencyName: string, isPlural: boolean): CurrencyPrependAndAppendText | null {
if (!currencyDisplayType) {
return null;
}
let symbol = '';
if (currencyDisplayType.symbol === CurrencyDisplaySymbol.Symbol) {
const currencyInfo = ALL_CURRENCIES[currencyCode];
if (currencyInfo && currencyInfo.symbol && currencyInfo.symbol.normal) {
symbol = currencyInfo.symbol.normal;
if (isPlural && currencyInfo.symbol.plural) {
symbol = currencyInfo.symbol.plural;
}
}
if (!symbol) {
symbol = DEFAULT_CURRENCY_SYMBOL;
}
} else if (currencyDisplayType.symbol === CurrencyDisplaySymbol.Code) {
symbol = currencyCode;
} else if (currencyDisplayType.symbol === CurrencyDisplaySymbol.Unit) {
symbol = currencyUnit;
} else if (currencyDisplayType.symbol === CurrencyDisplaySymbol.Name) {
symbol = currencyName;
}
if (currencyDisplayType.location === CurrencyDisplayLocation.BeforeAmount) {
return {
prependText: symbol
};
} else if (currencyDisplayType.location === CurrencyDisplayLocation.AfterAmount) {
return {
appendText: symbol
};
} else {
return null;
}
}
+1 -1
View File
@@ -1,7 +1,7 @@
import moment from 'moment';
import dateTimeConstants from '@/consts/datetime.js';
import { isObject, isString, isNumber } from './common.js';
import { isObject, isString, isNumber } from './common.ts';
export function isYearMonthValid(year, month) {
if (!isNumber(year) || !isNumber(month)) {
+3 -3
View File
@@ -1,6 +1,6 @@
import { isString } from './common.js';
import { isString } from './common.ts';
export function getFileExtension(filename) {
export function getFileExtension(filename: string): string {
if (!filename || !isString(filename)) {
return '';
}
@@ -9,7 +9,7 @@ export function getFileExtension(filename) {
return parts[parts.length - 1];
}
export function isFileExtensionSupported(filename, supportedExtensions) {
export function isFileExtensionSupported(filename: string, supportedExtensions: string): boolean {
if (!supportedExtensions) {
return false;
}
+99 -146
View File
@@ -1,18 +1,23 @@
import moment from 'moment-timezone';
import { defaultLanguage, allLanguages } from '@/locales/index.js';
import { defaultLanguage, allLanguages } from '@/locales/index.ts';
import { TimezoneTypeForStatistics } from '@/core/timezone.ts';
import { CurrencyDisplayType, CurrencySortingType } from '@/core/currency.ts';
import { PresetAmountColor } from '@/core/color.ts';
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 numeralConstants from '@/consts/numeral.js';
import datetimeConstants from '@/consts/datetime.js';
import timezoneConstants from '@/consts/timezone.js';
import currencyConstants from '@/consts/currency.js';
import colorConstants from '@/consts/color.js';
import accountConstants from '@/consts/account.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 { 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 apiConstants from '@/consts/api.js';
import { KnownErrorCode, SPECIFIED_API_NOT_FOUND_ERRORS, PARAMETERIZED_ERRORS } from '@/consts/api.ts';
import {
isDefined,
@@ -22,7 +27,7 @@ import {
getNameByKeyValue,
copyObjectTo,
copyArrayTo
} from './common.js';
} from './common.ts';
import {
isPM,
@@ -53,7 +58,7 @@ import {
getCurrencyFraction,
appendCurrencySymbol,
getAmountPrependAndAppendCurrencySymbol
} from './currency.js';
} from './currency.ts';
import {
getCategorizedAccountsMap,
@@ -201,6 +206,21 @@ function getCurrentLanguageDisplayName(i18nGlobal) {
return currentLanguageInfo.displayName;
}
function getLocalizedDisplayNameAndType(nameAndTypes, translateFn) {
const ret = [];
for (let i = 0; i < nameAndTypes.length; i++) {
const nameAndType = nameAndTypes[i];
ret.push({
type: nameAndType.type,
displayName: translateFn(nameAndType.name)
});
}
return ret;
}
function getDefaultCurrency(translateFn) {
return translateFn('default.currency');
}
@@ -214,7 +234,7 @@ function getCurrencyName(currencyCode, translateFn) {
}
function getCurrencyUnitName(currencyCode, isPlural, translateFn) {
const currencyInfo = currencyConstants.all[currencyCode];
const currencyInfo = ALL_CURRENCIES[currencyCode];
if (currencyInfo && currencyInfo.unit) {
if (isPlural) {
@@ -521,17 +541,16 @@ function getDateTimeFormat(translateFn, allFormatMap, allFormatArray, localeForm
function getAllTimezones(includeSystemDefault, translateFn) {
const defaultTimezoneOffset = getBrowserTimezoneOffset();
const defaultTimezoneOffsetMinutes = getBrowserTimezoneOffsetMinutes();
const allTimezones = timezoneConstants.all;
const allTimezoneInfos = [];
for (let i = 0; i < allTimezones.length; i++) {
const utcOffset = (allTimezones[i].timezoneName !== timezoneConstants.utcTimezoneName ? getTimezoneOffset(allTimezones[i].timezoneName) : '');
const displayName = translateFn(`timezone.${allTimezones[i].displayName}`);
for (let i = 0; i < ALL_TIMEZONES.length; i++) {
const utcOffset = (ALL_TIMEZONES[i].timezoneName !== UTC_TIMEZONE.timezoneName ? getTimezoneOffset(ALL_TIMEZONES[i].timezoneName) : '');
const displayName = translateFn(`timezone.${ALL_TIMEZONES[i].displayName}`);
allTimezoneInfos.push({
name: allTimezones[i].timezoneName,
name: ALL_TIMEZONES[i].timezoneName,
utcOffset: utcOffset,
utcOffsetMinutes: getTimezoneOffsetMinutes(allTimezones[i].timezoneName),
utcOffsetMinutes: getTimezoneOffsetMinutes(ALL_TIMEZONES[i].timezoneName),
displayName: displayName,
displayNameWithUtcOffset: `(UTC${utcOffset}) ${displayName}`
});
@@ -595,11 +614,10 @@ function getTimezoneDifferenceDisplayText(utcOffset, translateFn) {
}
function getAllCurrencies(translateFn) {
const allCurrencyCodes = currencyConstants.all;
const allCurrencies = [];
for (let currencyCode in allCurrencyCodes) {
if (!Object.prototype.hasOwnProperty.call(allCurrencyCodes, currencyCode)) {
for (let currencyCode in ALL_CURRENCIES) {
if (!Object.prototype.hasOwnProperty.call(ALL_CURRENCIES, currencyCode)) {
continue;
}
@@ -772,12 +790,12 @@ function getAllTimezoneTypesUsedForStatistics(currentTimezone, translateFn) {
return [
{
displayName: translateFn('Application Timezone') + ` (UTC${currentTimezoneOffset})`,
type: timezoneConstants.allTimezoneTypesUsedForStatistics.ApplicationTimezone
displayName: translateFn(TimezoneTypeForStatistics.ApplicationTimezone.name) + ` (UTC${currentTimezoneOffset})`,
type: TimezoneTypeForStatistics.ApplicationTimezone.type
},
{
displayName: translateFn('Transaction Timezone'),
type: timezoneConstants.allTimezoneTypesUsedForStatistics.TransactionTimezone
displayName: translateFn(TimezoneTypeForStatistics.TransactionTimezone.name),
type: TimezoneTypeForStatistics.TransactionTimezone.type
}
];
}
@@ -851,10 +869,10 @@ function getAllDigitGroupingTypes(translateFn) {
function getAllCurrencyDisplayTypes(userStore, settingsStore, translateFn) {
const defaultCurrencyDisplayTypeName = translateFn('default.currencyDisplayType');
let defaultCurrencyDisplayType = currencyConstants.allCurrencyDisplayType[defaultCurrencyDisplayTypeName];
let defaultCurrencyDisplayType = CurrencyDisplayType.parse(defaultCurrencyDisplayTypeName);
if (!defaultCurrencyDisplayType) {
defaultCurrencyDisplayType = currencyConstants.defaultCurrencyDisplayType;
defaultCurrencyDisplayType = CurrencyDisplayType.Default;
}
const defaultCurrency = userStore.currentUserDefaultCurrency;
@@ -863,12 +881,14 @@ function getAllCurrencyDisplayTypes(userStore, settingsStore, translateFn) {
const defaultSampleValue = getFormattedAmountWithCurrency(12345, defaultCurrency, translateFn, userStore, settingsStore, false, defaultCurrencyDisplayType);
ret.push({
type: currencyConstants.defaultCurrencyDisplayTypeValue,
type: CurrencyDisplayType.LanguageDefaultType,
displayName: `${translateFn('Language Default')} (${defaultSampleValue})`
});
for (let i = 0; i < currencyConstants.allCurrencyDisplayTypeArray.length; i++) {
const type = currencyConstants.allCurrencyDisplayTypeArray[i];
const allCurrencyDisplayTypes = CurrencyDisplayType.values();
for (let i = 0; i < allCurrencyDisplayTypes.length; i++) {
const type = allCurrencyDisplayTypes[i];
const sampleValue = getFormattedAmountWithCurrency(12345, defaultCurrency, translateFn, userStore, settingsStore, false, type);
const displayName = `${translateFn(type.name)} (${sampleValue})`
@@ -882,22 +902,7 @@ function getAllCurrencyDisplayTypes(userStore, settingsStore, translateFn) {
}
function getAllCurrencySortingTypes(translateFn) {
const allCurrencySortingTypes = [];
for (const sortingTypeField in currencyConstants.allCurrencySortingTypes) {
if (!Object.prototype.hasOwnProperty.call(currencyConstants.allCurrencySortingTypes, sortingTypeField)) {
continue;
}
const sortingType = currencyConstants.allCurrencySortingTypes[sortingTypeField];
allCurrencySortingTypes.push({
type: sortingType.type,
displayName: translateFn(sortingType.name)
});
}
return allCurrencySortingTypes;
return getLocalizedDisplayNameAndType(CurrencySortingType.values(), translateFn);
}
function getCurrentDecimalSeparator(translateFn, decimalSeparator) {
@@ -970,15 +975,15 @@ function getFormattedAmount(value, translateFn, userStore, currencyCode) {
}
function getCurrentCurrencyDisplayType(translateFn, userStore) {
let currencyDisplayType = currencyConstants.allCurrencyDisplayTypeMap[userStore.currentUserCurrencyDisplayType];
let currencyDisplayType = CurrencyDisplayType.valueOf(userStore.currentUserCurrencyDisplayType);
if (!currencyDisplayType) {
const defaultCurrencyDisplayTypeName = translateFn('default.currencyDisplayType');
currencyDisplayType = currencyConstants.allCurrencyDisplayType[defaultCurrencyDisplayTypeName];
currencyDisplayType = CurrencyDisplayType.parse(defaultCurrencyDisplayTypeName);
}
if (!currencyDisplayType) {
currencyDisplayType = currencyConstants.defaultCurrencyDisplayType;
currencyDisplayType = CurrencyDisplayType.Default;
}
return currencyDisplayType;
@@ -1047,65 +1052,57 @@ function getAmountPrependAndAppendText(currencyCode, userStore, settingsStore, i
}
function getAllExpenseIncomeAmountColors(translateFn, expenseOrIncome) {
const allAmountColors = [];
const ret = [];
let defaultAmountName = '';
if (expenseOrIncome === 1) { // expense
defaultAmountName = colorConstants.defaultExpenseAmountColor.name;
defaultAmountName = PresetAmountColor.DefaultExpenseColor.name;
} else if (expenseOrIncome === 2) { // income
defaultAmountName = colorConstants.defaultIncomeAmountColor.name;
defaultAmountName = PresetAmountColor.DefaultIncomeColor.name;
}
if (defaultAmountName) {
defaultAmountName = translateFn('color.amount.' + defaultAmountName);
}
allAmountColors.push({
type: colorConstants.defaultExpenseIncomeAmountValue,
ret.push({
type: PresetAmountColor.SystemDefaultType,
displayName: translateFn('System Default') + (defaultAmountName ? ` (${defaultAmountName})` : '')
});
for (let i = 0; i < colorConstants.allAmountColorsArray.length; i++) {
const amountColor = colorConstants.allAmountColorsArray[i];
const allPresetAmountColors = PresetAmountColor.values();
allAmountColors.push({
for (let i = 0; i < allPresetAmountColors.length; i++) {
const amountColor = allPresetAmountColors[i];
ret.push({
type: amountColor.type,
displayName: translateFn('color.amount.' + amountColor.name)
});
}
return allAmountColors;
return ret;
}
function getAllAccountCategories(translateFn) {
const allAccountCategories = [];
const ret = [];
const allCategories = AccountCategory.values();
for (let i = 0; i < accountConstants.allCategories.length; i++) {
const accountCategory = accountConstants.allCategories[i];
for (let i = 0; i < allCategories.length; i++) {
const accountCategory = allCategories[i];
allAccountCategories.push({
id: accountCategory.id,
ret.push({
type: accountCategory.type,
displayName: translateFn(accountCategory.name),
defaultAccountIconId: accountCategory.defaultAccountIconId
});
}
return allAccountCategories;
return ret;
}
function getAllAccountTypes(translateFn) {
const allAccountTypes = [];
for (let i = 0; i < accountConstants.allAccountTypesArray.length; i++) {
const accountType = accountConstants.allAccountTypesArray[i];
allAccountTypes.push({
id: accountType.id,
displayName: translateFn(accountType.name)
});
}
return allAccountTypes;
return getLocalizedDisplayNameAndType(AccountType.values(), translateFn);
}
function getAllCategoricalChartTypes(translateFn) {
@@ -1202,60 +1199,15 @@ function getAllStatisticsDateAggregationTypes(translateFn) {
}
function getAllTransactionEditScopeTypes(translateFn) {
const allEditScopeTypes = [];
for (const typeName in transactionConstants.allTransactionEditScopeTypes) {
if (!Object.prototype.hasOwnProperty.call(transactionConstants.allTransactionEditScopeTypes, typeName)) {
continue;
}
const editScopeType = transactionConstants.allTransactionEditScopeTypes[typeName];
allEditScopeTypes.push({
type: editScopeType.type,
displayName: translateFn(editScopeType.name)
});
}
return allEditScopeTypes;
return getLocalizedDisplayNameAndType(TransactionEditScopeType.values(), translateFn);
}
function getAllTransactionTagFilterTypes(translateFn) {
const allTagFilterTypes = [];
for (const typeName in transactionConstants.allTransactionTagFilterTypes) {
if (!Object.prototype.hasOwnProperty.call(transactionConstants.allTransactionTagFilterTypes, typeName)) {
continue;
}
const tagFilterType = transactionConstants.allTransactionTagFilterTypes[typeName];
allTagFilterTypes.push({
type: tagFilterType.type,
displayName: translateFn(tagFilterType.name)
});
}
return allTagFilterTypes;
return getLocalizedDisplayNameAndType(TransactionTagFilterType.values(), translateFn);
}
function getAllTransactionScheduledFrequencyTypes(translateFn) {
const allScheduledFrequencyTypes = [];
for (const typeName in templateConstants.allTemplateScheduledFrequencyTypes) {
if (!Object.prototype.hasOwnProperty.call(templateConstants.allTemplateScheduledFrequencyTypes, typeName)) {
continue;
}
const frequencyType = templateConstants.allTemplateScheduledFrequencyTypes[typeName];
allScheduledFrequencyTypes.push({
type: frequencyType.type,
displayName: translateFn(frequencyType.name)
});
}
return allScheduledFrequencyTypes;
return getLocalizedDisplayNameAndType(ScheduledTemplateFrequencyType.values(), translateFn);
}
function getAllTransactionDefaultCategories(categoryType, locale, translateFn) {
@@ -1263,7 +1215,7 @@ function getAllTransactionDefaultCategories(categoryType, locale, translateFn) {
const categoryTypes = [];
if (categoryType === 0) {
for (let i = categoryConstants.allCategoryTypes.Income; i <= categoryConstants.allCategoryTypes.Transfer; i++) {
for (let i = CategoryType.Income; i <= CategoryType.Transfer; i++) {
categoryTypes.push(i);
}
} else {
@@ -1275,12 +1227,12 @@ function getAllTransactionDefaultCategories(categoryType, locale, translateFn) {
const categoryType = categoryTypes[i];
let defaultCategories = [];
if (categoryType === categoryConstants.allCategoryTypes.Income) {
defaultCategories = copyArrayTo(categoryConstants.defaultIncomeCategories, []);
} else if (categoryType === categoryConstants.allCategoryTypes.Expense) {
defaultCategories = copyArrayTo(categoryConstants.defaultExpenseCategories, []);
} else if (categoryType === categoryConstants.allCategoryTypes.Transfer) {
defaultCategories = copyArrayTo(categoryConstants.defaultTransferCategories, []);
if (categoryType === CategoryType.Income) {
defaultCategories = copyArrayTo(DEFAULT_INCOME_CATEGORIES, []);
} else if (categoryType === CategoryType.Expense) {
defaultCategories = copyArrayTo(DEFAULT_EXPENSE_CATEGORIES, []);
} else if (categoryType === CategoryType.Transfer) {
defaultCategories = copyArrayTo(DEFAULT_TRANSFER_CATEGORIES, []);
}
for (let j = 0; j < defaultCategories.length; j++) {
@@ -1330,15 +1282,15 @@ function getAllDisplayExchangeRates(settingsStore, exchangeRatesData, translateF
});
}
if (settingsStore.appSettings.currencySortByInExchangeRatesPage === currencyConstants.allCurrencySortingTypes.Name.type) {
if (settingsStore.appSettings.currencySortByInExchangeRatesPage === CurrencySortingType.Name.type) {
availableExchangeRates.sort(function(c1, c2) {
return c1.currencyDisplayName.localeCompare(c2.currencyDisplayName);
});
} else if (settingsStore.appSettings.currencySortByInExchangeRatesPage === currencyConstants.allCurrencySortingTypes.CurrencyCode.type) {
} else if (settingsStore.appSettings.currencySortByInExchangeRatesPage === CurrencySortingType.CurrencyCode.type) {
availableExchangeRates.sort(function(c1, c2) {
return c1.currencyCode.localeCompare(c2.currencyCode);
});
} else if (settingsStore.appSettings.currencySortByInExchangeRatesPage === currencyConstants.allCurrencySortingTypes.ExchangeRate.type) {
} else if (settingsStore.appSettings.currencySortByInExchangeRatesPage === CurrencySortingType.ExchangeRate.type) {
availableExchangeRates.sort(function(c1, c2) {
const rate1 = parseFloat(c1.rate);
const rate2 = parseFloat(c2.rate);
@@ -1359,8 +1311,8 @@ function getAllDisplayExchangeRates(settingsStore, exchangeRatesData, translateF
function getAllSupportedImportFileTypes(i18nGlobal, translateFn) {
const allSupportedImportFileTypes = [];
for (let i = 0; i < fileConstants.supportedImportFileTypes.length; i++) {
const fileType = fileConstants.supportedImportFileTypes[i];
for (let i = 0; i < SUPPORTED_IMPORT_FILE_TYPES.length; i++) {
const fileType = SUPPORTED_IMPORT_FILE_TYPES[i];
let document = {
language: '',
displayLanguageName: '',
@@ -1434,16 +1386,17 @@ function getEnableDisableOptions(translateFn) {
function getCategorizedAccountsWithDisplayBalance(allVisibleAccounts, showAccountBalance, defaultCurrency, userStore, settingsStore, exchangeRatesStore, translateFn) {
const ret = [];
const allCategories = AccountCategory.values();
const categorizedAccounts = copyObjectTo(getCategorizedAccountsMap(allVisibleAccounts), {});
for (let i = 0; i < accountConstants.allCategories.length; i++) {
const category = accountConstants.allCategories[i];
for (let i = 0; i < allCategories.length; i++) {
const category = allCategories[i];
if (!categorizedAccounts[category.id]) {
if (!categorizedAccounts[category.type]) {
continue;
}
const accountCategory = categorizedAccounts[category.id];
const accountCategory = categorizedAccounts[category.type];
if (accountCategory.accounts) {
for (let i = 0; i < accountCategory.accounts.length; i++) {
@@ -1527,20 +1480,20 @@ function joinMultiText(textArray, translateFn) {
}
function getLocalizedError(error) {
if (error.errorCode === apiConstants.apiNotFoundErrorCode && apiConstants.specifiedApiNotFoundErrors[error.path]) {
if (error.errorCode === KnownErrorCode.ApiNotFound && SPECIFIED_API_NOT_FOUND_ERRORS[error.path]) {
return {
message: `${apiConstants.specifiedApiNotFoundErrors[error.path].message}`
message: `${SPECIFIED_API_NOT_FOUND_ERRORS[error.path].message}`
};
}
if (error.errorCode !== apiConstants.validatorErrorCode) {
if (error.errorCode !== KnownErrorCode.ValidatorError) {
return {
message: `error.${error.errorMessage}`
};
}
for (let i = 0; i < apiConstants.parameterizedErrors.length; i++) {
const errorInfo = apiConstants.parameterizedErrors[i];
for (let i = 0; i < PARAMETERIZED_ERRORS.length; i++) {
const errorInfo = PARAMETERIZED_ERRORS[i];
const matches = error.errorMessage.match(errorInfo.regex);
if (matches && matches.length === errorInfo.parameters.length + 1) {
+5 -3
View File
@@ -1,8 +1,10 @@
export function getIconsInRows(allIconInfos, itemPerRow) {
const ret = [];
import type { IconInfo, IconInfoWithId } from '@/core/icon.ts';
export function getIconsInRows(allIconInfos: IconInfo[], itemPerRow: number): IconInfoWithId[][] {
const ret: IconInfoWithId[][] = [];
let rowCount = 0;
for (let iconInfoId in allIconInfos) {
for (const iconInfoId in allIconInfos) {
if (!Object.prototype.hasOwnProperty.call(allIconInfos, iconInfoId)) {
continue;
}
-8
View File
@@ -1,8 +0,0 @@
export default {
getLicense: () => {
return __EZBOOKKEEPING_LICENSE__; // eslint-disable-line
},
getThirdPartyLicenses: () => {
return __EZBOOKKEEPING_THIRD_PARTY_LICENSES__ || []; // eslint-disable-line
}
};
+7
View File
@@ -0,0 +1,7 @@
export function getLicense(): string {
return __EZBOOKKEEPING_LICENSE__;
}
export function getThirdPartyLicenses(): string[] {
return __EZBOOKKEEPING_THIRD_PARTY_LICENSES__ || [];
}
+2 -2
View File
@@ -1,10 +1,10 @@
import { asyncLoadAssets } from '@/lib/misc.js';
import { asyncLoadAssets } from '@/lib/misc.ts';
import services from '@/lib/services.js';
import {
getAmapSecurityVerificationMethod,
getAmapApiExternalProxyUrl,
getAmapApplicationSecret
} from '@/lib/server_settings.js';
} from '@/lib/server_settings.ts';
import logger from '@/lib/logger.js';
const amapHolder = {
+1 -1
View File
@@ -1,4 +1,4 @@
import { asyncLoadAssets } from '@/lib/misc.js';
import { asyncLoadAssets } from '@/lib/misc.ts';
import services from '@/lib/services.js';
import logger from '@/lib/logger.js';
+1 -1
View File
@@ -1,4 +1,4 @@
import { asyncLoadAssets } from '@/lib/misc.js';
import { asyncLoadAssets } from '@/lib/misc.ts';
import services from '@/lib/services.js';
const googleMapHolder = {
+10 -10
View File
@@ -1,7 +1,7 @@
import mapConstants from '@/consts/map.js';
import { LEAFLET_TILE_SOURCES } from '@/consts/map.ts';
import {
getMapProvider
} from '@/lib/server_settings.js';
} from '@/lib/server_settings.ts';
import {
loadLeafletMapAssets,
@@ -45,8 +45,8 @@ import {
export function getMapWebsite() {
if (getMapProvider() === 'custom') {
return '';
} else if (mapConstants.leafletTileSources[getMapProvider()]) {
return mapConstants.leafletTileSources[getMapProvider()].website;
} else if (LEAFLET_TILE_SOURCES[getMapProvider()]) {
return LEAFLET_TILE_SOURCES[getMapProvider()].website;
} else if (getMapProvider() === 'googlemap') {
return getGoogleMapWebsite();
} else if (getMapProvider() === 'baidumap') {
@@ -57,7 +57,7 @@ export function getMapWebsite() {
}
export function loadMapAssets(language) {
if (mapConstants.leafletTileSources[getMapProvider()] || getMapProvider() === 'custom') {
if (LEAFLET_TILE_SOURCES[getMapProvider()] || getMapProvider() === 'custom') {
return loadLeafletMapAssets(language);
} else if (getMapProvider() === 'googlemap') {
return loadGoogleMapAssets(language);
@@ -69,7 +69,7 @@ export function loadMapAssets(language) {
}
export function createMapHolder() {
if (mapConstants.leafletTileSources[getMapProvider()] || getMapProvider() === 'custom') {
if (LEAFLET_TILE_SOURCES[getMapProvider()] || getMapProvider() === 'custom') {
return createLeafletMapHolder(getMapProvider());
} else if (getMapProvider() === 'googlemap') {
return createGoogleMapHolder(getMapProvider());
@@ -87,7 +87,7 @@ export function initMapInstance(mapHolder, mapContainer, options) {
return;
}
if (mapConstants.leafletTileSources[getMapProvider()] || getMapProvider() === 'custom') {
if (LEAFLET_TILE_SOURCES[getMapProvider()] || getMapProvider() === 'custom') {
createLeafletMapInstance(mapHolder, mapContainer, options);
} else if (mapHolder.mapProvider === 'googlemap') {
createGoogleMapInstance(mapHolder, mapContainer, options);
@@ -103,7 +103,7 @@ export function setMapCenterTo(mapHolder, center, zoomLevel) {
return;
}
if (mapConstants.leafletTileSources[getMapProvider()] || getMapProvider() === 'custom') {
if (LEAFLET_TILE_SOURCES[getMapProvider()] || getMapProvider() === 'custom') {
setLeafletMapCenterTo(mapHolder, center, zoomLevel);
} else if (mapHolder.mapProvider === 'googlemap') {
setGoogleMapCenterTo(mapHolder, center, zoomLevel);
@@ -119,7 +119,7 @@ export function setMapCenterMarker(mapHolder, position) {
return;
}
if (mapConstants.leafletTileSources[getMapProvider()] || getMapProvider() === 'custom') {
if (LEAFLET_TILE_SOURCES[getMapProvider()] || getMapProvider() === 'custom') {
setLeafletMapCenterMaker(mapHolder, position);
} else if (mapHolder.mapProvider === 'googlemap') {
setGoogleMapCenterMaker(mapHolder, position);
@@ -135,7 +135,7 @@ export function removeMapCenterMarker(mapHolder) {
return;
}
if (mapConstants.leafletTileSources[getMapProvider()] || getMapProvider() === 'custom') {
if (LEAFLET_TILE_SOURCES[getMapProvider()] || getMapProvider() === 'custom') {
removeLeafletMapCenterMaker(mapHolder);
} else if (mapHolder.mapProvider === 'googlemap') {
removeGoogleMapCenterMaker(mapHolder);
+4 -4
View File
@@ -1,4 +1,4 @@
import mapConstants from '@/consts/map.js';
import { LEAFLET_TILE_SOURCES } from '@/consts/map.ts';
import {
isMapDataFetchProxyEnabled,
getCustomMapTileLayerUrl,
@@ -9,7 +9,7 @@ import {
getCustomMapDefaultZoomLevel,
getTomTomMapAPIKey,
getTianDiTuMapAPIKey
} from '@/lib/server_settings.js';
} from '@/lib/server_settings.ts';
import services from '@/lib/services.js';
const leafletHolder = {
@@ -24,7 +24,7 @@ export function loadLeafletMapAssets() {
}
export function createLeafletMapHolder(mapProvider) {
const mapTileSource = mapConstants.leafletTileSources[mapProvider];
const mapTileSource = LEAFLET_TILE_SOURCES[mapProvider];
if (mapProvider !== 'custom' && !mapTileSource) {
return null;
@@ -60,7 +60,7 @@ export function createLeafletMapInstance(mapHolder, mapContainer, options) {
let mapTileSource = null;
if (mapHolder.mapProvider !== 'custom') {
mapTileSource = Object.assign({}, mapConstants.leafletTileSources[mapHolder.mapProvider]);
mapTileSource = Object.assign({}, LEAFLET_TILE_SOURCES[mapHolder.mapProvider]);
} else {
mapTileSource = createCustomMapSource();
}
-229
View File
@@ -1,229 +0,0 @@
import Clipboard from 'clipboard';
import CryptoJS from 'crypto-js';
import uaParser from 'ua-parser-js';
import { base64encode } from './common.js';
export function asyncLoadAssets(type, assetUrl) {
return new Promise(function (resolve, reject) {
let addElement = false;
let el = null;
if (type === 'js') {
el = document.querySelector('script[src="' + assetUrl + '"]');
} else if (type === 'css') {
el = document.querySelector('link[href="' + assetUrl + '"]');
} else {
reject({
type: type,
assetUrl: assetUrl,
error: 'notsupport'
});
return;
}
if (!el) {
if (type === 'js') {
el = document.createElement('script');
el.setAttribute('type', 'text/javascript');
el.setAttribute('async', 'true');
el.setAttribute('src', assetUrl);
} else if (type === 'css') {
el = document.createElement('link');
el.setAttribute('rel', 'stylesheet');
el.setAttribute('type', 'text/css');
el.setAttribute('href', assetUrl);
}
addElement = true;
} else if (el.hasAttribute('data-loaded')) {
resolve({
type: type,
assetUrl: assetUrl
});
return;
}
el.addEventListener('load', () => {
el.setAttribute('data-loaded', true);
resolve({
type: type,
assetUrl: assetUrl
});
});
el.addEventListener('error', () => {
reject({
type: type,
assetUrl: assetUrl,
error: 'error'
});
});
el.addEventListener('abort', () => {
reject({
type: type,
assetUrl: assetUrl,
error: 'abort'
});
});
if (addElement) {
document.head.appendChild(el);
}
});
}
export function generateRandomString() {
let baseString = 'ebk_' + new Date().getTime();
if (crypto && crypto.getRandomValues) {
const randoms = new Uint8Array(256);
crypto.getRandomValues(randoms);
baseString += '_' + base64encode(randoms);
} else {
baseString += '_' + Math.random();
}
return CryptoJS.SHA256(baseString).toString();
}
export function generateRandomUUID() {
const randomString = generateRandomString();
// convert hash string to UUID Version 8
const uuid = randomString.substring(0, 8) + '-'
+ randomString.substring(8, 12) + '-'
+ '8' + randomString.substring(13, 16) + '-'
+ (0x8 | (parseInt(randomString.charAt(16), 16) & 0x3)).toString(16) + randomString.substring(17, 20) + '-'
+ randomString.substring(20, 32);
return uuid;
}
export function isSessionUserAgentCreatedByCli(ua) {
return ua === 'ezbookkeeping Cli';
}
export function parseUserAgent(ua) {
const uaParseRet = uaParser(ua);
return {
device: {
vendor: uaParseRet.device.vendor,
model: uaParseRet.device.model,
type: uaParseRet.device.type
},
os: {
name: uaParseRet.os.name,
version: uaParseRet.os.version
},
browser: {
name: uaParseRet.browser.name,
version: uaParseRet.browser.version
}
};
}
export function parseDeviceInfo(uaInfo) {
if (!uaInfo) {
return '';
}
let result = '';
if (uaInfo.device && uaInfo.device.model) {
result = uaInfo.device.model;
} else if (uaInfo.os && uaInfo.os.name) {
result = uaInfo.os.name;
if (uaInfo.os.version) {
result += ' ' + uaInfo.os.version;
}
}
if (uaInfo.browser && uaInfo.browser.name) {
let browserInfo = uaInfo.browser.name;
if (uaInfo.browser.version) {
browserInfo += ' ' + uaInfo.browser.version;
}
if (result) {
result += ' (' + browserInfo + ')';
} else {
result = browserInfo;
}
}
if (!result) {
return 'Unknown Device';
}
return result;
}
export function parseSessionInfo(token) {
const isCreatedByCli = isSessionUserAgentCreatedByCli(token.userAgent);
const uaInfo = parseUserAgent(token.userAgent);
let deviceType = '';
if (isCreatedByCli) {
deviceType = 'cli';
} else {
if (uaInfo && uaInfo.device) {
if (uaInfo.device.type === 'mobile') {
deviceType = 'phone';
} else if (uaInfo.device.type === 'wearable') {
deviceType = 'wearable';
} else if (uaInfo.device.type === 'tablet') {
deviceType = 'tablet';
} else if (uaInfo.device.type === 'smarttv') {
deviceType = 'tv';
} else {
deviceType = 'default';
}
} else {
deviceType = 'default';
}
}
return {
tokenId: token.tokenId,
isCurrent: token.isCurrent,
deviceType: deviceType,
deviceInfo: isCreatedByCli ? token.userAgent : parseDeviceInfo(uaInfo),
createdByCli: isCreatedByCli,
lastSeen: token.lastSeen
}
}
export function makeButtonCopyToClipboard({ text, el, successCallback, errorCallback }) {
const clipboard = new Clipboard(el, {
text: function () {
return text;
}
});
clipboard.on('success', (e) => {
if (successCallback) {
successCallback(e);
}
});
clipboard.on('error', (e) => {
if (errorCallback) {
errorCallback(e);
}
});
return clipboard;
}
export function changeClipboardObjectText(clipboard, text) {
if (!clipboard) {
return;
}
clipboard.text = function () {
return text;
};
}
+112
View File
@@ -0,0 +1,112 @@
import CryptoJS from 'crypto-js';
import { base64encode } from './common.ts';
export interface AsyncLoadAssetsResult {
readonly type: string;
readonly assetUrl: string;
}
export function asyncLoadAssets(type: string, assetUrl: string): Promise<AsyncLoadAssetsResult> {
return new Promise(function (resolve, reject) {
let addElement = false;
let el = null;
if (type === 'js') {
el = document.querySelector('script[src="' + assetUrl + '"]');
} else if (type === 'css') {
el = document.querySelector('link[href="' + assetUrl + '"]');
} else {
reject({
type: type,
assetUrl: assetUrl,
error: 'notsupport'
});
return;
}
if (!el) {
if (type === 'js') {
el = document.createElement('script');
el.setAttribute('type', 'text/javascript');
el.setAttribute('async', 'true');
el.setAttribute('src', assetUrl);
} else if (type === 'css') {
el = document.createElement('link');
el.setAttribute('rel', 'stylesheet');
el.setAttribute('type', 'text/css');
el.setAttribute('href', assetUrl);
}
addElement = true;
} else if (el.hasAttribute('data-loaded')) {
resolve({
type: type,
assetUrl: assetUrl
});
return;
}
if (!el) {
reject({
type: type,
assetUrl: assetUrl,
error: 'unexpected'
});
return;
}
el.addEventListener('load', () => {
el.setAttribute('data-loaded', 'true');
resolve({
type: type,
assetUrl: assetUrl
});
});
el.addEventListener('error', () => {
reject({
type: type,
assetUrl: assetUrl,
error: 'error'
});
});
el.addEventListener('abort', () => {
reject({
type: type,
assetUrl: assetUrl,
error: 'abort'
});
});
if (addElement) {
document.head.appendChild(el);
}
});
}
export function generateRandomString(): string {
let baseString = 'ebk_' + new Date().getTime();
if (crypto && crypto.getRandomValues) {
const randoms = new Uint8Array(256);
crypto.getRandomValues(randoms);
baseString += '_' + base64encode(randoms.buffer);
} else {
baseString += '_' + Math.random();
}
return CryptoJS.SHA256(baseString).toString();
}
export function generateRandomUUID(): string {
const randomString = generateRandomString();
// convert hash string to UUID Version 8
const uuid = randomString.substring(0, 8) + '-'
+ randomString.substring(8, 12) + '-'
+ '8' + randomString.substring(13, 16) + '-'
+ (0x8 | (parseInt(randomString.charAt(16), 16) & 0x3)).toString(16) + randomString.substring(17, 20) + '-'
+ randomString.substring(20, 32);
return uuid;
}
+1 -1
View File
@@ -1,6 +1,6 @@
import numeralConstants from '@/consts/numeral.js';
import { isString, isNumber, removeAll } from './common.js';
import { isString, isNumber, removeAll } from './common.ts';
export function appendDigitGroupingSymbol(value, options) {
if (isNumber(value)) {
-109
View File
@@ -1,109 +0,0 @@
const serverSettingsGlobalVariableName = 'EZBOOKKEEPING_SERVER_SETTINGS';
function getServerSetting(key) {
const settings = window[serverSettingsGlobalVariableName] || {};
return settings[key];
}
export function isUserRegistrationEnabled() {
return getServerSetting('r') === 1;
}
export function isUserForgetPasswordEnabled() {
return getServerSetting('f') === 1;
}
export function isUserVerifyEmailEnabled() {
return getServerSetting('v') === 1;
}
export function isTransactionPicturesEnabled() {
return getServerSetting('p') === 1;
}
export function isUserScheduledTransactionEnabled() {
return getServerSetting('s') === 1;
}
export function isDataExportingEnabled() {
return getServerSetting('e') === 1;
}
export function isDataImportingEnabled() {
return getServerSetting('i') === 1;
}
export function getLoginPageTips() {
return getServerSetting('lpt');
}
export function getMapProvider() {
return getServerSetting('m');
}
export function isMapDataFetchProxyEnabled() {
return getServerSetting('mp') === 1;
}
export function getCustomMapTileLayerUrl() {
return getServerSetting('cmsu');
}
export function getCustomMapAnnotationLayerUrl() {
return getServerSetting('cmau');
}
export function isCustomMapAnnotationLayerDataFetchProxyEnabled() {
return getServerSetting('cmap') === 1;
}
export function getCustomMapMinZoomLevel() {
const zoomLevelSettings = (getServerSetting('cmzl') || '').split('-');
return (zoomLevelSettings && zoomLevelSettings[0]) ? parseInt(zoomLevelSettings[0]) : 1;
}
export function getCustomMapMaxZoomLevel() {
const zoomLevelSettings = (getServerSetting('cmzl') || '').split('-');
return (zoomLevelSettings && zoomLevelSettings[1]) ? parseInt(zoomLevelSettings[1]) : 18;
}
export function getCustomMapDefaultZoomLevel() {
const zoomLevelSettings = (getServerSetting('cmzl') || '').split('-');
return (zoomLevelSettings && zoomLevelSettings[2]) ? parseInt(zoomLevelSettings[2]) : 14;
}
export function getTomTomMapAPIKey() {
return getServerSetting('tmak');
}
export function getTianDiTuMapAPIKey() {
return getServerSetting('tdak');
}
export function getGoogleMapAPIKey() {
return getServerSetting('gmak');
}
export function getBaiduMapAK() {
return getServerSetting('bmak');
}
export function getAmapApplicationKey() {
return getServerSetting('amak');
}
export function getAmapSecurityVerificationMethod() {
return getServerSetting('amsv');
}
export function getAmapApiExternalProxyUrl() {
return getServerSetting('amep');
}
export function getAmapApplicationSecret() {
return getServerSetting('amas');
}
export function getExchangeRatesRequestTimeout() {
return getServerSetting('errt');
}
+107
View File
@@ -0,0 +1,107 @@
function getServerSetting(key: string): string | number | boolean | undefined | null {
const settings = window.EZBOOKKEEPING_SERVER_SETTINGS || {};
return settings[key];
}
export function isUserRegistrationEnabled(): boolean {
return getServerSetting('r') === 1;
}
export function isUserForgetPasswordEnabled(): boolean {
return getServerSetting('f') === 1;
}
export function isUserVerifyEmailEnabled(): boolean {
return getServerSetting('v') === 1;
}
export function isTransactionPicturesEnabled(): boolean {
return getServerSetting('p') === 1;
}
export function isUserScheduledTransactionEnabled(): boolean {
return getServerSetting('s') === 1;
}
export function isDataExportingEnabled(): boolean {
return getServerSetting('e') === 1;
}
export function isDataImportingEnabled(): boolean {
return getServerSetting('i') === 1;
}
export function getLoginPageTips(): string {
return getServerSetting('lpt') as string;
}
export function getMapProvider(): string {
return getServerSetting('m') as string;
}
export function isMapDataFetchProxyEnabled(): boolean {
return getServerSetting('mp') === 1;
}
export function getCustomMapTileLayerUrl(): string {
return getServerSetting('cmsu') as string;
}
export function getCustomMapAnnotationLayerUrl(): string {
return getServerSetting('cmau') as string;
}
export function isCustomMapAnnotationLayerDataFetchProxyEnabled(): boolean {
return getServerSetting('cmap') === 1;
}
export function getCustomMapMinZoomLevel(): number {
const zoomLevelSettings = (getServerSetting('cmzl') as string || '').split('-');
return (zoomLevelSettings && zoomLevelSettings[0]) ? parseInt(zoomLevelSettings[0]) : 1;
}
export function getCustomMapMaxZoomLevel(): number {
const zoomLevelSettings = (getServerSetting('cmzl') as string || '').split('-');
return (zoomLevelSettings && zoomLevelSettings[1]) ? parseInt(zoomLevelSettings[1]) : 18;
}
export function getCustomMapDefaultZoomLevel(): number {
const zoomLevelSettings = (getServerSetting('cmzl') as string || '').split('-');
return (zoomLevelSettings && zoomLevelSettings[2]) ? parseInt(zoomLevelSettings[2]) : 14;
}
export function getTomTomMapAPIKey(): string {
return getServerSetting('tmak') as string;
}
export function getTianDiTuMapAPIKey(): string {
return getServerSetting('tdak') as string;
}
export function getGoogleMapAPIKey(): string {
return getServerSetting('gmak') as string;
}
export function getBaiduMapAK(): string {
return getServerSetting('bmak') as string;
}
export function getAmapApplicationKey(): string {
return getServerSetting('amak') as string;
}
export function getAmapSecurityVerificationMethod(): string {
return getServerSetting('amsv') as string;
}
export function getAmapApiExternalProxyUrl(): string {
return getServerSetting('amep') as string;
}
export function getAmapApplicationSecret(): string {
return getServerSetting('amas') as string;
}
export function getExchangeRatesRequestTimeout(): number {
return getServerSetting('errt') as number;
}
+29 -18
View File
@@ -1,25 +1,36 @@
import axios from 'axios';
import apiConstants from '@/consts/api.js';
import {
BASE_API_URL_PATH,
BASE_QRCODE_PATH,
BASE_PROXY_URL_PATH,
BASE_AMAP_API_PROXY_URL_PATH,
DEFAULT_API_TIMEOUT,
DEFAULT_UPLOAD_API_TIMEOUT,
DEFAULT_IMPORT_API_TIMEOUT,
GOOGLE_MAP_JAVASCRIPT_URL,
BAIDU_MAP_JAVASCRIPT_URL,
AMAP_JAVASCRIPT_URL
} from '@/consts/api.ts';
import userState from './userstate.js';
import {
isDefined,
isBoolean
} from './common.js';
} from './common.ts';
import {
getGoogleMapAPIKey,
getBaiduMapAK,
getAmapApplicationKey,
getExchangeRatesRequestTimeout
} from './server_settings.js';
} from './server_settings.ts';
import { getTimezoneOffsetMinutes } from './datetime.js';
import { generateRandomUUID } from './misc.js';
import { generateRandomUUID } from './misc.ts';
let needBlockRequest = false;
let blockedRequests = [];
axios.defaults.baseURL = apiConstants.baseApiUrlPath;
axios.defaults.timeout = apiConstants.defaultTimeout;
axios.defaults.baseURL = BASE_API_URL_PATH;
axios.defaults.timeout = DEFAULT_API_TIMEOUT;
axios.interceptors.request.use(config => {
const token = userState.getToken();
@@ -202,7 +213,7 @@ export default {
return axios.postForm('v1/users/avatar/update.json', {
avatar: avatarFile
}, {
timeout: apiConstants.uploadTimeout
timeout: DEFAULT_UPLOAD_API_TIMEOUT
});
},
removeAvatar: () => {
@@ -471,7 +482,7 @@ export default {
fileType: fileType,
file: importFile
}, {
timeout: apiConstants.uploadTimeout
timeout: DEFAULT_UPLOAD_API_TIMEOUT
});
},
importTransactions: ({ transactions, clientSessionId }) => {
@@ -479,7 +490,7 @@ export default {
transactions: transactions,
clientSessionId: clientSessionId
}, {
timeout: apiConstants.importTimeout
timeout: DEFAULT_IMPORT_API_TIMEOUT
});
},
uploadTransactionPicture: ({ pictureFile, clientSessionId }) => {
@@ -487,7 +498,7 @@ export default {
picture: pictureFile,
clientSessionId: clientSessionId
}, {
timeout: apiConstants.uploadTimeout
timeout: DEFAULT_UPLOAD_API_TIMEOUT
});
},
removeUnusedTransactionPicture: ({ id }) => {
@@ -639,15 +650,15 @@ export default {
getLatestExchangeRates: ({ ignoreError }) => {
return axios.get('v1/exchange_rates/latest.json', {
ignoreError: !!ignoreError,
timeout: getExchangeRatesRequestTimeout() || apiConstants.defaultTimeout
timeout: getExchangeRatesRequestTimeout() || DEFAULT_API_TIMEOUT
});
},
generateQrCodeUrl: (qrCodeName) => {
return `${apiConstants.baseQrcodePath}/${qrCodeName}.png`;
return `${BASE_QRCODE_PATH}/${qrCodeName}.png`;
},
generateMapProxyTileImageUrl: (mapProvider, language) => {
const token = userState.getToken();
let url = `${apiConstants.baseProxyUrlPath}/map/tile/{z}/{x}/{y}.png?provider=${mapProvider}&token=${token}`;
let url = `${BASE_PROXY_URL_PATH}/map/tile/{z}/{x}/{y}.png?provider=${mapProvider}&token=${token}`;
if (language) {
url = url + `&language=${language}`;
@@ -657,7 +668,7 @@ export default {
},
generateMapProxyAnnotationImageUrl: (mapProvider, language) => {
const token = userState.getToken();
let url = `${apiConstants.baseProxyUrlPath}/map/annotation/{z}/{x}/{y}.png?provider=${mapProvider}&token=${token}`;
let url = `${BASE_PROXY_URL_PATH}/map/annotation/{z}/{x}/{y}.png?provider=${mapProvider}&token=${token}`;
if (language) {
url = url + `&language=${language}`;
@@ -666,7 +677,7 @@ export default {
return url;
},
generateGoogleMapJavascriptUrl: (language, callbackFnName) => {
let url = `${apiConstants.googleMapJavascriptUrl}?key=${getGoogleMapAPIKey()}&libraries=core,marker&callback=${callbackFnName}`;
let url = `${GOOGLE_MAP_JAVASCRIPT_URL}?key=${getGoogleMapAPIKey()}&libraries=core,marker&callback=${callbackFnName}`;
if (language) {
url = url + `&language=${language}`;
@@ -675,13 +686,13 @@ export default {
return url;
},
generateBaiduMapJavascriptUrl: (callbackFnName) => {
return `${apiConstants.baiduMapJavascriptUrl}&ak=${getBaiduMapAK()}&callback=${callbackFnName}`;
return `${BAIDU_MAP_JAVASCRIPT_URL}&ak=${getBaiduMapAK()}&callback=${callbackFnName}`;
},
generateAmapJavascriptUrl: (callbackFnName) => {
return `${apiConstants.amapJavascriptUrl}&key=${getAmapApplicationKey()}&plugin=AMap.ToolBar&callback=${callbackFnName}`;
return `${AMAP_JAVASCRIPT_URL}&key=${getAmapApplicationKey()}&plugin=AMap.ToolBar&callback=${callbackFnName}`;
},
generateAmapApiInternalProxyUrl: () => {
return `${window.location.origin}${apiConstants.baseAmapApiProxyUrlPath}`;
return `${window.location.origin}${BASE_AMAP_API_PROXY_URL_PATH}`;
},
getInternalAvatarUrlWithToken(avatarUrl, disableBrowserCache) {
if (!avatarUrl) {
+116
View File
@@ -0,0 +1,116 @@
import uaParser from 'ua-parser-js';
import { CliUserAgent, type TokenInfoResponse, SessionInfo } from '@/models/token.ts';
interface UserAgentInfo {
device: {
vendor?: string;
model?: string;
type?: string;
};
os: {
name?: string;
version?: string;
};
browser: {
name?: string;
version?: string;
};
}
function parseUserAgent(ua: string): UserAgentInfo {
const uaParseRet = uaParser(ua);
return {
device: {
vendor: uaParseRet.device.vendor,
model: uaParseRet.device.model,
type: uaParseRet.device.type
},
os: {
name: uaParseRet.os.name,
version: uaParseRet.os.version
},
browser: {
name: uaParseRet.browser.name,
version: uaParseRet.browser.version
}
};
}
function isSessionUserAgentCreatedByCli(ua: string): boolean {
return ua === CliUserAgent;
}
function parseDeviceInfo(uaInfo: UserAgentInfo): string {
if (!uaInfo) {
return '';
}
let result = '';
if (uaInfo.device && uaInfo.device.model) {
result = uaInfo.device.model;
} else if (uaInfo.os && uaInfo.os.name) {
result = uaInfo.os.name;
if (uaInfo.os.version) {
result += ' ' + uaInfo.os.version;
}
}
if (uaInfo.browser && uaInfo.browser.name) {
let browserInfo = uaInfo.browser.name;
if (uaInfo.browser.version) {
browserInfo += ' ' + uaInfo.browser.version;
}
if (result) {
result += ' (' + browserInfo + ')';
} else {
result = browserInfo;
}
}
if (!result) {
return 'Unknown Device';
}
return result;
}
export function parseSessionInfo(token: TokenInfoResponse): SessionInfo {
const isCreatedByCli = isSessionUserAgentCreatedByCli(token.userAgent);
const uaInfo = parseUserAgent(token.userAgent);
let deviceType = '';
if (isCreatedByCli) {
deviceType = 'cli';
} else {
if (uaInfo && uaInfo.device) {
if (uaInfo.device.type === 'mobile') {
deviceType = 'phone';
} else if (uaInfo.device.type === 'wearable') {
deviceType = 'wearable';
} else if (uaInfo.device.type === 'tablet') {
deviceType = 'tablet';
} else if (uaInfo.device.type === 'smarttv') {
deviceType = 'tv';
} else {
deviceType = 'default';
}
} else {
deviceType = 'default';
}
}
return SessionInfo.of(
token.tokenId,
token.isCurrent,
deviceType,
isCreatedByCli ? token.userAgent : parseDeviceInfo(uaInfo),
isCreatedByCli,
token.lastSeen
);
}
+5 -5
View File
@@ -1,5 +1,5 @@
import timezoneConstants from '@/consts/timezone.js';
import currencyConstants from '@/consts/currency.js';
import { TimezoneTypeForStatistics } from '@/core/timezone.ts';
import { CurrencySortingType } from '@/core/currency.ts';
import statisticsConstants from '@/consts/statistics.js';
const settingsLocalStorageKey = 'ebk_app_settings';
@@ -15,15 +15,15 @@ const defaultSettings = {
autoSaveTransactionDraft: 'disabled',
autoGetCurrentGeoLocation: false,
showAmountInHomePage: true,
timezoneUsedForStatisticsInHomePage: timezoneConstants.defaultTimezoneTypesUsedForStatistics,
timezoneUsedForStatisticsInHomePage: TimezoneTypeForStatistics.Default.type,
itemsCountInTransactionListPage: 15,
showTotalAmountInTransactionListPage: true,
showTagInTransactionListPage: true,
showAccountBalance: true,
currencySortByInExchangeRatesPage: currencyConstants.defaultCurrencySortingType,
currencySortByInExchangeRatesPage: CurrencySortingType.Default.type,
statistics: {
defaultChartDataType: statisticsConstants.defaultChartDataType,
defaultTimezoneType: timezoneConstants.defaultTimezoneTypesUsedForStatistics,
defaultTimezoneType: TimezoneTypeForStatistics.Default.type,
defaultAccountFilter: {},
defaultTransactionCategoryFilter: {},
defaultSortingType: statisticsConstants.defaultSortingType,
+21 -21
View File
@@ -1,8 +1,8 @@
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 {
isNumber
} from './common.js';
} from './common.ts';
import {
getBrowserTimezoneOffsetMinutes,
getDummyUnixTimeForLocalUsage
@@ -32,48 +32,48 @@ export function setTransactionModelByTransaction(transaction, transaction2, allC
}
}
if (allCategories[categoryConstants.allCategoryTypes.Expense] &&
allCategories[categoryConstants.allCategoryTypes.Expense].length) {
if (allCategories[CategoryType.Expense] &&
allCategories[CategoryType.Expense].length) {
if (options.categoryId && options.categoryId !== '0') {
if (isSubCategoryIdAvailable(allCategories[categoryConstants.allCategoryTypes.Expense], options.categoryId)) {
if (isSubCategoryIdAvailable(allCategories[CategoryType.Expense], options.categoryId)) {
transaction.expenseCategory = options.categoryId;
} else {
transaction.expenseCategory = getFirstAvailableSubCategoryId(allCategories[categoryConstants.allCategoryTypes.Expense], options.categoryId);
transaction.expenseCategory = getFirstAvailableSubCategoryId(allCategories[CategoryType.Expense], options.categoryId);
}
}
if (!transaction.expenseCategory) {
transaction.expenseCategory = getFirstAvailableCategoryId(allCategories[categoryConstants.allCategoryTypes.Expense]);
transaction.expenseCategory = getFirstAvailableCategoryId(allCategories[CategoryType.Expense]);
}
}
if (allCategories[categoryConstants.allCategoryTypes.Income] &&
allCategories[categoryConstants.allCategoryTypes.Income].length) {
if (allCategories[CategoryType.Income] &&
allCategories[CategoryType.Income].length) {
if (options.categoryId && options.categoryId !== '0') {
if (isSubCategoryIdAvailable(allCategories[categoryConstants.allCategoryTypes.Income], options.categoryId)) {
if (isSubCategoryIdAvailable(allCategories[CategoryType.Income], options.categoryId)) {
transaction.incomeCategory = options.categoryId;
} else {
transaction.incomeCategory = getFirstAvailableSubCategoryId(allCategories[categoryConstants.allCategoryTypes.Income], options.categoryId);
transaction.incomeCategory = getFirstAvailableSubCategoryId(allCategories[CategoryType.Income], options.categoryId);
}
}
if (!transaction.incomeCategory) {
transaction.incomeCategory = getFirstAvailableCategoryId(allCategories[categoryConstants.allCategoryTypes.Income]);
transaction.incomeCategory = getFirstAvailableCategoryId(allCategories[CategoryType.Income]);
}
}
if (allCategories[categoryConstants.allCategoryTypes.Transfer] &&
allCategories[categoryConstants.allCategoryTypes.Transfer].length) {
if (allCategories[CategoryType.Transfer] &&
allCategories[CategoryType.Transfer].length) {
if (options.categoryId && options.categoryId !== '0') {
if (isSubCategoryIdAvailable(allCategories[categoryConstants.allCategoryTypes.Transfer], options.categoryId)) {
if (isSubCategoryIdAvailable(allCategories[CategoryType.Transfer], options.categoryId)) {
transaction.transferCategory = options.categoryId;
} else {
transaction.transferCategory = getFirstAvailableSubCategoryId(allCategories[categoryConstants.allCategoryTypes.Transfer], options.categoryId);
transaction.transferCategory = getFirstAvailableSubCategoryId(allCategories[CategoryType.Transfer], options.categoryId);
}
}
if (!transaction.transferCategory) {
transaction.transferCategory = getFirstAvailableCategoryId(allCategories[categoryConstants.allCategoryTypes.Transfer]);
transaction.transferCategory = getFirstAvailableCategoryId(allCategories[CategoryType.Transfer]);
}
}
@@ -128,11 +128,11 @@ export function setTransactionModelByTransaction(transaction, transaction2, allC
transaction.type = transaction2.type;
if (transaction.type === transactionConstants.allTransactionTypes.Expense) {
if (transaction.type === TransactionType.Expense) {
transaction.expenseCategory = transaction2.categoryId || '';
} else if (transaction.type === transactionConstants.allTransactionTypes.Income) {
} else if (transaction.type === TransactionType.Income) {
transaction.incomeCategory = transaction2.categoryId || '';
} else if (transaction.type === transactionConstants.allTransactionTypes.Transfer) {
} else if (transaction.type === TransactionType.Transfer) {
transaction.transferCategory = transaction2.categoryId || '';
}
+25 -17
View File
@@ -1,23 +1,25 @@
import colorConstants from '@/consts/color.js';
import { ThemeType } from '@/core/theme.ts';
export function getSystemTheme() {
import { type AmountColor, PresetAmountColor } from '@/core/color.ts';
export function getSystemTheme(): ThemeType {
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
return 'dark';
return ThemeType.Dark;
} else {
return 'light';
return ThemeType.Light;
}
}
export function getExpenseAndIncomeAmountColor(expenseAmountColorType, incomeAmountColorType, isDarkMode) {
let expenseAmountColor = expenseAmountColorType ? colorConstants.allAmountColorTypesMap[expenseAmountColorType] : null;
let incomeAmountColor = incomeAmountColorType ? colorConstants.allAmountColorTypesMap[incomeAmountColorType] : null;
export function getExpenseAndIncomeAmountColor(expenseAmountColorType: number, incomeAmountColorType: number, isDarkMode: boolean): AmountColor {
let expenseAmountColor = expenseAmountColorType ? PresetAmountColor.valueOf(expenseAmountColorType) : null;
let incomeAmountColor = incomeAmountColorType ? PresetAmountColor.valueOf(incomeAmountColorType) : null;
if (!expenseAmountColor) {
expenseAmountColor = colorConstants.defaultExpenseAmountColor;
expenseAmountColor = PresetAmountColor.DefaultExpenseColor;
}
if (!incomeAmountColor) {
incomeAmountColor = colorConstants.defaultIncomeAmountColor;
incomeAmountColor = PresetAmountColor.DefaultIncomeColor;
}
if (isDarkMode) {
@@ -33,22 +35,28 @@ export function getExpenseAndIncomeAmountColor(expenseAmountColorType, incomeAmo
}
}
export function setExpenseAndIncomeAmountColor(expenseAmountColorType, incomeAmountColorType) {
let expenseAmountColor = expenseAmountColorType ? colorConstants.allAmountColorTypesMap[expenseAmountColorType] : null;
let incomeAmountColor = incomeAmountColorType ? colorConstants.allAmountColorTypesMap[incomeAmountColorType] : null;
export function setExpenseAndIncomeAmountColor(expenseAmountColorType: number, incomeAmountColorType: number): void {
let expenseAmountColor = expenseAmountColorType ? PresetAmountColor.valueOf(expenseAmountColorType) : null;
let incomeAmountColor = incomeAmountColorType ? PresetAmountColor.valueOf(incomeAmountColorType) : null;
if (!expenseAmountColor) {
expenseAmountColor = colorConstants.defaultExpenseAmountColor;
expenseAmountColor = PresetAmountColor.DefaultExpenseColor;
}
if (!incomeAmountColor) {
incomeAmountColor = colorConstants.defaultIncomeAmountColor;
incomeAmountColor = PresetAmountColor.DefaultIncomeColor;
}
const htmlElement = document.querySelector('html');
for (let i = 0; i < colorConstants.allAmountColorsArray.length; i++) {
const amountColor = colorConstants.allAmountColorsArray[i];
if (!htmlElement) {
return;
}
const allPresetAmountColors = PresetAmountColor.values();
for (let i = 0; i < allPresetAmountColors.length; i++) {
const amountColor = allPresetAmountColors[i];
if (amountColor.type === expenseAmountColor.type) {
if (!htmlElement.classList.contains(amountColor.expenseClassName)) {
@@ -68,7 +76,7 @@ export function setExpenseAndIncomeAmountColor(expenseAmountColorType, incomeAmo
}
}
export function startDownloadFile(fileName, fileData) {
export function startDownloadFile(fileName: string, fileData: Blob): void {
const dataObjectUrl = URL.createObjectURL(fileData);
const dataLink = document.createElement('a');
+12 -9
View File
@@ -1,8 +1,8 @@
import { f7, f7ready } from 'framework7-vue';
import fontConstants from '@/consts/font.js';
import { isEnableAnimate } from './settings.js';
import { translateError } from './i18n.js';
import { FontSize, FONT_SIZE_PREVIEW_CLASSNAME_PREFIX } from '@/core/font.ts';
import { isEnableAnimate } from '../settings.js';
import { translateError } from '../i18n.js';
export function showAlert(message, confirmCallback, translateFn) {
f7ready((f7) => {
@@ -126,9 +126,10 @@ export function autoChangeTextareaSize(el) {
export function setAppFontSize(type) {
const htmlElement = elements('html');
const allFontSizes = FontSize.values();
for (let i = 0; i < fontConstants.allFontSizeArray.length; i++) {
const fontSizeType = fontConstants.allFontSizeArray[i];
for (let i = 0; i < allFontSizes.length; i++) {
const fontSizeType = allFontSizes[i];
if (fontSizeType.type === type) {
if (!htmlElement.hasClass(fontSizeType.className)) {
@@ -141,15 +142,17 @@ export function setAppFontSize(type) {
}
export function getFontSizePreviewClassName(type) {
for (let i = 0; i < fontConstants.allFontSizeArray.length; i++) {
const fontSizeType = fontConstants.allFontSizeArray[i];
const allFontSizes = FontSize.values();
for (let i = 0; i < allFontSizes.length; i++) {
const fontSizeType = allFontSizes[i];
if (fontSizeType.type === type) {
return fontConstants.fontSizePreviewClassNamePrefix + fontSizeType.className;
return FONT_SIZE_PREVIEW_CLASSNAME_PREFIX + fontSizeType.className;
}
}
return fontConstants.fontSizePreviewClassNamePrefix + fontConstants.defaultFontSize.className;
return FONT_SIZE_PREVIEW_CLASSNAME_PREFIX + FontSize.Default.className;
}
export function scrollToSelectedItem(parentEl, containerSelector, selectedItemSelector) {
+1 -1
View File
@@ -1,6 +1,6 @@
import CryptoJS from 'crypto-js';
import { isString, isObject } from './common.js';
import { isString, isObject } from './common.ts';
import { isEnableApplicationLock } from './settings.js';
import logger from './logger.js';
+9 -9
View File
@@ -1,11 +1,11 @@
export function isProduction() {
return process.env.NODE_ENV === 'production';
export function isProduction(): boolean {
return __EZBOOKKEEPING_IS_PRODUCTION__;
}
export function getVersion() {
export function getVersion(): string {
const isRelease = !getBuildTime();
const commitHash = __EZBOOKKEEPING_BUILD_COMMIT_HASH__; // eslint-disable-line
let version = __EZBOOKKEEPING_VERSION__; // eslint-disable-line
const commitHash = __EZBOOKKEEPING_BUILD_COMMIT_HASH__;
let version = __EZBOOKKEEPING_VERSION__;
if (version && (!isRelease || !isProduction())) {
version += '-dev';
@@ -22,18 +22,18 @@ export function getVersion() {
return version;
}
export function getBuildTime() {
return __EZBOOKKEEPING_BUILD_UNIX_TIME__; // eslint-disable-line
export function getBuildTime(): string {
return __EZBOOKKEEPING_BUILD_UNIX_TIME__;
}
export function getMobileVersionPath() {
export function getMobileVersionPath(): string {
if (isProduction()) {
return '../mobile';
} else {
return 'mobile.html';
}
}
export function getDesktopVersionPath() {
export function getDesktopVersionPath(): string {
if (isProduction()) {
return '../desktop';
} else {
+2 -2
View File
@@ -6,10 +6,10 @@ import {
arrayBufferToString,
base64encode,
base64decode
} from './common.js';
} from './common.ts';
import {
generateRandomString
} from './misc.js';
} from './misc.ts';
const publicKeyCredentialCreationOptionsBaseTemplate = {
attestation: "none",