add search box in filter account page / dialog

This commit is contained in:
MaysWind
2025-12-14 17:41:50 +08:00
parent aebd65449b
commit e825323bb0
22 changed files with 180 additions and 218 deletions
@@ -7,10 +7,10 @@ import { useStatisticsStore } from '@/stores/statistics.ts';
import { useOverviewStore } from '@/stores/overview.ts';
import { keys, keysIfValueEquals, values } from '@/core/base.ts';
import type { Account, AccountCategoriesWithVisibleCount } from '@/models/account.ts';
import type {Account, CategorizedAccount} from '@/models/account.ts';
import {
getCategorizedAccountsWithVisibleCount,
filterCategorizedAccounts,
selectAccountOrSubAccounts,
isAccountOrSubAccountsAllChecked
} from '@/lib/account.ts';
@@ -26,6 +26,7 @@ export function useAccountFilterSettingPageBase(type?: AccountFilterType) {
const loading = ref<boolean>(true);
const showHidden = ref<boolean>(false);
const filterContent = ref<string>('');
const filterAccountIds = ref<Record<string, boolean>>({});
const title = computed<string>(() => {
@@ -48,15 +49,33 @@ export function useAccountFilterSettingPageBase(type?: AccountFilterType) {
return type === 'statisticsDefault' || type === 'statisticsCurrent' || type === 'homePageOverview' || type === 'transactionListCurrent';
});
const allCategorizedAccounts = computed<AccountCategoriesWithVisibleCount[]>(() => getCategorizedAccountsWithVisibleCount(accountsStore.allCategorizedAccountsMap));
const hasAnyAvailableAccount = computed<boolean>(() => accountsStore.allAvailableAccountsCount > 0);
const allCategorizedAccounts = computed<Record<number, CategorizedAccount>>(() => filterCategorizedAccounts(accountsStore.allCategorizedAccountsMap, filterContent.value, showHidden.value));
const allVisibleAccountMap = computed<Record<string, Account>>(() => {
const accountMap: Record<string, Account> = {};
const hasAnyVisibleAccount = computed<boolean>(() => {
if (showHidden.value) {
return accountsStore.allAvailableAccountsCount > 0;
} else {
return accountsStore.allVisibleAccountsCount > 0;
for (const accountCategory of values(allCategorizedAccounts.value)) {
for (const account of accountCategory.accounts) {
accountMap[account.id] = account;
if (account.subAccounts) {
for (const subAccount of account.subAccounts) {
accountMap[subAccount.id] = subAccount;
}
}
}
}
return accountMap;
});
const hasAnyAvailableAccount = computed<boolean>(() => accountsStore.allAvailableAccountsCount > 0);
const hasAnyVisibleAccount = computed<boolean>(() => {
for (const accountCategory of values(allCategorizedAccounts.value)) {
if (accountCategory.accounts.length > 0) {
return true;
}
}
return false;
});
function isAccountChecked(account: Account, filterAccountIds: Record<string, boolean>): boolean {
@@ -162,12 +181,14 @@ export function useAccountFilterSettingPageBase(type?: AccountFilterType) {
// states
loading,
showHidden,
filterContent,
filterAccountIds,
// computed states
title,
applyText,
allowHiddenAccount,
allCategorizedAccounts,
allVisibleAccountMap,
hasAnyAvailableAccount,
hasAnyVisibleAccount,
// functions
@@ -1,81 +1,48 @@
<template>
<v-card :class="{ 'pa-sm-1 pa-md-2': dialogMode }">
<template #title>
<div class="d-flex align-center justify-center" v-if="dialogMode">
<div class="w-100 text-center">
<h4 class="text-h4">{{ tt(title) }}</h4>
</div>
<v-btn density="comfortable" color="default" variant="text" class="ms-2"
:disabled="loading || !hasAnyAvailableAccount" :icon="true">
<v-icon :icon="mdiDotsVertical" />
<v-menu activator="parent">
<v-list>
<v-list-item :prepend-icon="mdiSelectAll"
:title="tt('Select All')"
:disabled="!hasAnyVisibleAccount"
@click="selectAllAccounts"></v-list-item>
<v-list-item :prepend-icon="mdiSelect"
:title="tt('Select None')"
:disabled="!hasAnyVisibleAccount"
@click="selectNoneAccounts"></v-list-item>
<v-list-item :prepend-icon="mdiSelectInverse"
:title="tt('Invert Selection')"
:disabled="!hasAnyVisibleAccount"
@click="selectInvertAccounts"></v-list-item>
<v-divider class="my-2" v-if="allowHiddenAccount"/>
<v-list-item :prepend-icon="mdiSelectAll"
:title="tt('Select All Visible')"
:disabled="!hasAnyVisibleAccount"
@click="selectAllVisibleAccounts"
v-if="allowHiddenAccount"></v-list-item>
<v-divider class="my-2" v-if="allowHiddenAccount"/>
<v-list-item :prepend-icon="mdiEyeOutline"
:title="tt('Show Hidden Accounts')"
v-if="allowHiddenAccount && !showHidden" @click="showHidden = true"></v-list-item>
<v-list-item :prepend-icon="mdiEyeOffOutline"
:title="tt('Hide Hidden Accounts')"
v-if="allowHiddenAccount && showHidden" @click="showHidden = false"></v-list-item>
</v-list>
</v-menu>
</v-btn>
</div>
<div class="d-flex align-center" v-else-if="!dialogMode">
<span>{{ tt(title) }}</span>
<v-spacer/>
<v-btn density="comfortable" color="default" variant="text" class="ms-2"
:disabled="loading" :icon="true">
<v-icon :icon="mdiDotsVertical" />
<v-menu activator="parent">
<v-list>
<v-list-item :prepend-icon="mdiSelectAll"
:title="tt('Select All')"
:disabled="!hasAnyVisibleAccount"
@click="selectAllAccounts"></v-list-item>
<v-list-item :prepend-icon="mdiSelect"
:title="tt('Select None')"
:disabled="!hasAnyVisibleAccount"
@click="selectNoneAccounts"></v-list-item>
<v-list-item :prepend-icon="mdiSelectInverse"
:title="tt('Invert Selection')"
:disabled="!hasAnyVisibleAccount"
@click="selectInvertAccounts"></v-list-item>
<v-divider class="my-2" v-if="allowHiddenAccount"/>
<v-list-item :prepend-icon="mdiSelectAll"
:title="tt('Select All Visible')"
:disabled="!hasAnyVisibleAccount"
@click="selectAllVisibleAccounts"
v-if="allowHiddenAccount"></v-list-item>
<v-divider class="my-2" v-if="allowHiddenAccount"/>
<v-list-item :prepend-icon="mdiEyeOutline"
:title="tt('Show Hidden Accounts')"
v-if="allowHiddenAccount && !showHidden" @click="showHidden = true"></v-list-item>
<v-list-item :prepend-icon="mdiEyeOffOutline"
:title="tt('Hide Hidden Accounts')"
v-if="allowHiddenAccount && showHidden" @click="showHidden = false"></v-list-item>
</v-list>
</v-menu>
</v-btn>
</div>
<v-row>
<v-col cols="6">
<div :class="{ 'text-h4': dialogMode, 'text-wrap': true }">
{{ tt(title) }}
</div>
</v-col>
<v-col cols="6" class="d-flex align-center">
<v-spacer v-if="!dialogMode"/>
<v-text-field density="compact" :disabled="loading || !hasAnyAvailableAccount"
:prepend-inner-icon="mdiMagnify"
:placeholder="tt('Find account')"
v-model="filterContent"
v-if="dialogMode"></v-text-field>
<v-btn density="comfortable" color="default" variant="text" class="ms-2"
:disabled="loading || !hasAnyAvailableAccount" :icon="true">
<v-icon :icon="mdiDotsVertical" />
<v-menu activator="parent">
<v-list>
<v-list-item :prepend-icon="mdiSelectAll"
:title="tt('Select All')"
:disabled="!hasAnyVisibleAccount"
@click="selectAllAccounts"></v-list-item>
<v-list-item :prepend-icon="mdiSelect"
:title="tt('Select None')"
:disabled="!hasAnyVisibleAccount"
@click="selectNoneAccounts"></v-list-item>
<v-list-item :prepend-icon="mdiSelectInverse"
:title="tt('Invert Selection')"
:disabled="!hasAnyVisibleAccount"
@click="selectInvertAccounts"></v-list-item>
<v-divider class="my-2" v-if="allowHiddenAccount"/>
<v-list-item :prepend-icon="mdiEyeOutline"
:title="tt('Show Hidden Accounts')"
v-if="allowHiddenAccount && !showHidden" @click="showHidden = true"></v-list-item>
<v-list-item :prepend-icon="mdiEyeOffOutline"
:title="tt('Hide Hidden Accounts')"
v-if="allowHiddenAccount && showHidden" @click="showHidden = false"></v-list-item>
</v-list>
</v-menu>
</v-btn>
</v-col>
</v-row>
</template>
<div v-if="loading">
@@ -92,18 +59,17 @@
<v-expansion-panel :key="accountCategory.category"
:value="accountCategory.category"
class="border"
v-for="accountCategory in allCategorizedAccounts"
v-show="showHidden || accountCategory.allVisibleAccountCount > 0">
v-for="accountCategory in allCategorizedAccounts">
<v-expansion-panel-title class="expand-panel-title-with-bg py-0">
<span class="ms-3">{{ tt(accountCategory.name) }}</span>
</v-expansion-panel-title>
<v-expansion-panel-text>
<v-list rounded density="comfortable" class="pa-0">
<template :key="account.id"
v-for="(account, idx) in accountCategory.allAccounts">
<v-divider v-if="showHidden ? idx > 0 : (!account.hidden ? idx > accountCategory.firstVisibleAccountIndex : false)"/>
v-for="(account, idx) in accountCategory.accounts">
<v-divider v-if="idx > 0"/>
<v-list-item v-if="showHidden || !account.hidden">
<v-list-item>
<template #prepend>
<v-checkbox :model-value="isAccountOrSubAccountsAllChecked(account, filterAccountIds)"
:indeterminate="isAccountOrSubAccountsHasButNotAllChecked(account, filterAccountIds)"
@@ -117,13 +83,13 @@
</template>
</v-list-item>
<v-divider v-if="(showHidden || !account.hidden) && account.type === AccountType.MultiSubAccounts.type && ((showHidden && accountCategory.allSubAccounts[account.id]) || accountCategory.allVisibleSubAccountCounts[account.id])"/>
<v-divider v-if="account.type === AccountType.MultiSubAccounts.type && account.subAccounts && account.subAccounts.length > 0"/>
<v-list rounded density="comfortable" class="pa-0 ms-4"
v-if="(showHidden || !account.hidden) && account.type === AccountType.MultiSubAccounts.type && ((showHidden && accountCategory.allSubAccounts[account.id]) || accountCategory.allVisibleSubAccountCounts[account.id])">
v-if="account.type === AccountType.MultiSubAccounts.type && account.subAccounts && account.subAccounts.length > 0">
<template :key="subAccount.id"
v-for="(subAccount, subIdx) in accountCategory.allSubAccounts[account.id]">
<v-divider v-if="showHidden ? subIdx > 0 : (!subAccount.hidden ? subIdx > (accountCategory.allFirstVisibleSubAccountIndexes[account.id] as number) : false)"/>
v-for="(subAccount, subIdx) in account.subAccounts">
<v-divider v-if="subIdx > 0"/>
<v-list-item v-if="showHidden || !subAccount.hidden">
<template #prepend>
@@ -148,7 +114,7 @@
<v-card-text class="overflow-y-visible" v-if="dialogMode">
<div class="w-100 d-flex justify-center flex-wrap mt-sm-1 mt-md-2 gap-4">
<v-btn :disabled="!hasAnyVisibleAccount" @click="save">{{ tt(applyText) }}</v-btn>
<v-btn :disabled="!hasAnyAvailableAccount" @click="save">{{ tt(applyText) }}</v-btn>
<v-btn color="secondary" variant="tonal" @click="cancel">{{ tt('Cancel') }}</v-btn>
</div>
</v-card-text>
@@ -175,7 +141,6 @@ import type { Account } from '@/models/account.ts';
import {
selectAccountOrSubAccounts,
selectAllVisible,
selectAll,
selectNone,
selectInvert,
@@ -184,6 +149,7 @@ import {
} from '@/lib/account.ts';
import {
mdiMagnify,
mdiSelectAll,
mdiSelect,
mdiSelectInverse,
@@ -209,11 +175,13 @@ const { tt } = useI18n();
const {
loading,
showHidden,
filterContent,
filterAccountIds,
title,
applyText,
allowHiddenAccount,
allCategorizedAccounts,
allVisibleAccountMap,
hasAnyAvailableAccount,
hasAnyVisibleAccount,
isAccountChecked,
@@ -262,7 +230,7 @@ function updateAccountSelected(account: Account, value: boolean | null): void {
}
function selectAllAccounts(): void {
selectAll(filterAccountIds.value, accountsStore.allAccountsMap, !allowHiddenAccount.value);
selectAll(filterAccountIds.value, allVisibleAccountMap.value);
if (props.autoSave) {
save();
@@ -270,7 +238,7 @@ function selectAllAccounts(): void {
}
function selectNoneAccounts(): void {
selectNone(filterAccountIds.value, accountsStore.allAccountsMap, !allowHiddenAccount.value);
selectNone(filterAccountIds.value, allVisibleAccountMap.value);
if (props.autoSave) {
save();
@@ -278,15 +246,7 @@ function selectNoneAccounts(): void {
}
function selectInvertAccounts(): void {
selectInvert(filterAccountIds.value, accountsStore.allAccountsMap, !allowHiddenAccount.value);
if (props.autoSave) {
save();
}
}
function selectAllVisibleAccounts(): void {
selectAllVisible(filterAccountIds.value, accountsStore.allAccountsMap);
selectInvert(filterAccountIds.value, allVisibleAccountMap.value);
if (props.autoSave) {
save();
@@ -1,12 +1,22 @@
<template>
<f7-page @page:afterin="onPageAfterIn">
<f7-page with-subnavbar @page:beforein="onPageBeforeIn" @page:afterin="onPageAfterIn">
<f7-navbar>
<f7-nav-left :back-link="tt('Back')"></f7-nav-left>
<f7-nav-title :title="tt(title)"></f7-nav-title>
<f7-nav-right class="navbar-compact-icons">
<f7-link icon-f7="ellipsis" :class="{ 'disabled': !hasAnyAvailableAccount }" @click="showMoreActionSheet = true"></f7-link>
<f7-link icon-f7="checkmark_alt" :class="{ 'disabled': !hasAnyVisibleAccount }" @click="save"></f7-link>
<f7-link icon-f7="checkmark_alt" :class="{ 'disabled': !hasAnyAvailableAccount }" @click="save"></f7-link>
</f7-nav-right>
<f7-subnavbar :inner="false">
<f7-searchbar
custom-searchs
:value="filterContent"
:placeholder="tt('Find account')"
:disable-button-text="tt('Cancel')"
@change="filterContent = $event.target.value"
></f7-searchbar>
</f7-subnavbar>
</f7-navbar>
<div class="skeleton-text" v-if="loading">
@@ -45,8 +55,7 @@
<f7-block class="no-margin no-padding" v-show="!loading && hasAnyVisibleAccount">
<f7-block class="combination-list-wrapper margin-vertical"
:key="accountCategory.category"
v-for="accountCategory in allCategorizedAccounts"
v-show="showHidden || accountCategory.allVisibleAccountCount > 0">
v-for="accountCategory in allCategorizedAccounts">
<f7-accordion-item :opened="collapseStates[accountCategory.category]!.opened"
@accordion:open="collapseStates[accountCategory.category]!.opened = true"
@accordion:close="collapseStates[accountCategory.category]!.opened = false">
@@ -65,14 +74,13 @@
<f7-accordion-content :style="{ height: collapseStates[accountCategory.category]!.opened ? 'auto' : '' }">
<f7-list strong inset dividers accordion-list class="combination-list-content">
<f7-list-item checkbox
:class="{ 'has-child-list-item': account.type === AccountType.MultiSubAccounts.type && ((showHidden && accountCategory.allSubAccounts[account.id]) || accountCategory.allVisibleSubAccountCounts[account.id]) }"
:class="{ 'has-child-list-item': account.type === AccountType.MultiSubAccounts.type && account.subAccounts && account.subAccounts.length > 0 }"
:title="account.name"
:value="account.id"
:checked="isAccountOrSubAccountsAllChecked(account, filterAccountIds)"
:indeterminate="isAccountOrSubAccountsHasButNotAllChecked(account, filterAccountIds)"
:key="account.id"
v-for="account in accountCategory.allAccounts"
v-show="showHidden || !account.hidden"
v-for="account in accountCategory.accounts"
@change="updateAccountOrSubAccountsSelected">
<template #media>
<ItemIcon icon-type="account" :icon-id="account.icon" :color="account.color">
@@ -84,14 +92,13 @@
<template #root>
<ul class="padding-inline-start"
v-if="account.type === AccountType.MultiSubAccounts.type && ((showHidden && accountCategory.allSubAccounts[account.id]) || accountCategory.allVisibleSubAccountCounts[account.id])">
v-if="account.type === AccountType.MultiSubAccounts.type && account.subAccounts && account.subAccounts.length > 0">
<f7-list-item checkbox
:title="subAccount.name"
:value="subAccount.id"
:checked="isAccountChecked(subAccount, filterAccountIds)"
:key="subAccount.id"
v-for="subAccount in accountCategory.allSubAccounts[account.id]"
v-show="showHidden || !subAccount.hidden"
v-for="subAccount in account.subAccounts"
@change="updateAccountSelected">
<template #media>
<ItemIcon icon-type="account" :icon-id="subAccount.icon" :color="subAccount.color">
@@ -116,9 +123,6 @@
<f7-actions-button :class="{ 'disabled': !hasAnyVisibleAccount }" @click="selectNoneAccounts">{{ tt('Select None') }}</f7-actions-button>
<f7-actions-button :class="{ 'disabled': !hasAnyVisibleAccount }" @click="selectInvertAccounts">{{ tt('Invert Selection') }}</f7-actions-button>
</f7-actions-group>
<f7-actions-group v-if="allowHiddenAccount">
<f7-actions-button :class="{ 'disabled': !hasAnyVisibleAccount }" @click="selectAllVisibleAccounts">{{ tt('Select All Visible') }}</f7-actions-button>
</f7-actions-group>
<f7-actions-group v-if="allowHiddenAccount">
<f7-actions-button v-if="!showHidden" @click="showHidden = true">{{ tt('Show Hidden Accounts') }}</f7-actions-button>
<f7-actions-button v-if="showHidden" @click="showHidden = false">{{ tt('Hide Hidden Accounts') }}</f7-actions-button>
@@ -146,7 +150,6 @@ import { useAccountsStore } from '@/stores/account.ts';
import { AccountType, AccountCategory } from '@/core/account.ts';
import {
selectAccountOrSubAccounts,
selectAllVisible,
selectAll,
selectNone,
selectInvert,
@@ -171,10 +174,12 @@ const { showToast, routeBackOnError } = useI18nUIComponents();
const {
loading,
showHidden,
filterContent,
filterAccountIds,
title,
allowHiddenAccount,
allCategorizedAccounts,
allVisibleAccountMap,
hasAnyAvailableAccount,
hasAnyVisibleAccount,
isAccountChecked,
@@ -224,7 +229,7 @@ function init(): void {
function updateAccountOrSubAccountsSelected(e: Event): void {
const target = e.target as HTMLInputElement;
const accountId = target.value;
const account = accountsStore.allAccountsMap[accountId];
const account = allVisibleAccountMap.value[accountId];
if (!account) {
return;
@@ -236,7 +241,7 @@ function updateAccountOrSubAccountsSelected(e: Event): void {
function updateAccountSelected(e: Event): void {
const target = e.target as HTMLInputElement;
const accountId = target.value;
const account = accountsStore.allAccountsMap[accountId];
const account = allVisibleAccountMap.value[accountId];
if (!account) {
return;
@@ -246,19 +251,15 @@ function updateAccountSelected(e: Event): void {
}
function selectAllAccounts(): void {
selectAll(filterAccountIds.value, accountsStore.allAccountsMap, !allowHiddenAccount.value);
selectAll(filterAccountIds.value, allVisibleAccountMap.value);
}
function selectNoneAccounts(): void {
selectNone(filterAccountIds.value, accountsStore.allAccountsMap, !allowHiddenAccount.value);
selectNone(filterAccountIds.value, allVisibleAccountMap.value);
}
function selectInvertAccounts(): void {
selectInvert(filterAccountIds.value, accountsStore.allAccountsMap, !allowHiddenAccount.value);
}
function selectAllVisibleAccounts(): void {
selectAllVisible(filterAccountIds.value, accountsStore.allAccountsMap);
selectInvert(filterAccountIds.value, allVisibleAccountMap.value);
}
function save(): void {
@@ -266,6 +267,10 @@ function save(): void {
props.f7router.back();
}
function onPageBeforeIn(): void {
filterContent.value = '';
}
function onPageAfterIn(): void {
routeBackOnError(props.f7router, loadingError);
}