connection modal supports file database

This commit is contained in:
Jan Prochazka
2021-04-25 20:38:41 +02:00
parent d1bf2dbc4b
commit 3c089a5b81
3 changed files with 90 additions and 79 deletions

View File

@@ -16,12 +16,20 @@
import createRef from '../utility/createRef';
import Link from '../elements/Link.svelte';
import ErrorMessageModal from './ErrorMessageModal.svelte';
import { writable } from 'svelte/store';
import FormProviderCore from '../forms/FormProviderCore.svelte';
import { extensions } from '../stores';
export let connection;
let isTesting;
let sqlConnectResult;
const values = writable(connection || { server: 'localhost', engine: 'mssql@dbgate-plugin-mssql' });
$: engine = $values.engine;
$: driver = $extensions.drivers.find(x => x.engine == engine);
const testIdRef = createRef(0);
async function handleTest(e) {
@@ -49,10 +57,7 @@
}
</script>
<FormProvider
template={FormFieldTemplateLarge}
initialValues={connection || { server: 'localhost', engine: 'mssql@dbgate-plugin-mssql' }}
>
<FormProviderCore template={FormFieldTemplateLarge} {values}>
<ModalBase {...$$restProps} noPadding>
<div slot="header">Add connection</div>
@@ -63,11 +68,11 @@
label: 'Main',
component: ConnectionModalDriverFields,
},
{
!driver?.isFileDatabase && {
label: 'SSH Tunnel',
component: ConnectionModalSshTunnelFields,
},
{
!driver?.isFileDatabase && {
label: 'SSL',
component: ConnectionModalSslFields,
},
@@ -114,7 +119,7 @@
</div>
</div>
</ModalBase>
</FormProvider>
</FormProviderCore>
<style>
.buttons {

View File

@@ -1,5 +1,6 @@
<script lang="ts">
import FormCheckboxField from '../forms/FormCheckboxField.svelte';
import FormElectronFileSelector from '../forms/FormElectronFileSelector.svelte';
import FormPasswordField from '../forms/FormPasswordField.svelte';
@@ -9,7 +10,7 @@
import FormTextField from '../forms/FormTextField.svelte';
import { extensions } from '../stores';
import getElectron from '../utility/getElectron';
import getElectron from '../utility/getElectron';
import { useAuthTypes } from '../utility/metadataLoaders';
const { values } = getFormContext();
@@ -39,87 +40,91 @@ import getElectron from '../utility/getElectron';
]}
/>
{#if driver?.supportsDatabaseUrl}
<div class="radio">
<FormRadioGroupField
name="useDatabaseUrl"
options={[
{ label: 'Fill database connection details', value: '', default: true },
{ label: 'Use database URL', value: '1' },
]}
/>
</div>
{/if}
{#if driver?.supportsDatabaseUrl && useDatabaseUrl}
<FormTextField label="Database URL" name="databaseUrl" placeholder={driver?.databaseUrlPlaceholder} />
{#if driver?.isFileDatabase}
<FormElectronFileSelector label="Database file" name="databaseFile" disabled={!electron} />
{:else}
{#if $authTypes}
<FormSelectField
label="Authentication"
name="authType"
options={$authTypes.map(auth => ({
value: auth.name,
label: auth.title,
}))}
/>
{#if driver?.supportsDatabaseUrl}
<div class="radio">
<FormRadioGroupField
name="useDatabaseUrl"
options={[
{ label: 'Fill database connection details', value: '', default: true },
{ label: 'Use database URL', value: '1' },
]}
/>
</div>
{/if}
<div class="row">
<div class="col-9 mr-1">
<FormTextField
label="Server"
name="server"
disabled={disabledFields.includes('server')}
templateProps={{ noMargin: true }}
{#if driver?.supportsDatabaseUrl && useDatabaseUrl}
<FormTextField label="Database URL" name="databaseUrl" placeholder={driver?.databaseUrlPlaceholder} />
{:else}
{#if $authTypes}
<FormSelectField
label="Authentication"
name="authType"
options={$authTypes.map(auth => ({
value: auth.name,
label: auth.title,
}))}
/>
</div>
<div class="col-3 mr-1">
<FormTextField
label="Port"
name="port"
disabled={disabledFields.includes('port')}
templateProps={{ noMargin: true }}
placeholder={driver && driver.defaultPort}
/>
</div>
</div>
{/if}
<div class="row">
<div class="col-6 mr-1">
<FormTextField
label="User"
name="user"
disabled={disabledFields.includes('user')}
templateProps={{ noMargin: true }}
/>
<div class="row">
<div class="col-9 mr-1">
<FormTextField
label="Server"
name="server"
disabled={disabledFields.includes('server')}
templateProps={{ noMargin: true }}
/>
</div>
<div class="col-3 mr-1">
<FormTextField
label="Port"
name="port"
disabled={disabledFields.includes('port')}
templateProps={{ noMargin: true }}
placeholder={driver && driver.defaultPort}
/>
</div>
</div>
<div class="col-6 mr-1">
<FormPasswordField
label="Password"
name="password"
disabled={disabledFields.includes('password')}
templateProps={{ noMargin: true }}
/>
</div>
</div>
{#if !disabledFields.includes('password')}
<FormSelectField
label="Password mode"
name="passwordMode"
options={[
{ value: 'saveEncrypted', label: 'Save and encrypt' },
{ value: 'saveRaw', label: 'Save raw (UNSAFE!!)' },
]}
/>
<div class="row">
<div class="col-6 mr-1">
<FormTextField
label="User"
name="user"
disabled={disabledFields.includes('user')}
templateProps={{ noMargin: true }}
/>
</div>
<div class="col-6 mr-1">
<FormPasswordField
label="Password"
name="password"
disabled={disabledFields.includes('password')}
templateProps={{ noMargin: true }}
/>
</div>
</div>
{#if !disabledFields.includes('password')}
<FormSelectField
label="Password mode"
name="passwordMode"
options={[
{ value: 'saveEncrypted', label: 'Save and encrypt' },
{ value: 'saveRaw', label: 'Save raw (UNSAFE!!)' },
]}
/>
{/if}
{/if}
{/if}
<FormTextField label="Default database" name="defaultDatabase" />
<FormTextField label="Default database" name="defaultDatabase" />
{#if defaultDatabase}
<FormCheckboxField label={`Use only database ${defaultDatabase}`} name="singleDatabase" />
{#if defaultDatabase}
<FormCheckboxField label={`Use only database ${defaultDatabase}`} name="singleDatabase" />
{/if}
{/if}
<FormTextField label="Display name" name="displayName" />

View File

@@ -11,6 +11,7 @@
import getElectron from '../utility/getElectron';
import { usePlatformInfo } from '../utility/metadataLoaders';
import FontIcon from '../icons/FontIcon.svelte';
import { extensions } from '../stores';
const { values, setFieldValue } = getFormContext();
const electron = getElectron();