mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
single database support
This commit is contained in:
parent
ccdce6ef43
commit
e104feef14
@ -1,5 +1,5 @@
|
|||||||
<script context="module">
|
<script context="module">
|
||||||
const getContextMenu = (data, $openedConnections) => () => {
|
const getContextMenu = (data, $openedConnections, $extensions) => () => {
|
||||||
const config = getCurrentConfig();
|
const config = getCurrentConfig();
|
||||||
const handleRefresh = () => {
|
const handleRefresh = () => {
|
||||||
axiosInstance.post('server-connections/refresh', { conid: data._id });
|
axiosInstance.post('server-connections/refresh', { conid: data._id });
|
||||||
@ -55,24 +55,27 @@
|
|||||||
onClick: handleDelete,
|
onClick: handleDelete,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
!$openedConnections.includes(data._id) && {
|
!data.singleDatabase && [
|
||||||
text: 'Connect',
|
!$openedConnections.includes(data._id) && {
|
||||||
onClick: handleConnect,
|
text: 'Connect',
|
||||||
},
|
onClick: handleConnect,
|
||||||
{ onClick: handleNewQuery, text: 'New query' },
|
|
||||||
$openedConnections.includes(data._id) &&
|
|
||||||
data.status && {
|
|
||||||
text: 'Refresh',
|
|
||||||
onClick: handleRefresh,
|
|
||||||
},
|
},
|
||||||
$openedConnections.includes(data._id) && {
|
{ onClick: handleNewQuery, text: 'New query' },
|
||||||
text: 'Disconnect',
|
$openedConnections.includes(data._id) &&
|
||||||
onClick: handleDisconnect,
|
data.status && {
|
||||||
},
|
text: 'Refresh',
|
||||||
$openedConnections.includes(data._id) && {
|
onClick: handleRefresh,
|
||||||
text: 'Create database',
|
},
|
||||||
onClick: handleCreateDatabase,
|
$openedConnections.includes(data._id) && {
|
||||||
},
|
text: 'Disconnect',
|
||||||
|
onClick: handleDisconnect,
|
||||||
|
},
|
||||||
|
$openedConnections.includes(data._id) && {
|
||||||
|
text: 'Create database',
|
||||||
|
onClick: handleCreateDatabase,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
data.singleDatabase && [{ divider: true }, getDatabaseMenuItems(data, data.defaultDatabase, $extensions)],
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -91,6 +94,7 @@
|
|||||||
import ConfirmModal from '../modals/ConfirmModal.svelte';
|
import ConfirmModal from '../modals/ConfirmModal.svelte';
|
||||||
import InputTextModal from '../modals/InputTextModal.svelte';
|
import InputTextModal from '../modals/InputTextModal.svelte';
|
||||||
import openNewTab from '../utility/openNewTab';
|
import openNewTab from '../utility/openNewTab';
|
||||||
|
import { getDatabaseMenuItems } from './DatabaseAppObject.svelte';
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
|
|
||||||
@ -149,13 +153,20 @@
|
|||||||
<AppObjectCore
|
<AppObjectCore
|
||||||
{...$$restProps}
|
{...$$restProps}
|
||||||
{data}
|
{data}
|
||||||
title={data.displayName || data.server}
|
title={data.singleDatabase
|
||||||
icon="img server"
|
? data.displayName || `${data.defaultDatabase} on ${data.server}`
|
||||||
isBold={_.get($currentDatabase, 'connection._id') == data._id}
|
: data.displayName || data.server}
|
||||||
|
icon={data.singleDatabase ? 'img database' : 'img server'}
|
||||||
|
isBold={data.singleDatabase
|
||||||
|
? _.get($currentDatabase, 'connection._id') == data._id && _.get($currentDatabase, 'name') == data.defaultDatabase
|
||||||
|
: _.get($currentDatabase, 'connection._id') == data._id}
|
||||||
statusIcon={statusIcon || engineStatusIcon}
|
statusIcon={statusIcon || engineStatusIcon}
|
||||||
statusTitle={statusTitle || engineStatusTitle}
|
statusTitle={statusTitle || engineStatusTitle}
|
||||||
{extInfo}
|
{extInfo}
|
||||||
menu={getContextMenu(data, $openedConnections)}
|
menu={getContextMenu(data, $openedConnections, $extensions)}
|
||||||
on:click={() => ($openedConnections = _.uniq([...$openedConnections, data._id]))}
|
on:click={() => {
|
||||||
|
if (data.singleDatabase) $currentDatabase = { connection: data, name: data.defaultDatabase };
|
||||||
|
else $openedConnections = _.uniq([...$openedConnections, data._id]);
|
||||||
|
}}
|
||||||
on:click
|
on:click
|
||||||
/>
|
/>
|
||||||
|
@ -1,5 +1,57 @@
|
|||||||
<script lang="ts" context="module">
|
<script lang="ts" context="module">
|
||||||
export const extractKey = props => props.name;
|
export const extractKey = props => props.name;
|
||||||
|
|
||||||
|
export function getDatabaseMenuItems(connection, name, $extensions) {
|
||||||
|
const handleNewQuery = () => {
|
||||||
|
const tooltip = `${connection.displayName || connection.server}\n${name}`;
|
||||||
|
openNewTab({
|
||||||
|
title: 'Query #',
|
||||||
|
icon: 'img sql-file',
|
||||||
|
tooltip,
|
||||||
|
tabComponent: 'QueryTab',
|
||||||
|
props: {
|
||||||
|
conid: connection._id,
|
||||||
|
database: name,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleImport = () => {
|
||||||
|
showModal(ImportExportModal, {
|
||||||
|
initialValues: {
|
||||||
|
sourceStorageType: getDefaultFileFormat($extensions).storageType,
|
||||||
|
targetStorageType: 'database',
|
||||||
|
targetConnectionId: connection._id,
|
||||||
|
targetDatabaseName: name,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleExport = () => {
|
||||||
|
showModal(ImportExportModal, {
|
||||||
|
initialValues: {
|
||||||
|
targetStorageType: getDefaultFileFormat($extensions).storageType,
|
||||||
|
sourceStorageType: 'database',
|
||||||
|
sourceConnectionId: connection._id,
|
||||||
|
sourceDatabaseName: name,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSqlGenerator = () => {
|
||||||
|
showModal(SqlGeneratorModal, {
|
||||||
|
conid: connection._id,
|
||||||
|
database: name,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return [
|
||||||
|
{ onClick: handleNewQuery, text: 'New query' },
|
||||||
|
{ onClick: handleImport, text: 'Import' },
|
||||||
|
{ onClick: handleExport, text: 'Export' },
|
||||||
|
{ onClick: handleSqlGenerator, text: 'SQL Generator' },
|
||||||
|
];
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
@ -13,63 +65,8 @@
|
|||||||
import AppObjectCore from './AppObjectCore.svelte';
|
import AppObjectCore from './AppObjectCore.svelte';
|
||||||
export let data;
|
export let data;
|
||||||
|
|
||||||
const handleNewQuery = () => {
|
|
||||||
const { connection, name } = data;
|
|
||||||
const tooltip = `${connection.displayName || connection.server}\n${name}`;
|
|
||||||
openNewTab({
|
|
||||||
title: 'Query #',
|
|
||||||
icon: 'img sql-file',
|
|
||||||
tooltip,
|
|
||||||
tabComponent: 'QueryTab',
|
|
||||||
props: {
|
|
||||||
conid: connection._id,
|
|
||||||
database: name,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleImport = () => {
|
|
||||||
const { connection, name } = data;
|
|
||||||
|
|
||||||
showModal(ImportExportModal, {
|
|
||||||
initialValues: {
|
|
||||||
sourceStorageType: getDefaultFileFormat($extensions).storageType,
|
|
||||||
targetStorageType: 'database',
|
|
||||||
targetConnectionId: connection._id,
|
|
||||||
targetDatabaseName: name,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleExport = () => {
|
|
||||||
const { connection, name } = data;
|
|
||||||
|
|
||||||
showModal(ImportExportModal, {
|
|
||||||
initialValues: {
|
|
||||||
targetStorageType: getDefaultFileFormat($extensions).storageType,
|
|
||||||
sourceStorageType: 'database',
|
|
||||||
sourceConnectionId: connection._id,
|
|
||||||
sourceDatabaseName: name,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleSqlGenerator = () => {
|
|
||||||
const { connection, name } = data;
|
|
||||||
|
|
||||||
showModal(SqlGeneratorModal, {
|
|
||||||
conid: connection._id,
|
|
||||||
database: name,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
function createMenu() {
|
function createMenu() {
|
||||||
return [
|
return getDatabaseMenuItems(data.connection, data.name, $extensions);
|
||||||
{ onClick: handleNewQuery, text: 'New query' },
|
|
||||||
{ onClick: handleImport, text: 'Import' },
|
|
||||||
{ onClick: handleExport, text: 'Export' },
|
|
||||||
{ onClick: handleSqlGenerator, text: 'SQL Generator' },
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import FormCheckboxField from '../forms/FormCheckboxField.svelte';
|
||||||
|
|
||||||
import FormPasswordField from '../forms/FormPasswordField.svelte';
|
import FormPasswordField from '../forms/FormPasswordField.svelte';
|
||||||
|
|
||||||
import { getFormContext } from '../forms/FormProviderCore.svelte';
|
import { getFormContext } from '../forms/FormProviderCore.svelte';
|
||||||
@ -17,6 +19,7 @@
|
|||||||
$: currentAuthType = $authTypes && $authTypes.find(x => x.name == authType);
|
$: currentAuthType = $authTypes && $authTypes.find(x => x.name == authType);
|
||||||
$: disabledFields = (currentAuthType ? currentAuthType.disabledFields : null) || [];
|
$: disabledFields = (currentAuthType ? currentAuthType.disabledFields : null) || [];
|
||||||
$: driver = $extensions.drivers.find(x => x.engine == engine);
|
$: driver = $extensions.drivers.find(x => x.engine == engine);
|
||||||
|
$: defaultDatabase = $values.defaultDatabase;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<FormSelectField
|
<FormSelectField
|
||||||
@ -44,11 +47,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if driver?.supportsDatabaseUrl && useDatabaseUrl}
|
{#if driver?.supportsDatabaseUrl && useDatabaseUrl}
|
||||||
<FormTextField
|
<FormTextField label="Database URL" name="databaseUrl" placeholder={driver?.databaseUrlPlaceholder} />
|
||||||
label="Database URL"
|
|
||||||
name="databaseUrl"
|
|
||||||
placeholder={driver?.databaseUrlPlaceholder}
|
|
||||||
/>
|
|
||||||
{:else}
|
{:else}
|
||||||
{#if $authTypes}
|
{#if $authTypes}
|
||||||
<FormSelectField
|
<FormSelectField
|
||||||
@ -114,6 +113,10 @@
|
|||||||
|
|
||||||
<FormTextField label="Default database" name="defaultDatabase" />
|
<FormTextField label="Default database" name="defaultDatabase" />
|
||||||
|
|
||||||
|
{#if defaultDatabase}
|
||||||
|
<FormCheckboxField label={`Use only database ${defaultDatabase}`} name="singleDatabase" />
|
||||||
|
{/if}
|
||||||
|
|
||||||
<FormTextField label="Display name" name="displayName" />
|
<FormTextField label="Display name" name="displayName" />
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
module={connectionAppObject}
|
module={connectionAppObject}
|
||||||
subItemsComponent={SubDatabaseList}
|
subItemsComponent={SubDatabaseList}
|
||||||
expandOnClick
|
expandOnClick
|
||||||
isExpandable={data => $openedConnections.includes(data._id)}
|
isExpandable={data => $openedConnections.includes(data._id) && !data.singleDatabase}
|
||||||
{filter}
|
{filter}
|
||||||
/>
|
/>
|
||||||
{#if $connections && $connections.length == 0 && $commandsCustomized['new.connection']?.enabled}
|
{#if $connections && $connections.length == 0 && $commandsCustomized['new.connection']?.enabled}
|
||||||
|
Loading…
Reference in New Issue
Block a user