2020-05-12 18:27:31 +02:00
|
|
|
<template>
|
|
|
|
<div class="modal active">
|
|
|
|
<a class="modal-overlay c-hand" @click="closeModal" />
|
|
|
|
<div class="modal-container">
|
2020-08-12 18:11:48 +02:00
|
|
|
<div class="modal-header pl-2">
|
2020-05-12 18:27:31 +02:00
|
|
|
<div class="modal-title h6">
|
2020-08-12 18:11:48 +02:00
|
|
|
<div class="d-flex">
|
|
|
|
<i class="mdi mdi-24px mdi-server-plus mr-1" /> {{ $t('message.createNewConnection') }}
|
|
|
|
</div>
|
2020-05-12 18:27:31 +02:00
|
|
|
</div>
|
|
|
|
<a class="btn btn-clear c-hand" @click="closeModal" />
|
|
|
|
</div>
|
2021-02-03 21:53:24 +01:00
|
|
|
<div class="modal-body p-0">
|
|
|
|
<div class="panel">
|
|
|
|
<div class="panel-nav">
|
|
|
|
<ul class="tab tab-block">
|
|
|
|
<li
|
|
|
|
class="tab-item"
|
|
|
|
:class="{'active': selectedTab === 'general'}"
|
|
|
|
@click="selectTab('general')"
|
|
|
|
>
|
|
|
|
<a class="c-hand">{{ $t('word.general') }}</a>
|
|
|
|
</li>
|
|
|
|
<li
|
|
|
|
class="tab-item"
|
|
|
|
:class="{'active': selectedTab === 'ssl'}"
|
|
|
|
@click="selectTab('ssl')"
|
|
|
|
>
|
|
|
|
<a class="c-hand">{{ $t('word.ssl') }}</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div v-if="selectedTab === 'general'" class="panel-body py-0">
|
|
|
|
<div class="container">
|
|
|
|
<form class="form-horizontal">
|
|
|
|
<fieldset class="m-0" :disabled="isTesting">
|
|
|
|
<div class="form-group">
|
|
|
|
<div class="col-4 col-sm-12">
|
|
|
|
<label class="form-label">{{ $t('word.connectionName') }}</label>
|
|
|
|
</div>
|
|
|
|
<div class="col-8 col-sm-12">
|
|
|
|
<input
|
|
|
|
ref="firstInput"
|
|
|
|
v-model="connection.name"
|
|
|
|
class="form-input"
|
|
|
|
type="text"
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
|
|
<div class="col-4 col-sm-12">
|
|
|
|
<label class="form-label">{{ $t('word.client') }}</label>
|
|
|
|
</div>
|
|
|
|
<div class="col-8 col-sm-12">
|
|
|
|
<select
|
|
|
|
v-model="connection.client"
|
|
|
|
class="form-select"
|
|
|
|
@change="setDefaults"
|
|
|
|
>
|
|
|
|
<option value="mysql">
|
|
|
|
MySQL
|
|
|
|
</option>
|
|
|
|
<option value="maria">
|
|
|
|
MariaDB
|
|
|
|
</option>
|
2021-03-16 18:42:03 +01:00
|
|
|
<option value="pg">
|
|
|
|
PostgreSQL
|
|
|
|
</option>
|
2021-02-03 21:53:24 +01:00
|
|
|
<!-- <option value="mssql">
|
|
|
|
Microsoft SQL
|
|
|
|
</option>
|
|
|
|
<option value="oracledb">
|
|
|
|
Oracle DB
|
|
|
|
</option> -->
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
|
|
<div class="col-4 col-sm-12">
|
|
|
|
<label class="form-label">{{ $t('word.hostName') }}/IP</label>
|
|
|
|
</div>
|
|
|
|
<div class="col-8 col-sm-12">
|
|
|
|
<input
|
|
|
|
v-model="connection.host"
|
|
|
|
class="form-input"
|
|
|
|
type="text"
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
|
|
<div class="col-4 col-sm-12">
|
|
|
|
<label class="form-label">{{ $t('word.port') }}</label>
|
|
|
|
</div>
|
|
|
|
<div class="col-8 col-sm-12">
|
|
|
|
<input
|
|
|
|
v-model="connection.port"
|
|
|
|
class="form-input"
|
|
|
|
type="number"
|
|
|
|
min="1"
|
|
|
|
max="65535"
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-03-17 16:51:26 +01:00
|
|
|
<div v-if="customizations.database" class="form-group">
|
|
|
|
<div class="col-4 col-sm-12">
|
|
|
|
<label class="form-label">{{ $t('word.database') }}</label>
|
|
|
|
</div>
|
|
|
|
<div class="col-8 col-sm-12">
|
|
|
|
<input
|
|
|
|
v-model="connection.database"
|
|
|
|
class="form-input"
|
|
|
|
type="text"
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-03 21:53:24 +01:00
|
|
|
<div class="form-group">
|
|
|
|
<div class="col-4 col-sm-12">
|
|
|
|
<label class="form-label">{{ $t('word.user') }}</label>
|
|
|
|
</div>
|
|
|
|
<div class="col-8 col-sm-12">
|
|
|
|
<input
|
|
|
|
v-model="connection.user"
|
|
|
|
class="form-input"
|
|
|
|
type="text"
|
|
|
|
:disabled="connection.ask"
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
|
|
<div class="col-4 col-sm-12">
|
|
|
|
<label class="form-label">{{ $t('word.password') }}</label>
|
|
|
|
</div>
|
|
|
|
<div class="col-8 col-sm-12">
|
|
|
|
<input
|
|
|
|
v-model="connection.password"
|
|
|
|
class="form-input"
|
|
|
|
type="password"
|
|
|
|
:disabled="connection.ask"
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
|
|
<div class="col-4 col-sm-12" />
|
|
|
|
<div class="col-8 col-sm-12">
|
|
|
|
<label class="form-checkbox form-inline">
|
|
|
|
<input v-model="connection.ask" type="checkbox"><i class="form-icon" /> {{ $t('message.askCredentials') }}
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</fieldset>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
<BaseToast
|
|
|
|
class="mb-2"
|
|
|
|
:message="toast.message"
|
|
|
|
:status="toast.status"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div v-if="selectedTab === 'ssl'" class="panel-body py-0">
|
|
|
|
<div class="container">
|
|
|
|
<form class="form-horizontal">
|
|
|
|
<div class="form-group">
|
|
|
|
<div class="col-4 col-sm-12">
|
|
|
|
<label class="form-label">
|
|
|
|
{{ $t('message.enableSsl') }}
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<div class="col-8 col-sm-12">
|
|
|
|
<label class="form-switch d-inline-block" @click.prevent="toggleSsl">
|
|
|
|
<input type="checkbox" :checked="connection.ssl">
|
|
|
|
<i class="form-icon" />
|
|
|
|
</label>
|
|
|
|
</div>
|
2020-05-12 18:27:31 +02:00
|
|
|
</div>
|
2021-02-03 21:53:24 +01:00
|
|
|
<fieldset class="m-0" :disabled="isTesting || !connection.ssl">
|
|
|
|
<div class="form-group">
|
|
|
|
<div class="col-4 col-sm-12">
|
|
|
|
<label class="form-label">{{ $t('word.privateKey') }}</label>
|
|
|
|
</div>
|
|
|
|
<div class="col-8 col-sm-12">
|
2021-02-05 19:37:35 +01:00
|
|
|
<BaseUploadInput
|
|
|
|
:value="connection.key"
|
2021-02-08 09:36:44 +01:00
|
|
|
:message="$t('word.browse')"
|
2021-02-05 19:37:35 +01:00
|
|
|
@clear="pathClear('key')"
|
2021-02-03 21:53:24 +01:00
|
|
|
@change="pathSelection($event, 'key')"
|
2021-02-05 19:37:35 +01:00
|
|
|
/>
|
2021-02-03 21:53:24 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
|
|
<div class="col-4 col-sm-12">
|
|
|
|
<label class="form-label">{{ $t('word.certificate') }}</label>
|
|
|
|
</div>
|
|
|
|
<div class="col-8 col-sm-12">
|
2021-02-05 19:37:35 +01:00
|
|
|
<BaseUploadInput
|
|
|
|
:value="connection.cert"
|
2021-02-08 09:36:44 +01:00
|
|
|
:message="$t('word.browse')"
|
2021-02-05 19:37:35 +01:00
|
|
|
@clear="pathClear('cert')"
|
2021-02-03 21:53:24 +01:00
|
|
|
@change="pathSelection($event, 'cert')"
|
2021-02-05 19:37:35 +01:00
|
|
|
/>
|
2021-02-03 21:53:24 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
|
|
<div class="col-4 col-sm-12">
|
|
|
|
<label class="form-label">{{ $t('word.caCertificate') }}</label>
|
|
|
|
</div>
|
|
|
|
<div class="col-8 col-sm-12">
|
2021-02-05 19:37:35 +01:00
|
|
|
<BaseUploadInput
|
|
|
|
:value="connection.ca"
|
2021-02-08 09:36:44 +01:00
|
|
|
:message="$t('word.browse')"
|
2021-02-05 19:37:35 +01:00
|
|
|
@clear="pathClear('ca')"
|
2021-02-03 21:53:24 +01:00
|
|
|
@change="pathSelection($event, 'ca')"
|
2021-02-05 19:37:35 +01:00
|
|
|
/>
|
2021-02-03 21:53:24 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="form-group">
|
|
|
|
<div class="col-4 col-sm-12">
|
|
|
|
<label class="form-label">{{ $t('word.ciphers') }}</label>
|
|
|
|
</div>
|
|
|
|
<div class="col-8 col-sm-12">
|
|
|
|
<input
|
|
|
|
ref="firstInput"
|
|
|
|
v-model="connection.ciphers"
|
|
|
|
class="form-input"
|
|
|
|
type="text"
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</fieldset>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
<BaseToast
|
|
|
|
class="mb-2"
|
|
|
|
:message="toast.message"
|
|
|
|
:status="toast.status"
|
|
|
|
/>
|
|
|
|
</div>
|
2020-05-12 18:27:31 +02:00
|
|
|
</div>
|
2020-09-24 13:09:01 +02:00
|
|
|
</div>
|
|
|
|
<div class="modal-footer text-light">
|
2020-05-12 18:27:31 +02:00
|
|
|
<button
|
|
|
|
class="btn btn-gray mr-2"
|
|
|
|
:class="{'loading': isTesting}"
|
|
|
|
@click="startTest"
|
|
|
|
>
|
2020-05-25 15:37:59 +02:00
|
|
|
{{ $t('message.testConnection') }}
|
2020-05-12 18:27:31 +02:00
|
|
|
</button>
|
|
|
|
<button class="btn btn-primary mr-2" @click="saveNewConnection">
|
2020-05-25 15:37:59 +02:00
|
|
|
{{ $t('word.save') }}
|
2020-05-12 18:27:31 +02:00
|
|
|
</button>
|
|
|
|
<button class="btn btn-link" @click="closeModal">
|
2020-05-25 15:37:59 +02:00
|
|
|
{{ $t('word.close') }}
|
2020-05-12 18:27:31 +02:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<ModalAskCredentials
|
|
|
|
v-if="isAsking"
|
2020-08-18 18:03:59 +02:00
|
|
|
@close-asking="closeAsking"
|
2020-05-12 18:27:31 +02:00
|
|
|
@credentials="continueTest"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { mapActions } from 'vuex';
|
2021-03-17 16:51:26 +01:00
|
|
|
import customizations from 'common/customizations';
|
2020-05-14 15:21:57 +02:00
|
|
|
import Connection from '@/ipc-api/Connection';
|
2020-08-04 17:54:19 +02:00
|
|
|
import { uidGen } from 'common/libs/uidGen';
|
2020-05-12 18:27:31 +02:00
|
|
|
import ModalAskCredentials from '@/components/ModalAskCredentials';
|
|
|
|
import BaseToast from '@/components/BaseToast';
|
2021-02-05 19:37:35 +01:00
|
|
|
import BaseUploadInput from '@/components/BaseUploadInput';
|
2020-05-12 18:27:31 +02:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'ModalNewConnection',
|
|
|
|
components: {
|
|
|
|
ModalAskCredentials,
|
2021-02-05 19:37:35 +01:00
|
|
|
BaseToast,
|
|
|
|
BaseUploadInput
|
2020-05-12 18:27:31 +02:00
|
|
|
},
|
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
connection: {
|
2020-05-31 17:56:33 +02:00
|
|
|
name: '',
|
2020-05-12 18:27:31 +02:00
|
|
|
client: 'mysql',
|
|
|
|
host: '127.0.0.1',
|
2021-03-17 16:51:26 +01:00
|
|
|
database: null,
|
|
|
|
port: null,
|
|
|
|
user: null,
|
2020-05-12 18:27:31 +02:00
|
|
|
password: '',
|
2020-05-13 18:40:49 +02:00
|
|
|
ask: false,
|
2021-02-03 21:53:24 +01:00
|
|
|
uid: uidGen('C'),
|
|
|
|
ssl: false,
|
|
|
|
cert: '',
|
|
|
|
key: '',
|
|
|
|
ca: '',
|
|
|
|
ciphers: ''
|
|
|
|
|
2020-05-12 18:27:31 +02:00
|
|
|
},
|
|
|
|
toast: {
|
|
|
|
status: '',
|
|
|
|
message: ''
|
|
|
|
},
|
|
|
|
isTesting: false,
|
2021-02-03 21:53:24 +01:00
|
|
|
isAsking: false,
|
|
|
|
selectedTab: 'general'
|
2020-05-12 18:27:31 +02:00
|
|
|
};
|
|
|
|
},
|
2021-03-17 16:51:26 +01:00
|
|
|
computed: {
|
|
|
|
customizations () {
|
|
|
|
return customizations[this.connection.client];
|
|
|
|
}
|
|
|
|
},
|
2020-10-04 17:21:21 +02:00
|
|
|
created () {
|
2021-03-17 16:51:26 +01:00
|
|
|
this.setDefaults();
|
2020-10-04 17:21:21 +02:00
|
|
|
window.addEventListener('keydown', this.onKey);
|
2020-12-11 18:09:17 +01:00
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
this.$refs.firstInput.focus();
|
|
|
|
}, 20);
|
2020-10-04 17:21:21 +02:00
|
|
|
},
|
|
|
|
beforeDestroy () {
|
|
|
|
window.removeEventListener('keydown', this.onKey);
|
|
|
|
},
|
2020-05-12 18:27:31 +02:00
|
|
|
methods: {
|
|
|
|
...mapActions({
|
2020-05-30 12:54:05 +02:00
|
|
|
closeModal: 'application/hideNewConnModal',
|
2020-05-12 18:27:31 +02:00
|
|
|
addConnection: 'connections/addConnection'
|
|
|
|
}),
|
2020-05-15 17:52:59 +02:00
|
|
|
setDefaults () {
|
2021-03-17 16:51:26 +01:00
|
|
|
this.connection.user = this.customizations.defaultUser;
|
|
|
|
this.connection.port = this.customizations.defaultPort;
|
|
|
|
this.connection.database = this.customizations.defaultDatabase;
|
2020-05-15 17:52:59 +02:00
|
|
|
},
|
2020-05-12 18:27:31 +02:00
|
|
|
async startTest () {
|
|
|
|
this.isTesting = true;
|
|
|
|
this.toast = {
|
|
|
|
status: '',
|
|
|
|
message: ''
|
|
|
|
};
|
|
|
|
|
|
|
|
if (this.connection.ask)
|
|
|
|
this.isAsking = true;
|
2020-05-14 15:21:57 +02:00
|
|
|
else {
|
|
|
|
try {
|
|
|
|
const res = await Connection.makeTest(this.connection);
|
|
|
|
if (res.status === 'error')
|
|
|
|
this.toast = { status: 'error', message: res.response.message };
|
|
|
|
else
|
2020-05-26 18:10:11 +02:00
|
|
|
this.toast = { status: 'success', message: this.$t('message.connectionSuccessfullyMade') };
|
2020-05-14 15:21:57 +02:00
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.toast = { status: 'error', message: err.stack };
|
|
|
|
}
|
|
|
|
|
|
|
|
this.isTesting = false;
|
|
|
|
}
|
2020-05-12 18:27:31 +02:00
|
|
|
},
|
|
|
|
async continueTest (credentials) { // if "Ask for credentials" is true
|
|
|
|
this.isAsking = false;
|
|
|
|
const params = Object.assign({}, this.connection, credentials);
|
2020-05-24 11:03:20 +02:00
|
|
|
|
2020-05-23 13:32:14 +02:00
|
|
|
try {
|
|
|
|
const res = await Connection.makeTest(params);
|
|
|
|
if (res.status === 'error')
|
|
|
|
this.toast = { status: 'error', message: res.response.message };
|
|
|
|
else
|
2020-05-26 18:10:11 +02:00
|
|
|
this.toast = { status: 'success', message: this.$t('message.connectionSuccessfullyMade') };
|
2020-05-23 13:32:14 +02:00
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.toast = { status: 'error', message: err.stack };
|
|
|
|
}
|
|
|
|
|
|
|
|
this.isTesting = false;
|
2020-05-12 18:27:31 +02:00
|
|
|
},
|
|
|
|
saveNewConnection () {
|
|
|
|
this.addConnection(this.connection);
|
|
|
|
this.closeModal();
|
|
|
|
},
|
|
|
|
closeAsking () {
|
|
|
|
this.isAsking = false;
|
|
|
|
this.isTesting = false;
|
2020-10-04 17:21:21 +02:00
|
|
|
},
|
|
|
|
onKey (e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
if (e.key === 'Escape')
|
|
|
|
this.closeModal();
|
2021-02-03 21:53:24 +01:00
|
|
|
},
|
|
|
|
selectTab (tab) {
|
|
|
|
this.selectedTab = tab;
|
|
|
|
},
|
|
|
|
toggleSsl () {
|
|
|
|
this.connection.ssl = !this.connection.ssl;
|
|
|
|
},
|
|
|
|
pathSelection (event, name) {
|
|
|
|
const { files } = event.target;
|
|
|
|
if (!files.length) return;
|
|
|
|
|
|
|
|
this.connection[name] = files[0].path;
|
2021-02-05 19:37:35 +01:00
|
|
|
},
|
|
|
|
pathClear (name) {
|
|
|
|
this.connection[name] = '';
|
2020-05-12 18:27:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
2020-07-31 18:16:28 +02:00
|
|
|
.modal-container {
|
2021-02-03 21:53:24 +01:00
|
|
|
position: absolute;
|
2020-07-31 18:16:28 +02:00
|
|
|
max-width: 450px;
|
2021-02-03 21:53:24 +01:00
|
|
|
top: 17.5vh;
|
2020-07-31 18:16:28 +02:00
|
|
|
}
|
2020-05-12 18:27:31 +02:00
|
|
|
</style>
|