batch removing specified tag or batch removing invalid tag in import transaction tool

This commit is contained in:
MaysWind
2025-09-13 22:35:18 +08:00
parent 77d2426c14
commit 422cf49517
14 changed files with 172 additions and 23 deletions
@@ -8,6 +8,7 @@
<h4 class="text-h4" v-if="mode === 'batchReplace' && type === 'transferCategory'">{{ tt('Batch Replace Selected Transfer Categories') }}</h4>
<h4 class="text-h4" v-if="mode === 'batchReplace' && type === 'account'">{{ tt('Batch Replace Selected Accounts') }}</h4>
<h4 class="text-h4" v-if="mode === 'batchReplace' && type === 'destinationAccount'">{{ tt('Batch Replace Selected Destination Accounts') }}</h4>
<h4 class="text-h4" v-if="mode === 'batchReplace' && type === 'tag'">{{ tt('Batch Replace Selected Transaction Tags') }}</h4>
<h4 class="text-h4" v-if="mode === 'replaceInvalidItems' && type === 'expenseCategory'">{{ tt('Replace Invalid Expense Categories') }}</h4>
<h4 class="text-h4" v-if="mode === 'replaceInvalidItems' && type === 'incomeCategory'">{{ tt('Replace Invalid Income Categories') }}</h4>
<h4 class="text-h4" v-if="mode === 'replaceInvalidItems' && type === 'transferCategory'">{{ tt('Replace Invalid Transfer Categories') }}</h4>
@@ -131,6 +132,19 @@
</v-card-text>
<v-card-text class="my-md-4 w-100 d-flex justify-center" v-if="type === 'tag'">
<v-row>
<v-col cols="12" v-if="mode === 'batchReplace'">
<v-autocomplete
item-title="name"
item-value="value"
persistent-placeholder
:disabled="loading"
:label="tt('Source Value')"
:placeholder="tt('Source Value')"
:items="allSourceTagItems"
:no-data-text="tt('No available tag')"
v-model="sourceItem">
</v-autocomplete>
</v-col>
<v-col cols="12" v-if="mode === 'replaceInvalidItems'">
<v-autocomplete
item-title="name"
@@ -150,7 +164,7 @@
item-value="id"
persistent-placeholder
chips
:disabled="loading"
:disabled="loading || removeTag"
:label="tt('Target Tag')"
:placeholder="tt('Target Tag')"
:items="allTags"
@@ -175,11 +189,15 @@
</template>
</v-autocomplete>
</v-col>
<v-col cols="12" class="pt-0">
<v-switch :disabled="loading"
:label="tt('Remove Tag')" v-model="removeTag"/>
</v-col>
</v-row>
</v-card-text>
<v-card-text class="overflow-y-visible">
<div class="w-100 d-flex justify-center gap-4">
<v-btn :disabled="loading || (mode === 'replaceInvalidItems' && !sourceItem && sourceItem !== '') || (!targetItem && targetItem !== '')" @click="confirm">{{ tt('OK') }}</v-btn>
<v-btn :disabled="loading || ((mode === 'replaceInvalidItems' || (mode === 'batchReplace' && type === 'tag')) && !sourceItem && sourceItem !== '') || (!targetItem && targetItem !== '' && !removeTag)" @click="confirm">{{ tt('OK') }}</v-btn>
<v-btn color="secondary" variant="tonal" :disabled="loading" @click="cancel">{{ tt('Cancel') }}</v-btn>
</div>
</v-card-text>
@@ -192,7 +210,7 @@
<script setup lang="ts">
import SnackBar from '@/components/desktop/SnackBar.vue';
import { ref, computed, useTemplateRef } from 'vue';
import { ref, computed, useTemplateRef, watch } from 'vue';
import { useI18n } from '@/locales/helpers.ts';
@@ -241,8 +259,10 @@ const loading = ref<boolean>(false);
const mode = ref<BatchReplaceDialogMode | ''>('');
const type = ref<BatchReplaceDialogDataType | ''>('');
const invalidItems = ref<NameValue[] | undefined>([]);
const allSourceTagItems = ref<NameValue[] | undefined>([]);
const sourceItem = ref<string | undefined>(undefined);
const targetItem = ref<string | undefined>(undefined);
const removeTag = ref<boolean>(false);
let resolveFunc: ((response: BatchReplaceDialogResponse) => void) | null = null;
let rejectFunc: ((reason?: unknown) => void) | null = null;
@@ -266,7 +286,7 @@ function getAccountDisplayName(accountId?: string): string {
}
}
function open(options: { mode: BatchReplaceDialogMode; type: BatchReplaceDialogDataType; invalidItems?: NameValue[] }): Promise<BatchReplaceDialogResponse> {
function open(options: { mode: BatchReplaceDialogMode; type: BatchReplaceDialogDataType; invalidItems?: NameValue[], allSourceTagItems?: NameValue[] }): Promise<BatchReplaceDialogResponse> {
mode.value = options.mode;
type.value = options.type;
sourceItem.value = undefined;
@@ -277,7 +297,14 @@ function open(options: { mode: BatchReplaceDialogMode; type: BatchReplaceDialogD
invalidItems.value = options.invalidItems;
}
if (type.value === 'tag' && mode.value === 'batchReplace') {
allSourceTagItems.value = options.allSourceTagItems;
} else {
allSourceTagItems.value = undefined;
}
targetItem.value = undefined;
removeTag.value = false;
showState.value = true;
return new Promise((resolve, reject) => {
@@ -327,14 +354,25 @@ function reload(): void {
}
function confirm(): void {
if (mode.value === 'batchReplace') {
let targetItemValue: string | undefined = targetItem.value;
if (type.value === 'tag' && removeTag.value) {
targetItemValue = undefined;
}
if (mode.value === 'batchReplace' && type.value !== 'tag') {
resolveFunc?.({
targetItem: targetItem.value
targetItem: targetItemValue
});
} else if (mode.value === 'batchReplace' && type.value === 'tag') {
resolveFunc?.({
sourceItem: sourceItem.value,
targetItem: targetItemValue
});
} else if (mode.value === 'replaceInvalidItems') {
resolveFunc?.({
sourceItem: sourceItem.value,
targetItem: targetItem.value
targetItem: targetItemValue
});
}
@@ -346,6 +384,12 @@ function cancel(): void {
showState.value = false;
}
watch(removeTag, (newValue) => {
if (newValue) {
targetItem.value = undefined;
}
});
defineExpose({
open
});