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.
165 lines
5.3 KiB
165 lines
5.3 KiB
2 years ago
|
<script lang="ts" setup>
|
||
2 years ago
|
import { ref } from 'vue'
|
||
|
import { useI18n } from 'vue-i18n'
|
||
|
import { useToast } from 'vue-toastification'
|
||
2 years ago
|
import { navigateTo, useNuxtApp } from '#app'
|
||
2 years ago
|
import { extractSdkResponseErrorMsg } from '~/utils/errorUtils'
|
||
|
import { clientTypes, getDefaultConnectionConfig, getTestDatabaseName } from '~/utils/projectCreateUtils'
|
||
2 years ago
|
import MaterialSymbolsRocketLaunchOutline from '~icons/material-symbols/rocket-launch-outline'
|
||
2 years ago
|
|
||
2 years ago
|
const name = ref('')
|
||
|
const loading = ref(false)
|
||
|
const valid = ref(false)
|
||
2 years ago
|
const testSuccess = ref(true)
|
||
2 years ago
|
const projectDatasource = ref(getDefaultConnectionConfig('mysql2'))
|
||
2 years ago
|
const inflection = reactive({
|
||
2 years ago
|
tableName: 'camelize',
|
||
|
columnName: 'camelize',
|
||
|
})
|
||
2 years ago
|
|
||
2 years ago
|
const { $api, $e } = useNuxtApp()
|
||
|
const toast = useToast()
|
||
2 years ago
|
const { t } = useI18n()
|
||
2 years ago
|
|
||
2 years ago
|
const titleValidationRule = [
|
||
|
(v: string) => !!v || 'Title is required',
|
||
|
(v: string) => v.length <= 50 || 'Project name exceeds 50 characters',
|
||
|
]
|
||
2 years ago
|
|
||
|
const createProject = async () => {
|
||
2 years ago
|
loading.value = true
|
||
2 years ago
|
try {
|
||
2 years ago
|
const result = await $api.project.create({
|
||
2 years ago
|
title: name.value,
|
||
|
bases: [
|
||
|
{
|
||
2 years ago
|
type: projectDatasource.value.client,
|
||
|
config: projectDatasource.value,
|
||
2 years ago
|
inflection_column: inflection.columnName,
|
||
2 years ago
|
inflection_table: inflection.tableName,
|
||
|
},
|
||
2 years ago
|
],
|
||
2 years ago
|
external: true,
|
||
|
})
|
||
2 years ago
|
|
||
2 years ago
|
await navigateTo(`/nc/${result.id}`)
|
||
2 years ago
|
} catch (e: any) {
|
||
2 years ago
|
// todo: toast
|
||
2 years ago
|
toast.error(await extractSdkResponseErrorMsg(e))
|
||
2 years ago
|
}
|
||
2 years ago
|
loading.value = false
|
||
|
}
|
||
2 years ago
|
|
||
|
const testConnection = async () => {
|
||
2 years ago
|
$e('a:project:create:extdb:test-connection', [])
|
||
2 years ago
|
try {
|
||
|
// this.handleSSL(projectDatasource)
|
||
|
|
||
2 years ago
|
if (projectDatasource.value.client === 'sqlite3') {
|
||
|
testSuccess.value = true
|
||
2 years ago
|
} else {
|
||
2 years ago
|
const testConnectionConfig = {
|
||
|
...projectDatasource,
|
||
|
connection: {
|
||
|
...projectDatasource.value.connection,
|
||
2 years ago
|
database: getTestDatabaseName(projectDatasource.value),
|
||
|
},
|
||
|
}
|
||
2 years ago
|
|
||
2 years ago
|
const result = await $api.utils.testConnection(testConnectionConfig)
|
||
2 years ago
|
|
||
|
if (result.code === 0) {
|
||
2 years ago
|
testSuccess.value = true
|
||
2 years ago
|
} else {
|
||
2 years ago
|
testSuccess.value = false
|
||
2 years ago
|
toast.error(`${t('msg.error.dbConnectionFailed')} ${result.message}`)
|
||
2 years ago
|
}
|
||
|
}
|
||
2 years ago
|
} catch (e: any) {
|
||
|
testSuccess.value = false
|
||
|
toast.error(await extractSdkResponseErrorMsg(e))
|
||
2 years ago
|
}
|
||
2 years ago
|
}
|
||
2 years ago
|
</script>
|
||
|
|
||
2 years ago
|
<template>
|
||
|
<NuxtLayout>
|
||
2 years ago
|
<v-form ref="formValidator" v-model="valid" class="h-full" @submit.prevent="createProject">
|
||
|
<v-container fluid class="flex justify-center items-center h-5/6">
|
||
2 years ago
|
<v-card max-width="600">
|
||
2 years ago
|
<!-- Create Project -->
|
||
2 years ago
|
<v-container class="pb-10 px-12">
|
||
2 years ago
|
<h1 class="my-4 prose-lg text-center">
|
||
2 years ago
|
{{ $t('activity.createProject') }}
|
||
2 years ago
|
</h1>
|
||
|
|
||
2 years ago
|
<v-row>
|
||
|
<v-col offset="2" cols="8">
|
||
|
<v-text-field
|
||
|
v-model="name"
|
||
|
:rules="titleValidationRule"
|
||
|
class="nc-metadb-project-name"
|
||
|
:label="$t('labels.projName')"
|
||
|
/>
|
||
|
</v-col>
|
||
|
|
||
|
<v-col cols="6">
|
||
|
<v-select
|
||
|
v-model="projectDatasource.client"
|
||
|
density="compact"
|
||
|
:items="clientTypes"
|
||
|
item-title="text"
|
||
|
item-value="value"
|
||
|
class="nc-metadb-project-name"
|
||
|
label="Database client"
|
||
|
/>
|
||
|
</v-col>
|
||
|
<v-col cols="6">
|
||
|
<v-text-field v-model="projectDatasource.connection.host" density="compact" :label="$t('labels.hostAddress')" />
|
||
|
</v-col>
|
||
|
<v-col cols="6">
|
||
|
<v-text-field
|
||
|
v-model="projectDatasource.connection.port"
|
||
|
density="compact"
|
||
|
:label="$t('labels.port')"
|
||
|
type="number"
|
||
|
/>
|
||
|
</v-col>
|
||
|
<v-col cols="6">
|
||
|
<v-text-field v-model="projectDatasource.connection.user" density="compact" :label="$t('labels.username')" />
|
||
|
</v-col>
|
||
|
<v-col cols="6">
|
||
|
<v-text-field
|
||
|
v-model="projectDatasource.connection.password"
|
||
|
density="compact"
|
||
|
type="password"
|
||
|
:label="$t('labels.password')"
|
||
|
/>
|
||
|
</v-col>
|
||
|
<v-col cols="6">
|
||
|
<v-text-field v-model="projectDatasource.connection.database" density="compact" label="Database name" />
|
||
|
</v-col>
|
||
2 years ago
|
</v-row>
|
||
|
|
||
2 years ago
|
<div class="d-flex justify-center" style="gap: 4px">
|
||
|
<v-btn :disabled="!testSuccess" large :loading="loading" color="primary" @click="createProject">
|
||
|
<MaterialSymbolsRocketLaunchOutline class="mr-1" />
|
||
|
<span> {{ $t('general.create') }} </span>
|
||
|
</v-btn>
|
||
|
|
||
|
<!-- <v-btn small class="px-2"> -->
|
||
|
<!-- todo:implement test connection -->
|
||
|
<!-- <v-btn size="sm" class="text-sm text-capitalize">
|
||
|
<!– Test Database Connection –>
|
||
|
{{ $t('activity.testDbConn') }}
|
||
|
</v-btn> -->
|
||
|
</div>
|
||
|
</v-container>
|
||
2 years ago
|
</v-card>
|
||
2 years ago
|
</v-container>
|
||
|
</v-form>
|
||
2 years ago
|
</NuxtLayout>
|
||
|
</template>
|
||
|
|
||
2 years ago
|
<style scoped></style>
|