code refactor

This commit is contained in:
MaysWind
2024-09-20 00:10:40 +08:00
parent 220f9f15e5
commit 6655d725ae
11 changed files with 69 additions and 69 deletions
+3 -3
View File
@@ -146,17 +146,17 @@ export function getCategorizedAccounts(allAccounts) {
return ret;
}
export function getCategorizedAccountsWithVisibleCount(categorizedAccounts) {
export function getCategorizedAccountsWithVisibleCount(categorizedAccountsMap) {
const ret = [];
for (let i = 0; i < accountConstants.allCategories.length; i++) {
const accountCategory = accountConstants.allCategories[i];
if (!categorizedAccounts[accountCategory.id] || !categorizedAccounts[accountCategory.id].accounts) {
if (!categorizedAccountsMap[accountCategory.id] || !categorizedAccountsMap[accountCategory.id].accounts) {
continue;
}
const allAccounts = categorizedAccounts[accountCategory.id].accounts;
const allAccounts = categorizedAccountsMap[accountCategory.id].accounts;
const allSubAccounts = {};
const allVisibleSubAccountCounts = {};
const allFirstVisibleSubAccountIndexes = {};
+41 -41
View File
@@ -28,7 +28,7 @@ function loadAccountList(state, accounts) {
}
}
state.allCategorizedAccounts = getCategorizedAccountsMap(accounts);
state.allCategorizedAccountsMap = getCategorizedAccountsMap(accounts);
}
function addAccountToAccountList(state, account) {
@@ -52,11 +52,11 @@ function addAccountToAccountList(state, account) {
}
}
if (state.allCategorizedAccounts[account.category]) {
const accountList = state.allCategorizedAccounts[account.category].accounts;
if (state.allCategorizedAccountsMap[account.category]) {
const accountList = state.allCategorizedAccountsMap[account.category].accounts;
accountList.push(account);
} else {
state.allCategorizedAccounts = getCategorizedAccountsMap(state.allAccounts);
state.allCategorizedAccountsMap = getCategorizedAccountsMap(state.allAccounts);
}
}
@@ -77,8 +77,8 @@ function updateAccountToAccountList(state, account) {
}
}
if (state.allCategorizedAccounts[account.category]) {
const accountList = state.allCategorizedAccounts[account.category].accounts;
if (state.allCategorizedAccountsMap[account.category]) {
const accountList = state.allCategorizedAccountsMap[account.category].accounts;
for (let i = 0; i < accountList.length; i++) {
if (accountList[i].id === account.id) {
@@ -93,8 +93,8 @@ function updateAccountDisplayOrderInAccountList(state, { account, from, to, upda
let fromAccount = null;
let toAccount = null;
if (state.allCategorizedAccounts[account.category]) {
const accountList = state.allCategorizedAccounts[account.category].accounts;
if (state.allCategorizedAccountsMap[account.category]) {
const accountList = state.allCategorizedAccountsMap[account.category].accounts;
if (updateListOrder) {
fromAccount = accountList[from];
@@ -158,8 +158,8 @@ function removeAccountFromAccountList(state, account) {
delete state.allAccountsMap[account.id];
}
if (state.allCategorizedAccounts[account.category]) {
const accountList = state.allCategorizedAccounts[account.category].accounts;
if (state.allCategorizedAccountsMap[account.category]) {
const accountList = state.allCategorizedAccountsMap[account.category].accounts;
for (let i = 0; i < accountList.length; i++) {
if (accountList[i].id === account.id) {
@@ -174,7 +174,7 @@ export const useAccountsStore = defineStore('accounts', {
state: () => ({
allAccounts: [],
allAccountsMap: {},
allCategorizedAccounts: {},
allCategorizedAccountsMap: {},
accountListStateInvalid: true,
}),
getters: {
@@ -221,12 +221,12 @@ export const useAccountsStore = defineStore('accounts', {
allAvailableAccountsCount(state) {
let allAccountCount = 0;
for (let category in state.allCategorizedAccounts) {
if (!Object.prototype.hasOwnProperty.call(state.allCategorizedAccounts, category)) {
for (let category in state.allCategorizedAccountsMap) {
if (!Object.prototype.hasOwnProperty.call(state.allCategorizedAccountsMap, category)) {
continue;
}
allAccountCount += state.allCategorizedAccounts[category].accounts.length;
allAccountCount += state.allCategorizedAccountsMap[category].accounts.length;
}
return allAccountCount;
@@ -234,12 +234,12 @@ export const useAccountsStore = defineStore('accounts', {
allVisibleAccountsCount(state) {
let shownAccountCount = 0;
for (let category in state.allCategorizedAccounts) {
if (!Object.prototype.hasOwnProperty.call(state.allCategorizedAccounts, category)) {
for (let category in state.allCategorizedAccountsMap) {
if (!Object.prototype.hasOwnProperty.call(state.allCategorizedAccountsMap, category)) {
continue;
}
const accountList = state.allCategorizedAccounts[category].accounts;
const accountList = state.allCategorizedAccountsMap[category].accounts;
for (let i = 0; i < accountList.length; i++) {
if (!accountList[i].hidden) {
@@ -288,7 +288,7 @@ export const useAccountsStore = defineStore('accounts', {
resetAccounts() {
this.allAccounts = [];
this.allAccountsMap = {};
this.allCategorizedAccounts = {};
this.allCategorizedAccountsMap = {};
this.accountListStateInvalid = true;
},
getFirstShowingIds(showHidden) {
@@ -297,16 +297,16 @@ export const useAccountsStore = defineStore('accounts', {
subAccounts: {}
};
for (let category in this.allCategorizedAccounts) {
if (!Object.prototype.hasOwnProperty.call(this.allCategorizedAccounts, category)) {
for (let category in this.allCategorizedAccountsMap) {
if (!Object.prototype.hasOwnProperty.call(this.allCategorizedAccountsMap, category)) {
continue;
}
if (!this.allCategorizedAccounts[category] || !this.allCategorizedAccounts[category].accounts) {
if (!this.allCategorizedAccountsMap[category] || !this.allCategorizedAccountsMap[category].accounts) {
continue;
}
const accounts = this.allCategorizedAccounts[category].accounts;
const accounts = this.allCategorizedAccountsMap[category].accounts;
for (let i = 0; i < accounts.length; i++) {
const account = accounts[i];
@@ -337,16 +337,16 @@ export const useAccountsStore = defineStore('accounts', {
subAccounts: {}
};
for (let category in this.allCategorizedAccounts) {
if (!Object.prototype.hasOwnProperty.call(this.allCategorizedAccounts, category)) {
for (let category in this.allCategorizedAccountsMap) {
if (!Object.prototype.hasOwnProperty.call(this.allCategorizedAccountsMap, category)) {
continue;
}
if (!this.allCategorizedAccounts[category] || !this.allCategorizedAccounts[category].accounts) {
if (!this.allCategorizedAccountsMap[category] || !this.allCategorizedAccountsMap[category].accounts) {
continue;
}
const accounts = this.allCategorizedAccounts[category].accounts;
const accounts = this.allCategorizedAccountsMap[category].accounts;
for (let i = accounts.length - 1; i >= 0; i--) {
const account = accounts[i];
@@ -378,7 +378,7 @@ export const useAccountsStore = defineStore('accounts', {
const userStore = useUserStore();
const exchangeRatesStore = useExchangeRatesStore();
const accountsBalance = getAllFilteredAccountsBalance(this.allCategorizedAccounts, () => true);
const accountsBalance = getAllFilteredAccountsBalance(this.allCategorizedAccountsMap, () => true);
let netAssets = 0;
let hasUnCalculatedAmount = false;
@@ -410,7 +410,7 @@ export const useAccountsStore = defineStore('accounts', {
const userStore = useUserStore();
const exchangeRatesStore = useExchangeRatesStore();
const accountsBalance = getAllFilteredAccountsBalance(this.allCategorizedAccounts, account => account.isAsset);
const accountsBalance = getAllFilteredAccountsBalance(this.allCategorizedAccountsMap, account => account.isAsset);
let totalAssets = 0;
let hasUnCalculatedAmount = false;
@@ -442,7 +442,7 @@ export const useAccountsStore = defineStore('accounts', {
const userStore = useUserStore();
const exchangeRatesStore = useExchangeRatesStore();
const accountsBalance = getAllFilteredAccountsBalance(this.allCategorizedAccounts, account => account.isLiability);
const accountsBalance = getAllFilteredAccountsBalance(this.allCategorizedAccountsMap, account => account.isLiability);
let totalLiabilities = 0;
let hasUnCalculatedAmount = false;
@@ -474,7 +474,7 @@ export const useAccountsStore = defineStore('accounts', {
const userStore = useUserStore();
const exchangeRatesStore = useExchangeRatesStore();
const accountsBalance = getAllFilteredAccountsBalance(this.allCategorizedAccounts, account => account.category === accountCategory.id);
const accountsBalance = getAllFilteredAccountsBalance(this.allCategorizedAccountsMap, account => account.category === accountCategory.id);
let totalBalance = 0;
let hasUnCalculatedAmount = false;
@@ -630,16 +630,16 @@ export const useAccountsStore = defineStore('accounts', {
};
},
hasAccount(accountCategory, visibleOnly) {
if (!this.allCategorizedAccounts[accountCategory.id] ||
!this.allCategorizedAccounts[accountCategory.id].accounts ||
!this.allCategorizedAccounts[accountCategory.id].accounts.length) {
if (!this.allCategorizedAccountsMap[accountCategory.id] ||
!this.allCategorizedAccountsMap[accountCategory.id].accounts ||
!this.allCategorizedAccountsMap[accountCategory.id].accounts.length) {
return false;
}
let shownCount = 0;
for (let i = 0; i < this.allCategorizedAccounts[accountCategory.id].accounts.length; i++) {
const account = this.allCategorizedAccounts[accountCategory.id].accounts[i];
for (let i = 0; i < this.allCategorizedAccountsMap[accountCategory.id].accounts.length; i++) {
const account = this.allCategorizedAccountsMap[accountCategory.id].accounts[i];
if (!visibleOnly || !account.hidden) {
shownCount++;
@@ -842,9 +842,9 @@ export const useAccountsStore = defineStore('accounts', {
return new Promise((resolve, reject) => {
if (!account ||
!self.allCategorizedAccounts[account.category] ||
!self.allCategorizedAccounts[account.category].accounts ||
!self.allCategorizedAccounts[account.category].accounts[to]) {
!self.allCategorizedAccountsMap[account.category] ||
!self.allCategorizedAccountsMap[account.category].accounts ||
!self.allCategorizedAccountsMap[account.category].accounts[to]) {
reject({ message: 'Unable to move account' });
return;
}
@@ -868,12 +868,12 @@ export const useAccountsStore = defineStore('accounts', {
const self = this;
const newDisplayOrders = [];
for (let category in self.allCategorizedAccounts) {
if (!Object.prototype.hasOwnProperty.call(self.allCategorizedAccounts, category)) {
for (let category in self.allCategorizedAccountsMap) {
if (!Object.prototype.hasOwnProperty.call(self.allCategorizedAccountsMap, category)) {
continue;
}
const accountList = self.allCategorizedAccounts[category].accounts;
const accountList = self.allCategorizedAccountsMap[category].accounts;
for (let i = 0; i < accountList.length; i++) {
newDisplayOrders.push({
+6 -6
View File
@@ -146,8 +146,8 @@
handle=".drag-handle"
ghost-class="dragging-item"
:disabled="activeAccountCategoryVisibleAccountCount <= 1"
:list="categorizedAccounts[activeAccountCategory.id].accounts"
v-if="categorizedAccounts[activeAccountCategory.id] && categorizedAccounts[activeAccountCategory.id].accounts && categorizedAccounts[activeAccountCategory.id].accounts.length"
:list="allCategorizedAccountsMap[activeAccountCategory.id].accounts"
v-if="allCategorizedAccountsMap[activeAccountCategory.id] && allCategorizedAccountsMap[activeAccountCategory.id].accounts && allCategorizedAccountsMap[activeAccountCategory.id].accounts.length"
@change="onMove"
>
<template #item="{ element }">
@@ -330,8 +330,8 @@ export default {
allAccountCategories() {
return accountConstants.allCategories;
},
categorizedAccounts() {
return this.accountsStore.allCategorizedAccounts;
allCategorizedAccountsMap() {
return this.accountsStore.allCategorizedAccountsMap;
},
allAccountCount() {
return this.accountsStore.allAvailableAccountsCount;
@@ -355,11 +355,11 @@ export default {
return this.accountCategoryTotalBalance(this.activeAccountCategory);
},
activeAccountCategoryVisibleAccountCount() {
if (!this.categorizedAccounts[this.activeAccountCategory.id] || !this.categorizedAccounts[this.activeAccountCategory.id].accounts) {
if (!this.allCategorizedAccountsMap[this.activeAccountCategory.id] || !this.allCategorizedAccountsMap[this.activeAccountCategory.id].accounts) {
return 0;
}
const accounts = this.categorizedAccounts[this.activeAccountCategory.id].accounts;
const accounts = this.allCategorizedAccountsMap[this.activeAccountCategory.id].accounts;
if (this.showHidden) {
return accounts.length;
@@ -216,7 +216,7 @@ export default {
return accountConstants.allAccountTypes;
},
allCategorizedAccounts() {
return getCategorizedAccountsWithVisibleCount(this.accountsStore.allCategorizedAccounts);
return getCategorizedAccountsWithVisibleCount(this.accountsStore.allCategorizedAccountsMap);
},
hasAnyAvailableAccount() {
return this.accountsStore.allAvailableAccountsCount > 0;
@@ -168,7 +168,7 @@
:custom-selection-primary-text="sourceAccountName"
:label="$t(sourceAccountTitle)"
:placeholder="$t(sourceAccountTitle)"
:items="categorizedAccounts"
:items="allVisibleCategorizedAccounts"
v-model="transaction.sourceAccountId">
</two-column-select>
</v-col>
@@ -186,7 +186,7 @@
:custom-selection-primary-text="destinationAccountName"
:label="$t('Destination Account')"
:placeholder="$t('Destination Account')"
:items="categorizedAccounts"
:items="allVisibleCategorizedAccounts"
v-model="transaction.destinationAccountId">
</two-column-select>
</v-col>
@@ -576,7 +576,7 @@ export default {
allVisibleAccounts() {
return this.accountsStore.allVisiblePlainAccounts;
},
categorizedAccounts() {
allVisibleCategorizedAccounts() {
return this.$locale.getCategorizedAccountsWithDisplayBalance(this.allVisibleAccounts, this.showAccountBalance, this.defaultCurrency, this.settingsStore, this.userStore, this.exchangeRatesStore);
},
allAccountsMap() {
@@ -224,7 +224,7 @@
:disabled="loading || submitting || !allVisibleAccounts.length"
:custom-selection-primary-text="getSourceAccountDisplayName(item)"
:placeholder="getSourceAccountTitle(item)"
:items="categorizedAccounts"
:items="allVisibleCategorizedAccounts"
v-model="item.sourceAccountId"
@update:model-value="updateTransactionData(item)">
</two-column-select>
@@ -242,7 +242,7 @@
:disabled="loading || submitting || !allVisibleAccounts.length"
:custom-selection-primary-text="getDestinationAccountDisplayName(item)"
:placeholder="$t('Destination Account')"
:items="categorizedAccounts"
:items="allVisibleCategorizedAccounts"
v-model="item.destinationAccountId"
@update:model-value="updateTransactionData(item)">
</two-column-select>
@@ -480,7 +480,7 @@ export default {
allVisibleAccounts() {
return this.accountsStore.allVisiblePlainAccounts;
},
categorizedAccounts() {
allVisibleCategorizedAccounts() {
return this.$locale.getCategorizedAccountsWithDisplayBalance(this.allVisibleAccounts, this.showAccountBalance, this.defaultCurrency, this.settingsStore, this.userStore, this.exchangeRatesStore);
},
allAccountsMap() {
@@ -89,7 +89,7 @@
:disabled="loading || saving || !allVisibleAccounts.length"
:label="$t('Default Account')"
:placeholder="$t('Default Account')"
:items="allCategorizedAccounts"
:items="allVisibleCategorizedAccounts"
:no-item-text="$t('Unspecified')"
v-model="newProfile.defaultAccountId">
</two-column-select>
@@ -420,7 +420,7 @@ export default {
allVisibleAccounts() {
return this.accountsStore.allVisiblePlainAccounts;
},
allCategorizedAccounts() {
allVisibleCategorizedAccounts() {
return getCategorizedAccounts(this.allVisibleAccounts);
},
allWeekDays() {
+4 -4
View File
@@ -71,7 +71,7 @@
v-show="(showHidden && hasAccount(accountCategory, false)) || hasAccount(accountCategory, true)">
<f7-list strong inset dividers sortable class="list-has-group-title account-list margin-vertical"
:sortable-enabled="sortable"
v-if="categorizedAccounts[accountCategory.id]"
v-if="allCategorizedAccountsMap[accountCategory.id]"
@sortable:sort="onSort">
<f7-list-item group-title :sortable="false">
<small>
@@ -86,7 +86,7 @@
:after="accountBalance(account)"
:link="!sortable ? '/transaction/list?accountIds=' + account.id : null"
:key="account.id"
v-for="account in categorizedAccounts[accountCategory.id].accounts"
v-for="account in allCategorizedAccountsMap[accountCategory.id].accounts"
v-show="showHidden || !account.hidden"
@taphold="setSortable()"
>
@@ -210,8 +210,8 @@ export default {
allAccountCategories() {
return accountConstants.allCategories;
},
categorizedAccounts() {
return this.accountsStore.allCategorizedAccounts;
allCategorizedAccountsMap() {
return this.accountsStore.allCategorizedAccountsMap;
},
allAccountCount() {
return this.accountsStore.allAvailableAccountsCount;
@@ -186,7 +186,7 @@ export default {
return accountConstants.allAccountTypes;
},
allCategorizedAccounts() {
return getCategorizedAccountsWithVisibleCount(this.accountsStore.allCategorizedAccounts);
return getCategorizedAccountsWithVisibleCount(this.accountsStore.allCategorizedAccountsMap);
},
hasAnyAvailableAccount() {
return this.accountsStore.allAvailableAccountsCount > 0;
+3 -3
View File
@@ -200,7 +200,7 @@
secondary-key-field="id" secondary-value-field="id"
secondary-title-field="name" secondary-footer-field="displayBalance"
secondary-icon-field="icon" secondary-icon-type="account" secondary-color-field="color"
:items="categorizedAccounts"
:items="allVisibleCategorizedAccounts"
v-model:show="showSourceAccountSheet"
v-model="transaction.sourceAccountId">
</two-column-list-item-selection-sheet>
@@ -223,7 +223,7 @@
secondary-key-field="id" secondary-value-field="id"
secondary-title-field="name" secondary-footer-field="displayBalance"
secondary-icon-field="icon" secondary-icon-type="account" secondary-color-field="color"
:items="categorizedAccounts"
:items="allVisibleCategorizedAccounts"
v-model:show="showDestinationAccountSheet"
v-model="transaction.destinationAccountId">
</two-column-list-item-selection-sheet>
@@ -606,7 +606,7 @@ export default {
allAccountsMap() {
return this.accountsStore.allAccountsMap;
},
categorizedAccounts() {
allVisibleCategorizedAccounts() {
return this.$locale.getCategorizedAccountsWithDisplayBalance(this.allVisibleAccounts, this.showAccountBalance, this.defaultCurrency, this.settingsStore, this.userStore, this.exchangeRatesStore);
},
allCategories() {
+2 -2
View File
@@ -103,7 +103,7 @@
secondary-key-field="id" secondary-value-field="id"
secondary-title-field="name"
secondary-icon-field="icon" secondary-icon-type="account" secondary-color-field="color"
:items="allCategorizedAccounts"
:items="allVisibleCategorizedAccounts"
v-model:show="showAccountSheet"
v-model="newProfile.defaultAccountId">
</two-column-list-item-selection-sheet>
@@ -415,7 +415,7 @@ export default {
allVisibleAccounts() {
return this.accountsStore.allVisiblePlainAccounts;
},
allCategorizedAccounts() {
allVisibleCategorizedAccounts() {
return getCategorizedAccounts(this.allVisibleAccounts);
},
allWeekDays() {