mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-25 00:36:00 +00:00
simplify settings
This commit is contained in:
@@ -1,11 +1,15 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import CommandListener from './commands/CommandListener.svelte';
|
import CommandListener from './commands/CommandListener.svelte';
|
||||||
import DataGridRowHeightMeter from './datagrid/DataGridRowHeightMeter.svelte';
|
import DataGridRowHeightMeter from './datagrid/DataGridRowHeightMeter.svelte';
|
||||||
|
import LoadingInfo from './elements/LoadingInfo.svelte';
|
||||||
|
|
||||||
import PluginsProvider from './plugins/PluginsProvider.svelte';
|
import PluginsProvider from './plugins/PluginsProvider.svelte';
|
||||||
import Screen from './Screen.svelte';
|
import Screen from './Screen.svelte';
|
||||||
import ErrorHandler from './utility/ErrorHandler.svelte';
|
import ErrorHandler from './utility/ErrorHandler.svelte';
|
||||||
|
import { useSettings } from './utility/metadataLoaders';
|
||||||
import OpenTabsOnStartup from './utility/OpenTabsOnStartup.svelte';
|
import OpenTabsOnStartup from './utility/OpenTabsOnStartup.svelte';
|
||||||
|
|
||||||
|
const settings = useSettings();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<DataGridRowHeightMeter />
|
<DataGridRowHeightMeter />
|
||||||
@@ -13,4 +17,9 @@
|
|||||||
<PluginsProvider />
|
<PluginsProvider />
|
||||||
<CommandListener />
|
<CommandListener />
|
||||||
<OpenTabsOnStartup />
|
<OpenTabsOnStartup />
|
||||||
<Screen />
|
|
||||||
|
{#if $settings}
|
||||||
|
<Screen />
|
||||||
|
{:else}
|
||||||
|
<LoadingInfo message="Loading settings..." />
|
||||||
|
{/if}
|
||||||
|
|||||||
@@ -67,6 +67,8 @@
|
|||||||
import registerCommand from '../commands/registerCommand';
|
import registerCommand from '../commands/registerCommand';
|
||||||
import { registerMenu } from '../utility/contextMenu';
|
import { registerMenu } from '../utility/contextMenu';
|
||||||
import { useSettings } from '../utility/metadataLoaders';
|
import { useSettings } from '../utility/metadataLoaders';
|
||||||
|
import { getCurrentSettings } from '../stores';
|
||||||
|
import { getBoolSettingsValue } from '../settings/settingsTools';
|
||||||
|
|
||||||
export let config;
|
export let config;
|
||||||
export let setConfig;
|
export let setConfig;
|
||||||
@@ -98,13 +100,7 @@
|
|||||||
setContext('macroValues', macroValues);
|
setContext('macroValues', macroValues);
|
||||||
|
|
||||||
let managerSize;
|
let managerSize;
|
||||||
let collapsedLeftColumnStore = writable(null);
|
const collapsedLeftColumnStore = writable(getBoolSettingsValue('dataGrid.hideLeftColumn', false));
|
||||||
|
|
||||||
const settings = useSettings();
|
|
||||||
|
|
||||||
$: if ($collapsedLeftColumnStore == null && $settings) {
|
|
||||||
$collapsedLeftColumnStore = !!$settings['dataGrid.hideLeftColumn'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$: isFormView = !!(formDisplay && formDisplay.config && formDisplay.config.isFormView);
|
$: isFormView = !!(formDisplay && formDisplay.config && formDisplay.config.isFormView);
|
||||||
$: isJsonView = !!config?.isJsonView;
|
$: isJsonView = !!config?.isJsonView;
|
||||||
|
|||||||
@@ -26,7 +26,6 @@
|
|||||||
|
|
||||||
const loadNextDataRef = createRef(false);
|
const loadNextDataRef = createRef(false);
|
||||||
const loadedTimeRef = createRef(null);
|
const loadedTimeRef = createRef(null);
|
||||||
const settings = useSettings();
|
|
||||||
|
|
||||||
export function resetLoadedAll() {
|
export function resetLoadedAll() {
|
||||||
isLoadedAll = false;
|
isLoadedAll = false;
|
||||||
@@ -52,7 +51,7 @@
|
|||||||
const nextRows = await loadDataPage(
|
const nextRows = await loadDataPage(
|
||||||
$$props,
|
$$props,
|
||||||
loadedRows.length,
|
loadedRows.length,
|
||||||
getIntSettingsValue($settings, 'dataGrid.pageSize', 100, 5, 1000)
|
getIntSettingsValue('dataGrid.pageSize', 100, 5, 1000)
|
||||||
);
|
);
|
||||||
if (loadedTimeRef.get() !== loadStart) {
|
if (loadedTimeRef.get() !== loadStart) {
|
||||||
// new load was dispatched
|
// new load was dispatched
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import { getCurrentSettings } from '../stores';
|
||||||
|
|
||||||
export function getIntSettingsValue(settings, name, defaultValue, min = null, max = null) {
|
export function getIntSettingsValue(name, defaultValue, min = null, max = null) {
|
||||||
|
const settings = getCurrentSettings();
|
||||||
const parsed = parseInt(settings[name]);
|
const parsed = parseInt(settings[name]);
|
||||||
if (_.isNaN(parsed)) {
|
if (_.isNaN(parsed)) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
@@ -12,3 +14,10 @@ export function getIntSettingsValue(settings, name, defaultValue, min = null, ma
|
|||||||
}
|
}
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getBoolSettingsValue(name, defaultValue) {
|
||||||
|
const settings = getCurrentSettings();
|
||||||
|
const res = settings[name];
|
||||||
|
if (res == null) return defaultValue;
|
||||||
|
return !!res;
|
||||||
|
}
|
||||||
|
|||||||
@@ -43,14 +43,12 @@ export const activeTab = derived([openedTabs], ([$openedTabs]) => $openedTabs.fi
|
|||||||
export const recentDatabases = writableWithStorage([], 'recentDatabases');
|
export const recentDatabases = writableWithStorage([], 'recentDatabases');
|
||||||
export const commandsSettings = derived(useSettings(), (config: any) => (config || {}).commands || {});
|
export const commandsSettings = derived(useSettings(), (config: any) => (config || {}).commands || {});
|
||||||
export const allResultsInOneTabDefault = writableWithStorage(false, 'allResultsInOneTabDefault');
|
export const allResultsInOneTabDefault = writableWithStorage(false, 'allResultsInOneTabDefault');
|
||||||
export const commandsCustomized = derived(
|
export const commandsCustomized = derived([commands, commandsSettings], ([$commands, $commandsSettings]) =>
|
||||||
[commands, commandsSettings],
|
_.mapValues($commands, (v, k) => ({
|
||||||
([$commands, $commandsSettings]) =>
|
// @ts-ignore
|
||||||
_.mapValues($commands, (v, k) => ({
|
...v,
|
||||||
// @ts-ignore
|
...$commandsSettings[k],
|
||||||
...v,
|
}))
|
||||||
...$commandsSettings[k],
|
|
||||||
}))
|
|
||||||
);
|
);
|
||||||
|
|
||||||
export const visibleToolbar = writableWithStorage(1, 'visibleToolbar');
|
export const visibleToolbar = writableWithStorage(1, 'visibleToolbar');
|
||||||
@@ -137,3 +135,10 @@ currentDatabase.subscribe(value => {
|
|||||||
invalidateCommands();
|
invalidateCommands();
|
||||||
});
|
});
|
||||||
export const getCurrentDatabase = () => currentDatabaseValue;
|
export const getCurrentDatabase = () => currentDatabaseValue;
|
||||||
|
|
||||||
|
let currentSettingsValue = null;
|
||||||
|
useSettings().subscribe(value => {
|
||||||
|
currentSettingsValue = value;
|
||||||
|
invalidateCommands();
|
||||||
|
});
|
||||||
|
export const getCurrentSettings = () => currentSettingsValue || {};
|
||||||
|
|||||||
Reference in New Issue
Block a user