|
|
@ -3,6 +3,7 @@ import { useToast } from 'vue-toastification' |
|
|
|
import type { ColumnType } from 'nocodb-sdk' |
|
|
|
import type { ColumnType } from 'nocodb-sdk' |
|
|
|
import { isVirtualCol, UITypes } from 'nocodb-sdk' |
|
|
|
import { isVirtualCol, UITypes } from 'nocodb-sdk' |
|
|
|
import type { SizeType } from 'ant-design-vue/es/config-provider' |
|
|
|
import type { SizeType } from 'ant-design-vue/es/config-provider' |
|
|
|
|
|
|
|
import type { FormInstance } from 'ant-design-vue' |
|
|
|
import { computed, onMounted } from '#imports' |
|
|
|
import { computed, onMounted } from '#imports' |
|
|
|
import MdiTableIcon from '~icons/mdi/table' |
|
|
|
import MdiTableIcon from '~icons/mdi/table' |
|
|
|
import MdiStringIcon from '~icons/mdi/alpha-a' |
|
|
|
import MdiStringIcon from '~icons/mdi/alpha-a' |
|
|
@ -23,7 +24,7 @@ interface Option { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const { quickImportType, projectTemplate, importData } = defineProps<Props>() |
|
|
|
const { quickImportType, projectTemplate, importData } = defineProps<Props>() |
|
|
|
|
|
|
|
const formRef = ref<FormInstance>() |
|
|
|
const { $api } = useNuxtApp() |
|
|
|
const { $api } = useNuxtApp() |
|
|
|
const valid = ref(false) |
|
|
|
const valid = ref(false) |
|
|
|
const expansionPanel = ref(<number[]>[]) |
|
|
|
const expansionPanel = ref(<number[]>[]) |
|
|
@ -34,6 +35,14 @@ const { sqlUi, project, loadTables } = useProject() |
|
|
|
const loading = ref(false) |
|
|
|
const loading = ref(false) |
|
|
|
const buttonSize = ref<SizeType>('middle') |
|
|
|
const buttonSize = ref<SizeType>('middle') |
|
|
|
const toast = useToast() |
|
|
|
const toast = useToast() |
|
|
|
|
|
|
|
const templateForm = reactive<{ tables: object[] }>({ |
|
|
|
|
|
|
|
tables: [], |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const formRules = { |
|
|
|
|
|
|
|
columnName: [{ required: true, message: 'Please fill in column name', trigger: 'change' }], |
|
|
|
|
|
|
|
columnType: [{ required: true, message: 'Please fill in column type', trigger: 'change' }], |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const uiTypeOptions = ref<Option[]>( |
|
|
|
const uiTypeOptions = ref<Option[]>( |
|
|
|
(Object.keys(UITypes) as Array<keyof typeof UITypes>) |
|
|
|
(Object.keys(UITypes) as Array<keyof typeof UITypes>) |
|
|
@ -180,6 +189,14 @@ const remapColNames = (batchData: any[], columns: ColumnType[]) => { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const importTemplate = async () => { |
|
|
|
const importTemplate = async () => { |
|
|
|
|
|
|
|
// check if form is valid |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
const values = await formRef.value.validateFields() |
|
|
|
|
|
|
|
console.log('Success:', values) |
|
|
|
|
|
|
|
} catch (errorInfo) { |
|
|
|
|
|
|
|
console.log('Failed:', errorInfo) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let firstTable = null |
|
|
|
let firstTable = null |
|
|
|
try { |
|
|
|
try { |
|
|
|
loading.value = true |
|
|
|
loading.value = true |
|
|
@ -267,12 +284,13 @@ const importTemplate = async () => { |
|
|
|
{{ $t('activity.import') }} |
|
|
|
{{ $t('activity.import') }} |
|
|
|
</a-button> |
|
|
|
</a-button> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
<v-form ref="form" v-model="valid"> |
|
|
|
<a-form ref="formRef" :model="data" @finish="valid = true" @finish-failed="valid = false"> |
|
|
|
<p v-if="data.tables && quickImportType === 'excel'" class="caption grey--text mt-4"> |
|
|
|
<p v-if="data.tables && quickImportType === 'excel'" class="caption grey--text mt-4"> |
|
|
|
{{ data.tables.length }} sheet{{ data.tables.length > 1 ? 's' : '' }} |
|
|
|
{{ data.tables.length }} sheet{{ data.tables.length > 1 ? 's' : '' }} |
|
|
|
available for import |
|
|
|
available for import |
|
|
|
</p> |
|
|
|
</p> |
|
|
|
<a-collapse v-if="data.value?.tables && data.value?.tables.length" v-model:activeKey="expansionPanel"> |
|
|
|
<a-collapse v-if="data.value?.tables && data.value?.tables.length" v-model:activeKey="expansionPanel"> |
|
|
|
|
|
|
|
{{ data.value }} |
|
|
|
<a-collapse-panel v-for="(table, i) in data.value?.tables" :key="i"> |
|
|
|
<a-collapse-panel v-for="(table, i) in data.value?.tables" :key="i"> |
|
|
|
<template #header> |
|
|
|
<template #header> |
|
|
|
<a-input |
|
|
|
<a-input |
|
|
@ -298,6 +316,7 @@ const importTemplate = async () => { |
|
|
|
<MdiDeleteOutlineIcon v-if="data.value.tables.length > 1" @click.stop="deleteTable(i)" /> |
|
|
|
<MdiDeleteOutlineIcon v-if="data.value.tables.length > 1" @click.stop="deleteTable(i)" /> |
|
|
|
</a-tooltip> |
|
|
|
</a-tooltip> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
|
|
|
|
{{ table }} |
|
|
|
<a-table v-if="table.columns.length" :dataSource="table.columns" :columns="tableColumns" :pagination="false"> |
|
|
|
<a-table v-if="table.columns.length" :dataSource="table.columns" :columns="tableColumns" :pagination="false"> |
|
|
|
<template #headerCell="{ column }"> |
|
|
|
<template #headerCell="{ column }"> |
|
|
|
<template v-if="column.key === 'column_name'"> |
|
|
|
<template v-if="column.key === 'column_name'"> |
|
|
@ -313,6 +332,8 @@ const importTemplate = async () => { |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
<template #bodyCell="{ column, record }"> |
|
|
|
<template #bodyCell="{ column, record }"> |
|
|
|
<template v-if="column.key === 'column_name'"> |
|
|
|
<template v-if="column.key === 'column_name'"> |
|
|
|
|
|
|
|
<!-- TODO: FIX nested form path --> |
|
|
|
|
|
|
|
<a-form-item :name="['tables', i, 'columns', record.key, 'column_name']" :rules="formRules.columnName"> |
|
|
|
<a-input |
|
|
|
<a-input |
|
|
|
v-model:value="record.column_name" |
|
|
|
v-model:value="record.column_name" |
|
|
|
:ref=" |
|
|
|
:ref=" |
|
|
@ -321,14 +342,18 @@ const importTemplate = async () => { |
|
|
|
} |
|
|
|
} |
|
|
|
" |
|
|
|
" |
|
|
|
/> |
|
|
|
/> |
|
|
|
|
|
|
|
</a-form-item> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
<template v-else-if="column.key === 'column_type'"> |
|
|
|
<template v-else-if="column.key === 'column_type'"> |
|
|
|
|
|
|
|
<!-- TODO: fix form item name--> |
|
|
|
|
|
|
|
<a-form-item name="column_type" :rules="formRules.columnType"> |
|
|
|
<a-auto-complete |
|
|
|
<a-auto-complete |
|
|
|
v-model:value="record.uidt" |
|
|
|
v-model:value="record.uidt" |
|
|
|
:options="uiTypeOptions" |
|
|
|
:options="uiTypeOptions" |
|
|
|
:filter-option="filterOption" |
|
|
|
:filter-option="filterOption" |
|
|
|
style="width: 200px" |
|
|
|
style="width: 200px" |
|
|
|
/> |
|
|
|
/> |
|
|
|
|
|
|
|
</a-form-item> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
|
|
<template v-else-if="column.key === 'select_option'"> |
|
|
|
<template v-else-if="column.key === 'select_option'"> |
|
|
@ -410,6 +435,6 @@ const importTemplate = async () => { |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</a-collapse-panel> |
|
|
|
</a-collapse-panel> |
|
|
|
</a-collapse> |
|
|
|
</a-collapse> |
|
|
|
</v-form> |
|
|
|
</a-form> |
|
|
|
</a-card> |
|
|
|
</a-card> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|