code refactor
This commit is contained in:
@@ -16,7 +16,6 @@ import {
|
||||
} from '@/models/account.ts';
|
||||
|
||||
import { isNumber, isEquals } from '@/lib/common.ts';
|
||||
import { getCurrentUnixTime } from '@/lib/datetime.ts';
|
||||
import { getCategorizedAccountsMap, getAllFilteredAccountsBalance } from '@/lib/account.ts';
|
||||
import services from '@/lib/services.ts';
|
||||
import logger from '@/lib/logger.ts';
|
||||
@@ -268,14 +267,6 @@ export const useAccountsStore = defineStore('accounts', () => {
|
||||
return shownAccountCount;
|
||||
});
|
||||
|
||||
function generateNewAccountModel(): Account {
|
||||
return Account.createNewAccount(userStore.currentUserDefaultCurrency, getCurrentUnixTime());
|
||||
}
|
||||
|
||||
function generateNewSubAccountModel(parentAccount: Account): Account {
|
||||
return parentAccount.createNewSubAccount(userStore.currentUserDefaultCurrency, getCurrentUnixTime());
|
||||
}
|
||||
|
||||
function updateAccountListInvalidState(invalidState: boolean): void {
|
||||
accountListStateInvalid.value = invalidState;
|
||||
}
|
||||
@@ -990,8 +981,6 @@ export const useAccountsStore = defineStore('accounts', () => {
|
||||
allAvailableAccountsCount,
|
||||
allVisibleAccountsCount,
|
||||
// functions
|
||||
generateNewAccountModel,
|
||||
generateNewSubAccountModel,
|
||||
updateAccountListInvalidState,
|
||||
resetAccounts,
|
||||
getFirstShowingIds,
|
||||
|
||||
@@ -2,14 +2,15 @@ import { ref, computed, watch } from 'vue';
|
||||
|
||||
import { useI18n } from '@/locales/helpers.ts';
|
||||
|
||||
import { useAccountsStore } from '@/stores/account.ts';
|
||||
import { useUserStore } from '@/stores/user.ts';
|
||||
|
||||
import type { TypeAndDisplayName } from '@/core/base.ts';
|
||||
import { AccountCategory, AccountType } from '@/core/account.ts';
|
||||
import type { LocalizedCurrencyInfo } from '@/core/currency.ts';
|
||||
import type { LocalizedAccountCategory } from '@/core/account.ts';
|
||||
import type { Account } from '@/models/account.ts';
|
||||
import { Account } from '@/models/account.ts';
|
||||
|
||||
import { getCurrentUnixTime } from '@/lib/datetime.ts';
|
||||
import { setAccountSuitableIcon } from '@/lib/account.ts';
|
||||
|
||||
export interface DayAndDisplayName {
|
||||
@@ -19,13 +20,14 @@ export interface DayAndDisplayName {
|
||||
|
||||
export function useAccountEditPageBaseBase() {
|
||||
const { tt, getAllCurrencies, getAllAccountCategories, getAllAccountTypes, getMonthdayShortName } = useI18n();
|
||||
const accountsStore = useAccountsStore();
|
||||
|
||||
const userStore = useUserStore();
|
||||
|
||||
const editAccountId = ref<string | null>(null);
|
||||
const clientSessionId = ref<string>('');
|
||||
const loading = ref<boolean>(false);
|
||||
const submitting = ref<boolean>(false);
|
||||
const account = ref<Account>(accountsStore.generateNewAccountModel());
|
||||
const account = ref<Account>(Account.createNewAccount(userStore.currentUserDefaultCurrency, getCurrentUnixTime()));
|
||||
const subAccounts = ref<Account[]>([]);
|
||||
|
||||
const title = computed<string>(() => {
|
||||
@@ -133,7 +135,7 @@ export function useAccountEditPageBaseBase() {
|
||||
return false;
|
||||
}
|
||||
|
||||
const subAccount = accountsStore.generateNewSubAccountModel(account.value);
|
||||
const subAccount = account.value.createNewSubAccount(userStore.currentUserDefaultCurrency, getCurrentUnixTime());
|
||||
subAccounts.value.push(subAccount);
|
||||
return true;
|
||||
}
|
||||
@@ -144,7 +146,7 @@ export function useAccountEditPageBaseBase() {
|
||||
|
||||
if (newAccount.childrenAccounts && newAccount.childrenAccounts.length > 0) {
|
||||
for (let i = 0; i < newAccount.childrenAccounts.length; i++) {
|
||||
const subAccount = accountsStore.generateNewSubAccountModel(account.value);
|
||||
const subAccount = account.value.createNewSubAccount(userStore.currentUserDefaultCurrency, getCurrentUnixTime());
|
||||
subAccount.from(newAccount.childrenAccounts[i]);
|
||||
|
||||
subAccounts.value.push(subAccount);
|
||||
|
||||
@@ -204,14 +204,16 @@ import { ref, computed, useTemplateRef, watch } from 'vue';
|
||||
import { useI18n } from '@/locales/helpers.ts';
|
||||
import { useAccountEditPageBaseBase } from '@/views/base/accounts/AccountEditPageBase.ts';
|
||||
|
||||
import { useUserStore } from '@/stores/user.ts';
|
||||
import { useAccountsStore } from '@/stores/account.ts';
|
||||
|
||||
import { AccountType } from '@/core/account.ts';
|
||||
import { ALL_ACCOUNT_ICONS } from '@/consts/icon.ts';
|
||||
import { ALL_ACCOUNT_COLORS } from '@/consts/color.ts';
|
||||
import type { Account } from '@/models/account.ts';
|
||||
import { Account } from '@/models/account.ts';
|
||||
|
||||
import { isNumber } from '@/lib/common.ts';
|
||||
import { getCurrentUnixTime } from '@/lib/datetime.ts';
|
||||
import { generateRandomUUID } from '@/lib/misc.ts';
|
||||
import { setAccountSuitableIcon } from '@/lib/account.ts';
|
||||
|
||||
@@ -254,6 +256,7 @@ const {
|
||||
setAccount
|
||||
} = useAccountEditPageBaseBase();
|
||||
|
||||
const userStore = useUserStore();
|
||||
const accountsStore = useAccountsStore();
|
||||
|
||||
const icons = {
|
||||
@@ -285,7 +288,7 @@ function open(options?: { id?: string, currentAccount?: Account, category?: numb
|
||||
loading.value = true;
|
||||
submitting.value = false;
|
||||
|
||||
const newAccount = accountsStore.generateNewAccountModel();
|
||||
const newAccount = Account.createNewAccount(userStore.currentUserDefaultCurrency, getCurrentUnixTime());
|
||||
account.value.from(newAccount);
|
||||
subAccounts.value = [];
|
||||
currentAccountIndex.value = -1;
|
||||
|
||||
Reference in New Issue
Block a user