|
|
@ -21,6 +21,7 @@ interface Props { |
|
|
|
importData: Record<string, any>[] |
|
|
|
importData: Record<string, any>[] |
|
|
|
importColumns: any[] |
|
|
|
importColumns: any[] |
|
|
|
importOnly: boolean |
|
|
|
importOnly: boolean |
|
|
|
|
|
|
|
maxRowsToParse: number |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
interface Option { |
|
|
|
interface Option { |
|
|
@ -28,7 +29,7 @@ interface Option { |
|
|
|
value: string |
|
|
|
value: string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const { quickImportType, projectTemplate, importData, importColumns, importOnly } = defineProps<Props>() |
|
|
|
const { quickImportType, projectTemplate, importData, importColumns, importOnly, maxRowsToParse } = defineProps<Props>() |
|
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits(['import']) |
|
|
|
const emit = defineEmits(['import']) |
|
|
|
|
|
|
|
|
|
|
@ -211,7 +212,6 @@ function atLeastOneEnabledValidation() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function fieldsValidation(table: Record<string, any>, record: Record<string, any>) { |
|
|
|
function fieldsValidation(table: Record<string, any>, record: Record<string, any>) { |
|
|
|
console.log(importData[table.ref_table_name].slice(0, 500)) |
|
|
|
|
|
|
|
// if it is not selected, then pass validation |
|
|
|
// if it is not selected, then pass validation |
|
|
|
if (!record.enabled) { |
|
|
|
if (!record.enabled) { |
|
|
|
return true |
|
|
|
return true |
|
|
@ -231,7 +231,7 @@ function fieldsValidation(table: Record<string, any>, record: Record<string, any |
|
|
|
if (v.pk ? !v.ai && !v.cdf : !v.cdf && v.rqd) { |
|
|
|
if (v.pk ? !v.ai && !v.cdf : !v.cdf && v.rqd) { |
|
|
|
if ( |
|
|
|
if ( |
|
|
|
importData[table.ref_table_name] |
|
|
|
importData[table.ref_table_name] |
|
|
|
.slice(0, 500) |
|
|
|
.slice(0, maxRowsToParse) |
|
|
|
.some((r: Record<string, any>) => r[record.srcCn] === null || r[record.srcCn] === undefined || r[record.srcCn] === '') |
|
|
|
.some((r: Record<string, any>) => r[record.srcCn] === null || r[record.srcCn] === undefined || r[record.srcCn] === '') |
|
|
|
) { |
|
|
|
) { |
|
|
|
notification.error({ |
|
|
|
notification.error({ |
|
|
@ -245,7 +245,7 @@ function fieldsValidation(table: Record<string, any>, record: Record<string, any |
|
|
|
case UITypes.Number: |
|
|
|
case UITypes.Number: |
|
|
|
if ( |
|
|
|
if ( |
|
|
|
importData[table.ref_table_name] |
|
|
|
importData[table.ref_table_name] |
|
|
|
.slice(0, 500) |
|
|
|
.slice(0, maxRowsToParse) |
|
|
|
.some( |
|
|
|
.some( |
|
|
|
(r: Record<string, any>) => r[record.sourceCn] !== null && r[record.srcCn] !== undefined && isNaN(+r[record.srcCn]), |
|
|
|
(r: Record<string, any>) => r[record.sourceCn] !== null && r[record.srcCn] !== undefined && isNaN(+r[record.srcCn]), |
|
|
|
) |
|
|
|
) |
|
|
@ -259,7 +259,7 @@ function fieldsValidation(table: Record<string, any>, record: Record<string, any |
|
|
|
break |
|
|
|
break |
|
|
|
case UITypes.Checkbox: |
|
|
|
case UITypes.Checkbox: |
|
|
|
if ( |
|
|
|
if ( |
|
|
|
importData[table.ref_table_name].slice(0, 500).some((r: Record<string, any>) => { |
|
|
|
importData[table.ref_table_name].slice(0, maxRowsToParse).some((r: Record<string, any>) => { |
|
|
|
if ((r: Record<string, any>) => r[record.srcCn] !== null && r[record.srcCn] !== undefined) { |
|
|
|
if ((r: Record<string, any>) => r[record.srcCn] !== null && r[record.srcCn] !== undefined) { |
|
|
|
let input = r[record.srcCn] |
|
|
|
let input = r[record.srcCn] |
|
|
|
if (typeof input === 'string') { |
|
|
|
if (typeof input === 'string') { |
|
|
@ -292,7 +292,6 @@ function fieldsValidation(table: Record<string, any>, record: Record<string, any |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function importTemplate() { |
|
|
|
async function importTemplate() { |
|
|
|
console.log('importTemplate') |
|
|
|
|
|
|
|
if (importOnly) { |
|
|
|
if (importOnly) { |
|
|
|
// validate required columns |
|
|
|
// validate required columns |
|
|
|
if (!missingRequiredColumnsValidation()) return |
|
|
|
if (!missingRequiredColumnsValidation()) return |
|
|
@ -301,13 +300,13 @@ async function importTemplate() { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
isImporting.value = true |
|
|
|
isImporting.value = true |
|
|
|
console.log(importData) |
|
|
|
|
|
|
|
const data = importData[meta?.value?.title as string] |
|
|
|
const data = importData[meta?.value?.title as string] |
|
|
|
console.log(srcDestMapping.value) |
|
|
|
const projectName = project.value.title as string |
|
|
|
for (let i = 0, progress = 0; i < data.length; i += 500) { |
|
|
|
const tableName = meta?.value.title as string |
|
|
|
const batchData = data.slice(i, i + 500).map((row: Record<string, any>) => |
|
|
|
const total = data.length |
|
|
|
|
|
|
|
for (let i = 0, progress = 0; i < total; i += maxRowsToParse) { |
|
|
|
|
|
|
|
const batchData = data.slice(i, i + maxRowsToParse).map((row: Record<string, any>) => |
|
|
|
srcDestMapping.value.reduce((res: Record<string, any>, col: Record<string, any>) => { |
|
|
|
srcDestMapping.value.reduce((res: Record<string, any>, col: Record<string, any>) => { |
|
|
|
console.log(col) |
|
|
|
|
|
|
|
if (col.enabled && col.destCn) { |
|
|
|
if (col.enabled && col.destCn) { |
|
|
|
const v = columns.value.find((c: Record<string, any>) => c.title === col.destCn) as Record<string, any> |
|
|
|
const v = columns.value.find((c: Record<string, any>) => c.title === col.destCn) as Record<string, any> |
|
|
|
let input = row[col.srcCn] |
|
|
|
let input = row[col.srcCn] |
|
|
@ -333,10 +332,9 @@ async function importTemplate() { |
|
|
|
return res |
|
|
|
return res |
|
|
|
}, {}), |
|
|
|
}, {}), |
|
|
|
) |
|
|
|
) |
|
|
|
await $api.dbTableRow.bulkCreate('noco', project.value.title as string, meta?.value.title as string, batchData) |
|
|
|
await $api.dbTableRow.bulkCreate('noco', projectName, tableName, batchData) |
|
|
|
|
|
|
|
importingTip.value = `Importing data to ${projectName}: ${progress}/${total} records` |
|
|
|
progress += batchData.length |
|
|
|
progress += batchData.length |
|
|
|
// this.$store.commit('loader/MutMessage', `Importing data : ${progress}/${data.length}`); |
|
|
|
|
|
|
|
// this.$store.commit('loader/MutProgress', Math.round((100 * progress) / data.length)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// reload table |
|
|
|
// reload table |
|
|
@ -415,7 +413,7 @@ async function importTemplate() { |
|
|
|
if (importData) { |
|
|
|
if (importData) { |
|
|
|
let total = 0 |
|
|
|
let total = 0 |
|
|
|
let progress = 0 |
|
|
|
let progress = 0 |
|
|
|
const offset = 500 |
|
|
|
const offset = maxRowsToParse |
|
|
|
const projectName = project.value.title as string |
|
|
|
const projectName = project.value.title as string |
|
|
|
await Promise.all( |
|
|
|
await Promise.all( |
|
|
|
data.tables.map((table: Record<string, any>) => |
|
|
|
data.tables.map((table: Record<string, any>) => |
|
|
|