remember last selected file type in import transaction dialog (#412)

This commit is contained in:
MaysWind
2026-01-05 00:48:47 +08:00
parent c64b4502cb
commit 9a037ace5a
26 changed files with 201 additions and 4 deletions
@@ -13,6 +13,7 @@ export interface CategorizedApplicationCloudSettingItems {
export interface ApplicationCloudSettingItem {
readonly settingKey: string;
readonly relatedSettingKeys?: string[];
readonly settingName: string;
readonly mobile: boolean;
readonly desktop: boolean;
@@ -50,6 +51,12 @@ export const ALL_APPLICATION_CLOUD_SETTINGS: CategorizedApplicationCloudSettingI
{ settingKey: 'alwaysShowTransactionPicturesInMobileTransactionEditPage', settingName: 'Always Show Transaction Pictures', mobile: true, desktop: false }
]
},
{
categoryName: 'Import Transaction Dialog',
items: [
{ settingKey: 'rememberLastSelectedFileTypeInImportTransactionDialog', relatedSettingKeys: ['lastSelectedFileTypeInImportTransactionDialog'], settingName: 'Remember Last Selected File Type', mobile: false, desktop: true }
]
},
{
categoryName: 'Insights Explorer Page',
items: [
@@ -161,6 +168,22 @@ export function useAppCloudSyncBase() {
function updateSettingsSelected(categorizedItems: CategorizedApplicationCloudSettingItems, value: boolean): void {
for (const item of categorizedItems.items) {
enabledApplicationCloudSettings.value[item.settingKey] = value;
if (item.relatedSettingKeys) {
for (const relatedKey of item.relatedSettingKeys) {
enabledApplicationCloudSettings.value[relatedKey] = value;
}
}
}
}
function updateSettingSelected(settingItem: ApplicationCloudSettingItem, value: boolean): void {
enabledApplicationCloudSettings.value[settingItem.settingKey] = value;
if (settingItem.relatedSettingKeys) {
for (const relatedKey of settingItem.relatedSettingKeys) {
enabledApplicationCloudSettings.value[relatedKey] = value;
}
}
}
@@ -168,6 +191,12 @@ export function useAppCloudSyncBase() {
for (const categorizedItems of ALL_APPLICATION_CLOUD_SETTINGS) {
for (const item of categorizedItems.items) {
enabledApplicationCloudSettings.value[item.settingKey] = true;
if (item.relatedSettingKeys) {
for (const relatedKey of item.relatedSettingKeys) {
enabledApplicationCloudSettings.value[relatedKey] = true;
}
}
}
}
}
@@ -176,6 +205,12 @@ export function useAppCloudSyncBase() {
for (const categorizedItems of ALL_APPLICATION_CLOUD_SETTINGS) {
for (const item of categorizedItems.items) {
enabledApplicationCloudSettings.value[item.settingKey] = false;
if (item.relatedSettingKeys) {
for (const relatedKey of item.relatedSettingKeys) {
enabledApplicationCloudSettings.value[relatedKey] = false;
}
}
}
}
}
@@ -183,7 +218,14 @@ export function useAppCloudSyncBase() {
function selectInvertSettings(): void {
for (const categorizedItems of ALL_APPLICATION_CLOUD_SETTINGS) {
for (const item of categorizedItems.items) {
enabledApplicationCloudSettings.value[item.settingKey] = !enabledApplicationCloudSettings.value[item.settingKey];
const newValue = !enabledApplicationCloudSettings.value[item.settingKey];
enabledApplicationCloudSettings.value[item.settingKey] = newValue;
if (item.relatedSettingKeys) {
for (const relatedKey of item.relatedSettingKeys) {
enabledApplicationCloudSettings.value[relatedKey] = newValue;
}
}
}
}
}
@@ -219,6 +261,7 @@ export function useAppCloudSyncBase() {
isAllSettingsSelected,
hasSettingSelectedButNotAllChecked,
updateSettingsSelected,
updateSettingSelected,
selectAllSettings,
selectNoneSettings,
selectInvertSettings,
@@ -224,6 +224,28 @@
</v-card>
</v-col>
<v-col cols="12">
<v-card :title="tt('Import Transaction Dialog')">
<v-form>
<v-card-text>
<v-row>
<v-col cols="12" md="6">
<v-select
item-title="displayName"
item-value="value"
persistent-placeholder
:label="tt('Remember Last Selected File Type')"
:placeholder="tt('Remember Last Selected File Type')"
:items="enableDisableOptions"
v-model="rememberLastSelectedFileTypeInImportTransactionDialog"
/>
</v-col>
</v-row>
</v-card-text>
</v-form>
</v-card>
</v-col>
<v-col cols="12">
<v-card :title="tt('Insights Explorer Page')">
<v-form>
@@ -441,6 +463,11 @@ const showAddTransactionButtonInDesktopNavbar = computed<boolean>({
set: (value) => settingsStore.setShowAddTransactionButtonInDesktopNavbar(value)
});
const rememberLastSelectedFileTypeInImportTransactionDialog = computed<boolean>({
get: () => settingsStore.appSettings.rememberLastSelectedFileTypeInImportTransactionDialog,
set: (value) => settingsStore.setRememberLastSelectedFileTypeInImportTransactionDialog(value)
});
const insightsExplorerDefaultDateRangeType = computed<number>({
get: () => settingsStore.appSettings.insightsExplorerDefaultDateRangeType,
set: (value) => settingsStore.setInsightsExplorerDefaultDateRangeType(value)
@@ -82,7 +82,7 @@
<template #prepend>
<v-checkbox :disabled="loading || enabling || disabling"
:model-value="enabledApplicationCloudSettings[settingItem.settingKey]"
@update:model-value="enabledApplicationCloudSettings[settingItem.settingKey] = !!$event">
@update:model-value="updateSettingSelected(settingItem, !!$event)">
<template #label>
<span>{{ tt(settingItem.settingName) }}</span>
<v-icon class="ms-2 me-0" start size="16" :icon="mdiCellphone" v-if="settingItem.mobile"/>
@@ -159,6 +159,7 @@ const {
isAllSettingsSelected,
hasSettingSelectedButNotAllChecked,
updateSettingsSelected,
updateSettingSelected,
selectAllSettings,
selectNoneSettings,
selectInvertSettings,
@@ -278,6 +278,7 @@ import { ref, computed, useTemplateRef, watch } from 'vue';
import { useI18n } from '@/locales/helpers.ts';
import { useSettingsStore } from '@/stores/setting.ts';
import { useAccountsStore } from '@/stores/account.ts';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts';
import { useTransactionTagsStore } from '@/stores/transactionTag.ts';
@@ -339,6 +340,7 @@ const {
getLocalizedFileEncodingName
} = useI18n();
const settingsStore = useSettingsStore();
const accountsStore = useAccountsStore();
const transactionCategoriesStore = useTransactionCategoriesStore();
const transactionTagsStore = useTransactionTagsStore();
@@ -545,9 +547,52 @@ function getDisplayCount(count: number): string {
return numeralSystem.value.formatNumber(count);
}
function loadInitFileTypeFromSettings(): void {
if (!settingsStore.appSettings.lastSelectedFileTypeInImportTransactionDialog) {
return;
}
const lastSelectedFileTypes = settingsStore.appSettings.lastSelectedFileTypeInImportTransactionDialog.split('|');
const lastSelectedFileType = lastSelectedFileTypes[0];
if (!lastSelectedFileType || !allSupportedImportFileTypesMap.value[lastSelectedFileType]) {
return;
}
fileType.value = lastSelectedFileType;
const fileSubTypes = allSupportedImportFileTypesMap.value[lastSelectedFileType].subTypes;
if (!fileSubTypes || fileSubTypes.length < 1) {
return;
}
const lastSelectedFileSubType = lastSelectedFileTypes[1];
if (lastSelectedFileSubType) {
for (const subType of fileSubTypes) {
if (subType.type === lastSelectedFileSubType) {
fileSubType.value = lastSelectedFileSubType;
return;
}
}
}
const firstFileSubType = fileSubTypes[0];
if (firstFileSubType) {
fileSubType.value = firstFileSubType.type;
}
}
function open(): Promise<void> {
fileType.value = 'ezbookkeeping';
fileSubType.value = 'ezbookkeeping_csv';
if (settingsStore.appSettings.rememberLastSelectedFileTypeInImportTransactionDialog && settingsStore.appSettings.lastSelectedFileTypeInImportTransactionDialog) {
loadInitFileTypeFromSettings();
}
fileEncoding.value = 'auto';
detectingFileEncoding.value = false;
autoDetectedFileEncoding.value = undefined;
@@ -912,9 +957,13 @@ function close(completed: boolean): void {
showState.value = false;
}
watch(fileType, () => {
watch(fileType, (newValue) => {
if (allFileSubTypes.value && allFileSubTypes.value.length) {
fileSubType.value = allFileSubTypes.value[0]!.type;
} else {
if (settingsStore.appSettings.rememberLastSelectedFileTypeInImportTransactionDialog) {
settingsStore.setLastSelectedFileTypeInImportTransactionDialog(`${newValue}|`);
}
}
importFile.value = null;
@@ -924,6 +973,10 @@ watch(fileType, () => {
});
watch(fileSubType, (newValue) => {
if (settingsStore.appSettings.rememberLastSelectedFileTypeInImportTransactionDialog) {
settingsStore.setLastSelectedFileTypeInImportTransactionDialog(`${fileType.value}|${newValue}`);
}
let supportedExtensions: string | undefined = findExtensionByType(allFileSubTypes.value, newValue);
if (!supportedExtensions) {
@@ -38,7 +38,7 @@
:checked="enabledApplicationCloudSettings[settingItem.settingKey]"
:key="settingItem.settingKey"
v-for="settingItem in categorizedItems.items"
@change="enabledApplicationCloudSettings[settingItem.settingKey] = $event.target.checked">
@change="updateSettingSelected(settingItem, $event.target.checked)">
<template #after>
<f7-icon class="synchronized-settings-device-icon" f7="device_phone_portrait" v-if="settingItem.mobile"></f7-icon>
<f7-icon class="synchronized-settings-device-icon" f7="device_desktop" v-if="settingItem.desktop"></f7-icon>
@@ -115,6 +115,7 @@ const {
isAllSettingsSelected,
hasSettingSelectedButNotAllChecked,
updateSettingsSelected,
updateSettingSelected,
selectAllSettings,
selectNoneSettings,
selectInvertSettings,