|
|
|
@ -1,31 +1,30 @@
|
|
|
|
|
<script lang="ts" setup> |
|
|
|
|
import { ref } from 'vue' |
|
|
|
|
import { useI18n } from 'vue-i18n' |
|
|
|
|
import { useToast } from 'vue-toastification' |
|
|
|
|
import { useNuxtApp, useRouter } from '#app' |
|
|
|
|
import { extractSdkResponseErrorMsg } from '~/helpers/errorUtils' |
|
|
|
|
import { clientTypes, getDefaultConnectionConfig, getTestDatabaseName } from '~/helpers/projectCreateUtils' |
|
|
|
|
import { ref } from "vue"; |
|
|
|
|
import { useI18n } from "vue-i18n"; |
|
|
|
|
import { useToast } from "vue-toastification"; |
|
|
|
|
import { useNuxtApp, useRouter } from "#app"; |
|
|
|
|
import { extractSdkResponseErrorMsg } from "~/utils/errorUtils"; |
|
|
|
|
import { clientTypes, getDefaultConnectionConfig, getTestDatabaseName } from "~/utils/projectCreateUtils"; |
|
|
|
|
|
|
|
|
|
const name = ref('') |
|
|
|
|
const loading = ref(false) |
|
|
|
|
const valid = ref(false) |
|
|
|
|
const testSuccess = ref(false) |
|
|
|
|
const projectDatasource = ref(getDefaultConnectionConfig('mysql2')) |
|
|
|
|
const name = ref(""); |
|
|
|
|
const loading = ref(false); |
|
|
|
|
const valid = ref(false); |
|
|
|
|
const testSuccess = ref(false); |
|
|
|
|
const projectDatasource = ref(getDefaultConnectionConfig("mysql2")); |
|
|
|
|
const inflection = reactive({ |
|
|
|
|
tableName: 'camelize', |
|
|
|
|
columnName: 'camelize', |
|
|
|
|
}) |
|
|
|
|
tableName: "camelize", |
|
|
|
|
columnName: "camelize" |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const $router = useRouter() |
|
|
|
|
const { $api, $e } = useNuxtApp() |
|
|
|
|
const { user } = useUser() |
|
|
|
|
const toast = useToast() |
|
|
|
|
const { t: $t } = useI18n() |
|
|
|
|
const $router = useRouter(); |
|
|
|
|
const { $api, $e } = useNuxtApp(); |
|
|
|
|
const toast = useToast(); |
|
|
|
|
const { t: $t } = useI18n(); |
|
|
|
|
|
|
|
|
|
const titleValidationRule = [(v) => !!v || 'Title is required', (v) => v.length <= 50 || 'Project name exceeds 50 characters'] |
|
|
|
|
const titleValidationRule = [(v: string) => !!v || "Title is required", (v: string) => v.length <= 50 || "Project name exceeds 50 characters"]; |
|
|
|
|
|
|
|
|
|
const createProject = async () => { |
|
|
|
|
loading.value = true |
|
|
|
|
loading.value = true; |
|
|
|
|
try { |
|
|
|
|
const result = await $api.project.create({ |
|
|
|
|
title: name.value, |
|
|
|
@ -34,50 +33,50 @@ const createProject = async () => {
|
|
|
|
|
type: projectDatasource.value.client, |
|
|
|
|
config: projectDatasource.value, |
|
|
|
|
inflection_column: inflection.columnName, |
|
|
|
|
inflection_table: inflection.tableName, |
|
|
|
|
}, |
|
|
|
|
inflection_table: inflection.tableName |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
external: true, |
|
|
|
|
}) |
|
|
|
|
external: true |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
await $router.push(`/dashboard/${result.id}`) |
|
|
|
|
} catch (e) { |
|
|
|
|
await $router.push(`/dashboard/${result.id}`); |
|
|
|
|
} catch (e: any) { |
|
|
|
|
// todo: toast |
|
|
|
|
toast.error(await extractSdkResponseErrorMsg(e)) |
|
|
|
|
toast.error(await extractSdkResponseErrorMsg(e)); |
|
|
|
|
} |
|
|
|
|
loading.value = false |
|
|
|
|
} |
|
|
|
|
loading.value = false; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const testConnection = async () => { |
|
|
|
|
$e('a:project:create:extdb:test-connection') |
|
|
|
|
$e("a:project:create:extdb:test-connection",[]); |
|
|
|
|
try { |
|
|
|
|
// this.handleSSL(projectDatasource) |
|
|
|
|
|
|
|
|
|
if (projectDatasource.value.client === 'sqlite3') { |
|
|
|
|
testSuccess.value = true |
|
|
|
|
if (projectDatasource.value.client === "sqlite3") { |
|
|
|
|
testSuccess.value = true; |
|
|
|
|
} else { |
|
|
|
|
const testConnectionConfig = { |
|
|
|
|
...projectDatasource, |
|
|
|
|
connection: { |
|
|
|
|
...projectDatasource.value.connection, |
|
|
|
|
database: getTestDatabaseName(projectDatasource.value), |
|
|
|
|
}, |
|
|
|
|
database: getTestDatabaseName(projectDatasource.value) |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const result = await $api.utils.testConnection(testConnectionConfig) |
|
|
|
|
const result = await $api.utils.testConnection(testConnectionConfig); |
|
|
|
|
|
|
|
|
|
if (result.code === 0) { |
|
|
|
|
testSuccess.value = true |
|
|
|
|
testSuccess.value = true; |
|
|
|
|
} else { |
|
|
|
|
testSuccess.value = false |
|
|
|
|
toast.error($t('msg.error.dbConnectionFailed') + result.message) |
|
|
|
|
testSuccess.value = false; |
|
|
|
|
toast.error($t("msg.error.dbConnectionFailed") + result.message); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
testSuccess.value = false |
|
|
|
|
toast.error(await extractSdkResponseErrorMsg(e)) |
|
|
|
|
} catch (e:any) { |
|
|
|
|
testSuccess.value = false; |
|
|
|
|
toast.error(await extractSdkResponseErrorMsg(e)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
<template> |
|
|
|
@ -94,7 +93,8 @@ const testConnection = async () => {
|
|
|
|
|
<div class="mx-auto" style="width: 350px"> |
|
|
|
|
<!-- label="Enter Project Name" --> |
|
|
|
|
<!-- rule text: Required --> |
|
|
|
|
<v-text-field v-model="name" :rules="titleValidationRule" class="nc-metadb-project-name" label="Project name" /> |
|
|
|
|
<v-text-field v-model="name" :rules="titleValidationRule" class="nc-metadb-project-name" |
|
|
|
|
label="Project name" /> |
|
|
|
|
<!-- :rules="titleValidationRule" --> |
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
@ -115,7 +115,8 @@ const testConnection = async () => {
|
|
|
|
|
<v-text-field v-model="projectDatasource.connection.host" density="compact" label="Host" /> |
|
|
|
|
</v-col> |
|
|
|
|
<v-col cols="6"> |
|
|
|
|
<v-text-field v-model="projectDatasource.connection.port" density="compact" label="Port" type="number" /> |
|
|
|
|
<v-text-field v-model="projectDatasource.connection.port" density="compact" label="Port" |
|
|
|
|
type="number" /> |
|
|
|
|
</v-col> |
|
|
|
|
<v-col cols="6"> |
|
|
|
|
<v-text-field v-model="projectDatasource.connection.user" density="compact" label="Username" /> |
|
|
|
@ -129,7 +130,8 @@ const testConnection = async () => {
|
|
|
|
|
/> |
|
|
|
|
</v-col> |
|
|
|
|
<v-col cols="6"> |
|
|
|
|
<v-text-field v-model="projectDatasource.connection.database" density="compact" label="Database name" /> |
|
|
|
|
<v-text-field v-model="projectDatasource.connection.database" density="compact" |
|
|
|
|
label="Database name" /> |
|
|
|
|
</v-col> |
|
|
|
|
|
|
|
|
|
<!-- <v-col cols="6"> |
|
|
|
@ -152,14 +154,14 @@ const testConnection = async () => {
|
|
|
|
|
|
|
|
|
|
<div class="d-flex justify-center" style="gap: 4px"> |
|
|
|
|
<v-btn :disabled="!testSuccess" class="" large :loading="loading" color="primary" @click="createProject"> |
|
|
|
|
<v-icon class="mr-1 mt-n1"> mdi-rocket-launch-outline </v-icon> |
|
|
|
|
<v-icon class="mr-1 mt-n1"> mdi-rocket-launch-outline</v-icon> |
|
|
|
|
<!-- Create --> |
|
|
|
|
<span class="mr-1">{{ $t('general.create') }} </span> |
|
|
|
|
<span class="mr-1">{{ $t("general.create") }} </span> |
|
|
|
|
</v-btn> |
|
|
|
|
|
|
|
|
|
<v-btn size="sm" class="text-sm text-capitalize"> |
|
|
|
|
<!-- Test Database Connection --> |
|
|
|
|
{{ $t('activity.testDbConn') }} |
|
|
|
|
{{ $t("activity.testDbConn") }} |
|
|
|
|
</v-btn> |
|
|
|
|
</div> |
|
|
|
|
</v-container> |
|
|
|
|