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">
|
||||
const getContextMenu = (data, $openedConnections) => () => {
|
||||
const getContextMenu = (data, $openedConnections, $extensions) => () => {
|
||||
const config = getCurrentConfig();
|
||||
const handleRefresh = () => {
|
||||
axiosInstance.post('server-connections/refresh', { conid: data._id });
|
||||
@ -55,6 +55,7 @@
|
||||
onClick: handleDelete,
|
||||
},
|
||||
],
|
||||
!data.singleDatabase && [
|
||||
!$openedConnections.includes(data._id) && {
|
||||
text: 'Connect',
|
||||
onClick: handleConnect,
|
||||
@ -73,6 +74,8 @@
|
||||
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 InputTextModal from '../modals/InputTextModal.svelte';
|
||||
import openNewTab from '../utility/openNewTab';
|
||||
import { getDatabaseMenuItems } from './DatabaseAppObject.svelte';
|
||||
|
||||
export let data;
|
||||
|
||||
@ -149,13 +153,20 @@
|
||||
<AppObjectCore
|
||||
{...$$restProps}
|
||||
{data}
|
||||
title={data.displayName || data.server}
|
||||
icon="img server"
|
||||
isBold={_.get($currentDatabase, 'connection._id') == data._id}
|
||||
title={data.singleDatabase
|
||||
? data.displayName || `${data.defaultDatabase} on ${data.server}`
|
||||
: 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}
|
||||
statusTitle={statusTitle || engineStatusTitle}
|
||||
{extInfo}
|
||||
menu={getContextMenu(data, $openedConnections)}
|
||||
on:click={() => ($openedConnections = _.uniq([...$openedConnections, data._id]))}
|
||||
menu={getContextMenu(data, $openedConnections, $extensions)}
|
||||
on:click={() => {
|
||||
if (data.singleDatabase) $currentDatabase = { connection: data, name: data.defaultDatabase };
|
||||
else $openedConnections = _.uniq([...$openedConnections, data._id]);
|
||||
}}
|
||||
on:click
|
||||
/>
|
||||
|
@ -1,20 +1,8 @@
|
||||
<script lang="ts" context="module">
|
||||
export const extractKey = props => props.name;
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import _ from 'lodash';
|
||||
import ImportExportModal from '../modals/ImportExportModal.svelte';
|
||||
import { showModal } from '../modals/modalTools';
|
||||
import SqlGeneratorModal from '../modals/SqlGeneratorModal.svelte';
|
||||
import { getDefaultFileFormat } from '../plugins/fileformats';
|
||||
import { currentDatabase, extensions } from '../stores';
|
||||
import openNewTab from '../utility/openNewTab';
|
||||
import AppObjectCore from './AppObjectCore.svelte';
|
||||
export let data;
|
||||
|
||||
export function getDatabaseMenuItems(connection, name, $extensions) {
|
||||
const handleNewQuery = () => {
|
||||
const { connection, name } = data;
|
||||
const tooltip = `${connection.displayName || connection.server}\n${name}`;
|
||||
openNewTab({
|
||||
title: 'Query #',
|
||||
@ -29,8 +17,6 @@
|
||||
};
|
||||
|
||||
const handleImport = () => {
|
||||
const { connection, name } = data;
|
||||
|
||||
showModal(ImportExportModal, {
|
||||
initialValues: {
|
||||
sourceStorageType: getDefaultFileFormat($extensions).storageType,
|
||||
@ -42,8 +28,6 @@
|
||||
};
|
||||
|
||||
const handleExport = () => {
|
||||
const { connection, name } = data;
|
||||
|
||||
showModal(ImportExportModal, {
|
||||
initialValues: {
|
||||
targetStorageType: getDefaultFileFormat($extensions).storageType,
|
||||
@ -55,15 +39,12 @@
|
||||
};
|
||||
|
||||
const handleSqlGenerator = () => {
|
||||
const { connection, name } = data;
|
||||
|
||||
showModal(SqlGeneratorModal, {
|
||||
conid: connection._id,
|
||||
database: name,
|
||||
});
|
||||
};
|
||||
|
||||
function createMenu() {
|
||||
return [
|
||||
{ onClick: handleNewQuery, text: 'New query' },
|
||||
{ onClick: handleImport, text: 'Import' },
|
||||
@ -73,6 +54,22 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import _ from 'lodash';
|
||||
import ImportExportModal from '../modals/ImportExportModal.svelte';
|
||||
import { showModal } from '../modals/modalTools';
|
||||
import SqlGeneratorModal from '../modals/SqlGeneratorModal.svelte';
|
||||
import { getDefaultFileFormat } from '../plugins/fileformats';
|
||||
import { currentDatabase, extensions } from '../stores';
|
||||
import openNewTab from '../utility/openNewTab';
|
||||
import AppObjectCore from './AppObjectCore.svelte';
|
||||
export let data;
|
||||
|
||||
function createMenu() {
|
||||
return getDatabaseMenuItems(data.connection, data.name, $extensions);
|
||||
}
|
||||
</script>
|
||||
|
||||
<AppObjectCore
|
||||
{...$$restProps}
|
||||
{data}
|
||||
|
@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import FormCheckboxField from '../forms/FormCheckboxField.svelte';
|
||||
|
||||
import FormPasswordField from '../forms/FormPasswordField.svelte';
|
||||
|
||||
import { getFormContext } from '../forms/FormProviderCore.svelte';
|
||||
@ -17,6 +19,7 @@
|
||||
$: currentAuthType = $authTypes && $authTypes.find(x => x.name == authType);
|
||||
$: disabledFields = (currentAuthType ? currentAuthType.disabledFields : null) || [];
|
||||
$: driver = $extensions.drivers.find(x => x.engine == engine);
|
||||
$: defaultDatabase = $values.defaultDatabase;
|
||||
</script>
|
||||
|
||||
<FormSelectField
|
||||
@ -44,11 +47,7 @@
|
||||
{/if}
|
||||
|
||||
{#if driver?.supportsDatabaseUrl && useDatabaseUrl}
|
||||
<FormTextField
|
||||
label="Database URL"
|
||||
name="databaseUrl"
|
||||
placeholder={driver?.databaseUrlPlaceholder}
|
||||
/>
|
||||
<FormTextField label="Database URL" name="databaseUrl" placeholder={driver?.databaseUrlPlaceholder} />
|
||||
{:else}
|
||||
{#if $authTypes}
|
||||
<FormSelectField
|
||||
@ -114,6 +113,10 @@
|
||||
|
||||
<FormTextField label="Default database" name="defaultDatabase" />
|
||||
|
||||
{#if defaultDatabase}
|
||||
<FormCheckboxField label={`Use only database ${defaultDatabase}`} name="singleDatabase" />
|
||||
{/if}
|
||||
|
||||
<FormTextField label="Display name" name="displayName" />
|
||||
|
||||
<style>
|
||||
|
@ -40,7 +40,7 @@
|
||||
module={connectionAppObject}
|
||||
subItemsComponent={SubDatabaseList}
|
||||
expandOnClick
|
||||
isExpandable={data => $openedConnections.includes(data._id)}
|
||||
isExpandable={data => $openedConnections.includes(data._id) && !data.singleDatabase}
|
||||
{filter}
|
||||
/>
|
||||
{#if $connections && $connections.length == 0 && $commandsCustomized['new.connection']?.enabled}
|
||||
|
Loading…
Reference in New Issue
Block a user