mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
400 lines
11 KiB
400 lines
11 KiB
2 years ago
|
<script setup lang="ts">
|
||
2 years ago
|
import type { Socket } from 'socket.io-client'
|
||
2 years ago
|
import io from 'socket.io-client'
|
||
2 years ago
|
import type { Card as AntCard } from 'ant-design-vue'
|
||
2 years ago
|
import { Form, message } from 'ant-design-vue'
|
||
|
import {
|
||
|
computed,
|
||
|
extractSdkResponseErrorMsg,
|
||
|
fieldRequiredValidator,
|
||
|
nextTick,
|
||
|
onBeforeUnmount,
|
||
|
onMounted,
|
||
|
ref,
|
||
2 years ago
|
useGlobal,
|
||
2 years ago
|
useNuxtApp,
|
||
|
useProject,
|
||
|
watch,
|
||
|
} from '#imports'
|
||
2 years ago
|
|
||
2 years ago
|
interface Props {
|
||
|
modelValue: boolean
|
||
|
}
|
||
2 years ago
|
|
||
2 years ago
|
const { modelValue } = defineProps<Props>()
|
||
2 years ago
|
|
||
2 years ago
|
const emit = defineEmits(['update:modelValue'])
|
||
|
|
||
2 years ago
|
const { appInfo } = $(useGlobal())
|
||
|
|
||
|
const baseURL = appInfo.ncSiteUrl
|
||
2 years ago
|
|
||
2 years ago
|
const { $state } = useNuxtApp()
|
||
2 years ago
|
|
||
2 years ago
|
const { project, loadTables } = useProject()
|
||
2 years ago
|
|
||
|
const showGoToDashboardButton = ref(false)
|
||
|
|
||
2 years ago
|
const step = ref(1)
|
||
2 years ago
|
|
||
2 years ago
|
const progress = ref<Record<string, any>[]>([])
|
||
2 years ago
|
|
||
2 years ago
|
const logRef = ref<typeof AntCard>()
|
||
2 years ago
|
|
||
2 years ago
|
let socket: Socket | null
|
||
2 years ago
|
|
||
2 years ago
|
const syncSource = ref({
|
||
2 years ago
|
id: '',
|
||
2 years ago
|
type: 'Airtable',
|
||
|
details: {
|
||
|
syncInterval: '15mins',
|
||
|
syncDirection: 'Airtable to NocoDB',
|
||
|
syncRetryCount: 1,
|
||
|
apiKey: '',
|
||
|
shareId: '',
|
||
2 years ago
|
syncSourceUrlOrId: '',
|
||
2 years ago
|
options: {
|
||
|
syncViews: true,
|
||
|
syncData: true,
|
||
|
syncRollup: false,
|
||
|
syncLookup: true,
|
||
|
syncFormula: false,
|
||
|
syncAttachment: true,
|
||
|
},
|
||
|
},
|
||
|
})
|
||
|
|
||
2 years ago
|
const validators = computed(() => ({
|
||
|
'details.apiKey': [fieldRequiredValidator],
|
||
|
'details.syncSourceUrlOrId': [fieldRequiredValidator],
|
||
|
}))
|
||
2 years ago
|
|
||
2 years ago
|
const dialogShow = computed({
|
||
2 years ago
|
get: () => modelValue,
|
||
|
set: (v) => emit('update:modelValue', v),
|
||
2 years ago
|
})
|
||
2 years ago
|
|
||
2 years ago
|
const useForm = Form.useForm
|
||
2 years ago
|
|
||
2 years ago
|
const { validateInfos } = useForm(syncSource, validators)
|
||
2 years ago
|
|
||
2 years ago
|
const disableImportButton = computed(() => !syncSource.value.details.apiKey || !syncSource.value.details.syncSourceUrlOrId)
|
||
2 years ago
|
|
||
2 years ago
|
async function saveAndSync() {
|
||
2 years ago
|
await createOrUpdate()
|
||
2 years ago
|
await sync()
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async function createOrUpdate() {
|
||
2 years ago
|
try {
|
||
|
const { id, ...payload } = syncSource.value
|
||
2 years ago
|
|
||
2 years ago
|
if (id !== '') {
|
||
|
await $fetch(`/api/v1/db/meta/syncs/${id}`, {
|
||
2 years ago
|
baseURL,
|
||
2 years ago
|
method: 'PATCH',
|
||
2 years ago
|
headers: { 'xc-auth': $state.token.value as string },
|
||
2 years ago
|
body: payload,
|
||
|
})
|
||
|
} else {
|
||
2 years ago
|
syncSource.value = await $fetch(`/api/v1/db/meta/projects/${project.value.id}/syncs`, {
|
||
2 years ago
|
baseURL,
|
||
2 years ago
|
method: 'POST',
|
||
2 years ago
|
headers: { 'xc-auth': $state.token.value as string },
|
||
2 years ago
|
body: payload,
|
||
|
})
|
||
|
}
|
||
|
} catch (e: any) {
|
||
2 years ago
|
message.error(await extractSdkResponseErrorMsg(e))
|
||
2 years ago
|
}
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async function loadSyncSrc() {
|
||
2 years ago
|
const data: any = await $fetch(`/api/v1/db/meta/projects/${project.value.id}/syncs`, {
|
||
|
baseURL,
|
||
2 years ago
|
method: 'GET',
|
||
2 years ago
|
headers: { 'xc-auth': $state.token.value as string },
|
||
2 years ago
|
})
|
||
2 years ago
|
|
||
2 years ago
|
const { list: srcs } = data
|
||
2 years ago
|
|
||
2 years ago
|
if (srcs && srcs[0]) {
|
||
|
srcs[0].details = srcs[0].details || {}
|
||
|
syncSource.value = migrateSync(srcs[0])
|
||
2 years ago
|
syncSource.value.details.syncSourceUrlOrId = srcs[0].details.shareId
|
||
2 years ago
|
} else {
|
||
|
syncSource.value = {
|
||
|
id: '',
|
||
|
type: 'Airtable',
|
||
|
details: {
|
||
|
syncInterval: '15mins',
|
||
|
syncDirection: 'Airtable to NocoDB',
|
||
|
syncRetryCount: 1,
|
||
|
apiKey: '',
|
||
|
shareId: '',
|
||
2 years ago
|
syncSourceUrlOrId: '',
|
||
2 years ago
|
options: {
|
||
|
syncViews: true,
|
||
|
syncData: true,
|
||
|
syncRollup: false,
|
||
|
syncLookup: true,
|
||
|
syncFormula: false,
|
||
|
syncAttachment: true,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
}
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async function sync() {
|
||
2 years ago
|
step.value = 2
|
||
2 years ago
|
try {
|
||
|
await $fetch(`/api/v1/db/meta/syncs/${syncSource.value.id}/trigger`, {
|
||
|
baseURL,
|
||
|
method: 'POST',
|
||
|
headers: { 'xc-auth': $state.token.value as string },
|
||
2 years ago
|
params: {
|
||
2 years ago
|
id: socket?.id,
|
||
2 years ago
|
},
|
||
|
})
|
||
|
} catch (e: any) {
|
||
2 years ago
|
message.error(await extractSdkResponseErrorMsg(e))
|
||
2 years ago
|
}
|
||
2 years ago
|
}
|
||
|
|
||
|
function migrateSync(src: any) {
|
||
2 years ago
|
if (!src.details?.options) {
|
||
|
src.details.options = {
|
||
|
syncViews: false,
|
||
|
syncData: true,
|
||
|
syncRollup: false,
|
||
|
syncLookup: true,
|
||
|
syncFormula: false,
|
||
|
syncAttachment: true,
|
||
|
}
|
||
|
src.details.options.syncViews = src.syncViews
|
||
|
delete src.syncViews
|
||
|
}
|
||
2 years ago
|
|
||
2 years ago
|
return src
|
||
|
}
|
||
|
|
||
2 years ago
|
watch(
|
||
|
() => syncSource.value.details.syncSourceUrlOrId,
|
||
|
(v) => {
|
||
|
if (syncSource.value.details) {
|
||
|
const m = v && v.match(/(exp|shr).{14}/g)
|
||
|
syncSource.value.details.shareId = m ? m[0] : ''
|
||
|
}
|
||
|
},
|
||
|
)
|
||
2 years ago
|
|
||
2 years ago
|
onMounted(async () => {
|
||
2 years ago
|
socket = io(new URL(baseURL, window.location.href.split(/[?#]/)[0]).href, {
|
||
2 years ago
|
extraHeaders: { 'xc-auth': $state.token.value as string },
|
||
|
})
|
||
2 years ago
|
|
||
2 years ago
|
socket.on('connect_error', () => {
|
||
2 years ago
|
socket?.disconnect()
|
||
2 years ago
|
socket = null
|
||
2 years ago
|
})
|
||
|
|
||
2 years ago
|
// connect event does not provide data
|
||
|
socket.on('connect', () => {
|
||
|
console.log(socket?.id)
|
||
|
console.log('socket connected')
|
||
2 years ago
|
})
|
||
|
|
||
2 years ago
|
socket.on('progress', async (d: Record<string, any>) => {
|
||
2 years ago
|
progress.value.push(d)
|
||
2 years ago
|
|
||
2 years ago
|
// FIXME: this doesn't work
|
||
2 years ago
|
await nextTick(() => {
|
||
2 years ago
|
;(logRef.value?.$el as HTMLDivElement).scrollTo()
|
||
2 years ago
|
})
|
||
2 years ago
|
|
||
2 years ago
|
if (d.status === 'COMPLETED') {
|
||
2 years ago
|
showGoToDashboardButton.value = true
|
||
2 years ago
|
await loadTables()
|
||
|
// TODO: add tab of the first table
|
||
2 years ago
|
}
|
||
|
})
|
||
2 years ago
|
|
||
2 years ago
|
await loadSyncSrc()
|
||
|
})
|
||
|
|
||
|
onBeforeUnmount(() => {
|
||
2 years ago
|
if (socket) {
|
||
|
socket.disconnect()
|
||
2 years ago
|
}
|
||
2 years ago
|
})
|
||
2 years ago
|
</script>
|
||
|
|
||
|
<template>
|
||
2 years ago
|
<a-modal v-model:visible="dialogShow" width="max(30vw, 600px)" class="p-2" @keydown.esc="dialogShow = false">
|
||
2 years ago
|
<div class="px-5">
|
||
2 years ago
|
<!-- Quick Import -->
|
||
|
<div class="mt-5 prose-xl font-weight-bold">{{ $t('title.quickImport') }} - AIRTABLE</div>
|
||
2 years ago
|
|
||
2 years ago
|
<div v-if="step === 1">
|
||
|
<div class="mb-4">
|
||
2 years ago
|
<!-- Credentials -->
|
||
|
<span class="mr-3 pt-2 text-gray-500 text-xs">{{ $t('general.credentials') }}</span>
|
||
|
<!-- Where to find this? -->
|
||
2 years ago
|
<a
|
||
|
href="https://docs.nocodb.com/setup-and-usages/import-airtable-to-sql-database-within-a-minute-for-free/#get-airtable-credentials"
|
||
2 years ago
|
class="prose-sm underline text-grey text-xs"
|
||
2 years ago
|
target="_blank"
|
||
2 years ago
|
>{{ $t('msg.info.airtable.credentials') }}
|
||
2 years ago
|
</a>
|
||
|
</div>
|
||
2 years ago
|
|
||
2 years ago
|
<a-form ref="form" :model="syncSource" name="quick-import-airtable-form" layout="horizontal" class="m-0">
|
||
2 years ago
|
<a-form-item v-bind="validateInfos['details.apiKey']">
|
||
2 years ago
|
<a-input-password
|
||
|
v-model:value="syncSource.details.apiKey"
|
||
|
class="nc-input-api-key"
|
||
2 years ago
|
:placeholder="$t('labels.apiKey')"
|
||
2 years ago
|
size="large"
|
||
|
/>
|
||
2 years ago
|
</a-form-item>
|
||
2 years ago
|
|
||
2 years ago
|
<a-form-item v-bind="validateInfos['details.syncSourceUrlOrId']">
|
||
2 years ago
|
<a-input
|
||
|
v-model:value="syncSource.details.syncSourceUrlOrId"
|
||
|
class="nc-input-shared-base"
|
||
2 years ago
|
:placeholder="`${$t('labels.sharedBase')} ID / URL`"
|
||
2 years ago
|
size="large"
|
||
|
/>
|
||
2 years ago
|
</a-form-item>
|
||
2 years ago
|
|
||
2 years ago
|
<!-- Advanced Settings -->
|
||
|
<div class="prose-lg self-center my-4 text-gray-500">{{ $t('title.advancedSettings') }}</div>
|
||
2 years ago
|
|
||
2 years ago
|
<a-divider class="mt-2 mb-5" />
|
||
2 years ago
|
|
||
2 years ago
|
<!-- Import Data -->
|
||
2 years ago
|
<div class="mt-0 my-2">
|
||
2 years ago
|
<a-checkbox v-model:checked="syncSource.details.options.syncData">{{ $t('labels.importData') }}</a-checkbox>
|
||
2 years ago
|
</div>
|
||
2 years ago
|
|
||
2 years ago
|
<!-- Import Secondary Views -->
|
||
2 years ago
|
<div class="my-2">
|
||
2 years ago
|
<a-checkbox v-model:checked="syncSource.details.options.syncViews">{{
|
||
|
$t('labels.importSecondaryViews')
|
||
|
}}</a-checkbox>
|
||
2 years ago
|
</div>
|
||
2 years ago
|
|
||
2 years ago
|
<!-- Import Rollup Columns -->
|
||
2 years ago
|
<div class="my-2">
|
||
2 years ago
|
<a-checkbox v-model:checked="syncSource.details.options.syncRollup">{{
|
||
|
$t('labels.importRollupColumns')
|
||
|
}}</a-checkbox>
|
||
2 years ago
|
</div>
|
||
2 years ago
|
|
||
2 years ago
|
<!-- Import Lookup Columns -->
|
||
2 years ago
|
<div class="my-2">
|
||
2 years ago
|
<a-checkbox v-model:checked="syncSource.details.options.syncLookup">{{
|
||
|
$t('labels.importLookupColumns')
|
||
|
}}</a-checkbox>
|
||
2 years ago
|
</div>
|
||
2 years ago
|
|
||
2 years ago
|
<!-- Import Attachment Columns -->
|
||
2 years ago
|
<div class="my-2">
|
||
2 years ago
|
<a-checkbox v-model:checked="syncSource.details.options.syncAttachment">{{
|
||
|
$t('labels.importAttachmentColumns')
|
||
|
}}</a-checkbox>
|
||
2 years ago
|
</div>
|
||
2 years ago
|
|
||
2 years ago
|
<!-- Import Formula Columns -->
|
||
2 years ago
|
<a-tooltip placement="top">
|
||
|
<template #title>
|
||
|
<span>Coming Soon!</span>
|
||
|
</template>
|
||
2 years ago
|
<a-checkbox v-model:checked="syncSource.details.options.syncFormula" disabled>{{
|
||
|
$t('labels.importFormulaColumns')
|
||
|
}}</a-checkbox>
|
||
2 years ago
|
</a-tooltip>
|
||
|
</a-form>
|
||
2 years ago
|
|
||
2 years ago
|
<a-divider />
|
||
2 years ago
|
|
||
2 years ago
|
<!-- Questions / Help - Reach out here -->
|
||
2 years ago
|
<div>
|
||
2 years ago
|
<a href="https://github.com/nocodb/nocodb/issues/2052" target="_blank"
|
||
|
>{{ $t('general.questions') }} / {{ $t('general.help') }} - {{ $t('general.reachOut') }}</a
|
||
|
>
|
||
2 years ago
|
|
||
2 years ago
|
<br />
|
||
2 years ago
|
<!-- This feature is currently in beta and more information can be found here -->
|
||
2 years ago
|
<div>
|
||
2 years ago
|
{{ $t('general.betaNote') }}
|
||
|
<a class="prose-sm" href="https://github.com/nocodb/nocodb/discussions/2122" target="_blank">{{
|
||
|
$t('general.moreInfo')
|
||
|
}}</a
|
||
|
>.
|
||
2 years ago
|
</div>
|
||
2 years ago
|
</div>
|
||
|
</div>
|
||
2 years ago
|
|
||
2 years ago
|
<div v-if="step === 2">
|
||
2 years ago
|
<!-- Logs -->
|
||
|
<div class="mb-4 prose-xl font-bold">{{ $t('general.logs') }}</div>
|
||
2 years ago
|
|
||
2 years ago
|
<a-card ref="logRef" :body-style="{ backgroundColor: '#000000', height: '400px', overflow: 'auto' }">
|
||
2 years ago
|
<div v-for="({ msg, status }, i) in progress" :key="i">
|
||
|
<div v-if="status === 'FAILED'" class="flex items-center">
|
||
2 years ago
|
<MdiCloseCircleOutline class="text-red-500" />
|
||
2 years ago
|
|
||
2 years ago
|
<span class="text-red-500 ml-2">{{ msg }}</span>
|
||
|
</div>
|
||
2 years ago
|
|
||
2 years ago
|
<div v-else class="flex items-center">
|
||
2 years ago
|
<MdiCurrencyUsd class="text-green-500" />
|
||
2 years ago
|
|
||
2 years ago
|
<span class="text-green-500 ml-2">{{ msg }}</span>
|
||
|
</div>
|
||
|
</div>
|
||
2 years ago
|
|
||
2 years ago
|
<div
|
||
|
v-if="
|
||
|
!progress ||
|
||
|
!progress.length ||
|
||
|
(progress[progress.length - 1].status !== 'COMPLETED' && progress[progress.length - 1].status !== 'FAILED')
|
||
|
"
|
||
2 years ago
|
class="flex items-center"
|
||
2 years ago
|
>
|
||
2 years ago
|
<!-- Importing -->
|
||
2 years ago
|
<MdiLoading class="text-green-500 animate-spin" />
|
||
2 years ago
|
<span class="text-green-500 ml-2"> {{ $t('labels.importing') }}</span>
|
||
2 years ago
|
</div>
|
||
|
</a-card>
|
||
2 years ago
|
|
||
2 years ago
|
<!-- Go to Dashboard -->
|
||
2 years ago
|
<div class="flex justify-center items-center">
|
||
2 years ago
|
<a-button v-if="showGoToDashboardButton" class="mt-4" size="large" @click="dialogShow = false">
|
||
2 years ago
|
{{ $t('labels.goToDashboard') }}
|
||
2 years ago
|
</a-button>
|
||
2 years ago
|
</div>
|
||
2 years ago
|
</div>
|
||
2 years ago
|
</div>
|
||
2 years ago
|
|
||
|
<template #footer>
|
||
|
<div v-if="step === 1">
|
||
|
<a-button key="back" @click="dialogShow = false">{{ $t('general.cancel') }}</a-button>
|
||
2 years ago
|
<!-- Import -->
|
||
2 years ago
|
<a-button
|
||
|
key="submit"
|
||
|
v-t="['c:sync-airtable:save-and-sync']"
|
||
|
type="primary"
|
||
|
class="nc-btn-airtable-import"
|
||
|
:disabled="disableImportButton"
|
||
|
@click="saveAndSync"
|
||
|
>
|
||
2 years ago
|
{{ $t('activity.import') }}
|
||
2 years ago
|
</a-button>
|
||
|
</div>
|
||
|
</template>
|
||
2 years ago
|
</a-modal>
|
||
2 years ago
|
</template>
|