mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-17 00:12:11 +08:00
batch adding transaction tags in import transaction tool
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
<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 === 'batchAdd' && type === 'tag'">{{ tt('Batch Add 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>
|
||||
@@ -189,7 +190,7 @@
|
||||
</template>
|
||||
</v-autocomplete>
|
||||
</v-col>
|
||||
<v-col cols="12" class="pt-0">
|
||||
<v-col cols="12" class="pt-0" v-if="mode === 'batchReplace' || mode === 'replaceInvalidItems'">
|
||||
<v-switch :disabled="loading"
|
||||
:label="tt('Remove Tag')" v-model="removeTag"/>
|
||||
</v-col>
|
||||
@@ -235,7 +236,7 @@ import {
|
||||
mdiPound
|
||||
} from '@mdi/js';
|
||||
|
||||
export type BatchReplaceDialogMode = 'batchReplace' | 'replaceInvalidItems';
|
||||
export type BatchReplaceDialogMode = 'batchReplace' | 'batchAdd' | 'replaceInvalidItems';
|
||||
export type BatchReplaceDialogDataType = 'expenseCategory' | 'incomeCategory' | 'transferCategory' | 'account' | 'destinationAccount' | 'tag';
|
||||
|
||||
type SnackBarType = InstanceType<typeof SnackBar>;
|
||||
@@ -291,10 +292,10 @@ function open(options: { mode: BatchReplaceDialogMode; type: BatchReplaceDialogD
|
||||
type.value = options.type;
|
||||
sourceItem.value = undefined;
|
||||
|
||||
if (mode.value === 'batchReplace') {
|
||||
invalidItems.value = undefined;
|
||||
} else if (mode.value === 'replaceInvalidItems') {
|
||||
if (mode.value === 'replaceInvalidItems') {
|
||||
invalidItems.value = options.invalidItems;
|
||||
} else {
|
||||
invalidItems.value = undefined;
|
||||
}
|
||||
|
||||
if (type.value === 'tag' && mode.value === 'batchReplace') {
|
||||
@@ -369,6 +370,10 @@ function confirm(): void {
|
||||
sourceItem: sourceItem.value,
|
||||
targetItem: targetItemValue
|
||||
});
|
||||
} else if (mode.value === 'batchAdd') {
|
||||
resolveFunc?.({
|
||||
targetItem: targetItemValue
|
||||
});
|
||||
} else if (mode.value === 'replaceInvalidItems') {
|
||||
resolveFunc?.({
|
||||
sourceItem: sourceItem.value,
|
||||
|
||||
@@ -671,6 +671,12 @@ const toolMenus = computed<ImportTransactionCheckDataMenu[]>(() => [
|
||||
disabled: isEditing.value || selectedImportTransactionCount.value < 1,
|
||||
onClick: () => showBatchReplaceDialog('tag', allOriginalTransactionTagNames.value)
|
||||
},
|
||||
{
|
||||
prependIcon: mdiFindReplace,
|
||||
title: tt('Batch Add Transaction Tags'),
|
||||
disabled: isEditing.value || selectedImportTransactionCount.value < 1,
|
||||
onClick: () => showBatchAddDialog('tag')
|
||||
},
|
||||
{
|
||||
prependIcon: mdiFindReplace,
|
||||
title: tt('Replace Invalid Expense Categories'),
|
||||
@@ -1485,7 +1491,7 @@ function showBatchReplaceDialog(type: BatchReplaceDialogDataType, allSourceTagIt
|
||||
updated = true;
|
||||
}
|
||||
} else if (type === 'tag') {
|
||||
let removeIndex: number[] = [];
|
||||
const removeIndex: number[] = [];
|
||||
|
||||
for (let tagIndex = 0; tagIndex < importTransaction.originalTagNames.length; tagIndex++) {
|
||||
const originalTagName = importTransaction.originalTagNames ? (importTransaction.originalTagNames[tagIndex] ?? '') : '';
|
||||
@@ -1522,6 +1528,69 @@ function showBatchReplaceDialog(type: BatchReplaceDialogDataType, allSourceTagIt
|
||||
});
|
||||
}
|
||||
|
||||
function showBatchAddDialog(type: BatchReplaceDialogDataType): void {
|
||||
if (isEditing.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
batchReplaceDialog.value?.open({
|
||||
mode: 'batchAdd',
|
||||
type: type
|
||||
}).then(result => {
|
||||
if (!result || !result.targetItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
let updatedCount = 0;
|
||||
|
||||
if (props.importTransactions) {
|
||||
for (const importTransaction of props.importTransactions) {
|
||||
if (!importTransaction.selected) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let updated = false;
|
||||
|
||||
if (type === 'tag') {
|
||||
let containsTag = false;
|
||||
|
||||
for (const tagName of importTransaction.originalTagNames) {
|
||||
if (tagName === result.targetItem) {
|
||||
containsTag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!containsTag) {
|
||||
if (!importTransaction.tagIds) {
|
||||
importTransaction.tagIds = [];
|
||||
}
|
||||
|
||||
if (!importTransaction.originalTagNames) {
|
||||
importTransaction.originalTagNames = [];
|
||||
}
|
||||
|
||||
importTransaction.tagIds.push(result.targetItem);
|
||||
importTransaction.originalTagNames.push(allTagsMap.value[result.targetItem]?.name ?? '');
|
||||
updated = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (updated) {
|
||||
updatedCount++;
|
||||
updateTransactionData(importTransaction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (updatedCount > 0) {
|
||||
snackbar.value?.showMessage('format.misc.youHaveUpdatedTransactions', {
|
||||
count: getDisplayCount(updatedCount)
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function showReplaceInvalidItemDialog(type: BatchReplaceDialogDataType, invalidItems: NameValue[]): void {
|
||||
if (isEditing.value) {
|
||||
return;
|
||||
@@ -1584,7 +1653,7 @@ function showReplaceInvalidItemDialog(type: BatchReplaceDialogDataType, invalidI
|
||||
updated = true;
|
||||
}
|
||||
} else if (type === 'tag' && importTransaction.tagIds) {
|
||||
let removeIndex: number[] = [];
|
||||
const removeIndex: number[] = [];
|
||||
|
||||
for (let tagIndex = 0; tagIndex < importTransaction.tagIds.length; tagIndex++) {
|
||||
const tagId = importTransaction.tagIds[tagIndex] as string;
|
||||
|
||||
Reference in New Issue
Block a user