|
|
@ -1,12 +1,20 @@ |
|
|
|
<script setup lang="ts"> |
|
|
|
<script setup lang="ts"> |
|
|
|
import io from 'socket.io-client' |
|
|
|
|
|
|
|
import type { Socket } from 'socket.io-client' |
|
|
|
import type { Socket } from 'socket.io-client' |
|
|
|
import { Form, message } from 'ant-design-vue' |
|
|
|
import io from 'socket.io-client' |
|
|
|
import type { Card as AntCard } from 'ant-design-vue' |
|
|
|
import type { Card as AntCard } from 'ant-design-vue' |
|
|
|
import { extractSdkResponseErrorMsg, fieldRequiredValidator } from '~/utils' |
|
|
|
import { Form, message } from 'ant-design-vue' |
|
|
|
import MdiCloseCircleOutlineIcon from '~icons/mdi/close-circle-outline' |
|
|
|
import { |
|
|
|
import MdiCurrencyUsdIcon from '~icons/mdi/currency-usd' |
|
|
|
computed, |
|
|
|
import MdiLoadingIcon from '~icons/mdi/loading' |
|
|
|
extractSdkResponseErrorMsg, |
|
|
|
|
|
|
|
fieldRequiredValidator, |
|
|
|
|
|
|
|
nextTick, |
|
|
|
|
|
|
|
onBeforeUnmount, |
|
|
|
|
|
|
|
onMounted, |
|
|
|
|
|
|
|
ref, |
|
|
|
|
|
|
|
useNuxtApp, |
|
|
|
|
|
|
|
useProject, |
|
|
|
|
|
|
|
watch, |
|
|
|
|
|
|
|
} from '#imports' |
|
|
|
|
|
|
|
|
|
|
|
interface Props { |
|
|
|
interface Props { |
|
|
|
modelValue: boolean |
|
|
|
modelValue: boolean |
|
|
@ -54,29 +62,21 @@ const syncSource = ref({ |
|
|
|
}, |
|
|
|
}, |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const validators = computed(() => { |
|
|
|
const validators = computed(() => ({ |
|
|
|
return { |
|
|
|
|
|
|
|
'details.apiKey': [fieldRequiredValidator], |
|
|
|
'details.apiKey': [fieldRequiredValidator], |
|
|
|
'details.syncSourceUrlOrId': [fieldRequiredValidator], |
|
|
|
'details.syncSourceUrlOrId': [fieldRequiredValidator], |
|
|
|
} |
|
|
|
})) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const dialogShow = computed({ |
|
|
|
const dialogShow = computed({ |
|
|
|
get() { |
|
|
|
get: () => modelValue, |
|
|
|
return modelValue |
|
|
|
set: (v) => emit('update:modelValue', v), |
|
|
|
}, |
|
|
|
|
|
|
|
set(v) { |
|
|
|
|
|
|
|
emit('update:modelValue', v) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const useForm = Form.useForm |
|
|
|
const useForm = Form.useForm |
|
|
|
|
|
|
|
|
|
|
|
const { validateInfos } = useForm(syncSource, validators) |
|
|
|
const { validateInfos } = useForm(syncSource, validators) |
|
|
|
|
|
|
|
|
|
|
|
const disableImportButton = computed(() => { |
|
|
|
const disableImportButton = computed(() => !syncSource.value.details.apiKey || !syncSource.value.details.syncSourceUrlOrId) |
|
|
|
return !syncSource.value.details.apiKey || !syncSource.value.details.syncSourceUrlOrId |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function saveAndSync() { |
|
|
|
async function saveAndSync() { |
|
|
|
await createOrUpdate() |
|
|
|
await createOrUpdate() |
|
|
@ -86,6 +86,7 @@ async function saveAndSync() { |
|
|
|
async function createOrUpdate() { |
|
|
|
async function createOrUpdate() { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const { id, ...payload } = syncSource.value |
|
|
|
const { id, ...payload } = syncSource.value |
|
|
|
|
|
|
|
|
|
|
|
if (id !== '') { |
|
|
|
if (id !== '') { |
|
|
|
await $fetch(`/api/v1/db/meta/syncs/${id}`, { |
|
|
|
await $fetch(`/api/v1/db/meta/syncs/${id}`, { |
|
|
|
baseURL, |
|
|
|
baseURL, |
|
|
@ -94,13 +95,12 @@ async function createOrUpdate() { |
|
|
|
body: payload, |
|
|
|
body: payload, |
|
|
|
}) |
|
|
|
}) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
const data: any = await $fetch(`/api/v1/db/meta/projects/${project.value.id}/syncs`, { |
|
|
|
syncSource.value = await $fetch(`/api/v1/db/meta/projects/${project.value.id}/syncs`, { |
|
|
|
baseURL, |
|
|
|
baseURL, |
|
|
|
method: 'POST', |
|
|
|
method: 'POST', |
|
|
|
headers: { 'xc-auth': $state.token.value as string }, |
|
|
|
headers: { 'xc-auth': $state.token.value as string }, |
|
|
|
body: payload, |
|
|
|
body: payload, |
|
|
|
}) |
|
|
|
}) |
|
|
|
syncSource.value = data |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} catch (e: any) { |
|
|
|
} catch (e: any) { |
|
|
|
message.error(await extractSdkResponseErrorMsg(e)) |
|
|
|
message.error(await extractSdkResponseErrorMsg(e)) |
|
|
@ -113,7 +113,9 @@ async function loadSyncSrc() { |
|
|
|
method: 'GET', |
|
|
|
method: 'GET', |
|
|
|
headers: { 'xc-auth': $state.token.value as string }, |
|
|
|
headers: { 'xc-auth': $state.token.value as string }, |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const { list: srcs } = data |
|
|
|
const { list: srcs } = data |
|
|
|
|
|
|
|
|
|
|
|
if (srcs && srcs[0]) { |
|
|
|
if (srcs && srcs[0]) { |
|
|
|
srcs[0].details = srcs[0].details || {} |
|
|
|
srcs[0].details = srcs[0].details || {} |
|
|
|
syncSource.value = migrateSync(srcs[0]) |
|
|
|
syncSource.value = migrateSync(srcs[0]) |
|
|
@ -171,6 +173,7 @@ function migrateSync(src: any) { |
|
|
|
src.details.options.syncViews = src.syncViews |
|
|
|
src.details.options.syncViews = src.syncViews |
|
|
|
delete src.syncViews |
|
|
|
delete src.syncViews |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return src |
|
|
|
return src |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -188,6 +191,7 @@ onMounted(async () => { |
|
|
|
socket = io(new URL(baseURL, window.location.href.split(/[?#]/)[0]).href, { |
|
|
|
socket = io(new URL(baseURL, window.location.href.split(/[?#]/)[0]).href, { |
|
|
|
extraHeaders: { 'xc-auth': $state.token.value as string }, |
|
|
|
extraHeaders: { 'xc-auth': $state.token.value as string }, |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
socket.on('connect_error', () => { |
|
|
|
socket.on('connect_error', () => { |
|
|
|
socket?.disconnect() |
|
|
|
socket?.disconnect() |
|
|
|
socket = null |
|
|
|
socket = null |
|
|
@ -203,7 +207,7 @@ onMounted(async () => { |
|
|
|
progress.value.push(d) |
|
|
|
progress.value.push(d) |
|
|
|
|
|
|
|
|
|
|
|
// FIXME: this doesn't work |
|
|
|
// FIXME: this doesn't work |
|
|
|
nextTick(() => { |
|
|
|
await nextTick(() => { |
|
|
|
;(logRef.value?.$el as HTMLDivElement).scrollTo() |
|
|
|
;(logRef.value?.$el as HTMLDivElement).scrollTo() |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -213,6 +217,7 @@ onMounted(async () => { |
|
|
|
// TODO: add tab of the first table |
|
|
|
// TODO: add tab of the first table |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
await loadSyncSrc() |
|
|
|
await loadSyncSrc() |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -317,13 +322,13 @@ onBeforeUnmount(() => { |
|
|
|
<a-card ref="logRef" :body-style="{ backgroundColor: '#000000', height: '400px', overflow: 'auto' }"> |
|
|
|
<a-card ref="logRef" :body-style="{ backgroundColor: '#000000', height: '400px', overflow: 'auto' }"> |
|
|
|
<div v-for="({ msg, status }, i) in progress" :key="i"> |
|
|
|
<div v-for="({ msg, status }, i) in progress" :key="i"> |
|
|
|
<div v-if="status === 'FAILED'" class="flex items-center"> |
|
|
|
<div v-if="status === 'FAILED'" class="flex items-center"> |
|
|
|
<MdiCloseCircleOutlineIcon class="text-red-500" /> |
|
|
|
<MdiCloseCircleOutline class="text-red-500" /> |
|
|
|
|
|
|
|
|
|
|
|
<span class="text-red-500 ml-2">{{ msg }}</span> |
|
|
|
<span class="text-red-500 ml-2">{{ msg }}</span> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
<div v-else class="flex items-center"> |
|
|
|
<div v-else class="flex items-center"> |
|
|
|
<MdiCurrencyUsdIcon class="text-green-500" /> |
|
|
|
<MdiCurrencyUsd class="text-green-500" /> |
|
|
|
|
|
|
|
|
|
|
|
<span class="text-green-500 ml-2">{{ msg }}</span> |
|
|
|
<span class="text-green-500 ml-2">{{ msg }}</span> |
|
|
|
</div> |
|
|
|
</div> |
|
|
@ -337,7 +342,7 @@ onBeforeUnmount(() => { |
|
|
|
" |
|
|
|
" |
|
|
|
class="flex items-center" |
|
|
|
class="flex items-center" |
|
|
|
> |
|
|
|
> |
|
|
|
<MdiLoadingIcon class="text-green-500 animate-spin" /> |
|
|
|
<MdiLoading class="text-green-500 animate-spin" /> |
|
|
|
<span class="text-green-500 ml-2"> Importing</span> |
|
|
|
<span class="text-green-500 ml-2"> Importing</span> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</a-card> |
|
|
|
</a-card> |
|
|
|