Browse Source

feat(nc-gui): templateGenerator logic for excel & json

pull/4135/head
Wing-Kam Wong 2 years ago
parent
commit
9732debc4b
  1. 27
      packages/nc-gui/components/dlg/QuickImport.vue

27
packages/nc-gui/components/dlg/QuickImport.vue

@ -146,7 +146,7 @@ async function handlePreImport() {
isParsingData.value = true isParsingData.value = true
if (activeKey.value === 'uploadTab') { if (activeKey.value === 'uploadTab') {
if (isImportTypeCsv) { if (isImportTypeCsv.value) {
await parseAndExtractStreamData(importState.fileList as streamImportFileList) await parseAndExtractStreamData(importState.fileList as streamImportFileList)
} else { } else {
await parseAndExtractData((importState.fileList as importFileList)[0].data) await parseAndExtractData((importState.fileList as importFileList)[0].data)
@ -161,10 +161,6 @@ async function handlePreImport() {
} else if (activeKey.value === 'jsonEditorTab') { } else if (activeKey.value === 'jsonEditorTab') {
await parseAndExtractData(JSON.stringify(importState.jsonEditor)) await parseAndExtractData(JSON.stringify(importState.jsonEditor))
} }
// TODO(import):
preImportLoading.value = false
// isParsingData.value = false
} }
async function handleImport() { async function handleImport() {
@ -207,6 +203,7 @@ async function parseAndExtractStreamData(val: UploadFile[]) {
// if (importOnly) importColumns.value = templateGenerator.getColumns() // if (importOnly) importColumns.value = templateGenerator.getColumns()
templateEditorModal.value = true templateEditorModal.value = true
isParsingData.value = false isParsingData.value = false
preImportLoading.value = false
}) })
} catch (e: any) { } catch (e: any) {
message.error(await extractSdkResponseErrorMsg(e)) message.error(await extractSdkResponseErrorMsg(e))
@ -219,7 +216,7 @@ async function parseAndExtractData(val: string | ArrayBuffer) {
importData.value = null importData.value = null
importColumns.value = [] importColumns.value = []
const templateGenerator = getAdapter(val) templateGenerator = getAdapter(val)
if (!templateGenerator) { if (!templateGenerator) {
message.error(t('msg.error.templateGeneratorNotFound')) message.error(t('msg.error.templateGeneratorNotFound'))
@ -228,13 +225,13 @@ async function parseAndExtractData(val: string | ArrayBuffer) {
await templateGenerator.init() await templateGenerator.init()
templateGenerator.parse(() => {}) templateGenerator.parse(() => {
templateData.value = templateGenerator.getTemplate() templateData.value = templateGenerator!.getTemplate()
if (importOnly) importColumns.value = templateGenerator!.getColumns()
// TODO(import): check templateEditorModal.value = true
if (importOnly) importColumns.value = templateGenerator.getColumns() isParsingData.value = false
preImportLoading.value = false
templateEditorModal.value = true })
} catch (e: any) { } catch (e: any) {
message.error(await extractSdkResponseErrorMsg(e)) message.error(await extractSdkResponseErrorMsg(e))
} }
@ -249,7 +246,7 @@ function rejectDrop(fileList: UploadFile[]) {
function handleChange(info: UploadChangeParam) { function handleChange(info: UploadChangeParam) {
const status = info.file.status const status = info.file.status
if (status && status !== 'uploading' && status !== 'removed') { if (status && status !== 'uploading' && status !== 'removed') {
if (isImportTypeCsv) { if (isImportTypeCsv.value) {
if (!importState.fileList.find((f) => f.uid === info.file.uid)) { if (!importState.fileList.find((f) => f.uid === info.file.uid)) {
;(importState.fileList as streamImportFileList).push({ ;(importState.fileList as streamImportFileList).push({
...info.file, ...info.file,
@ -308,7 +305,7 @@ function getAdapter(val: any) {
// TODO(import): implement one for CSV // TODO(import): implement one for CSV
return new ExcelUrlTemplateAdapter(val, importState.parserConfig) return new ExcelUrlTemplateAdapter(val, importState.parserConfig)
} }
} else if (IsImportTypeExcel.value || isImportTypeCsv.value) { } else if (IsImportTypeExcel.value) {
switch (activeKey.value) { switch (activeKey.value) {
case 'uploadTab': case 'uploadTab':
return new ExcelTemplateAdapter(val, importState.parserConfig) return new ExcelTemplateAdapter(val, importState.parserConfig)

Loading…
Cancel
Save