|
|
@ -211,12 +211,22 @@ function atLeastOneEnabledValidation() { |
|
|
|
return true |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function fieldsValidation(table: Record<string, any>, record: Record<string, any>) { |
|
|
|
function fieldsValidation(record: Record<string, any>) { |
|
|
|
// 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 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const tableName = meta?.value.title || '' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!record.destCn) { |
|
|
|
|
|
|
|
notification.error({ |
|
|
|
|
|
|
|
message: `Cannot find the destination column for ${record.srcCn}`, |
|
|
|
|
|
|
|
duration: 3, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (srcDestMapping.value.filter((v) => v.destCn === record.destCn).length > 1) { |
|
|
|
if (srcDestMapping.value.filter((v) => v.destCn === record.destCn).length > 1) { |
|
|
|
notification.error({ |
|
|
|
notification.error({ |
|
|
|
message: 'Duplicate mapping found, please remove one of the mapping', |
|
|
|
message: 'Duplicate mapping found, please remove one of the mapping', |
|
|
@ -230,7 +240,7 @@ function fieldsValidation(table: Record<string, any>, record: Record<string, any |
|
|
|
// check if the input contains null value for a required column |
|
|
|
// check if the input contains null value for a required column |
|
|
|
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[tableName] |
|
|
|
.slice(0, maxRowsToParse) |
|
|
|
.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] === '') |
|
|
|
) { |
|
|
|
) { |
|
|
@ -244,7 +254,7 @@ function fieldsValidation(table: Record<string, any>, record: Record<string, any |
|
|
|
switch (v.uidt) { |
|
|
|
switch (v.uidt) { |
|
|
|
case UITypes.Number: |
|
|
|
case UITypes.Number: |
|
|
|
if ( |
|
|
|
if ( |
|
|
|
importData[table.ref_table_name] |
|
|
|
importData[tableName] |
|
|
|
.slice(0, maxRowsToParse) |
|
|
|
.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 +269,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, maxRowsToParse).some((r: Record<string, any>) => { |
|
|
|
importData[tableName].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') { |
|
|
@ -300,9 +310,9 @@ async function importTemplate() { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
isImporting.value = true |
|
|
|
isImporting.value = true |
|
|
|
const data = importData[meta?.value?.title as string] |
|
|
|
|
|
|
|
const projectName = project.value.title as string |
|
|
|
|
|
|
|
const tableName = meta?.value.title as string |
|
|
|
const tableName = meta?.value.title as string |
|
|
|
|
|
|
|
const data = importData[tableName] |
|
|
|
|
|
|
|
const projectName = project.value.title as string |
|
|
|
const total = data.length |
|
|
|
const total = data.length |
|
|
|
for (let i = 0, progress = 0; i < total; i += maxRowsToParse) { |
|
|
|
for (let i = 0, progress = 0; i < total; i += maxRowsToParse) { |
|
|
|
const batchData = data.slice(i, i + maxRowsToParse).map((row: Record<string, any>) => |
|
|
|
const batchData = data.slice(i, i + maxRowsToParse).map((row: Record<string, any>) => |
|
|
@ -447,12 +457,20 @@ async function importTemplate() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const isValid = computed(() => { |
|
|
|
const isValid = computed(() => { |
|
|
|
for (const [_, o] of Object.entries(validateInfos)) { |
|
|
|
if (importOnly) { |
|
|
|
if (o?.validateStatus) { |
|
|
|
for (const record of srcDestMapping.value) { |
|
|
|
if (o.validateStatus === 'error') { |
|
|
|
if (!fieldsValidation(record)) { |
|
|
|
return false |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
for (const [_, o] of Object.entries(validateInfos)) { |
|
|
|
|
|
|
|
if (o?.validateStatus) { |
|
|
|
|
|
|
|
if (o.validateStatus === 'error') { |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return true |
|
|
|
return true |
|
|
|
}) |
|
|
|
}) |
|
|
@ -471,9 +489,6 @@ function mapDefaultColumns() { |
|
|
|
} |
|
|
|
} |
|
|
|
srcDestMapping.value.push(o) |
|
|
|
srcDestMapping.value.push(o) |
|
|
|
} |
|
|
|
} |
|
|
|
nextTick(() => { |
|
|
|
|
|
|
|
// TODO: validate |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
defineExpose({ |
|
|
|
defineExpose({ |
|
|
@ -528,7 +543,6 @@ onMounted(() => { |
|
|
|
class="w-52" |
|
|
|
class="w-52" |
|
|
|
show-search |
|
|
|
show-search |
|
|
|
:filter-option="filterOption" |
|
|
|
:filter-option="filterOption" |
|
|
|
@change="fieldsValidation(table, record)" |
|
|
|
|
|
|
|
> |
|
|
|
> |
|
|
|
<a-select-option v-for="(column, i) of columns" :key="i" :value="column.title"> |
|
|
|
<a-select-option v-for="(column, i) of columns" :key="i" :value="column.title"> |
|
|
|
<div class="flex items-center"> |
|
|
|
<div class="flex items-center"> |
|
|
@ -540,7 +554,7 @@ onMounted(() => { |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
|
|
<template v-if="column.key === 'action'"> |
|
|
|
<template v-if="column.key === 'action'"> |
|
|
|
<a-checkbox v-model:checked="record.enabled" @change="fieldsValidation(table, record)" /> |
|
|
|
<a-checkbox v-model:checked="record.enabled" /> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
</a-table> |
|
|
|
</a-table> |
|
|
|