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.
430 lines
14 KiB
430 lines
14 KiB
3 years ago
|
<template>
|
||
3 years ago
|
<v-dialog v-model="airtableModal" max-width="min(600px, 90%)" persistent>
|
||
3 years ago
|
<v-card class="nc-import-card h-100">
|
||
|
<v-toolbar class="elevation-0 align-center" height="68">
|
||
|
<h3 class="mt-2">
|
||
|
{{ $t('title.importFromAirtable') }}
|
||
3 years ago
|
</h3>
|
||
2 years ago
|
<div v-t="['c:airtable-import:turbo-mode']" class="ml-2 mt-3 title pointer nc-btn-enable-turbo">🚀</div>
|
||
3 years ago
|
<v-spacer />
|
||
3 years ago
|
|
||
2 years ago
|
<v-icon color="warning" class="" @click="airtableModal = false"> mdi-close </v-icon>
|
||
3 years ago
|
</v-toolbar>
|
||
|
|
||
3 years ago
|
<v-divider />
|
||
3 years ago
|
<div class="h-100" style="width: 100%">
|
||
|
<div>
|
||
2 years ago
|
<v-card :class="{ 'pb-4 mt-4': step === 2, 'py-6': step === 1 }" class="elevation-0" min-height="500">
|
||
3 years ago
|
<template v-if="step === 1">
|
||
|
<div class="d-flex flex-column justify-center align-center pt-2 pb-6">
|
||
3 years ago
|
<span
|
||
|
class="subtitle-1 font-weight-medium"
|
||
2 years ago
|
@dblclick="$set(syncSource.details.options, 'syncViews', true)"
|
||
3 years ago
|
>
|
||
3 years ago
|
Credentials
|
||
|
</span>
|
||
3 years ago
|
|
||
3 years ago
|
<a
|
||
|
href="https://docs.nocodb.com/setup-and-usages/import-airtable-to-sql-database-within-a-minute-for-free/#get-airtable-credentials"
|
||
|
class="caption grey--text"
|
||
|
target="_blank"
|
||
2 years ago
|
>Where to find this?</a
|
||
|
>
|
||
3 years ago
|
</div>
|
||
3 years ago
|
|
||
3 years ago
|
<v-form v-model="valid">
|
||
|
<div v-if="syncSource" class="px-10 mt-1 mx-auto" style="max-width: 400px">
|
||
|
<v-text-field
|
||
|
v-model="syncSource.details.apiKey"
|
||
|
outlined
|
||
|
dense
|
||
|
label="Api Key"
|
||
|
class="caption nc-input-api-key"
|
||
2 years ago
|
:type="isPasswordVisible ? 'text' : 'password'"
|
||
3 years ago
|
autocomplete="off"
|
||
2 years ago
|
:rules="[v => !!v || 'Api Key is required']"
|
||
3 years ago
|
>
|
||
|
<template #append="">
|
||
|
<v-icon class="mt-1" small @click="isPasswordVisible = !isPasswordVisible">
|
||
|
{{ isPasswordVisible ? 'visibility_off' : 'visibility' }}
|
||
|
</v-icon>
|
||
|
</template>
|
||
|
</v-text-field>
|
||
|
<v-text-field
|
||
|
v-model="syncSourceUrlOrId"
|
||
|
outlined
|
||
|
dense
|
||
|
label="Shared Base ID / URL"
|
||
|
class="caption nc-input-shared-base"
|
||
2 years ago
|
:rules="[v => !!v || 'Shared Base ID / URL is required']"
|
||
3 years ago
|
/>
|
||
|
</div>
|
||
2 years ago
|
<v-expansion-panels v-model="advanceOptionsPanel" class="mx-auto" style="width: 50%" flat>
|
||
3 years ago
|
<v-expansion-panel>
|
||
3 years ago
|
<v-expansion-panel-header hide-actions>
|
||
|
<v-spacer />
|
||
2 years ago
|
<span class="grey--text caption"
|
||
|
>More Options
|
||
|
<v-icon color="grey" small>
|
||
|
mdi-chevron-{{ advanceOptionsPanel === 0 ? 'up' : 'down' }}
|
||
|
</v-icon></span
|
||
|
>
|
||
3 years ago
|
</v-expansion-panel-header>
|
||
3 years ago
|
<v-expansion-panel-content>
|
||
|
<v-checkbox
|
||
|
v-model="syncSource.details.options.syncData"
|
||
3 years ago
|
class="caption mt-n4"
|
||
3 years ago
|
label="Import Data"
|
||
|
hide-details
|
||
|
dense
|
||
|
/>
|
||
2 years ago
|
<v-checkbox
|
||
|
v-model="syncSource.details.options.syncViews"
|
||
|
class="caption"
|
||
|
label="Import Secondary Views"
|
||
|
hide-details
|
||
|
dense
|
||
|
/>
|
||
3 years ago
|
<v-checkbox
|
||
|
v-model="syncSource.details.options.syncRollup"
|
||
3 years ago
|
class="caption"
|
||
3 years ago
|
label="Import Rollup Columns"
|
||
|
hide-details
|
||
|
dense
|
||
|
/>
|
||
|
<v-checkbox
|
||
|
v-model="syncSource.details.options.syncLookup"
|
||
3 years ago
|
class="caption"
|
||
3 years ago
|
label="Import Lookup Columns"
|
||
|
hide-details
|
||
|
dense
|
||
|
/>
|
||
3 years ago
|
<v-checkbox
|
||
|
v-model="syncSource.details.options.syncAttachment"
|
||
3 years ago
|
class="caption"
|
||
3 years ago
|
label="Import Attachment Columns"
|
||
|
hide-details
|
||
|
dense
|
||
2 years ago
|
/>
|
||
3 years ago
|
<v-tooltip bottom>
|
||
|
<template #activator="{ on }">
|
||
|
<div v-on="on">
|
||
|
<v-checkbox
|
||
|
v-model="syncSource.details.options.syncFormula"
|
||
3 years ago
|
class="caption"
|
||
3 years ago
|
label="Import Formula Columns"
|
||
|
hide-details
|
||
|
dense
|
||
|
disabled
|
||
|
/>
|
||
|
</div>
|
||
|
</template>
|
||
|
<span>Coming Soon!</span>
|
||
|
</v-tooltip>
|
||
|
</v-expansion-panel-content>
|
||
|
</v-expansion-panel>
|
||
|
</v-expansion-panels>
|
||
|
</v-form>
|
||
3 years ago
|
<v-card-actions class="justify-center pb-6 pt-6">
|
||
3 years ago
|
<v-btn
|
||
|
v-t="['c:sync-airtable:save-and-sync']"
|
||
|
class="nc-btn-airtable-import"
|
||
|
:disabled="!valid"
|
||
|
large
|
||
|
color="primary"
|
||
|
@click="saveAndSync"
|
||
3 years ago
|
>
|
||
3 years ago
|
Import
|
||
|
</v-btn>
|
||
|
</v-card-actions>
|
||
|
</template>
|
||
2 years ago
|
<template v-else-if="step === 2">
|
||
|
<v-card-title class="justify-center">
|
||
3 years ago
|
<span class="subtitle-1 font-weight-medium">Logs</span>
|
||
|
</v-card-title>
|
||
3 years ago
|
|
||
3 years ago
|
<v-card
|
||
|
ref="log"
|
||
|
dark
|
||
|
class="mt-2 mx-4 pa-4 elevation-0 green--text"
|
||
|
height="500"
|
||
|
style="overflow-y: auto"
|
||
|
>
|
||
2 years ago
|
<div v-for="({ msg, status }, i) in progress" :key="i">
|
||
|
<v-icon v-if="status === 'FAILED'" color="red" size="15"> mdi-close-circle-outline </v-icon>
|
||
|
<v-icon v-else color="green" size="15"> mdi-currency-usd </v-icon>
|
||
3 years ago
|
<span class="caption nc-text">{{ msg }}</span>
|
||
|
</div>
|
||
|
<div
|
||
2 years ago
|
v-if="
|
||
|
!progress ||
|
||
|
!progress.length ||
|
||
|
(progress[progress.length - 1].status !== 'COMPLETED' &&
|
||
|
progress[progress.length - 1].status !== 'FAILED')
|
||
|
"
|
||
3 years ago
|
class=""
|
||
|
>
|
||
2 years ago
|
<v-icon color="green" size="15"> mdi-loading mdi-spin </v-icon>
|
||
|
<span class="caption nc-text">Importing </span>
|
||
3 years ago
|
<!-- <div class="nc-progress" />-->
|
||
|
</div>
|
||
|
</v-card>
|
||
3 years ago
|
|
||
3 years ago
|
<div
|
||
2 years ago
|
v-if="progress && progress.length && progress[progress.length - 1].status === 'COMPLETED'"
|
||
3 years ago
|
class="pa-4 pt-8 text-center"
|
||
3 years ago
|
>
|
||
2 years ago
|
<v-btn large color="primary" class="nc-btn-go-dashboard" @click="airtableModal = false">
|
||
3 years ago
|
Go to dashboard
|
||
|
</v-btn>
|
||
3 years ago
|
</div>
|
||
3 years ago
|
</template>
|
||
|
<div class="text-center pa-4 pb-0">
|
||
2 years ago
|
<a class="caption grey--text" href="https://github.com/nocodb/nocodb/issues/2052" target="_blank"
|
||
|
>Questions / Help - reach out here</a
|
||
|
>
|
||
|
<br />
|
||
|
<span class="caption grey--text">
|
||
|
This feature is currently in beta and more information can be found
|
||
|
<a href="https://github.com/nocodb/nocodb/discussions/2122" class="caption grey--text" target="_blank"
|
||
|
>here</a
|
||
|
>.</span
|
||
|
>
|
||
3 years ago
|
</div>
|
||
|
</v-card>
|
||
|
</div>
|
||
|
</div>
|
||
|
</v-card>
|
||
|
</v-dialog>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
2 years ago
|
import io from 'socket.io-client';
|
||
3 years ago
|
|
||
|
export default {
|
||
|
name: 'ImportFromAirtable',
|
||
|
props: {
|
||
2 years ago
|
value: Boolean,
|
||
3 years ago
|
},
|
||
|
data: () => ({
|
||
3 years ago
|
advanceOptionsPanel: false,
|
||
3 years ago
|
isPasswordVisible: false,
|
||
3 years ago
|
valid: false,
|
||
|
socket: null,
|
||
|
step: 1,
|
||
|
progress: [],
|
||
3 years ago
|
syncSource: {
|
||
|
type: 'Airtable',
|
||
|
details: {
|
||
|
syncInterval: '15mins',
|
||
|
syncDirection: 'Airtable to NocoDB',
|
||
|
syncRetryCount: 1,
|
||
|
apiKey: '',
|
||
|
shareId: '',
|
||
|
options: {
|
||
2 years ago
|
syncViews: true,
|
||
3 years ago
|
syncData: true,
|
||
|
syncRollup: false,
|
||
|
syncLookup: true,
|
||
3 years ago
|
syncFormula: false,
|
||
2 years ago
|
syncAttachment: true,
|
||
|
},
|
||
|
},
|
||
3 years ago
|
},
|
||
2 years ago
|
syncSourceUrlOrId: '',
|
||
3 years ago
|
}),
|
||
|
computed: {
|
||
|
airtableModal: {
|
||
|
set(v) {
|
||
2 years ago
|
this.$emit('input', v);
|
||
3 years ago
|
},
|
||
|
get() {
|
||
2 years ago
|
return this.value;
|
||
|
},
|
||
|
},
|
||
3 years ago
|
},
|
||
|
watch: {
|
||
|
syncSourceUrlOrId(v) {
|
||
|
if (this.syncSource && this.syncSource.details) {
|
||
2 years ago
|
const m = v && v.match(/(exp|shr).{14}/g);
|
||
|
this.syncSource.details.shareId = m ? m[0] : null;
|
||
3 years ago
|
}
|
||
2 years ago
|
},
|
||
3 years ago
|
},
|
||
|
created() {
|
||
|
this.socket = io(new URL(this.$axios.defaults.baseURL, window.location.href.split(/[?#]/)[0]).href, {
|
||
2 years ago
|
extraHeaders: { 'xc-auth': this.$store.state.users.token },
|
||
|
});
|
||
3 years ago
|
this.socket.on('connect_error', () => {
|
||
2 years ago
|
this.socket.disconnect();
|
||
|
this.socket = null;
|
||
|
});
|
||
3 years ago
|
|
||
2 years ago
|
const socket = this.socket;
|
||
|
socket.on('connect', function (data) {
|
||
|
console.log(socket.id);
|
||
|
console.log('socket connected', data);
|
||
|
});
|
||
3 years ago
|
|
||
2 years ago
|
socket.on('progress', d => {
|
||
|
this.progress.push(d);
|
||
3 years ago
|
|
||
|
this.$nextTick(() => {
|
||
|
if (this.$refs.log) {
|
||
2 years ago
|
const el = this.$refs.log.$el;
|
||
|
el.scrollTop = el.scrollHeight;
|
||
3 years ago
|
}
|
||
2 years ago
|
});
|
||
3 years ago
|
|
||
|
if (d.status === 'COMPLETED') {
|
||
2 years ago
|
this.$store
|
||
|
.dispatch('project/_loadTables', {
|
||
|
dbKey: '0.projectJson.envs._noco.db.0',
|
||
|
key: '0.projectJson.envs._noco.db.0.tables',
|
||
|
_nodes: {
|
||
|
dbAlias: 'db',
|
||
|
env: '_noco',
|
||
|
type: 'tableDir',
|
||
|
},
|
||
|
})
|
||
|
.then(() => this.$store.dispatch('tabs/loadFirstTableTab'));
|
||
3 years ago
|
}
|
||
2 years ago
|
});
|
||
|
this.loadSyncSrc();
|
||
3 years ago
|
},
|
||
|
beforeDestroy() {
|
||
|
if (this.socket) {
|
||
2 years ago
|
this.socket.disconnect();
|
||
3 years ago
|
}
|
||
|
},
|
||
|
methods: {
|
||
|
async saveAndSync() {
|
||
2 years ago
|
await this.createOrUpdate();
|
||
|
this.sync();
|
||
3 years ago
|
},
|
||
|
sync() {
|
||
2 years ago
|
this.step = 2;
|
||
3 years ago
|
this.$axios.post(`/api/v1/db/meta/syncs/${this.syncSource.id}/trigger`, this.payload, {
|
||
|
params: {
|
||
2 years ago
|
id: this.socket.id,
|
||
|
},
|
||
|
});
|
||
3 years ago
|
},
|
||
|
async loadSyncSrc() {
|
||
2 years ago
|
const {
|
||
|
data: { list: srcs },
|
||
|
} = await this.$axios.get(`/api/v1/db/meta/projects/${this.projectId}/syncs`);
|
||
3 years ago
|
if (srcs && srcs[0]) {
|
||
2 years ago
|
srcs[0].details = srcs[0].details || {};
|
||
|
this.syncSource = this.migrateSync(srcs[0]);
|
||
|
this.syncSourceUrlOrId = srcs[0].details.shareId;
|
||
3 years ago
|
} else {
|
||
|
this.syncSource = {
|
||
|
type: 'Airtable',
|
||
|
details: {
|
||
|
syncInterval: '15mins',
|
||
|
syncDirection: 'Airtable to NocoDB',
|
||
|
syncRetryCount: 1,
|
||
|
apiKey: '',
|
||
3 years ago
|
shareId: '',
|
||
|
options: {
|
||
2 years ago
|
syncViews: true,
|
||
3 years ago
|
syncData: true,
|
||
|
syncRollup: false,
|
||
|
syncLookup: true,
|
||
3 years ago
|
syncFormula: false,
|
||
2 years ago
|
syncAttachment: true,
|
||
|
},
|
||
|
},
|
||
|
};
|
||
3 years ago
|
}
|
||
|
},
|
||
|
async createOrUpdate() {
|
||
|
try {
|
||
2 years ago
|
const { id, ...payload } = this.syncSource;
|
||
3 years ago
|
if (id) {
|
||
2 years ago
|
await this.$axios.patch(`/api/v1/db/meta/syncs/${id}`, payload);
|
||
3 years ago
|
} else {
|
||
2 years ago
|
this.syncSource = (await this.$axios.post(`/api/v1/db/meta/projects/${this.projectId}/syncs`, payload)).data;
|
||
3 years ago
|
}
|
||
|
} catch (e) {
|
||
2 years ago
|
this.$toast.error(await this._extractSdkResponseErrorMsg(e)).goAway(3000);
|
||
3 years ago
|
}
|
||
3 years ago
|
},
|
||
2 years ago
|
// enableTurbo() {
|
||
|
// this.$set(this.syncSource.details.options, 'syncViews', true)
|
||
|
// this.$toast.success('🚀🚀 Ludicrous mode activated! Let\'s go! 🚀🚀').goAway(3000)
|
||
|
// },
|
||
3 years ago
|
migrateSync(src) {
|
||
|
if (!src.details?.options) {
|
||
|
src.details.options = {
|
||
|
syncViews: false,
|
||
|
syncData: true,
|
||
|
syncRollup: false,
|
||
|
syncLookup: true,
|
||
3 years ago
|
syncFormula: false,
|
||
2 years ago
|
syncAttachment: true,
|
||
|
};
|
||
|
src.details.options.syncViews = src.syncViews;
|
||
|
delete src.syncViews;
|
||
3 years ago
|
}
|
||
2 years ago
|
return src;
|
||
|
},
|
||
|
},
|
||
|
};
|
||
3 years ago
|
</script>
|
||
|
|
||
|
<style scoped>
|
||
|
.nc-progress {
|
||
|
margin-left: 12px;
|
||
|
position: relative;
|
||
|
width: 5px;
|
||
|
height: 5px;
|
||
|
border-radius: 5px;
|
||
|
background-color: #9880ff;
|
||
|
color: #9880ff;
|
||
|
animation: dotFlashing 1s infinite linear alternate;
|
||
2 years ago
|
animation-delay: 0.5s;
|
||
3 years ago
|
}
|
||
|
|
||
2 years ago
|
.nc-progress::before,
|
||
|
.nc-progress::after {
|
||
3 years ago
|
content: '';
|
||
|
display: inline-block;
|
||
|
position: absolute;
|
||
|
top: 0;
|
||
|
}
|
||
|
|
||
|
.nc-progress::before {
|
||
|
left: -7.5px;
|
||
|
width: 5px;
|
||
|
height: 5px;
|
||
|
border-radius: 5px;
|
||
|
background-color: #9880ff;
|
||
|
color: #9880ff;
|
||
|
animation: dotFlashing 1s infinite alternate;
|
||
|
animation-delay: 0s;
|
||
|
}
|
||
|
|
||
|
.nc-progress::after {
|
||
|
left: 7.5px;
|
||
|
width: 5px;
|
||
|
height: 5px;
|
||
|
border-radius: 5px;
|
||
|
background-color: var(--v-primary-base);
|
||
|
color: var(--v-primary-base);
|
||
|
animation: dotFlashing 1s infinite alternate;
|
||
|
animation-delay: 1s;
|
||
|
}
|
||
|
|
||
|
@keyframes dotFlashing {
|
||
|
0% {
|
||
|
background-color: var(--v-primary-base);
|
||
|
}
|
||
|
50%,
|
||
|
100% {
|
||
|
background-color: var(--v-backgroundColor-base);
|
||
|
}
|
||
|
}
|
||
|
</style>
|