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.
1822 lines
67 KiB
1822 lines
67 KiB
3 years ago
|
<template>
|
||
|
<v-container fluid>
|
||
2 years ago
|
<v-col :class="{ 'col-md-8 offset-md-2 col-sm-10 offset-sm-1 col-12': !edit }" style="position: relative">
|
||
3 years ago
|
<v-form ref="form" v-model="valid" :class="{ 'mt-8 pt-8': !edit }">
|
||
|
<v-card ref="mainCard" class="elevation-5">
|
||
3 years ago
|
<div
|
||
|
v-if="!edit"
|
||
3 years ago
|
style="
|
||
|
position: absolute;
|
||
|
top: -30px;
|
||
|
left: -moz-calc(50% - 30px);
|
||
|
left: -webkit-calc(50% - 30px);
|
||
|
left: calc(50% - 30px);
|
||
|
z-index: 999;
|
||
|
border-radius: 10px;
|
||
|
"
|
||
3 years ago
|
class="primary"
|
||
|
>
|
||
|
<v-img
|
||
|
class="mx-auto"
|
||
|
width="60"
|
||
|
height="60"
|
||
|
:src="require('@/assets/img/icons/512x512-trans.png')"
|
||
3 years ago
|
@dblclick="enableAllSchemas()"
|
||
|
/>
|
||
3 years ago
|
</div>
|
||
3 years ago
|
<v-toolbar
|
||
|
flat
|
||
|
color=""
|
||
|
class="mb-3"
|
||
2 years ago
|
style="width: 100%; border-bottom: 1px solid var(--v-backgroundColor-base)"
|
||
3 years ago
|
>
|
||
|
<v-toolbar-title class="title">
|
||
|
<!-- Edit Project -->
|
||
2 years ago
|
<span v-if="edit">{{ $t('activity.editProject') }}</span>
|
||
3 years ago
|
<!-- Create Project -->
|
||
2 years ago
|
<span v-else>{{ $t('activity.createProject') }}</span>
|
||
3 years ago
|
</v-toolbar-title>
|
||
3 years ago
|
<v-spacer />
|
||
3 years ago
|
<!-- Cancel and Return -->
|
||
2 years ago
|
<x-btn v-ge="['project', 'cancel']" :tooltip="$t('tooltip.cancelReturn')" to="/" class="elevation-20">
|
||
3 years ago
|
<!-- Cancel -->
|
||
2 years ago
|
{{ $t('general.cancel') }}
|
||
3 years ago
|
</x-btn>
|
||
|
<x-btn
|
||
3 years ago
|
v-ge="['project', 'save']"
|
||
3 years ago
|
:disabled="!valid || !envStatusValid"
|
||
|
class="primary"
|
||
3 years ago
|
@click="createOrUpdateProject()"
|
||
|
>
|
||
|
<!-- Update & Restart -->
|
||
2 years ago
|
<span v-if="edit">{{ $t('tooltip.updateRestart') }}</span>
|
||
3 years ago
|
<!-- Save Project -->
|
||
2 years ago
|
<span v-else>{{ $t('activity.saveProject') }}</span>
|
||
3 years ago
|
</x-btn>
|
||
|
<v-progress-linear
|
||
|
v-if="projectReloading"
|
||
|
top
|
||
|
absolute
|
||
|
color="success"
|
||
|
indeterminate
|
||
|
height="3"
|
||
3 years ago
|
style="top: -3px"
|
||
3 years ago
|
/>
|
||
3 years ago
|
</v-toolbar>
|
||
|
|
||
|
<div ref="panelContainer" style="">
|
||
2 years ago
|
<api-overlay v-show="projectReloading" :project-created="projectCreated" />
|
||
3 years ago
|
<v-container fluid>
|
||
|
<v-row>
|
||
|
<v-col cols="12" class="mb-0 pb-0">
|
||
|
<div style="max-width: 360px" class="mx-auto mb-3">
|
||
3 years ago
|
<!-- Enter Project Name -->
|
||
3 years ago
|
<v-text-field
|
||
|
ref="name"
|
||
3 years ago
|
v-model="project.title"
|
||
3 years ago
|
v-ge="['project', 'name']"
|
||
2 years ago
|
:rules="form.titleValidationRule"
|
||
3 years ago
|
:height="20"
|
||
3 years ago
|
:label="$t('placeholder.projName')"
|
||
3 years ago
|
autofocus
|
||
3 years ago
|
/>
|
||
3 years ago
|
</div>
|
||
|
</v-col>
|
||
|
|
||
2 years ago
|
<v-col v-show="isTitle" cols="10" offset="1" :class="{ 'mt-0 pt-0': !edit, 'mt-3 pt-3': edit }">
|
||
3 years ago
|
<p
|
||
|
:class="{
|
||
|
'text-center mb-2 mt-3': !edit,
|
||
|
'text-center mb-2 mt-3 grey--text': edit,
|
||
|
}"
|
||
|
>
|
||
2 years ago
|
{{ $t('title.dbCredentials') }}
|
||
3 years ago
|
</p>
|
||
|
<v-expansion-panels
|
||
|
v-model="panel"
|
||
|
focusable
|
||
|
accordion=""
|
||
|
class="elevation-20"
|
||
|
style="border: 1px solid white"
|
||
|
>
|
||
3 years ago
|
<v-expansion-panel
|
||
3 years ago
|
v-for="(envData, envKey, panelIndex) in project.envs"
|
||
|
:key="panelIndex"
|
||
3 years ago
|
:ref="`panel${envKey}`"
|
||
3 years ago
|
@change="onPanelToggle(panelIndex, envKey)"
|
||
3 years ago
|
>
|
||
|
<v-expansion-panel-header disable-icon-rotate>
|
||
|
<p class="pa-0 ma-0">
|
||
2 years ago
|
<v-tooltip v-for="(db, tabIndex) in envData.db" :key="tabIndex" bottom>
|
||
3 years ago
|
<template #activator="{ on }">
|
||
3 years ago
|
<v-icon
|
||
|
small
|
||
3 years ago
|
:color="getDbStatusColor(db)"
|
||
2 years ago
|
@click.native.stop="showDBTabInEnvPanel(panelIndex, tabIndex)"
|
||
3 years ago
|
v-on="on"
|
||
3 years ago
|
>
|
||
|
mdi-database
|
||
3 years ago
|
</v-icon>
|
||
|
</template>
|
||
|
{{ getDbStatusTooltip(db) }}
|
||
|
</v-tooltip>
|
||
|
|
||
2 years ago
|
<span v-if="project.ui[envKey]" class="caption" :class="project.ui[envKey].color + '--text'">
|
||
3 years ago
|
<i>{{ project.ui[envKey].msg }}</i>
|
||
|
</span>
|
||
|
|
||
|
<x-btn
|
||
3 years ago
|
v-if="panelIndex"
|
||
|
v-ge="['project', 'env-delete']"
|
||
3 years ago
|
small
|
||
|
text
|
||
|
btn.class="float-right"
|
||
|
tooltip="Click here to remove environment"
|
||
|
@click.native.stop="removeEnv(envKey)"
|
||
3 years ago
|
>
|
||
3 years ago
|
<v-hover v-slot="{ hover }">
|
||
2 years ago
|
<v-icon :color="hover ? 'error' : 'grey'" @click.native.stop="removeEnv(envKey)">
|
||
3 years ago
|
mdi-delete
|
||
|
</v-icon>
|
||
|
</v-hover>
|
||
|
</x-btn>
|
||
|
</p>
|
||
3 years ago
|
<template #actions>
|
||
2 years ago
|
<v-tooltip v-if="getEnvironmentStatusAggregated(envData.db)" bottom>
|
||
3 years ago
|
<template #activator="{ on }">
|
||
2 years ago
|
<v-icon color="green" v-on="on"> mdi-check-circle </v-icon>
|
||
3 years ago
|
</template>
|
||
|
<span>Environment setup complete</span>
|
||
|
</v-tooltip>
|
||
3 years ago
|
<v-tooltip v-else-if="edit" bottom>
|
||
|
<template #activator="{ on }">
|
||
2 years ago
|
<v-icon color="orange" v-on="on"> mdi-alert-circle </v-icon>
|
||
3 years ago
|
</template>
|
||
|
<span>Environment setup pending</span>
|
||
|
</v-tooltip>
|
||
|
</template>
|
||
|
</v-expansion-panel-header>
|
||
|
<v-expansion-panel-content eager>
|
||
|
<v-col>
|
||
|
<v-card flat="">
|
||
2 years ago
|
<v-tabs v-model="databases[panelIndex]" height="34" background-color="">
|
||
|
<v-tab v-for="(db, dbIndex) in project.envs[envKey].db" :key="dbIndex">
|
||
|
<v-icon small> mdi-database </v-icon>
|
||
|
<span class="text-capitalize caption">{{ db.connection.database }}</span>
|
||
3 years ago
|
</v-tab>
|
||
|
<v-tabs-items v-model="databases[panelIndex]">
|
||
2 years ago
|
<v-tab-item v-for="(db, dbIndex) in project.envs[envKey].db" :key="dbIndex">
|
||
3 years ago
|
<v-card flat>
|
||
|
<!-- <form ref="form" class="pa-3">-->
|
||
|
<v-container class="justify-center">
|
||
3 years ago
|
<v-row style="position: relative">
|
||
2 years ago
|
<v-overlay v-if="showMonaco[dbIndex]" absolute class="monaco-overlay">
|
||
3 years ago
|
<v-container fluid class="h-100">
|
||
2 years ago
|
<v-card style="position: relative" class="h-100">
|
||
3 years ago
|
<v-icon
|
||
|
class="monaco-overlay-close pointer"
|
||
|
color="error"
|
||
2 years ago
|
@click="$set(showMonaco, dbIndex, false)"
|
||
3 years ago
|
>
|
||
3 years ago
|
mdi-close-circle
|
||
|
</v-icon>
|
||
|
|
||
2 years ago
|
<span class="ml-2 caption grey--text"
|
||
|
>Refer knex documentation
|
||
3 years ago
|
<a
|
||
|
href="https://knexjs.org/#Installation-client"
|
||
|
target="_blank"
|
||
|
class="grey--text"
|
||
2 years ago
|
>here</a
|
||
|
>
|
||
|
.</span
|
||
|
>
|
||
3 years ago
|
|
||
|
<monaco-json-object-editor
|
||
2 years ago
|
v-model="project.envs[envKey].db[dbIndex]"
|
||
|
style="height: calc(100% - 20px); width: 100%"
|
||
3 years ago
|
/>
|
||
3 years ago
|
</v-card>
|
||
|
</v-container>
|
||
|
</v-overlay>
|
||
|
|
||
|
<v-col cols="4" class="py-0">
|
||
3 years ago
|
<!-- Database Type -->
|
||
3 years ago
|
<v-select
|
||
3 years ago
|
v-model="client[dbIndex]"
|
||
3 years ago
|
v-ge="['project', 'env-db-change']"
|
||
3 years ago
|
class="body-2 db-select"
|
||
|
:items="Object.keys(databaseNames)"
|
||
3 years ago
|
:label="$t('labels.dbType')"
|
||
2 years ago
|
@change="onDatabaseTypeChanged(client[dbIndex], db, dbIndex, envKey)"
|
||
3 years ago
|
>
|
||
3 years ago
|
<template #selection="{ item }">
|
||
3 years ago
|
<v-chip
|
||
|
small
|
||
3 years ago
|
:color="
|
||
2 years ago
|
colors[Object.keys(databaseNames).indexOf(item) % colors.length]
|
||
3 years ago
|
"
|
||
|
class=""
|
||
3 years ago
|
>
|
||
|
{{ item }}
|
||
3 years ago
|
</v-chip>
|
||
|
</template>
|
||
|
|
||
2 years ago
|
<template slot="item" slot-scope="data">
|
||
3 years ago
|
<v-chip
|
||
3 years ago
|
:color="
|
||
2 years ago
|
colors[Object.keys(databaseNames).indexOf(data.item) % colors.length]
|
||
3 years ago
|
"
|
||
|
class="caption"
|
||
3 years ago
|
>
|
||
|
{{ data.item }}
|
||
3 years ago
|
</v-chip>
|
||
|
</template>
|
||
|
</v-select>
|
||
|
</v-col>
|
||
3 years ago
|
<!-- SQLite File -->
|
||
2 years ago
|
<v-col v-if="db.client === 'sqlite3'" class="py-0">
|
||
3 years ago
|
<v-text-field
|
||
2 years ago
|
v-model="db.connection.connection.filename"
|
||
3 years ago
|
v-ge="['project', 'env-db-file']"
|
||
3 years ago
|
:rules="form.folderRequiredRule"
|
||
3 years ago
|
:label="$t('labels.sqliteFile')"
|
||
3 years ago
|
@click="selectSqliteFile(db)"
|
||
|
>
|
||
2 years ago
|
<v-icon slot="prepend" color="info"> mdi-file-outline </v-icon>
|
||
3 years ago
|
</v-text-field>
|
||
|
</v-col>
|
||
3 years ago
|
<!-- Host Address -->
|
||
2 years ago
|
<v-col v-if="db.client !== 'sqlite3'" cols="4" class="py-0">
|
||
3 years ago
|
<v-text-field
|
||
3 years ago
|
v-model="db.connection.host"
|
||
3 years ago
|
v-ge="['project', 'env-db-host']"
|
||
3 years ago
|
class="body-2"
|
||
|
:rules="form.requiredRule"
|
||
3 years ago
|
:label="$t('labels.hostAddress')"
|
||
3 years ago
|
/>
|
||
3 years ago
|
</v-col>
|
||
3 years ago
|
<!-- Port Number -->
|
||
2 years ago
|
<v-col v-if="db.client !== 'sqlite3'" cols="4" class="py-0">
|
||
3 years ago
|
<v-text-field
|
||
|
v-model="db.connection.port"
|
||
3 years ago
|
v-ge="['project', 'env-db-port']"
|
||
|
class="body-2"
|
||
3 years ago
|
:label="$t('labels.port')"
|
||
3 years ago
|
:rules="form.portValidationRule"
|
||
3 years ago
|
/>
|
||
3 years ago
|
</v-col>
|
||
3 years ago
|
<!-- Username -->
|
||
2 years ago
|
<v-col v-if="db.client !== 'sqlite3'" cols="4" class="py-0">
|
||
3 years ago
|
<v-text-field
|
||
3 years ago
|
v-model="db.connection.user"
|
||
3 years ago
|
v-ge="['project', 'env-db-user']"
|
||
3 years ago
|
class="body-2"
|
||
3 years ago
|
:rules="form.requiredRule"
|
||
3 years ago
|
:label="$t('labels.username')"
|
||
3 years ago
|
/>
|
||
3 years ago
|
</v-col>
|
||
3 years ago
|
<!-- Password -->
|
||
2 years ago
|
<v-col v-if="db.client !== 'sqlite3'" cols="4" class="py-0">
|
||
3 years ago
|
<v-text-field
|
||
3 years ago
|
:ref="`password${envKey}`"
|
||
|
v-model="db.connection.password"
|
||
2 years ago
|
v-ge="['project', 'env-db-password']"
|
||
3 years ago
|
class="body-2 db-password"
|
||
2 years ago
|
:type="showPass[`${panelIndex}_${dbIndex}`] ? 'text' : 'password'"
|
||
3 years ago
|
:label="$t('labels.password')"
|
||
3 years ago
|
@dblclick="enableDbEdit++"
|
||
3 years ago
|
>
|
||
3 years ago
|
<template #append>
|
||
3 years ago
|
<v-icon
|
||
|
small
|
||
|
@click="
|
||
|
$set(
|
||
|
showPass,
|
||
|
`${panelIndex}_${dbIndex}`,
|
||
2 years ago
|
!showPass[`${panelIndex}_${dbIndex}`]
|
||
3 years ago
|
)
|
||
|
"
|
||
3 years ago
|
>
|
||
|
{{
|
||
2 years ago
|
showPass[`${panelIndex}_${dbIndex}`] ? 'visibility_off' : 'visibility'
|
||
3 years ago
|
}}
|
||
|
</v-icon>
|
||
|
</template>
|
||
|
</v-text-field>
|
||
|
</v-col>
|
||
3 years ago
|
<!-- Database : create if not exists -->
|
||
2 years ago
|
<v-col v-if="db.client !== 'sqlite3'" cols="4" class="py-0">
|
||
3 years ago
|
<v-text-field
|
||
|
v-model="db.connection.database"
|
||
3 years ago
|
v-ge="['project', 'env-db-name']"
|
||
3 years ago
|
:disabled="edit && enableDbEdit < 2"
|
||
3 years ago
|
class="body-2 database-field"
|
||
|
:rules="form.requiredRule"
|
||
2 years ago
|
:label="$t('labels.dbCreateIfNotExists')"
|
||
3 years ago
|
/>
|
||
3 years ago
|
</v-col>
|
||
2 years ago
|
<!-- Schema name -->
|
||
2 years ago
|
<v-col v-if="db.client === 'mssql' || db.client === 'pg'" cols="4" class="py-0">
|
||
3 years ago
|
<v-text-field
|
||
2 years ago
|
v-model="db.searchPath[0]"
|
||
3 years ago
|
:disabled="edit && enableDbEdit < 2"
|
||
|
class="body-2 database-field"
|
||
|
:rules="form.requiredRule"
|
||
2 years ago
|
:label="$t('labels.schemaName')"
|
||
3 years ago
|
/>
|
||
|
</v-col>
|
||
3 years ago
|
<!-- todo : ssl & inflection -->
|
||
2 years ago
|
<v-col v-if="db.client !== 'sqlite3'" cols="12" class="">
|
||
3 years ago
|
<v-expansion-panels>
|
||
2 years ago
|
<v-expansion-panel style="border: 1px solid wheat">
|
||
3 years ago
|
<v-expansion-panel-header>
|
||
3 years ago
|
<!-- SSL & Advanced parameters -->
|
||
2 years ago
|
<span class="grey--text caption">{{
|
||
|
$t('title.advancedParameters')
|
||
3 years ago
|
}}</span>
|
||
3 years ago
|
</v-expansion-panel-header>
|
||
|
<v-expansion-panel-content>
|
||
|
<v-card class="elevation-0">
|
||
|
<v-card-text>
|
||
|
<v-select
|
||
3 years ago
|
v-model="db.ui.sslUse"
|
||
3 years ago
|
class="caption"
|
||
2 years ago
|
:items="Object.keys(sslUsage)"
|
||
3 years ago
|
>
|
||
2 years ago
|
<template #item="{ item }">
|
||
|
<span class="caption">{{ item }}</span>
|
||
3 years ago
|
</template>
|
||
|
</v-select>
|
||
|
|
||
|
<v-row class="pa-0 ma-0">
|
||
3 years ago
|
<input
|
||
|
ref="certFilePath"
|
||
3 years ago
|
type="file"
|
||
3 years ago
|
class="d-none"
|
||
2 years ago
|
@change="readFileContent(db, 'ssl', 'cert', dbIndex)"
|
||
|
/>
|
||
3 years ago
|
<!-- Select .cert file -->
|
||
|
<x-btn
|
||
2 years ago
|
v-ge="['project', 'env-db-cert']"
|
||
|
:tooltip="$t('tooltip.clientCert')"
|
||
3 years ago
|
small
|
||
|
color="primary"
|
||
|
outlined
|
||
3 years ago
|
class="elevation-5"
|
||
2 years ago
|
@click="selectFile(db, 'ssl', 'certFilePath', dbIndex)"
|
||
3 years ago
|
>
|
||
|
{{ db.ui.ssl.cert }}
|
||
3 years ago
|
</x-btn>
|
||
3 years ago
|
<!-- Select .key file -->
|
||
|
<input
|
||
|
ref="keyFilePath"
|
||
3 years ago
|
type="file"
|
||
3 years ago
|
class="d-none"
|
||
2 years ago
|
@change="readFileContent(db, 'ssl', 'key', dbIndex)"
|
||
|
/>
|
||
3 years ago
|
<x-btn
|
||
2 years ago
|
v-ge="['project', 'env-db-key']"
|
||
|
:tooltip="$t('tooltip.clientKey')"
|
||
3 years ago
|
small
|
||
|
color="primary"
|
||
|
outlined
|
||
3 years ago
|
class="elevation-5"
|
||
2 years ago
|
@click="selectFile(db, 'ssl', 'keyFilePath', dbIndex)"
|
||
3 years ago
|
>
|
||
|
{{ db.ui.ssl.key }}
|
||
3 years ago
|
</x-btn>
|
||
3 years ago
|
<!-- Select CA file -->
|
||
|
<input
|
||
|
ref="caFilePath"
|
||
3 years ago
|
type="file"
|
||
3 years ago
|
class="d-none"
|
||
2 years ago
|
@change="readFileContent(db, 'ssl', 'ca', dbIndex)"
|
||
|
/>
|
||
3 years ago
|
<x-btn
|
||
2 years ago
|
v-ge="['project', 'env-db-ca']"
|
||
|
:tooltip="$t('tooltip.clientCA')"
|
||
3 years ago
|
small
|
||
|
color="primary"
|
||
|
outlined
|
||
2 years ago
|
@click="selectFile(db, 'ssl', 'caFilePath', dbIndex)"
|
||
3 years ago
|
>
|
||
|
{{ db.ui.ssl.ca }}
|
||
3 years ago
|
</x-btn>
|
||
|
</v-row>
|
||
|
|
||
|
<v-row>
|
||
|
<v-col>
|
||
3 years ago
|
<!-- Inflection - Table name -->
|
||
3 years ago
|
<v-select
|
||
2 years ago
|
v-model="db.meta.inflection.table_name"
|
||
3 years ago
|
:disabled="edit"
|
||
3 years ago
|
class="caption"
|
||
2 years ago
|
:label="$t('labels.inflection.tableName')"
|
||
3 years ago
|
:items="
|
||
2 years ago
|
project.projectType === 'rest'
|
||
|
? ['camelize', 'none']
|
||
3 years ago
|
: ['camelize']
|
||
|
"
|
||
3 years ago
|
>
|
||
2 years ago
|
<template #item="{ item }">
|
||
|
<span class="caption">{{ item }}</span>
|
||
3 years ago
|
</template>
|
||
|
</v-select>
|
||
|
</v-col>
|
||
|
<v-col>
|
||
3 years ago
|
<!-- Inflection - Column name -->
|
||
3 years ago
|
<v-select
|
||
2 years ago
|
v-model="db.meta.inflection.column_name"
|
||
3 years ago
|
:disabled="edit"
|
||
3 years ago
|
class="caption"
|
||
2 years ago
|
:label="$t('labels.inflection.columnName')"
|
||
3 years ago
|
:items="
|
||
2 years ago
|
project.projectType === 'rest'
|
||
|
? ['camelize', 'none']
|
||
3 years ago
|
: ['camelize']
|
||
|
"
|
||
3 years ago
|
>
|
||
2 years ago
|
<template #item="{ item }">
|
||
|
<span class="caption">{{ item }}</span>
|
||
3 years ago
|
</template>
|
||
|
</v-select>
|
||
|
</v-col>
|
||
2 years ago
|
<v-col class="d-flex align-center flex-shrink-1 flex-grow-0">
|
||
3 years ago
|
<x-btn
|
||
|
small
|
||
|
btn.class="text-capitalize"
|
||
2 years ago
|
:tooltip="$t('activity.editConnJson')"
|
||
3 years ago
|
outlined
|
||
2 years ago
|
@click="$set(showMonaco, dbIndex, !showMonaco[dbIndex])"
|
||
3 years ago
|
>
|
||
2 years ago
|
<v-icon small class="mr-1"> mdi-database-edit </v-icon>
|
||
3 years ago
|
<!-- Edit connection JSON -->
|
||
2 years ago
|
{{ $t('activity.editConnJson') }}
|
||
3 years ago
|
</x-btn>
|
||
|
</v-col>
|
||
|
</v-row>
|
||
|
</v-card-text>
|
||
|
</v-card>
|
||
|
</v-expansion-panel-content>
|
||
|
</v-expansion-panel>
|
||
|
</v-expansion-panels>
|
||
|
</v-col>
|
||
|
</v-row>
|
||
|
|
||
|
<v-row class="text-right justify-end">
|
||
3 years ago
|
<!-- Test Database Connection -->
|
||
|
<x-btn
|
||
2 years ago
|
v-ge="['project', 'env-db-test-connection']"
|
||
3 years ago
|
:tooltip="$t('activity.testDbConn')"
|
||
3 years ago
|
outlined
|
||
|
small
|
||
2 years ago
|
@click="testConnection(db, envKey, panelIndex)"
|
||
3 years ago
|
>
|
||
3 years ago
|
<!-- Test Database Connection -->
|
||
2 years ago
|
{{ $t('activity.testDbConn') }}
|
||
3 years ago
|
</x-btn>
|
||
3 years ago
|
<!-- Remove Database from environment -->
|
||
3 years ago
|
<x-btn
|
||
3 years ago
|
v-if="dbIndex"
|
||
|
v-ge="['project', 'env-db-delete']"
|
||
2 years ago
|
:tooltip="$t('activity.removeDbFromEnv')"
|
||
3 years ago
|
text
|
||
|
small
|
||
2 years ago
|
@click="removeDBFromEnv(db, envKey, panelIndex, dbIndex)"
|
||
3 years ago
|
>
|
||
3 years ago
|
<v-hover v-slot="{ hover }">
|
||
2 years ago
|
<v-icon :color="hover ? 'error' : 'grey'"> mdi-database-remove </v-icon>
|
||
3 years ago
|
</v-hover>
|
||
|
</x-btn>
|
||
|
</v-row>
|
||
|
</v-container>
|
||
|
<!-- </form>-->
|
||
|
</v-card>
|
||
|
</v-tab-item>
|
||
|
</v-tabs-items>
|
||
|
</v-tabs>
|
||
|
</v-card>
|
||
|
</v-col>
|
||
|
</v-expansion-panel-content>
|
||
|
</v-expansion-panel>
|
||
|
</v-expansion-panels>
|
||
|
</v-col>
|
||
|
</v-row>
|
||
|
</v-container>
|
||
|
</div>
|
||
|
</v-card>
|
||
|
</v-form>
|
||
|
</v-col>
|
||
|
<dlgOk
|
||
|
v-if="dialog.show"
|
||
3 years ago
|
:dialog-show="dialog.show"
|
||
|
:mtd-ok="dialog.mtdOk"
|
||
3 years ago
|
:heading="dialog.heading"
|
||
|
:type="dialog.type"
|
||
|
/>
|
||
|
|
||
3 years ago
|
<!-- heading="Connection was successful" -->
|
||
|
<!-- ok-label="Ok & Save Project" -->
|
||
3 years ago
|
<dlg-ok-new
|
||
|
v-model="testSuccess"
|
||
3 years ago
|
:heading="$t('msg.info.dbConnected')"
|
||
|
:ok-label="$t('activity.OkSaveProject')"
|
||
3 years ago
|
type="success"
|
||
3 years ago
|
:btn-attr="{ small: false }"
|
||
|
@ok="createOrUpdateProject"
|
||
3 years ago
|
/>
|
||
|
|
||
|
<textDlgSubmitCancel
|
||
|
v-if="dialogGetEnvName.dialogShow"
|
||
3 years ago
|
:dialog-show="dialogGetEnvName.dialogShow"
|
||
3 years ago
|
:heading="dialogGetEnvName.heading"
|
||
3 years ago
|
:mtd-dialog-submit="mtdDialogGetEnvNameSubmit"
|
||
|
:mtd-dialog-cancel="mtdDialogGetEnvNameCancel"
|
||
3 years ago
|
/>
|
||
|
|
||
3 years ago
|
<div v-if="isTitle && !edit" class="floating-button">
|
||
3 years ago
|
<v-tooltip top>
|
||
3 years ago
|
<template #activator="{ on }">
|
||
3 years ago
|
<v-btn
|
||
3 years ago
|
v-ge="['project', 'save']"
|
||
3 years ago
|
fab
|
||
|
dark
|
||
|
large
|
||
|
tooltip="Scroll to top"
|
||
|
:disabled="!valid || !envStatusValid"
|
||
|
class="primary"
|
||
3 years ago
|
v-on="on"
|
||
3 years ago
|
@click="createOrUpdateProject()"
|
||
|
>
|
||
3 years ago
|
<v-icon>save</v-icon>
|
||
|
</v-btn>
|
||
|
</template>
|
||
3 years ago
|
<span> Save Project </span>
|
||
3 years ago
|
</v-tooltip>
|
||
|
</div>
|
||
|
</v-container>
|
||
|
</template>
|
||
|
<script>
|
||
2 years ago
|
import JSON5 from 'json5';
|
||
3 years ago
|
|
||
2 years ago
|
import { mapGetters, mapActions } from 'vuex';
|
||
|
import Vue from 'vue';
|
||
3 years ago
|
|
||
2 years ago
|
import { v4 as uuidv4 } from 'uuid';
|
||
3 years ago
|
|
||
2 years ago
|
import XBtn from './global/XBtn';
|
||
|
import dlgOk from './utils/DlgOk.vue';
|
||
|
import textDlgSubmitCancel from './utils/DlgTextSubmitCancel';
|
||
|
import MonacoJsonObjectEditor from '@/components/monaco/MonacoJsonObjectEditor';
|
||
|
import ApiOverlay from '~/components/ApiOverlay';
|
||
|
import colors from '@/mixins/colors';
|
||
|
import DlgOkNew from '~/components/utils/DlgOkNew';
|
||
|
import readFile from '@/helpers/fileReader';
|
||
3 years ago
|
|
||
2 years ago
|
const { uniqueNamesGenerator, starWars, adjectives, animals } = require('unique-names-generator');
|
||
3 years ago
|
|
||
2 years ago
|
const homeDir = '';
|
||
3 years ago
|
|
||
|
export default {
|
||
|
components: {
|
||
|
DlgOkNew,
|
||
|
ApiOverlay,
|
||
|
MonacoJsonObjectEditor,
|
||
|
XBtn,
|
||
|
dlgOk,
|
||
2 years ago
|
textDlgSubmitCancel,
|
||
3 years ago
|
},
|
||
|
mixins: [colors],
|
||
3 years ago
|
layout: 'empty',
|
||
3 years ago
|
data() {
|
||
3 years ago
|
return {
|
||
|
testSuccess: false,
|
||
|
projectCreated: false,
|
||
|
allSchemas: false,
|
||
|
showMonaco: [],
|
||
|
smtpConfiguration: {
|
||
3 years ago
|
from: '',
|
||
2 years ago
|
options: '',
|
||
3 years ago
|
},
|
||
|
showSecret: false,
|
||
|
loaderMessages: [
|
||
3 years ago
|
'Setting up new database configs',
|
||
|
'Inferring database schema',
|
||
|
'Generating APIs.',
|
||
|
'Generating APIs..',
|
||
|
'Generating APIs...',
|
||
|
'Generating APIs....',
|
||
|
'Please wait',
|
||
|
'Please wait.',
|
||
|
'Please wait..',
|
||
|
'Please wait...',
|
||
|
'Please wait..',
|
||
|
'Please wait.',
|
||
|
'Please wait',
|
||
|
'Please wait.',
|
||
|
'Please wait..',
|
||
|
'Please wait...',
|
||
|
'Please wait..',
|
||
|
'Please wait.',
|
||
|
'Please wait..',
|
||
2 years ago
|
'Please wait...',
|
||
3 years ago
|
],
|
||
3 years ago
|
loaderMessage: '',
|
||
3 years ago
|
projectReloading: false,
|
||
3 years ago
|
enableDbEdit: 0,
|
||
3 years ago
|
authTypes: [
|
||
3 years ago
|
{
|
||
3 years ago
|
text: 'JWT',
|
||
2 years ago
|
value: 'jwt',
|
||
3 years ago
|
},
|
||
|
{
|
||
3 years ago
|
text: 'Master Key',
|
||
2 years ago
|
value: 'masterKey',
|
||
3 years ago
|
},
|
||
|
{
|
||
3 years ago
|
text: 'Middleware',
|
||
2 years ago
|
value: 'middleware',
|
||
3 years ago
|
},
|
||
|
{
|
||
3 years ago
|
text: 'Disabled',
|
||
2 years ago
|
value: 'none',
|
||
|
},
|
||
3 years ago
|
],
|
||
|
projectTypes: [
|
||
3 years ago
|
{
|
||
3 years ago
|
text: 'REST APIs',
|
||
|
value: 'rest',
|
||
|
icon: 'mdi-code-json',
|
||
2 years ago
|
iconColor: 'green',
|
||
3 years ago
|
},
|
||
|
{
|
||
3 years ago
|
text: 'GRAPHQL APIs',
|
||
|
value: 'graphql',
|
||
|
icon: 'mdi-graphql',
|
||
2 years ago
|
iconColor: 'pink',
|
||
|
},
|
||
3 years ago
|
],
|
||
|
|
||
|
showPass: {},
|
||
3 years ago
|
/** ************** START : form related ****************/
|
||
3 years ago
|
form: {
|
||
3 years ago
|
portValidationRule: [v => /^\d+$/.test(v) || 'Not a valid port'],
|
||
2 years ago
|
titleValidationRule: [
|
||
|
v => !!v || 'Title is required',
|
||
|
v => v.length <= 50 || 'Project name exceeds 50 characters',
|
||
|
],
|
||
3 years ago
|
requiredRule: [v => !!v || 'Field is required'],
|
||
2 years ago
|
folderRequiredRule: [v => !!v || 'Folder path is required'],
|
||
3 years ago
|
},
|
||
|
valid: null,
|
||
|
panel: 0,
|
||
3 years ago
|
client: ['Sqlite'],
|
||
3 years ago
|
baseFolder: homeDir,
|
||
|
|
||
|
tab: null,
|
||
|
env: null,
|
||
|
databases: [],
|
||
3 years ago
|
/** ************** END : form related ****************/
|
||
3 years ago
|
auth: {
|
||
|
authSecret: uuidv4(),
|
||
3 years ago
|
authType: 'jwt',
|
||
2 years ago
|
webhook: null,
|
||
3 years ago
|
},
|
||
|
project: {},
|
||
|
defaultProject: {
|
||
3 years ago
|
title: '',
|
||
|
version: '0.6',
|
||
3 years ago
|
folder: homeDir,
|
||
|
envs: {
|
||
3 years ago
|
_noco: {
|
||
3 years ago
|
db: [
|
||
|
{
|
||
3 years ago
|
client: 'pg',
|
||
3 years ago
|
connection: {
|
||
3 years ago
|
host: 'localhost',
|
||
|
port: '5432',
|
||
|
user: 'postgres',
|
||
|
password: 'password',
|
||
|
database: '_dev',
|
||
3 years ago
|
ssl: {
|
||
3 years ago
|
ca: '',
|
||
|
key: '',
|
||
2 years ago
|
cert: '',
|
||
|
},
|
||
3 years ago
|
},
|
||
3 years ago
|
searchPath: ['public'],
|
||
3 years ago
|
meta: {
|
||
3 years ago
|
tn: 'nc_evolutions',
|
||
|
dbAlias: 'db',
|
||
3 years ago
|
api: {
|
||
3 years ago
|
type: 'rest',
|
||
|
prefix: '',
|
||
2 years ago
|
graphqlDepthLimit: 10,
|
||
3 years ago
|
},
|
||
|
inflection: {
|
||
3 years ago
|
table_name: 'camelize',
|
||
2 years ago
|
column_name: 'camelize',
|
||
|
},
|
||
3 years ago
|
},
|
||
|
ui: {
|
||
|
setup: -1,
|
||
|
ssl: {
|
||
3 years ago
|
key: this.$t('labels.clientKey'), // Client Key
|
||
|
cert: this.$t('labels.clientCert'), // Client Cert
|
||
2 years ago
|
ca: this.$t('labels.serverCA'), // Server CA
|
||
3 years ago
|
},
|
||
2 years ago
|
sslUse: 'Preferred',
|
||
|
},
|
||
|
},
|
||
3 years ago
|
],
|
||
|
apiClient: {
|
||
2 years ago
|
data: [],
|
||
|
},
|
||
|
},
|
||
3 years ago
|
},
|
||
3 years ago
|
workingEnv: '_noco',
|
||
3 years ago
|
ui: {
|
||
|
envs: {
|
||
2 years ago
|
_noco: {},
|
||
|
},
|
||
3 years ago
|
},
|
||
|
meta: {
|
||
3 years ago
|
version: '0.6',
|
||
|
seedsFolder: 'seeds',
|
||
|
queriesFolder: 'queries',
|
||
|
apisFolder: 'apis',
|
||
|
projectType: 'rest',
|
||
|
type: 'mvc',
|
||
2 years ago
|
language: 'ts',
|
||
3 years ago
|
},
|
||
3 years ago
|
seedsFolder: 'seeds',
|
||
|
queriesFolder: 'queries',
|
||
|
apisFolder: 'apis',
|
||
|
projectType: 'rest',
|
||
|
type: 'mvc',
|
||
|
language: 'ts',
|
||
3 years ago
|
apiClient: {
|
||
2 years ago
|
data: [],
|
||
|
},
|
||
3 years ago
|
},
|
||
|
|
||
|
sampleConnectionData: {
|
||
|
Postgres: {
|
||
3 years ago
|
host: 'localhost',
|
||
|
port: '5432',
|
||
|
user: 'postgres',
|
||
|
password: 'password',
|
||
|
database: '_test',
|
||
3 years ago
|
ssl: {
|
||
3 years ago
|
ca: '',
|
||
|
key: '',
|
||
2 years ago
|
cert: '',
|
||
|
},
|
||
3 years ago
|
},
|
||
|
MySQL: {
|
||
3 years ago
|
host: 'localhost',
|
||
|
port: '3306',
|
||
|
user: 'root',
|
||
|
password: 'password',
|
||
|
database: '_test',
|
||
3 years ago
|
ssl: {
|
||
3 years ago
|
ca: '',
|
||
|
key: '',
|
||
2 years ago
|
cert: '',
|
||
|
},
|
||
3 years ago
|
},
|
||
|
Vitess: {
|
||
3 years ago
|
host: 'localhost',
|
||
|
port: '15306',
|
||
|
user: 'root',
|
||
|
password: 'password',
|
||
|
database: '_test',
|
||
3 years ago
|
ssl: {
|
||
3 years ago
|
ca: '',
|
||
|
key: '',
|
||
2 years ago
|
cert: '',
|
||
|
},
|
||
3 years ago
|
},
|
||
|
TiDB: {
|
||
3 years ago
|
host: 'localhost',
|
||
|
port: '4000',
|
||
|
user: 'root',
|
||
|
password: '',
|
||
|
database: '_test',
|
||
3 years ago
|
ssl: {
|
||
3 years ago
|
ca: '',
|
||
|
key: '',
|
||
2 years ago
|
cert: '',
|
||
|
},
|
||
3 years ago
|
},
|
||
|
Yugabyte: {
|
||
3 years ago
|
host: 'localhost',
|
||
|
port: '5432',
|
||
|
user: 'postgres',
|
||
|
password: '',
|
||
|
database: '_test',
|
||
3 years ago
|
ssl: {
|
||
3 years ago
|
ca: '',
|
||
|
key: '',
|
||
2 years ago
|
cert: '',
|
||
|
},
|
||
3 years ago
|
},
|
||
|
CitusDB: {
|
||
3 years ago
|
host: 'localhost',
|
||
|
port: '5432',
|
||
|
user: 'postgres',
|
||
|
password: '',
|
||
|
database: '_test',
|
||
3 years ago
|
ssl: {
|
||
3 years ago
|
ca: '',
|
||
|
key: '',
|
||
2 years ago
|
cert: '',
|
||
|
},
|
||
3 years ago
|
},
|
||
|
CockroachDB: {
|
||
3 years ago
|
host: 'localhost',
|
||
|
port: '5432',
|
||
|
user: 'postgres',
|
||
|
password: '',
|
||
|
database: '_test',
|
||
3 years ago
|
ssl: {
|
||
3 years ago
|
ca: '',
|
||
|
key: '',
|
||
2 years ago
|
cert: '',
|
||
|
},
|
||
3 years ago
|
},
|
||
|
Greenplum: {
|
||
3 years ago
|
host: 'localhost',
|
||
|
port: '5432',
|
||
|
user: 'postgres',
|
||
|
password: '',
|
||
|
database: '_test',
|
||
3 years ago
|
ssl: {
|
||
3 years ago
|
ca: '',
|
||
|
key: '',
|
||
2 years ago
|
cert: '',
|
||
|
},
|
||
3 years ago
|
},
|
||
|
MsSQL: {
|
||
3 years ago
|
host: 'localhost',
|
||
3 years ago
|
port: 1433,
|
||
3 years ago
|
user: 'sa',
|
||
|
password: 'Password123.',
|
||
|
database: '_test',
|
||
3 years ago
|
ssl: {
|
||
3 years ago
|
ca: '',
|
||
|
key: '',
|
||
2 years ago
|
cert: '',
|
||
|
},
|
||
3 years ago
|
},
|
||
|
Oracle: {
|
||
3 years ago
|
host: 'localhost',
|
||
|
port: '1521',
|
||
|
user: 'system',
|
||
|
password: 'Oracle18',
|
||
|
database: '_test',
|
||
3 years ago
|
ssl: {
|
||
3 years ago
|
ca: '',
|
||
|
key: '',
|
||
2 years ago
|
cert: '',
|
||
|
},
|
||
3 years ago
|
},
|
||
|
Sqlite: {
|
||
3 years ago
|
client: 'sqlite3',
|
||
3 years ago
|
database: homeDir,
|
||
|
connection: {
|
||
2 years ago
|
filename: homeDir,
|
||
3 years ago
|
},
|
||
2 years ago
|
useNullAsDefault: true,
|
||
|
},
|
||
3 years ago
|
},
|
||
|
dialog: {
|
||
|
show: false,
|
||
3 years ago
|
title: '',
|
||
|
heading: '',
|
||
3 years ago
|
mtdOk: this.testConnectionMethodSubmit,
|
||
2 years ago
|
type: 'primary',
|
||
3 years ago
|
},
|
||
3 years ago
|
// TODO: apply i18n for sslUsage
|
||
3 years ago
|
// See general.no - 5 in en.json
|
||
3 years ago
|
sslUsage: {
|
||
3 years ago
|
No: 'No',
|
||
|
Preferred: 'Preferred',
|
||
|
Required: 'pg',
|
||
|
'Required-CA': 'Required-CA',
|
||
2 years ago
|
'Required-IDENTITY': 'Required-IDENTITY',
|
||
3 years ago
|
},
|
||
3 years ago
|
sslUse: this.$t('general.preferred'), // Preferred
|
||
3 years ago
|
ssl: {
|
||
3 years ago
|
key: this.$t('labels.clientKey'), // Client Key
|
||
|
cert: this.$t('labels.clientCert'), // Client Cert
|
||
2 years ago
|
ca: this.$t('labels.serverCA'), // Server CA
|
||
3 years ago
|
},
|
||
|
databaseNames: {
|
||
3 years ago
|
MySQL: 'mysql2',
|
||
|
Postgres: 'pg',
|
||
3 years ago
|
// Oracle: "oracledb",
|
||
3 years ago
|
MsSQL: 'mssql',
|
||
2 years ago
|
Sqlite: 'sqlite3',
|
||
3 years ago
|
// Vitess: "mysql2",
|
||
|
// TiDB: "mysql2",
|
||
|
// Yugabyte: "pg",
|
||
|
// CitusDB: "pg",
|
||
|
// CockroachDB: "pg",
|
||
|
// Greenplum: "pg"
|
||
|
},
|
||
|
testDatabaseNames: {
|
||
|
mysql2: null,
|
||
|
mysql: null,
|
||
3 years ago
|
pg: 'postgres',
|
||
|
oracledb: 'xe',
|
||
3 years ago
|
mssql: undefined,
|
||
2 years ago
|
sqlite3: 'a.sqlite',
|
||
3 years ago
|
},
|
||
|
dbIcons: {
|
||
3 years ago
|
Oracle: 'temp/db/oracle.png',
|
||
|
Postgres: 'temp/db/postgre.png',
|
||
|
MySQL: 'temp/db/mysql.png',
|
||
|
MsSQL: 'temp/db/mssql.png',
|
||
|
Sqlite: 'temp/db/sqlite.svg',
|
||
|
Salesforce: 'temp/salesforce-3-569548.webp',
|
||
|
SAP: 'temp/sap.png',
|
||
2 years ago
|
Stripe: 'temp/stripe.svg',
|
||
3 years ago
|
},
|
||
|
dialogGetEnvName: {
|
||
|
dialogShow: false,
|
||
3 years ago
|
heading: 'Enter New Environment Name',
|
||
2 years ago
|
field: 'Environment Name',
|
||
3 years ago
|
},
|
||
|
|
||
|
compErrorMessages: [
|
||
3 years ago
|
this.$t('msg.error.invalidChar'), // Invalid character in folder path
|
||
|
this.$t('msg.error.invalidDbCredentials'), // Invalid database credentials
|
||
|
this.$t('msg.error.unableToConnectToDb'), // Unable to connect to database, please check your database is up
|
||
2 years ago
|
this.$t('msg.error.userDoesntHaveSufficientPermission'), // User does not exist or have sufficient permission to create schema
|
||
3 years ago
|
],
|
||
2 years ago
|
compErrorMessage: '',
|
||
|
};
|
||
3 years ago
|
},
|
||
|
computed: {
|
||
3 years ago
|
...mapGetters({ sqlMgr: 'sqlMgr/sqlMgr' }),
|
||
3 years ago
|
isTitle() {
|
||
2 years ago
|
return this.project.title && this.project.title.trim().length;
|
||
3 years ago
|
},
|
||
3 years ago
|
envStatusValid() {
|
||
2 years ago
|
return this.project.envs && Object.values(this.project.envs).every(this.getEnvironmentStatusAggregatedNew);
|
||
3 years ago
|
},
|
||
3 years ago
|
typeIcon() {
|
||
3 years ago
|
if (this.project.projectType) {
|
||
2 years ago
|
return this.projectTypes.find(({ value }) => value === this.project.projectType);
|
||
3 years ago
|
} else {
|
||
3 years ago
|
return {
|
||
3 years ago
|
icon: 'mdi-server',
|
||
2 years ago
|
iconColor: 'primary',
|
||
|
};
|
||
3 years ago
|
}
|
||
|
},
|
||
3 years ago
|
databaseNamesReverse() {
|
||
2 years ago
|
return Object.entries(this.databaseNames).reduce((newObj, [value, key]) => {
|
||
|
newObj[key] = value;
|
||
|
return newObj;
|
||
|
}, {});
|
||
|
},
|
||
3 years ago
|
},
|
||
|
methods: {
|
||
3 years ago
|
async enableAllSchemas() {
|
||
2 years ago
|
this.$toast.info('Enabled all schemas').goAway(3000);
|
||
|
this.allSchemas = true;
|
||
3 years ago
|
await this.$axios({
|
||
3 years ago
|
url: 'demo',
|
||
2 years ago
|
baseURL: `${this.$axios.defaults.baseURL}/dashboard`,
|
||
|
});
|
||
3 years ago
|
},
|
||
|
|
||
|
...mapActions({
|
||
2 years ago
|
loadProjects: 'project/loadProjects',
|
||
3 years ago
|
}),
|
||
3 years ago
|
onAdvancePanelToggle() {
|
||
3 years ago
|
if (this.$refs.monacoEditor) {
|
||
2 years ago
|
setTimeout(() => this.$refs.monacoEditor.resizeLayout(), 400);
|
||
3 years ago
|
}
|
||
|
},
|
||
3 years ago
|
getProjectEditTooltip() {
|
||
3 years ago
|
// return `Opens ${path.join(this.project.folder, 'config.xc.json')} and edit - its really simple`;
|
||
|
},
|
||
3 years ago
|
openJsonInSystemEditor() {
|
||
3 years ago
|
// shell.openItem(path.join(this.project.folder, 'config.xc.json'));
|
||
|
},
|
||
3 years ago
|
readFileContent(db, obj, key, index) {
|
||
2 years ago
|
readFile(this.$refs[`${key}FilePath`][index], data => {
|
||
|
Vue.set(db.connection[obj], key, data);
|
||
|
});
|
||
3 years ago
|
},
|
||
3 years ago
|
selectFile(db, obj, key, index) {
|
||
2 years ago
|
this.$refs[key][index].click();
|
||
3 years ago
|
},
|
||
3 years ago
|
onPanelToggle(panelIndex, envKey) {
|
||
3 years ago
|
this.$nextTick(() => {
|
||
|
if (this.panel !== undefined) {
|
||
2 years ago
|
const panelContainer = this.$refs.panelContainer;
|
||
|
const panel = this.$refs[`panel${envKey}`][0].$el;
|
||
3 years ago
|
setTimeout(
|
||
|
() =>
|
||
|
(panelContainer.scrollTop =
|
||
|
panel.getBoundingClientRect().top +
|
||
|
panelContainer.scrollTop -
|
||
|
panelContainer.getBoundingClientRect().top -
|
||
|
50),
|
||
|
500
|
||
2 years ago
|
);
|
||
|
setTimeout(() => this.$refs[`password${envKey}`][0].focus());
|
||
3 years ago
|
}
|
||
2 years ago
|
});
|
||
3 years ago
|
},
|
||
3 years ago
|
scrollToTop() {
|
||
2 years ago
|
document.querySelector('html').scrollTop = 0;
|
||
3 years ago
|
},
|
||
3 years ago
|
showDBTabInEnvPanel(panelIndex, tabIndex) {
|
||
2 years ago
|
this.panel = panelIndex;
|
||
|
Vue.set(this.databases, panelIndex, tabIndex);
|
||
3 years ago
|
},
|
||
3 years ago
|
getProjectJson() {
|
||
3 years ago
|
/**
|
||
|
* remove UI keys within project
|
||
|
*/
|
||
2 years ago
|
const xcConfig = JSON.parse(JSON.stringify(this.project));
|
||
|
delete xcConfig.ui;
|
||
3 years ago
|
|
||
3 years ago
|
for (const env in xcConfig.envs) {
|
||
3 years ago
|
for (let i = 0; i < xcConfig.envs[env].db.length; ++i) {
|
||
2 years ago
|
xcConfig.envs[env].db[i].meta.api.type = this.project.projectType;
|
||
|
if (xcConfig.envs[env].db[i].client === 'mysql' || xcConfig.envs[env].db[i].client === 'mysql2') {
|
||
|
xcConfig.envs[env].db[i].connection.multipleStatements = true;
|
||
3 years ago
|
}
|
||
2 years ago
|
this.handleSSL(xcConfig.envs[env].db[i], false);
|
||
|
delete xcConfig.envs[env].db[i].ui;
|
||
3 years ago
|
if (this.client[i] === 'Vitess') {
|
||
2 years ago
|
xcConfig.envs[env].db[i].meta.dbtype = 'vitess';
|
||
3 years ago
|
}
|
||
3 years ago
|
if (this.client[i] === 'TiDB') {
|
||
2 years ago
|
xcConfig.envs[env].db[i].meta.dbtype = 'tidb';
|
||
3 years ago
|
}
|
||
3 years ago
|
if (xcConfig.envs[env].db[i].client === 'oracledb') {
|
||
3 years ago
|
xcConfig.envs[env].db[i].pool = {
|
||
3 years ago
|
min: 0,
|
||
2 years ago
|
max: 50,
|
||
|
};
|
||
3 years ago
|
|
||
2 years ago
|
xcConfig.envs[env].db[i].acquireConnectionTimeout = 60000;
|
||
3 years ago
|
}
|
||
|
|
||
2 years ago
|
const inflectionObj = xcConfig.envs[env].db[i].meta.inflection;
|
||
3 years ago
|
|
||
|
if (inflectionObj) {
|
||
3 years ago
|
if (Array.isArray(inflectionObj.table_name)) {
|
||
2 years ago
|
inflectionObj.table_name = inflectionObj.table_name.join(',');
|
||
3 years ago
|
}
|
||
3 years ago
|
if (Array.isArray(inflectionObj.column_name)) {
|
||
2 years ago
|
inflectionObj.column_name = inflectionObj.column_name.join(',');
|
||
3 years ago
|
}
|
||
|
|
||
2 years ago
|
inflectionObj.table_name = inflectionObj.table_name || 'none';
|
||
|
inflectionObj.column_name = inflectionObj.column_name || 'none';
|
||
3 years ago
|
}
|
||
|
|
||
|
if (this.allSchemas) {
|
||
2 years ago
|
delete xcConfig.envs[env].db[i].connection.database;
|
||
|
xcConfig.envs[env].db[i].meta.allSchemas = true;
|
||
3 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
2 years ago
|
xcConfig.auth = {};
|
||
3 years ago
|
switch (this.auth.authType) {
|
||
3 years ago
|
case 'jwt':
|
||
3 years ago
|
xcConfig.auth.jwt = {
|
||
|
secret: this.auth.authSecret,
|
||
2 years ago
|
dbAlias: xcConfig.envs[Object.keys(xcConfig.envs)[0]].db[0].meta.dbAlias,
|
||
|
};
|
||
|
break;
|
||
3 years ago
|
case 'masterKey':
|
||
3 years ago
|
xcConfig.auth.masterKey = {
|
||
2 years ago
|
secret: this.auth.authSecret,
|
||
|
};
|
||
|
sessionStorage.setItem('masterKey', this.auth.authSecret);
|
||
|
break;
|
||
3 years ago
|
case 'middleware':
|
||
3 years ago
|
xcConfig.auth.masterKey = {
|
||
2 years ago
|
url: this.auth.webhook,
|
||
|
};
|
||
|
break;
|
||
3 years ago
|
default:
|
||
2 years ago
|
this.auth.disabled = true;
|
||
|
break;
|
||
3 years ago
|
}
|
||
|
|
||
2 years ago
|
xcConfig.type = this.$store.state.project.appInfo ? this.$store.state.project.appInfo.type : 'docker';
|
||
3 years ago
|
|
||
2 years ago
|
if (this.smtpConfiguration && this.smtpConfiguration.from && this.smtpConfiguration.options.trim()) {
|
||
3 years ago
|
try {
|
||
|
xcConfig.mailer = {
|
||
|
options: JSON5.parse(this.smtpConfiguration.options),
|
||
2 years ago
|
from: this.smtpConfiguration.from,
|
||
|
};
|
||
|
} catch (e) {}
|
||
3 years ago
|
}
|
||
|
|
||
2 years ago
|
xcConfig.meta = xcConfig.meta || {};
|
||
3 years ago
|
xcConfig.meta.db = {
|
||
3 years ago
|
client: 'sqlite3',
|
||
3 years ago
|
connection: {
|
||
2 years ago
|
filename: 'xc.db',
|
||
|
},
|
||
|
};
|
||
3 years ago
|
|
||
2 years ago
|
return xcConfig;
|
||
3 years ago
|
},
|
||
|
|
||
3 years ago
|
constructProjectJsonFromProject(project) {
|
||
2 years ago
|
const p = project; // JSON.parse(JSON.stringify(project.projectJson));
|
||
3 years ago
|
|
||
|
p.ui = {
|
||
|
envs: {
|
||
2 years ago
|
_noco: {},
|
||
|
},
|
||
|
};
|
||
3 years ago
|
for (const env in p.envs) {
|
||
2 years ago
|
let i = 0;
|
||
3 years ago
|
for (const db of p.envs[env].db) {
|
||
2 years ago
|
Vue.set(this.client, i++, this.databaseNamesReverse[db.client]);
|
||
3 years ago
|
|
||
3 years ago
|
Vue.set(db, 'ui', {
|
||
3 years ago
|
setup: 0,
|
||
|
ssl: {
|
||
3 years ago
|
key: this.$t('labels.clientKey'), // Client Key
|
||
|
cert: this.$t('labels.clientCert'), // Client Cert
|
||
2 years ago
|
ca: this.$t('labels.serverCA'), // Server CA
|
||
3 years ago
|
},
|
||
2 years ago
|
sslUse: this.$t('general.preferred'), // Preferred
|
||
|
});
|
||
3 years ago
|
}
|
||
|
}
|
||
|
// delete p.projectJson;
|
||
|
|
||
|
if (p.auth) {
|
||
|
if (p.auth.jwt) {
|
||
2 years ago
|
this.auth.authType = 'jwt';
|
||
|
this.auth.authSecret = p.auth.jwt.secret;
|
||
3 years ago
|
} else if (p.auth.masterKey) {
|
||
|
if (p.auth.masterKey.secret) {
|
||
2 years ago
|
this.auth.authSecret = p.auth.masterKey.secret;
|
||
|
this.auth.authType = 'masterKey';
|
||
3 years ago
|
} else if (p.auth.masterKey.url) {
|
||
2 years ago
|
this.auth.webhook = p.auth.masterKey.url;
|
||
|
this.auth.authType = 'middleware';
|
||
3 years ago
|
} else {
|
||
2 years ago
|
this.auth.authType = 'none';
|
||
3 years ago
|
}
|
||
|
} else {
|
||
2 years ago
|
this.auth.authType = 'none';
|
||
3 years ago
|
}
|
||
|
} else {
|
||
2 years ago
|
this.auth.authType = 'none';
|
||
3 years ago
|
}
|
||
|
|
||
2 years ago
|
this.project = p;
|
||
3 years ago
|
if (p.mailer) {
|
||
|
this.smtpConfiguration = {
|
||
|
from: p.mailer.from,
|
||
2 years ago
|
options: JSON.stringify(p.mailer.options, 0, 2),
|
||
|
};
|
||
3 years ago
|
}
|
||
2 years ago
|
delete p.mailer;
|
||
3 years ago
|
},
|
||
|
|
||
3 years ago
|
async createOrUpdateProject() {
|
||
2 years ago
|
const projectJson = this.getProjectJson();
|
||
|
delete projectJson.folder;
|
||
3 years ago
|
|
||
2 years ago
|
let i = 0;
|
||
|
const toast = this.$toast.info(this.loaderMessages[0]);
|
||
3 years ago
|
const interv = setInterval(() => {
|
||
3 years ago
|
if (this.edit) {
|
||
2 years ago
|
return;
|
||
3 years ago
|
}
|
||
|
if (i < this.loaderMessages.length - 1) {
|
||
2 years ago
|
i++;
|
||
3 years ago
|
}
|
||
3 years ago
|
if (toast) {
|
||
|
if (!this.allSchemas) {
|
||
2 years ago
|
toast.text(this.loaderMessages[i]);
|
||
3 years ago
|
} else {
|
||
2 years ago
|
toast.goAway(100);
|
||
3 years ago
|
}
|
||
|
}
|
||
2 years ago
|
}, 1000);
|
||
3 years ago
|
|
||
2 years ago
|
this.projectReloading = true;
|
||
3 years ago
|
|
||
2 years ago
|
const con = projectJson.envs._noco.db[0];
|
||
2 years ago
|
if (con.client !== 'pg' && con.client !== 'mssql' && 'searchPath' in con) {
|
||
2 years ago
|
delete con.searchPath;
|
||
3 years ago
|
}
|
||
|
|
||
2 years ago
|
const inflection = (con.meta && con.meta.inflection) || {};
|
||
3 years ago
|
try {
|
||
3 years ago
|
const result = await this.$api.project.create({
|
||
3 years ago
|
title: projectJson.title,
|
||
3 years ago
|
bases: [
|
||
|
{
|
||
|
type: con.client,
|
||
|
config: con,
|
||
|
inflection_column: inflection.column_name,
|
||
2 years ago
|
inflection_table: inflection.table_name,
|
||
|
},
|
||
3 years ago
|
],
|
||
2 years ago
|
external: true,
|
||
|
});
|
||
3 years ago
|
|
||
2 years ago
|
clearInterval(interv);
|
||
|
toast.goAway(100);
|
||
3 years ago
|
|
||
2 years ago
|
await this.$store.dispatch('project/ActLoadProjectInfo');
|
||
3 years ago
|
|
||
2 years ago
|
this.projectReloading = false;
|
||
3 years ago
|
|
||
|
if (!this.edit && !this.allSchemas) {
|
||
|
this.$router.push({
|
||
|
path: `/nc/${result.id}`,
|
||
|
query: {
|
||
2 years ago
|
new: 1,
|
||
|
},
|
||
|
});
|
||
3 years ago
|
}
|
||
3 years ago
|
|
||
2 years ago
|
this.projectCreated = true;
|
||
3 years ago
|
} catch (e) {
|
||
2 years ago
|
this.$toast.error(await this._extractSdkResponseErrorMsg(e)).goAway(3000);
|
||
|
toast.goAway(0);
|
||
3 years ago
|
}
|
||
|
|
||
2 years ago
|
this.projectReloading = false;
|
||
|
this.$e('a:project:create:extdb');
|
||
3 years ago
|
},
|
||
|
|
||
3 years ago
|
mtdDialogGetEnvNameSubmit(envName, cookie) {
|
||
2 years ago
|
this.dialogGetEnvName.dialogShow = false;
|
||
3 years ago
|
if (envName in this.project.envs) {
|
||
|
} else {
|
||
3 years ago
|
Vue.set(this.project.envs, envName, {
|
||
|
db: [
|
||
|
{
|
||
3 years ago
|
client: 'pg',
|
||
3 years ago
|
connection: {
|
||
3 years ago
|
host: 'localhost',
|
||
|
port: '5432',
|
||
|
user: 'postgres',
|
||
|
password: 'password',
|
||
2 years ago
|
database: 'new_database',
|
||
3 years ago
|
},
|
||
|
meta: {
|
||
3 years ago
|
tn: 'nc_evolutions',
|
||
|
dbAlias: 'db',
|
||
3 years ago
|
inflection: {
|
||
3 years ago
|
table_name: 'camelize',
|
||
2 years ago
|
column_name: 'camelize',
|
||
3 years ago
|
},
|
||
3 years ago
|
api: {
|
||
2 years ago
|
type: '',
|
||
|
},
|
||
3 years ago
|
},
|
||
3 years ago
|
ui: {
|
||
|
setup: 0,
|
||
|
ssl: {
|
||
3 years ago
|
key: this.$t('labels.clientKey'), // Client Key
|
||
|
cert: this.$t('labels.clientCert'), // Client Cert
|
||
2 years ago
|
ca: this.$t('labels.serverCA'), // Server CA
|
||
3 years ago
|
},
|
||
2 years ago
|
sslUse: this.$t('general.preferred'), // Preferred
|
||
|
},
|
||
|
},
|
||
3 years ago
|
],
|
||
2 years ago
|
apiClient: { data: [] },
|
||
|
});
|
||
3 years ago
|
}
|
||
|
},
|
||
3 years ago
|
mtdDialogGetEnvNameCancel() {
|
||
2 years ago
|
this.dialogGetEnvName.dialogShow = false;
|
||
3 years ago
|
},
|
||
|
|
||
3 years ago
|
addNewEnvironment() {
|
||
2 years ago
|
this.dialogGetEnvName.dialogShow = true;
|
||
3 years ago
|
},
|
||
3 years ago
|
addNewDB(envKey, panelIndex) {
|
||
2 years ago
|
const len = this.project.envs[envKey].db.length;
|
||
3 years ago
|
// eslint-disable-next-line no-unused-vars
|
||
2 years ago
|
const lastDbName = `${this.project.title}_${envKey}_${len}`;
|
||
|
const dbType = (this.client[len] = this.client[len] || this.client[len - 1]);
|
||
|
const newlyCreatedIndex = this.project.envs[envKey].db.length;
|
||
|
const dbAlias = this.project.envs[envKey].db.length <= 0 ? 'db' : `db${this.project.envs[envKey].db.length + 1}`;
|
||
3 years ago
|
this.project.envs[envKey].db.push({
|
||
3 years ago
|
client: this.databaseNames[dbType],
|
||
|
connection: {
|
||
3 years ago
|
...this.sampleConnectionData[dbType],
|
||
2 years ago
|
database: `${this.project.title}_${envKey}_${newlyCreatedIndex + 1}`,
|
||
3 years ago
|
},
|
||
3 years ago
|
meta: {
|
||
3 years ago
|
tn: 'nc_evolutions',
|
||
3 years ago
|
dbAlias,
|
||
3 years ago
|
inflection: {
|
||
3 years ago
|
table_name: 'camelize',
|
||
2 years ago
|
column_name: 'camelize',
|
||
3 years ago
|
},
|
||
|
api: {
|
||
2 years ago
|
type: '',
|
||
|
},
|
||
3 years ago
|
},
|
||
|
ui: {
|
||
|
setup: 0,
|
||
3 years ago
|
sslUse: this.$t('general.preferred'), // Preferred
|
||
3 years ago
|
ssl: {
|
||
3 years ago
|
key: this.$t('labels.clientKey'), // Client Key
|
||
|
cert: this.$t('labels.clientCert'), // Client Cert
|
||
2 years ago
|
ca: this.$t('labels.serverCA'), // Server CA
|
||
|
},
|
||
|
},
|
||
|
});
|
||
3 years ago
|
// set active tab as newly created
|
||
2 years ago
|
this.databases[panelIndex] = newlyCreatedIndex;
|
||
3 years ago
|
},
|
||
|
|
||
3 years ago
|
testConnectionMethodSubmit() {
|
||
2 years ago
|
this.dialog.show = false;
|
||
3 years ago
|
},
|
||
2 years ago
|
selectDir(ev) {},
|
||
|
selectSqliteFile(db) {},
|
||
3 years ago
|
|
||
3 years ago
|
getDbStatusColor(db) {
|
||
3 years ago
|
switch (db.ui.setup) {
|
||
|
case -1:
|
||
2 years ago
|
return 'red';
|
||
3 years ago
|
|
||
3 years ago
|
case 0:
|
||
2 years ago
|
return 'orange';
|
||
3 years ago
|
|
||
3 years ago
|
case 1:
|
||
2 years ago
|
return 'green';
|
||
3 years ago
|
|
||
3 years ago
|
default:
|
||
2 years ago
|
break;
|
||
3 years ago
|
}
|
||
|
},
|
||
|
|
||
3 years ago
|
getDbStatusTooltip(db) {
|
||
3 years ago
|
switch (db.ui.setup) {
|
||
|
case -1:
|
||
2 years ago
|
return 'DB Connection NOT successful';
|
||
3 years ago
|
|
||
3 years ago
|
case 0:
|
||
2 years ago
|
return 'MySql Database Detected - Test your connection';
|
||
3 years ago
|
|
||
3 years ago
|
case 1:
|
||
2 years ago
|
return 'DB Connection successful';
|
||
3 years ago
|
|
||
3 years ago
|
default:
|
||
2 years ago
|
break;
|
||
3 years ago
|
}
|
||
|
},
|
||
3 years ago
|
async newTestConnection(db, env, panelIndex) {
|
||
3 years ago
|
if (
|
||
3 years ago
|
db.connection.host === 'localhost' &&
|
||
3 years ago
|
!this.edit &&
|
||
3 years ago
|
env === '_noco' &&
|
||
3 years ago
|
this.project.envs[env].db.length === 1 &&
|
||
3 years ago
|
this.project.envs[env].db[0].connection.user === 'postgres' &&
|
||
3 years ago
|
this.project.envs[env].db[0].connection.database ===
|
||
2 years ago
|
`${this.project.title}_${env}_${this.project.envs[env].length}`
|
||
3 years ago
|
) {
|
||
2 years ago
|
this.handleSSL(db);
|
||
3 years ago
|
if (db.client === 'sqlite3') {
|
||
2 years ago
|
db.ui.setup = 1;
|
||
3 years ago
|
} else {
|
||
|
const c1 = {
|
||
3 years ago
|
connection: {
|
||
|
...db.connection,
|
||
2 years ago
|
...(db.client !== 'pg' ? { database: this.testDatabaseNames[db.client] } : {}),
|
||
3 years ago
|
},
|
||
2 years ago
|
client: db.client,
|
||
|
};
|
||
3 years ago
|
|
||
3 years ago
|
const result = await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
3 years ago
|
{
|
||
|
query: {
|
||
2 years ago
|
skipProjectHasDb: 1,
|
||
|
},
|
||
3 years ago
|
},
|
||
3 years ago
|
'testConnection',
|
||
2 years ago
|
c1,
|
||
|
]);
|
||
3 years ago
|
|
||
|
if (result.code === 0) {
|
||
2 years ago
|
db.ui.setup = 1;
|
||
|
let passed = true;
|
||
3 years ago
|
/**
|
||
|
* get other environments
|
||
|
* and if host is localhost - test and update connection status
|
||
|
* UI panel close
|
||
|
*/
|
||
|
|
||
3 years ago
|
for (const e in this.project.envs) {
|
||
3 years ago
|
if (e === env) {
|
||
3 years ago
|
// ignore
|
||
3 years ago
|
} else {
|
||
|
const c2 = {
|
||
3 years ago
|
connection: {
|
||
|
...this.project.envs[e].db[0].connection,
|
||
2 years ago
|
database: undefined,
|
||
3 years ago
|
},
|
||
2 years ago
|
client: this.project.envs[e].db[0].client,
|
||
|
};
|
||
3 years ago
|
|
||
2 years ago
|
this.handleSSL(c2);
|
||
3 years ago
|
|
||
2 years ago
|
const result = await this.sqlMgr.testConnection(c2);
|
||
3 years ago
|
|
||
|
if (result.code === 0) {
|
||
2 years ago
|
this.project.envs[e][0].ui.setup = 1;
|
||
3 years ago
|
} else {
|
||
2 years ago
|
this.project.envs[e][0].ui.setup = -1;
|
||
|
passed = false;
|
||
|
break;
|
||
3 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (passed) {
|
||
2 years ago
|
this.panel = null;
|
||
3 years ago
|
} else {
|
||
3 years ago
|
// Connection was successful
|
||
2 years ago
|
this.dialog.heading = this.$t('msg.info.dbConnected');
|
||
|
this.dialog.type = 'success';
|
||
|
this.dialog.show = true;
|
||
3 years ago
|
}
|
||
|
} else {
|
||
2 years ago
|
db.ui.setup = -1;
|
||
3 years ago
|
// Connection Failure:
|
||
2 years ago
|
this.dialog.heading = this.$t('msg.error.dbConnectionFailed') + result.message;
|
||
|
this.dialog.type = 'error';
|
||
|
this.dialog.show = true;
|
||
3 years ago
|
}
|
||
|
}
|
||
|
|
||
2 years ago
|
return true;
|
||
3 years ago
|
} else {
|
||
2 years ago
|
return false;
|
||
3 years ago
|
}
|
||
|
},
|
||
|
|
||
3 years ago
|
sendAdvancedConfig(connection) {
|
||
3 years ago
|
if (!connection.ssl) {
|
||
2 years ago
|
return false;
|
||
3 years ago
|
}
|
||
2 years ago
|
let sendAdvancedConfig = false;
|
||
|
const sslOptions = Object.values(connection.ssl).filter(el => !!el);
|
||
3 years ago
|
if (sslOptions[0]) {
|
||
2 years ago
|
sendAdvancedConfig = true;
|
||
3 years ago
|
} else {
|
||
|
}
|
||
2 years ago
|
return sendAdvancedConfig;
|
||
3 years ago
|
},
|
||
|
|
||
3 years ago
|
handleSSL(db, creating = true) {
|
||
2 years ago
|
const sendAdvancedConfig = this.sendAdvancedConfig(db.connection);
|
||
3 years ago
|
if (!sendAdvancedConfig) {
|
||
2 years ago
|
db.connection.ssl = undefined;
|
||
3 years ago
|
}
|
||
|
|
||
|
if (db.connection.ssl) {
|
||
|
}
|
||
|
},
|
||
2 years ago
|
getDatabaseForTestConnection(dbType) {},
|
||
3 years ago
|
async testConnection(db, env, panelIndex) {
|
||
2 years ago
|
this.$e('a:project:create:extdb:test-connection');
|
||
|
this.$store.commit('notification/MutToggleProgressBar', true);
|
||
3 years ago
|
try {
|
||
3 years ago
|
if (!(await this.newTestConnection(db, env, panelIndex))) {
|
||
2 years ago
|
this.handleSSL(db);
|
||
3 years ago
|
|
||
3 years ago
|
if (db.client === 'sqlite3') {
|
||
2 years ago
|
db.ui.setup = 1;
|
||
3 years ago
|
} else {
|
||
|
const c1 = {
|
||
|
connection: {
|
||
3 years ago
|
...db.connection,
|
||
2 years ago
|
...(db.client !== 'pg' ? { database: this.testDatabaseNames[db.client] } : {}),
|
||
3 years ago
|
},
|
||
2 years ago
|
client: db.client,
|
||
|
};
|
||
3 years ago
|
|
||
2 years ago
|
const result = await this.$api.utils.testConnection(c1);
|
||
3 years ago
|
|
||
3 years ago
|
if (result.code === 0) {
|
||
2 years ago
|
db.ui.setup = 1;
|
||
3 years ago
|
// this.dialog.heading = "Connection was successful"
|
||
|
// this.dialog.type = 'success';
|
||
|
// this.dialog.show = true;
|
||
2 years ago
|
this.testSuccess = true;
|
||
3 years ago
|
} else {
|
||
2 years ago
|
db.ui.setup = -1;
|
||
3 years ago
|
// this.activeDbNode.testConnectionStatus = false;
|
||
2 years ago
|
this.dialog.heading = this.$t('msg.error.dbConnectionFailed') + result.message;
|
||
|
this.dialog.type = 'error';
|
||
|
this.dialog.show = true;
|
||
3 years ago
|
}
|
||
|
}
|
||
|
}
|
||
3 years ago
|
} catch (e) {
|
||
2 years ago
|
console.log(e);
|
||
3 years ago
|
} finally {
|
||
2 years ago
|
this.$store.commit('notification/MutToggleProgressBar', false);
|
||
3 years ago
|
}
|
||
3 years ago
|
},
|
||
3 years ago
|
getEnvironmentStatusAggregated(dbs) {
|
||
2 years ago
|
return dbs.every(db => db.ui.setup === 1);
|
||
3 years ago
|
},
|
||
|
|
||
3 years ago
|
getEnvironmentStatusAggregatedNew(dbs) {
|
||
2 years ago
|
return dbs.db.every(db => db.ui.setup === 1);
|
||
3 years ago
|
},
|
||
3 years ago
|
openFirstPanel() {
|
||
3 years ago
|
if (!this.edit) {
|
||
2 years ago
|
this.panel = 0;
|
||
3 years ago
|
}
|
||
3 years ago
|
},
|
||
3 years ago
|
onDatabaseTypeChanged(client, db1, index, env) {
|
||
3 years ago
|
if (this.databaseNames[client] === 'mssql') {
|
||
2 years ago
|
this.project.envs[env].db[index].searchPath[0] = 'dbo';
|
||
3 years ago
|
} else if (this.databaseNames[client] === 'pg') {
|
||
2 years ago
|
this.project.envs[env].db[index].searchPath[0] = 'public';
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
for (const env in this.project.envs) {
|
||
3 years ago
|
if (this.project.envs[env].db.length > index) {
|
||
2 years ago
|
const db = this.project.envs[env].db[index];
|
||
|
Vue.set(db, 'client', this.databaseNames[client]);
|
||
3 years ago
|
|
||
3 years ago
|
if (client !== 'Sqlite') {
|
||
2 years ago
|
const { ssl, ...connectionDet } = this.sampleConnectionData[client];
|
||
3 years ago
|
|
||
|
Vue.set(db, 'connection', {
|
||
3 years ago
|
...connectionDet,
|
||
|
database: `${this.project.title}_${env}_${index + 1}`,
|
||
2 years ago
|
ssl: { ...ssl },
|
||
|
});
|
||
3 years ago
|
|
||
3 years ago
|
for (const env in this.project.envs) {
|
||
3 years ago
|
if (this.project.envs[env].length > index) {
|
||
2 years ago
|
this.setDBStatus(this.project.envs[env][index], 0);
|
||
3 years ago
|
}
|
||
|
}
|
||
|
} else {
|
||
2 years ago
|
db.connection = {};
|
||
3 years ago
|
Vue.set(db, 'connection', {
|
||
|
client: 'sqlite3',
|
||
3 years ago
|
// connection: {filename: path.join(this.project.folder, `${this.project.title}_${env}_${index + 1}`)},
|
||
3 years ago
|
connection: {
|
||
2 years ago
|
filename: [this.project.folder, `${this.project.title}_${env}_${index + 1}`].join('/'),
|
||
3 years ago
|
},
|
||
2 years ago
|
database: [this.project.folder, `${this.project.title}_${env}_${index + 1}`].join('/'),
|
||
|
useNullAsDefault: true,
|
||
|
});
|
||
3 years ago
|
}
|
||
|
}
|
||
|
}
|
||
3 years ago
|
},
|
||
3 years ago
|
selectDatabaseClient(database, index = 0) {
|
||
3 years ago
|
if (this.client) {
|
||
2 years ago
|
this.client[index] = database;
|
||
3 years ago
|
}
|
||
3 years ago
|
},
|
||
3 years ago
|
setDBStatus(db, status) {
|
||
2 years ago
|
db.ui.setup = status;
|
||
3 years ago
|
},
|
||
3 years ago
|
removeDBFromEnv(db, env, panelIndex, dbIndex) {
|
||
3 years ago
|
for (const env in this.project.envs) {
|
||
3 years ago
|
if (this.project.envs[env].db.length > dbIndex) {
|
||
2 years ago
|
this.project.envs[env].db.splice(dbIndex, 1);
|
||
3 years ago
|
}
|
||
|
}
|
||
|
},
|
||
3 years ago
|
removeEnv(envKey) {
|
||
2 years ago
|
delete this.project.envs[envKey];
|
||
|
Vue.set(this.project, 'envs', { ...this.project.envs });
|
||
|
},
|
||
3 years ago
|
},
|
||
2 years ago
|
fetch({ store, params }) {},
|
||
|
beforeCreated() {},
|
||
3 years ago
|
watch: {
|
||
3 years ago
|
'project.title'(newValue, oldValue) {
|
||
3 years ago
|
if (!newValue) {
|
||
2 years ago
|
return;
|
||
3 years ago
|
}
|
||
3 years ago
|
if (!this.edit) {
|
||
|
// Vue.set(this.project, 'folder', slash(path.join(this.baseFolder, newValue)))
|
||
2 years ago
|
Vue.set(this.project, 'folder', [this.baseFolder, newValue].join('/'));
|
||
3 years ago
|
// }//this.project.folder = `${this.baseFolder}/${newValue}`;
|
||
|
|
||
|
for (const env in this.project.envs) {
|
||
|
for (const [index, db] of this.project.envs[env].db.entries()) {
|
||
|
// db.connection.database = `${this.project.title}_${env}_${index}`
|
||
3 years ago
|
if (db.client !== 'sqlite3') {
|
||
2 years ago
|
Vue.set(db.connection, 'database', `${this.project.title}_${env}_${index + 1}`);
|
||
3 years ago
|
} else {
|
||
2 years ago
|
Vue.set(db.connection, 'database', `${this.project.title}_${env}_${index + 1}`);
|
||
3 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
3 years ago
|
},
|
||
3 years ago
|
'project.envs': {
|
||
3 years ago
|
deep: true,
|
||
3 years ago
|
handler(envs) {
|
||
3 years ago
|
if (typeof envs === 'object' && envs) {
|
||
3 years ago
|
Object.entries(envs).forEach(([key, env]) => {
|
||
2 years ago
|
let res = 1;
|
||
|
const msg = {};
|
||
3 years ago
|
for (const db of env.db) {
|
||
2 years ago
|
res = db.ui.setup < res ? db.ui.setup : res;
|
||
3 years ago
|
}
|
||
|
if (this.edit) {
|
||
2 years ago
|
Vue.set(this.project.ui, key, '');
|
||
3 years ago
|
} else {
|
||
|
switch (res) {
|
||
|
case -1:
|
||
2 years ago
|
msg.color = 'red';
|
||
3 years ago
|
// msg.msg = ' ( Invalid database parameters )'
|
||
2 years ago
|
msg.msg = `( ${this.$t('msg.error.dbConnectionStatus')} )`;
|
||
|
break;
|
||
3 years ago
|
case 0:
|
||
2 years ago
|
msg.color = 'warning';
|
||
|
msg.msg = ' ( Click to validate database credentials )';
|
||
|
break;
|
||
3 years ago
|
case 1:
|
||
2 years ago
|
msg.color = 'green';
|
||
3 years ago
|
// msg.msg = ' ( Environment Validated )'
|
||
2 years ago
|
msg.msg = `( ${this.$t('msg.info.dbConnectionStatus')} )`;
|
||
|
break;
|
||
3 years ago
|
}
|
||
2 years ago
|
Vue.set(this.project.ui, key, msg);
|
||
3 years ago
|
}
|
||
2 years ago
|
});
|
||
3 years ago
|
}
|
||
2 years ago
|
},
|
||
|
},
|
||
3 years ago
|
},
|
||
3 years ago
|
async created() {
|
||
2 years ago
|
this.compErrorMessage = this.compErrorMessages[Math.floor(Math.random() * this.compErrorMessages.length)];
|
||
3 years ago
|
|
||
|
if (this.edit) {
|
||
|
try {
|
||
2 years ago
|
let data = await this.$store.dispatch('sqlMgr/ActSqlOp', [null, 'xcProjectGetConfig']);
|
||
|
data = JSON.parse(data.config);
|
||
|
this.constructProjectJsonFromProject(data);
|
||
|
this.$set(this.project, 'folder', data.folder);
|
||
3 years ago
|
} catch (e) {
|
||
2 years ago
|
this.$toast.error(e.message).goAway(3000);
|
||
3 years ago
|
}
|
||
|
} else {
|
||
2 years ago
|
this.project = JSON.parse(JSON.stringify(this.defaultProject));
|
||
3 years ago
|
// this.edit = false;
|
||
|
|
||
|
/**
|
||
|
* Figure out which databases users has by scanning port numbers
|
||
|
* preference can be - pg | mysql | mssql | oracledb | sqlite
|
||
|
* create this.project based on the database
|
||
|
*
|
||
|
*
|
||
|
*/
|
||
2 years ago
|
let dbsAvailable = []; // await PortScanner.getOpenDbPortsAsList();
|
||
3 years ago
|
// // setting MySQL as default value if no databases are available
|
||
|
// if (!dbsAvailable || !dbsAvailable.length) {
|
||
2 years ago
|
dbsAvailable = ['MySQL'];
|
||
3 years ago
|
// }
|
||
|
|
||
2 years ago
|
this.selectDatabaseClient(dbsAvailable[0], 0);
|
||
3 years ago
|
|
||
|
// iterating over environment and setting default connection details based
|
||
|
// on first available database
|
||
3 years ago
|
for (const env in this.project.envs) {
|
||
|
for (const db of this.project.envs[env].db) {
|
||
2 years ago
|
db.client = this.databaseNames[dbsAvailable[0]];
|
||
3 years ago
|
|
||
3 years ago
|
if (db.client === 'sqlite3') {
|
||
3 years ago
|
db.connection = {
|
||
2 years ago
|
...this.sampleConnectionData[dbsAvailable[0]],
|
||
|
};
|
||
3 years ago
|
|
||
2 years ago
|
db.ui.setup = 0;
|
||
3 years ago
|
} else {
|
||
|
db.connection = {
|
||
|
...this.sampleConnectionData[dbsAvailable[0]],
|
||
2 years ago
|
ssl: { ...this.sampleConnectionData[dbsAvailable[0]].ssl },
|
||
|
};
|
||
3 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
},
|
||
2 years ago
|
beforeMount() {},
|
||
3 years ago
|
mounted() {
|
||
3 years ago
|
this.$set(
|
||
|
this.project,
|
||
3 years ago
|
'title',
|
||
3 years ago
|
uniqueNamesGenerator({
|
||
2 years ago
|
dictionaries: [[starWars], [adjectives, animals]][Math.floor(Math.random() * 2)],
|
||
3 years ago
|
})
|
||
|
.toLowerCase()
|
||
3 years ago
|
.replace(/[ -]/g, '_')
|
||
2 years ago
|
);
|
||
3 years ago
|
|
||
|
this.$nextTick(() => {
|
||
2 years ago
|
const input = this.$refs.name.$el.querySelector('input');
|
||
|
input.setSelectionRange(0, this.project.title.length);
|
||
|
input.focus();
|
||
|
});
|
||
3 years ago
|
},
|
||
2 years ago
|
beforeDestroy() {},
|
||
|
destroy() {},
|
||
3 years ago
|
validate({ params }) {
|
||
2 years ago
|
return true;
|
||
3 years ago
|
},
|
||
3 years ago
|
head() {
|
||
3 years ago
|
return {
|
||
2 years ago
|
title: this.$t('title.headCreateProject'),
|
||
|
};
|
||
3 years ago
|
},
|
||
|
props: {
|
||
|
edit: {
|
||
|
type: Boolean,
|
||
2 years ago
|
default: false,
|
||
|
},
|
||
3 years ago
|
},
|
||
2 years ago
|
directives: {},
|
||
|
};
|
||
3 years ago
|
</script>
|
||
|
|
||
|
<style scoped>
|
||
|
.floating-button {
|
||
|
position: fixed;
|
||
|
right: 7%;
|
||
3 years ago
|
bottom: 100px;
|
||
3 years ago
|
}
|
||
|
|
||
|
/deep/ .v-expansion-panel-header {
|
||
|
padding: 0 6px;
|
||
|
min-height: 50px !important;
|
||
|
}
|
||
|
|
||
|
/deep/ .monaco-overlay {
|
||
|
align-items: stretch;
|
||
|
}
|
||
|
|
||
|
/deep/ .monaco-overlay .v-overlay__content {
|
||
|
flex-grow: 1;
|
||
|
}
|
||
|
|
||
|
.monaco-overlay-close {
|
||
|
position: absolute;
|
||
|
right: 10px;
|
||
|
top: 10px;
|
||
|
z-index: 999;
|
||
|
cursor: pointer !important;
|
||
|
}
|
||
|
</style>
|
||
|
<!--
|
||
|
/**
|
||
|
* @copyright Copyright (c) 2021, Xgene Cloud Ltd
|
||
|
*
|
||
|
* @author Naveen MR <oof1lab@gmail.com>
|
||
|
* @author Pranav C Balan <pranavxc@gmail.com>
|
||
3 years ago
|
* @author Wing-Kam Wong <wingkwong.code@gmail.com>
|
||
3 years ago
|
*
|
||
|
* @license GNU AGPL version 3 or any later version
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU Affero General Public License as
|
||
|
* published by the Free Software Foundation, either version 3 of the
|
||
|
* License, or (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU Affero General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Affero General Public License
|
||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*
|
||
|
*/
|
||
3 years ago
|
-->
|