code refactor

This commit is contained in:
MaysWind
2023-08-13 20:32:51 +08:00
parent eb9a2ac2e0
commit f5ce6ed4bc
3 changed files with 119 additions and 144 deletions
+89
View File
@@ -214,3 +214,92 @@ export function getAllFilteredAccountsBalance(categorizedAccounts, accountFilter
return ret;
}
export function selectAccountOrSubAccounts(filterAccountIds, account, value) {
if (account.type === accountConstants.allAccountTypes.SingleAccount) {
filterAccountIds[account.id] = value;
} else if (account.type === accountConstants.allAccountTypes.MultiSubAccounts) {
if (!account.subAccounts || !account.subAccounts.length) {
return;
}
for (let i = 0; i < account.subAccounts.length; i++) {
const subAccount = account.subAccounts[i];
filterAccountIds[subAccount.id] = value;
}
}
}
export function selectAll(filterAccountIds, allAccountsMap) {
for (let accountId in filterAccountIds) {
if (!Object.prototype.hasOwnProperty.call(filterAccountIds, accountId)) {
continue;
}
const account = allAccountsMap[accountId];
if (account && account.type === accountConstants.allAccountTypes.SingleAccount) {
filterAccountIds[account.id] = false;
}
}
}
export function selectNone(filterAccountIds, allAccountsMap) {
for (let accountId in filterAccountIds) {
if (!Object.prototype.hasOwnProperty.call(filterAccountIds, accountId)) {
continue;
}
const account = allAccountsMap[accountId];
if (account && account.type === accountConstants.allAccountTypes.SingleAccount) {
filterAccountIds[account.id] = true;
}
}
}
export function selectInvert(filterAccountIds, allAccountsMap) {
for (let accountId in filterAccountIds) {
if (!Object.prototype.hasOwnProperty.call(filterAccountIds, accountId)) {
continue;
}
const account = allAccountsMap[accountId];
if (account && account.type === accountConstants.allAccountTypes.SingleAccount) {
filterAccountIds[account.id] = !filterAccountIds[account.id];
}
}
}
export function isAccountOrSubAccountsAllChecked(account, filterAccountIds) {
if (!account.subAccounts) {
return !filterAccountIds[account.id];
}
for (let i = 0; i < account.subAccounts.length; i++) {
const subAccount = account.subAccounts[i];
if (filterAccountIds[subAccount.id]) {
return false;
}
}
return true;
}
export function isAccountOrSubAccountsHasButNotAllChecked(account, filterAccountIds) {
if (!account.subAccounts) {
return false;
}
let checkedCount = 0;
for (let i = 0; i < account.subAccounts.length; i++) {
const subAccount = account.subAccounts[i];
if (!filterAccountIds[subAccount.id]) {
checkedCount++;
}
}
return checkedCount > 0 && checkedCount < account.subAccounts.length;
}