mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-25 20:06:00 +00:00
database & connection color overrides
This commit is contained in:
@@ -170,6 +170,23 @@ module.exports = {
|
|||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
updateDatabase_meta: 'post',
|
||||||
|
async updateDatabase({ conid, database, values }) {
|
||||||
|
if (portalConnections) return;
|
||||||
|
const conn = await this.datastore.find({ _id: conid });
|
||||||
|
let databaseConfig = conn.databaseConfig || {};
|
||||||
|
databaseConfig = {
|
||||||
|
...databaseConfig,
|
||||||
|
[database]: {
|
||||||
|
...databaseConfig[database],
|
||||||
|
...values,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const res = await this.datastore.update({ _id: conid }, { $set: { databaseConfig } });
|
||||||
|
socket.emitChanged('connection-list-changed');
|
||||||
|
return res;
|
||||||
|
},
|
||||||
|
|
||||||
delete_meta: 'post',
|
delete_meta: 'post',
|
||||||
async delete(connection) {
|
async delete(connection) {
|
||||||
if (portalConnections) return;
|
if (portalConnections) return;
|
||||||
|
|||||||
@@ -56,7 +56,7 @@
|
|||||||
|
|
||||||
{#if (isExpanded || isExpandedBySearch) && subItemsComponent}
|
{#if (isExpanded || isExpandedBySearch) && subItemsComponent}
|
||||||
<div class="subitems">
|
<div class="subitems">
|
||||||
<svelte:component this={subItemsComponent} {data} {filter} />
|
<svelte:component this={subItemsComponent} {data} {filter} {passProps} />
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -171,8 +171,10 @@
|
|||||||
import { findEngineDriver } from 'dbgate-tools';
|
import { findEngineDriver } from 'dbgate-tools';
|
||||||
import InputTextModal from '../modals/InputTextModal.svelte';
|
import InputTextModal from '../modals/InputTextModal.svelte';
|
||||||
import { getDatabaseInfo } from '../utility/metadataLoaders';
|
import { getDatabaseInfo } from '../utility/metadataLoaders';
|
||||||
import { openJsonDocument } from '../tabs/JsonTab.svelte';
|
import { openJsonDocument } from '../tabs/JsonTab.svelte';
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
|
export let passProps;
|
||||||
|
|
||||||
function createMenu() {
|
function createMenu() {
|
||||||
return getDatabaseMenuItems(data.connection, data.name, $extensions, $currentDatabase);
|
return getDatabaseMenuItems(data.connection, data.name, $extensions, $currentDatabase);
|
||||||
@@ -184,6 +186,12 @@ import { openJsonDocument } from '../tabs/JsonTab.svelte';
|
|||||||
{data}
|
{data}
|
||||||
title={data.name}
|
title={data.name}
|
||||||
icon="img database"
|
icon="img database"
|
||||||
|
colorMark={passProps?.connectionColorFactory(
|
||||||
|
{ conid: _.get(data.connection, '_id'), database: data.name },
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
false
|
||||||
|
)}
|
||||||
isBold={_.get($currentDatabase, 'connection._id') == _.get(data.connection, '_id') &&
|
isBold={_.get($currentDatabase, 'connection._id') == _.get(data.connection, '_id') &&
|
||||||
_.get($currentDatabase, 'name') == data.name}
|
_.get($currentDatabase, 'name') == data.name}
|
||||||
on:click={() => ($currentDatabase = data)}
|
on:click={() => ($currentDatabase = data)}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
export let filter;
|
export let filter;
|
||||||
export let data;
|
export let data;
|
||||||
|
export let passProps;
|
||||||
|
|
||||||
$: databases = useDatabaseList({ conid: data._id });
|
$: databases = useDatabaseList({ conid: data._id });
|
||||||
</script>
|
</script>
|
||||||
@@ -17,4 +18,5 @@
|
|||||||
'name'
|
'name'
|
||||||
).map(db => ({ ...db, connection: data }))}
|
).map(db => ({ ...db, connection: data }))}
|
||||||
module={databaseAppObject}
|
module={databaseAppObject}
|
||||||
|
{passProps}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -6,22 +6,33 @@
|
|||||||
|
|
||||||
export let conid;
|
export let conid;
|
||||||
export let database;
|
export let database;
|
||||||
|
export let header;
|
||||||
|
|
||||||
const initialColor = useConnectionColor({ conid, database }, null);
|
const initialColor = useConnectionColor({ conid, database }, null, null, false, false);
|
||||||
|
|
||||||
$: value = $initialColor;
|
$: value = $initialColor;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ModalBase {...$$restProps}>
|
<ModalBase {...$$restProps}>
|
||||||
|
<svelte:fragment slot="header">{header}</svelte:fragment>
|
||||||
|
|
||||||
<ColorSelector
|
<ColorSelector
|
||||||
{value}
|
{value}
|
||||||
on:change={e => {
|
on:change={e => {
|
||||||
value = e.detail;
|
value = e.detail;
|
||||||
|
|
||||||
axiosInstance.post('connections/update', {
|
if (database) {
|
||||||
_id: conid,
|
axiosInstance.post('connections/update-database', {
|
||||||
values: { connectionColor: e.detail },
|
conid,
|
||||||
});
|
database,
|
||||||
|
values: { databaseColor: e.detail },
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
axiosInstance.post('connections/update', {
|
||||||
|
_id: conid,
|
||||||
|
values: { connectionColor: e.detail },
|
||||||
|
});
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</ModalBase>
|
</ModalBase>
|
||||||
|
|||||||
@@ -56,6 +56,7 @@
|
|||||||
--theme-bg-statusbar-inv: #0050b3;
|
--theme-bg-statusbar-inv: #0050b3;
|
||||||
--theme-bg-statusbar-inv-hover: #096dd9;
|
--theme-bg-statusbar-inv-hover: #096dd9;
|
||||||
--theme-bg-statusbar-inv-font: #222;
|
--theme-bg-statusbar-inv-font: #222;
|
||||||
|
--theme-bg-statusbar-inv-bg: #ccc;
|
||||||
--theme-bg-modalheader: rgb(43, 60, 61);
|
--theme-bg-modalheader: rgb(43, 60, 61);
|
||||||
|
|
||||||
--theme-bg-button-inv: #004488;
|
--theme-bg-button-inv: #004488;
|
||||||
|
|||||||
@@ -50,6 +50,7 @@
|
|||||||
--theme-bg-statusbar-inv: #0050b3;
|
--theme-bg-statusbar-inv: #0050b3;
|
||||||
--theme-bg-statusbar-inv-hover: #096dd9;
|
--theme-bg-statusbar-inv-hover: #096dd9;
|
||||||
--theme-bg-statusbar-inv-font: #222;
|
--theme-bg-statusbar-inv-font: #222;
|
||||||
|
--theme-bg-statusbar-inv-bg: #ccc;
|
||||||
--theme-bg-modalheader: #eff;
|
--theme-bg-modalheader: #eff;
|
||||||
|
|
||||||
--theme-bg-button-inv: #337ab7;
|
--theme-bg-button-inv: #337ab7;
|
||||||
|
|||||||
@@ -3,35 +3,76 @@ import { derived } from 'svelte/store';
|
|||||||
import { currentThemeDefinition } from '../stores';
|
import { currentThemeDefinition } from '../stores';
|
||||||
import { useConnectionList } from '../utility/metadataLoaders';
|
import { useConnectionList } from '../utility/metadataLoaders';
|
||||||
|
|
||||||
export function getConnectionColor(connections, dbid, themeType, colorIndex, backgroundStyle = false) {
|
export function getConnectionColor(
|
||||||
|
connections,
|
||||||
|
dbid,
|
||||||
|
themeType,
|
||||||
|
colorIndex,
|
||||||
|
backgroundStyle = false,
|
||||||
|
useConnectionFallback = true
|
||||||
|
) {
|
||||||
if (!dbid || !connections) return undefined;
|
if (!dbid || !connections) return undefined;
|
||||||
const current = connections.find(x => x._id == dbid.conid);
|
const current = connections.find(x => x._id == dbid.conid);
|
||||||
if (!current?.connectionColor) return undefined;
|
const { database } = dbid;
|
||||||
|
let colorName = useConnectionFallback || !database ? current?.connectionColor : null;
|
||||||
|
if (
|
||||||
|
database &&
|
||||||
|
current.databaseConfig &&
|
||||||
|
current.databaseConfig[database] &&
|
||||||
|
current.databaseConfig[database].databaseColor
|
||||||
|
) {
|
||||||
|
colorName = current.databaseConfig[database].databaseColor;
|
||||||
|
}
|
||||||
|
if (!colorName) return undefined;
|
||||||
const palettes = themeType == 'dark' ? presetDarkPalettes : presetPalettes;
|
const palettes = themeType == 'dark' ? presetDarkPalettes : presetPalettes;
|
||||||
if (colorIndex == null) return current?.connectionColor;
|
if (colorIndex == null) return colorName;
|
||||||
const color = palettes[current?.connectionColor][colorIndex];
|
const color = palettes[colorName][colorIndex];
|
||||||
if (backgroundStyle) return `background:${color}`;
|
if (backgroundStyle) return `background:${color}`;
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useConnectionColor(dbid, colorIndex, themeType = null, backgroundStyle = false) {
|
export function useConnectionColor(
|
||||||
|
dbid,
|
||||||
|
colorIndex,
|
||||||
|
themeType = null,
|
||||||
|
backgroundStyle = false,
|
||||||
|
useConnectionFallback = true
|
||||||
|
) {
|
||||||
const connections = useConnectionList();
|
const connections = useConnectionList();
|
||||||
return derived([connections, currentThemeDefinition], ([$connections, $themeDef]) =>
|
return derived([connections, currentThemeDefinition], ([$connections, $themeDef]) =>
|
||||||
getConnectionColor($connections, dbid, themeType ?? $themeDef?.themeType, colorIndex, backgroundStyle)
|
getConnectionColor(
|
||||||
|
$connections,
|
||||||
|
dbid,
|
||||||
|
themeType ?? $themeDef?.themeType,
|
||||||
|
colorIndex,
|
||||||
|
backgroundStyle,
|
||||||
|
useConnectionFallback
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useConnectionColorFactory(colorIndex, themeType = null, backgroundStyle = false) {
|
export function useConnectionColorFactory(
|
||||||
|
colorIndex,
|
||||||
|
themeType = null,
|
||||||
|
backgroundStyle = false,
|
||||||
|
useConnectionFallback = true
|
||||||
|
) {
|
||||||
const connections = useConnectionList();
|
const connections = useConnectionList();
|
||||||
return derived(
|
return derived(
|
||||||
[connections, currentThemeDefinition],
|
[connections, currentThemeDefinition],
|
||||||
([$connections, $themeDef]) => (dbid, colorIndexOverride = null) =>
|
([$connections, $themeDef]) => (
|
||||||
|
dbid,
|
||||||
|
colorIndexOverride = null,
|
||||||
|
backgroundStyleOverride = null,
|
||||||
|
useConnectionFallbackOverride = null
|
||||||
|
) =>
|
||||||
getConnectionColor(
|
getConnectionColor(
|
||||||
$connections,
|
$connections,
|
||||||
dbid,
|
dbid,
|
||||||
themeType ?? $themeDef?.themeType,
|
themeType ?? $themeDef?.themeType,
|
||||||
colorIndexOverride || colorIndex,
|
colorIndexOverride ?? colorIndex,
|
||||||
backgroundStyle
|
backgroundStyleOverride ?? backgroundStyle,
|
||||||
|
useConnectionFallbackOverride ?? useConnectionFallback
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,13 +48,13 @@
|
|||||||
$: dbid = connection ? { conid: connection._id, database: databaseName } : null;
|
$: dbid = connection ? { conid: connection._id, database: databaseName } : null;
|
||||||
$: status = useDatabaseStatus(dbid || {});
|
$: status = useDatabaseStatus(dbid || {});
|
||||||
$: serverVersion = useDatabaseServerVersion(dbid || {});
|
$: serverVersion = useDatabaseServerVersion(dbid || {});
|
||||||
const connections = useConnectionList();
|
|
||||||
|
|
||||||
$: contextItems = $statusBarTabInfo[$activeTabId] as any[];
|
$: contextItems = $statusBarTabInfo[$activeTabId] as any[];
|
||||||
$: connectionLabel = getConnectionLabel(connection, { allowExplicitDatabase: false });
|
$: connectionLabel = getConnectionLabel(connection, { allowExplicitDatabase: false });
|
||||||
|
|
||||||
$: connectionBackground = useConnectionColor(dbid, 3, 'dark', true);
|
$: connectionBackground = useConnectionColor(dbid, 3, 'dark', true);
|
||||||
$: connectionButtonBackground = useConnectionColor(dbid, 6, 'dark', true);
|
$: connectionButtonBackground = useConnectionColor(dbid ? { conid: dbid.conid } : null, 6, 'dark', true);
|
||||||
|
$: databaseButtonBackground = useConnectionColor(dbid, 6, 'dark', true, false);
|
||||||
|
|
||||||
let timerValue = 1;
|
let timerValue = 1;
|
||||||
|
|
||||||
@@ -76,23 +76,38 @@
|
|||||||
<FontIcon icon="icon database" padRight />
|
<FontIcon icon="icon database" padRight />
|
||||||
{databaseName}
|
{databaseName}
|
||||||
</div>
|
</div>
|
||||||
|
{#if dbid}
|
||||||
|
<div
|
||||||
|
class="item clickable"
|
||||||
|
title="Database color. Overrides connection color"
|
||||||
|
on:click={() => {
|
||||||
|
showModal(ChooseConnectionColorModal, { ...dbid, header: 'Choose database color' });
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div style={$databaseButtonBackground} class="colorbox">
|
||||||
|
<FontIcon icon="icon palette" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
{#if connectionLabel && dbid}
|
{#if connectionLabel}
|
||||||
<div class="item">
|
<div class="item">
|
||||||
<FontIcon icon="icon server" padRight />
|
<FontIcon icon="icon server" padRight />
|
||||||
{connectionLabel}
|
{connectionLabel}
|
||||||
</div>
|
</div>
|
||||||
<div
|
{#if dbid}
|
||||||
class="item clickable"
|
<div
|
||||||
title="Connection color. Can be overriden by dataabse color"
|
class="item clickable"
|
||||||
on:click={() => {
|
title="Connection color. Can be overriden by database color"
|
||||||
showModal(ChooseConnectionColorModal, { conid: dbid.conid });
|
on:click={() => {
|
||||||
}}
|
showModal(ChooseConnectionColorModal, { conid: dbid.conid, header: 'Choose connection color' });
|
||||||
>
|
}}
|
||||||
<div style={$connectionButtonBackground} class="colorbox">
|
>
|
||||||
<FontIcon icon="icon palette" />
|
<div style={$connectionButtonBackground} class="colorbox">
|
||||||
|
<FontIcon icon="icon palette" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
{#if connection && connection.user}
|
{#if connection && connection.user}
|
||||||
<div class="item">
|
<div class="item">
|
||||||
@@ -192,5 +207,6 @@
|
|||||||
padding: 0px 3px;
|
padding: 0px 3px;
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
color: var(--theme-bg-statusbar-inv-font);
|
color: var(--theme-bg-statusbar-inv-font);
|
||||||
|
background: var(--theme-bg-statusbar-inv-bg);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user