mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-22 09:56:01 +00:00
settings modal
This commit is contained in:
@@ -4,6 +4,7 @@ import { derived, get } from 'svelte/store';
|
|||||||
import { ThemeDefinition } from 'dbgate-types';
|
import { ThemeDefinition } from 'dbgate-types';
|
||||||
import ConnectionModal from '../modals/ConnectionModal.svelte';
|
import ConnectionModal from '../modals/ConnectionModal.svelte';
|
||||||
import AboutModal from '../modals/AboutModal.svelte';
|
import AboutModal from '../modals/AboutModal.svelte';
|
||||||
|
import SettingsModal from '../settings/SettingsModal.svelte';
|
||||||
import ImportExportModal from '../modals/ImportExportModal.svelte';
|
import ImportExportModal from '../modals/ImportExportModal.svelte';
|
||||||
import SqlGeneratorModal from '../modals/SqlGeneratorModal.svelte';
|
import SqlGeneratorModal from '../modals/SqlGeneratorModal.svelte';
|
||||||
import { showModal } from '../modals/modalTools';
|
import { showModal } from '../modals/modalTools';
|
||||||
@@ -218,6 +219,14 @@ if (hasPermission('settings/change')) {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
registerCommand({
|
||||||
|
id: 'settings.show',
|
||||||
|
category: 'Settings',
|
||||||
|
name: 'Change',
|
||||||
|
toolbarName: 'Change settings',
|
||||||
|
onClick: () => showModal(SettingsModal),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function registerFileCommands({
|
export function registerFileCommands({
|
||||||
|
|||||||
@@ -66,6 +66,7 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
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';
|
||||||
|
|
||||||
export let config;
|
export let config;
|
||||||
export let setConfig;
|
export let setConfig;
|
||||||
@@ -97,7 +98,13 @@
|
|||||||
setContext('macroValues', macroValues);
|
setContext('macroValues', macroValues);
|
||||||
|
|
||||||
let managerSize;
|
let managerSize;
|
||||||
let collapsedLeftColumnStore = writable(false);
|
let collapsedLeftColumnStore = writable(null);
|
||||||
|
|
||||||
|
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;
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { getIntSettingsValue } from '../settings/settingsTools';
|
||||||
|
|
||||||
import createRef from '../utility/createRef';
|
import createRef from '../utility/createRef';
|
||||||
|
import { useSettings } from '../utility/metadataLoaders';
|
||||||
|
|
||||||
import DataGridCore from './DataGridCore.svelte';
|
import DataGridCore from './DataGridCore.svelte';
|
||||||
|
|
||||||
@@ -23,6 +26,7 @@
|
|||||||
|
|
||||||
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;
|
||||||
@@ -45,7 +49,11 @@
|
|||||||
loadedTimeRef.set(loadStart);
|
loadedTimeRef.set(loadStart);
|
||||||
// console.log('LOAD NEXT ROWS', loadedRows);
|
// console.log('LOAD NEXT ROWS', loadedRows);
|
||||||
|
|
||||||
const nextRows = await loadDataPage($$props, loadedRows.length, 100);
|
const nextRows = await loadDataPage(
|
||||||
|
$$props,
|
||||||
|
loadedRows.length,
|
||||||
|
getIntSettingsValue($settings, 'dataGrid.pageSize', 100, 5, 1000)
|
||||||
|
);
|
||||||
if (loadedTimeRef.get() !== loadStart) {
|
if (loadedTimeRef.get() !== loadStart) {
|
||||||
// new load was dispatched
|
// new load was dispatched
|
||||||
return;
|
return;
|
||||||
|
|||||||
44
packages/web/src/settings/SettingsModal.svelte
Normal file
44
packages/web/src/settings/SettingsModal.svelte
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import FormButton from '../forms/FormButton.svelte';
|
||||||
|
import FormCheckboxField from '../forms/FormCheckboxField.svelte';
|
||||||
|
|
||||||
|
import FormProvider from '../forms/FormProvider.svelte';
|
||||||
|
import FormSubmit from '../forms/FormSubmit.svelte';
|
||||||
|
import FormTextField from '../forms/FormTextField.svelte';
|
||||||
|
|
||||||
|
import ModalBase from '../modals/ModalBase.svelte';
|
||||||
|
import { closeCurrentModal } from '../modals/modalTools';
|
||||||
|
import axiosInstance from '../utility/axiosInstance';
|
||||||
|
import { useSettings } from '../utility/metadataLoaders';
|
||||||
|
|
||||||
|
const settings = useSettings();
|
||||||
|
|
||||||
|
function handleOk(e) {
|
||||||
|
axiosInstance.post('config/update-settings', e.detail);
|
||||||
|
closeCurrentModal();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if $settings}
|
||||||
|
<FormProvider initialValues={$settings}>
|
||||||
|
<ModalBase {...$$restProps}>
|
||||||
|
<div slot="header">Settings</div>
|
||||||
|
|
||||||
|
<div class="heading">Data grid</div>
|
||||||
|
<FormCheckboxField name="dataGrid.hideLeftColumn" label="Hide left column by default" />
|
||||||
|
<FormTextField name="dataGrid.pageSize" label="Page size" defaultValue="100" />
|
||||||
|
|
||||||
|
<div slot="footer">
|
||||||
|
<FormSubmit value="OK" on:click={handleOk} />
|
||||||
|
<FormButton value="Cancel" on:click={closeCurrentModal} />
|
||||||
|
</div>
|
||||||
|
</ModalBase>
|
||||||
|
</FormProvider>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.heading {
|
||||||
|
font-size: 20px;
|
||||||
|
margin: 5px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
14
packages/web/src/settings/settingsTools.ts
Normal file
14
packages/web/src/settings/settingsTools.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
export function getIntSettingsValue(settings, name, defaultValue, min = null, max = null) {
|
||||||
|
const parsed = parseInt(settings[name]);
|
||||||
|
if (_.isNaN(parsed)) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
if (_.isNumber(parsed)) {
|
||||||
|
if (min != null && parsed < min) return min;
|
||||||
|
if (max != null && parsed > max) return max;
|
||||||
|
return parsed;
|
||||||
|
}
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
const rect = domSettings.getBoundingClientRect();
|
const rect = domSettings.getBoundingClientRect();
|
||||||
const left = rect.right;
|
const left = rect.right;
|
||||||
const top = rect.top;
|
const top = rect.top;
|
||||||
const items = [{ command: 'settings.commands' }, { command: 'theme.changeTheme' }];
|
const items = [{ command: 'settings.commands' }, { command: 'theme.changeTheme' }, { command: 'settings.show' }];
|
||||||
currentDropDownMenu.set({ left, top, items });
|
currentDropDownMenu.set({ left, top, items });
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user