mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-20 17:54:30 +08:00
change csv and tsv to subtypes when importing ezbookkeeping exported files in import transaction dialog
This commit is contained in:
+15
-12
@@ -2,18 +2,21 @@ const supportedImageExtensions = '.jpg,.jpeg,.png,.gif,.webp';
|
|||||||
|
|
||||||
const supportedImportFileTypes = [
|
const supportedImportFileTypes = [
|
||||||
{
|
{
|
||||||
type: 'ezbookkeeping_csv',
|
type: 'ezbookkeeping',
|
||||||
name: 'ezbookkeeping Data Export File (CSV)',
|
name: 'ezbookkeeping Data Export File',
|
||||||
extensions: '.csv',
|
extensions: '.csv,.tsv',
|
||||||
document: {
|
subTypes: [
|
||||||
supportMultiLanguages: true,
|
{
|
||||||
anchor: 'export-transactions'
|
type: 'ezbookkeeping_csv',
|
||||||
}
|
name: 'CSV (Comma-separated values) File',
|
||||||
},
|
extensions: '.csv',
|
||||||
{
|
},
|
||||||
type: 'ezbookkeeping_tsv',
|
{
|
||||||
name: 'ezbookkeeping Data Export File (TSV)',
|
type: 'ezbookkeeping_tsv',
|
||||||
extensions: '.tsv',
|
name: 'TSV (Tab-separated values) File',
|
||||||
|
extensions: '.tsv',
|
||||||
|
}
|
||||||
|
],
|
||||||
document: {
|
document: {
|
||||||
supportMultiLanguages: true,
|
supportMultiLanguages: true,
|
||||||
anchor: 'export-transactions'
|
anchor: 'export-transactions'
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import { isString } from './common.js';
|
||||||
|
|
||||||
|
export function getFileExtension(filename) {
|
||||||
|
if (!filename || !isString(filename)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
const parts = filename.split('.');
|
||||||
|
return parts[parts.length - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isFileExtensionSupported(filename, supportedExtensions) {
|
||||||
|
if (!supportedExtensions) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const supportedExtensionsArray = supportedExtensions.split(',');
|
||||||
|
const fileExtension = getFileExtension(filename).toLowerCase();
|
||||||
|
|
||||||
|
for (let i = 0; i < supportedExtensionsArray.length; i++) {
|
||||||
|
const supportedExtension = getFileExtension(supportedExtensionsArray[i]).toLowerCase();
|
||||||
|
|
||||||
|
if (supportedExtension === fileExtension) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
@@ -1308,6 +1308,7 @@ function getAllSupportedImportFileTypes(i18nGlobal, translateFn) {
|
|||||||
subTypes.push({
|
subTypes.push({
|
||||||
type: subType.type,
|
type: subType.type,
|
||||||
displayName: translateFn(subType.name),
|
displayName: translateFn(subType.name),
|
||||||
|
extensions: subType.extensions
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1244,6 +1244,7 @@
|
|||||||
"Time": "Time",
|
"Time": "Time",
|
||||||
"Color": "Color",
|
"Color": "Color",
|
||||||
"Type": "Type",
|
"Type": "Type",
|
||||||
|
"Format": "Format",
|
||||||
"All Types": "All Types",
|
"All Types": "All Types",
|
||||||
"More": "More",
|
"More": "More",
|
||||||
"All": "All",
|
"All": "All",
|
||||||
@@ -1523,8 +1524,7 @@
|
|||||||
"Data Import Completed": "Data Import Completed",
|
"Data Import Completed": "Data Import Completed",
|
||||||
"File Type": "File Type",
|
"File Type": "File Type",
|
||||||
"How to export this file?": "How to export this file?",
|
"How to export this file?": "How to export this file?",
|
||||||
"ezbookkeeping Data Export File (CSV)": "ezbookkeeping Data Export File (CSV)",
|
"ezbookkeeping Data Export File": "ezbookkeeping Data Export File",
|
||||||
"ezbookkeeping Data Export File (TSV)": "ezbookkeeping Data Export File (TSV)",
|
|
||||||
"Quicken Interchange Format (QIF) File": "Quicken Interchange Format (QIF) File",
|
"Quicken Interchange Format (QIF) File": "Quicken Interchange Format (QIF) File",
|
||||||
"Year-month-day format": "Year-month-day format",
|
"Year-month-day format": "Year-month-day format",
|
||||||
"Month-day-year format": "Month-day-year format",
|
"Month-day-year format": "Month-day-year format",
|
||||||
|
|||||||
@@ -1244,6 +1244,7 @@
|
|||||||
"Time": "时间",
|
"Time": "时间",
|
||||||
"Color": "颜色",
|
"Color": "颜色",
|
||||||
"Type": "类型",
|
"Type": "类型",
|
||||||
|
"Format": "格式",
|
||||||
"All Types": "全部类型",
|
"All Types": "全部类型",
|
||||||
"More": "更多",
|
"More": "更多",
|
||||||
"All": "全部",
|
"All": "全部",
|
||||||
@@ -1523,8 +1524,7 @@
|
|||||||
"Data Import Completed": "数据导入完成",
|
"Data Import Completed": "数据导入完成",
|
||||||
"File Type": "文件类型",
|
"File Type": "文件类型",
|
||||||
"How to export this file?": "如何导出该文件?",
|
"How to export this file?": "如何导出该文件?",
|
||||||
"ezbookkeeping Data Export File (CSV)": "ezbookkeeping 数据导出文件 (CSV)",
|
"ezbookkeeping Data Export File": "ezbookkeeping 数据导出文件",
|
||||||
"ezbookkeeping Data Export File (TSV)": "ezbookkeeping 数据导出文件 (TSV)",
|
|
||||||
"Quicken Interchange Format (QIF) File": "Quicken Interchange Format (QIF) 文件",
|
"Quicken Interchange Format (QIF) File": "Quicken Interchange Format (QIF) 文件",
|
||||||
"Year-month-day format": "年-月-日 格式",
|
"Year-month-day format": "年-月-日 格式",
|
||||||
"Month-day-year format": "月-日-年 格式",
|
"Month-day-year format": "月-日-年 格式",
|
||||||
|
|||||||
@@ -83,8 +83,8 @@
|
|||||||
item-title="displayName"
|
item-title="displayName"
|
||||||
item-value="type"
|
item-value="type"
|
||||||
:disabled="submitting"
|
:disabled="submitting"
|
||||||
:label="$t('Type')"
|
:label="$t('Format')"
|
||||||
:placeholder="$t('Type')"
|
:placeholder="$t('Format')"
|
||||||
:items="allFileSubTypes"
|
:items="allFileSubTypes"
|
||||||
v-model="fileSubType"
|
v-model="fileSubType"
|
||||||
/>
|
/>
|
||||||
@@ -490,6 +490,7 @@ import { useExchangeRatesStore } from '@/stores/exchangeRates.js';
|
|||||||
import categoryConstants from '@/consts/category.js';
|
import categoryConstants from '@/consts/category.js';
|
||||||
import transactionConstants from '@/consts/transaction.js';
|
import transactionConstants from '@/consts/transaction.js';
|
||||||
import { getNameByKeyValue } from '@/lib/common.js';
|
import { getNameByKeyValue } from '@/lib/common.js';
|
||||||
|
import { isFileExtensionSupported } from '@/lib/file.js';
|
||||||
import { generateRandomUUID } from '@/lib/misc.js';
|
import { generateRandomUUID } from '@/lib/misc.js';
|
||||||
import logger from '@/lib/logger.js';
|
import logger from '@/lib/logger.js';
|
||||||
import {
|
import {
|
||||||
@@ -534,8 +535,8 @@ export default {
|
|||||||
showState: false,
|
showState: false,
|
||||||
clientSessionId: '',
|
clientSessionId: '',
|
||||||
currentStep: 'uploadFile',
|
currentStep: 'uploadFile',
|
||||||
fileType: 'ezbookkeeping_csv',
|
fileType: 'ezbookkeeping',
|
||||||
fileSubType: '',
|
fileSubType: 'ezbookkeeping_csv',
|
||||||
importFile: null,
|
importFile: null,
|
||||||
importTransactions: null,
|
importTransactions: null,
|
||||||
editingTransaction: null,
|
editingTransaction: null,
|
||||||
@@ -656,6 +657,14 @@ export default {
|
|||||||
return getTimezoneOffsetMinutes(this.settingsStore.appSettings.timeZone);
|
return getTimezoneOffsetMinutes(this.settingsStore.appSettings.timeZone);
|
||||||
},
|
},
|
||||||
supportedImportFileExtensions() {
|
supportedImportFileExtensions() {
|
||||||
|
if (this.allFileSubTypes && this.allFileSubTypes.length) {
|
||||||
|
const subTypeExtensions = getNameByKeyValue(this.allFileSubTypes, this.fileSubType, 'type', 'extensions');
|
||||||
|
|
||||||
|
if (subTypeExtensions) {
|
||||||
|
return subTypeExtensions;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return getNameByKeyValue(this.allSupportedImportFileTypes, this.fileType, 'type', 'extensions');
|
return getNameByKeyValue(this.allSupportedImportFileTypes, this.fileType, 'type', 'extensions');
|
||||||
},
|
},
|
||||||
exportFileGuideDocumentUrl() {
|
exportFileGuideDocumentUrl() {
|
||||||
@@ -852,12 +861,24 @@ export default {
|
|||||||
this.editingTags = [];
|
this.editingTags = [];
|
||||||
this.currentPage = 1;
|
this.currentPage = 1;
|
||||||
this.countPerPage = 10;
|
this.countPerPage = 10;
|
||||||
|
},
|
||||||
|
fileSubType: function (newValue) {
|
||||||
|
let supportedExtensions = getNameByKeyValue(this.allFileSubTypes, newValue, 'type', 'extensions');
|
||||||
|
|
||||||
|
if (!supportedExtensions) {
|
||||||
|
supportedExtensions = getNameByKeyValue(this.allSupportedImportFileTypes, this.fileType, 'type', 'extensions');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.importFile && this.importFile.name && !isFileExtensionSupported(this.importFile.name, supportedExtensions)) {
|
||||||
|
this.importFile = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
open() {
|
open() {
|
||||||
const self = this;
|
const self = this;
|
||||||
self.fileType = 'ezbookkeeping_csv';
|
self.fileType = 'ezbookkeeping';
|
||||||
|
self.fileSubType = 'ezbookkeeping_csv';
|
||||||
self.currentStep = 'uploadFile';
|
self.currentStep = 'uploadFile';
|
||||||
self.importFile = null;
|
self.importFile = null;
|
||||||
self.importTransactions = null;
|
self.importTransactions = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user