mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
quick export from table data grid toolstrip
This commit is contained in:
parent
e06b030707
commit
a8265cebff
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
function handleClick(e) {
|
function handleClick(e) {
|
||||||
if (disabled) return;
|
if (disabled) return;
|
||||||
dispatch('click');
|
dispatch('click', { target: e.target });
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import FontIcon from '../icons/FontIcon.svelte';
|
||||||
|
|
||||||
import { currentDropDownMenu } from '../stores';
|
import { currentDropDownMenu } from '../stores';
|
||||||
|
|
||||||
import ToolStripButton from './ToolStripButton.svelte';
|
import ToolStripButton from './ToolStripButton.svelte';
|
||||||
|
|
||||||
export let menu;
|
export let menu;
|
||||||
export let title;
|
export let title = undefined;
|
||||||
export let label;
|
export let label;
|
||||||
export let icon;
|
export let icon;
|
||||||
export let component = ToolStripButton;
|
export let component = ToolStripButton;
|
||||||
|
|
||||||
function handleClick(e) {
|
function handleClick(e) {
|
||||||
const rect = e.target.getBoundingClientRect();
|
const rect = e.detail.target.getBoundingClientRect();
|
||||||
const left = rect.left;
|
const left = rect.left;
|
||||||
const top = rect.bottom;
|
const top = rect.bottom;
|
||||||
currentDropDownMenu.set({ left, top, items: menu });
|
currentDropDownMenu.set({ left, top, items: menu });
|
||||||
@ -19,4 +21,5 @@
|
|||||||
|
|
||||||
<svelte:component this={component} {title} {icon} on:click={handleClick}>
|
<svelte:component this={component} {title} {icon} on:click={handleClick}>
|
||||||
{label}
|
{label}
|
||||||
|
<FontIcon icon="icon chevron-down" />
|
||||||
</svelte:component>
|
</svelte:component>
|
||||||
|
@ -34,7 +34,9 @@
|
|||||||
id: 'dataGrid.deleteSelectedRows',
|
id: 'dataGrid.deleteSelectedRows',
|
||||||
category: 'Data grid',
|
category: 'Data grid',
|
||||||
name: 'Delete selected rows',
|
name: 'Delete selected rows',
|
||||||
|
toolbarName: 'Delete row(s)',
|
||||||
keyText: 'Ctrl+Delete',
|
keyText: 'Ctrl+Delete',
|
||||||
|
icon: 'icon minus',
|
||||||
testEnabled: () => getCurrentDataGrid()?.getGrider()?.editable,
|
testEnabled: () => getCurrentDataGrid()?.getGrider()?.editable,
|
||||||
onClick: () => getCurrentDataGrid().deleteSelectedRows(),
|
onClick: () => getCurrentDataGrid().deleteSelectedRows(),
|
||||||
});
|
});
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
id: 'sqlDataGrid.export',
|
id: 'sqlDataGrid.export',
|
||||||
category: 'Data grid',
|
category: 'Data grid',
|
||||||
name: 'Export',
|
name: 'Export',
|
||||||
|
icon: 'icon export',
|
||||||
keyText: 'Ctrl+E',
|
keyText: 'Ctrl+E',
|
||||||
testEnabled: () => getCurrentEditor() != null,
|
testEnabled: () => getCurrentEditor() != null,
|
||||||
onClick: () => getCurrentEditor().exportGrid(),
|
onClick: () => getCurrentEditor().exportGrid(),
|
||||||
@ -64,6 +65,7 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import { getContext } from 'svelte';
|
||||||
|
|
||||||
import registerCommand from '../commands/registerCommand';
|
import registerCommand from '../commands/registerCommand';
|
||||||
import ImportExportModal from '../modals/ImportExportModal.svelte';
|
import ImportExportModal from '../modals/ImportExportModal.svelte';
|
||||||
@ -177,27 +179,31 @@
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const quickExportHandler = fmt => async () => {
|
||||||
|
const coninfo = await getConnectionInfo({ conid });
|
||||||
|
exportElectronFile(
|
||||||
|
pureName || 'Data',
|
||||||
|
{
|
||||||
|
functionName: 'queryReader',
|
||||||
|
props: {
|
||||||
|
connection: {
|
||||||
|
..._.omit(coninfo, ['_id', 'displayName']),
|
||||||
|
database,
|
||||||
|
},
|
||||||
|
sql: display.getExportQuery(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fmt
|
||||||
|
);
|
||||||
|
};
|
||||||
|
const setQuickExportHandler = getContext('setQuickExportHandler');
|
||||||
|
if (setQuickExportHandler) (setQuickExportHandler as any)(quickExportHandler);
|
||||||
|
|
||||||
registerMenu(
|
registerMenu(
|
||||||
{ command: 'sqlDataGrid.openActiveChart', tag: 'chart' },
|
{ command: 'sqlDataGrid.openActiveChart', tag: 'chart' },
|
||||||
{ command: 'sqlDataGrid.openQuery', tag: 'export' },
|
{ command: 'sqlDataGrid.openQuery', tag: 'export' },
|
||||||
{
|
{
|
||||||
...createQuickExportMenu($extensions, fmt => async () => {
|
...createQuickExportMenu($extensions, quickExportHandler),
|
||||||
const coninfo = await getConnectionInfo({ conid });
|
|
||||||
exportElectronFile(
|
|
||||||
pureName || 'Data',
|
|
||||||
{
|
|
||||||
functionName: 'queryReader',
|
|
||||||
props: {
|
|
||||||
connection: {
|
|
||||||
..._.omit(coninfo, ['_id', 'displayName']),
|
|
||||||
database,
|
|
||||||
},
|
|
||||||
sql: display.getExportQuery(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
fmt
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
tag: 'export',
|
tag: 'export',
|
||||||
},
|
},
|
||||||
{ command: 'sqlDataGrid.export', tag: 'export' }
|
{ command: 'sqlDataGrid.export', tag: 'export' }
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
'icon favorite': 'mdi mdi-star',
|
'icon favorite': 'mdi mdi-star',
|
||||||
'icon share': 'mdi mdi-share-variant',
|
'icon share': 'mdi mdi-share-variant',
|
||||||
'icon add': 'mdi mdi-plus-circle',
|
'icon add': 'mdi mdi-plus-circle',
|
||||||
|
'icon minus': 'mdi mdi-minus-circle',
|
||||||
'icon connection': 'mdi mdi-connection',
|
'icon connection': 'mdi mdi-connection',
|
||||||
'icon cell-data': 'mdi mdi-details',
|
'icon cell-data': 'mdi mdi-details',
|
||||||
'icon sql-generator': 'mdi mdi-cog-transfer',
|
'icon sql-generator': 'mdi mdi-cog-transfer',
|
||||||
|
@ -56,6 +56,8 @@
|
|||||||
import { getLocalStorage, setLocalStorage } from '../utility/storageCache';
|
import { getLocalStorage, setLocalStorage } from '../utility/storageCache';
|
||||||
import ToolStripContainer from '../buttons/ToolStripContainer.svelte';
|
import ToolStripContainer from '../buttons/ToolStripContainer.svelte';
|
||||||
import ToolStripCommandButton from '../buttons/ToolStripCommandButton.svelte';
|
import ToolStripCommandButton from '../buttons/ToolStripCommandButton.svelte';
|
||||||
|
import ToolStripDropDownButton from '../buttons/ToolStripDropDownButton.svelte';
|
||||||
|
import { createQuickExportMenuItems } from '../utility/createQuickExportMenu';
|
||||||
|
|
||||||
export let tabid;
|
export let tabid;
|
||||||
export let conid;
|
export let conid;
|
||||||
@ -116,6 +118,19 @@
|
|||||||
const collapsedLeftColumnStore = writable(getLocalStorage('dataGrid_collapsedLeftColumn', false));
|
const collapsedLeftColumnStore = writable(getLocalStorage('dataGrid_collapsedLeftColumn', false));
|
||||||
setContext('collapsedLeftColumnStore', collapsedLeftColumnStore);
|
setContext('collapsedLeftColumnStore', collapsedLeftColumnStore);
|
||||||
$: setLocalStorage('dataGrid_collapsedLeftColumn', $collapsedLeftColumnStore);
|
$: setLocalStorage('dataGrid_collapsedLeftColumn', $collapsedLeftColumnStore);
|
||||||
|
|
||||||
|
let quickExportHandler = null;
|
||||||
|
function setQuickExportHandler(value) {
|
||||||
|
quickExportHandler = value;
|
||||||
|
}
|
||||||
|
setContext('setQuickExportHandler', setQuickExportHandler);
|
||||||
|
function getExportMenu() {
|
||||||
|
return [
|
||||||
|
quickExportHandler ? createQuickExportMenuItems($extensions, quickExportHandler) : null,
|
||||||
|
{ divider: true },
|
||||||
|
{ command: 'sqlDataGrid.export', text: 'Advanced settings' },
|
||||||
|
];
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ToolStripContainer>
|
<ToolStripContainer>
|
||||||
@ -135,6 +150,8 @@
|
|||||||
<ToolStripCommandButton command="dataGrid.refresh" />
|
<ToolStripCommandButton command="dataGrid.refresh" />
|
||||||
<ToolStripCommandButton command="tableData.save" />
|
<ToolStripCommandButton command="tableData.save" />
|
||||||
<ToolStripCommandButton command="dataGrid.insertNewRow" />
|
<ToolStripCommandButton command="dataGrid.insertNewRow" />
|
||||||
|
<ToolStripCommandButton command="dataGrid.deleteSelectedRows" />
|
||||||
|
<ToolStripDropDownButton menu={getExportMenu} label="Export" icon="icon export" />
|
||||||
</svelte:fragment>
|
</svelte:fragment>
|
||||||
</ToolStripContainer>
|
</ToolStripContainer>
|
||||||
|
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
import { findEngineDriver } from 'dbgate-tools';
|
import { findEngineDriver } from 'dbgate-tools';
|
||||||
import { setContext } from 'svelte';
|
import { setContext } from 'svelte';
|
||||||
import { writable } from 'svelte/store';
|
import { writable } from 'svelte/store';
|
||||||
|
import ToolStripCommandButton from '../buttons/ToolStripCommandButton.svelte';
|
||||||
|
import ToolStripContainer from '../buttons/ToolStripContainer.svelte';
|
||||||
|
|
||||||
import DataGrid from '../datagrid/DataGrid.svelte';
|
import DataGrid from '../datagrid/DataGrid.svelte';
|
||||||
import SqlDataGridCore from '../datagrid/SqlDataGridCore.svelte';
|
import SqlDataGridCore from '../datagrid/SqlDataGridCore.svelte';
|
||||||
@ -51,16 +53,22 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if display}
|
{#if display}
|
||||||
<DataGrid
|
<ToolStripContainer>
|
||||||
{...$$props}
|
<DataGrid
|
||||||
{display}
|
{...$$props}
|
||||||
config={$config}
|
{display}
|
||||||
setConfig={config.update}
|
config={$config}
|
||||||
cache={$cache}
|
setConfig={config.update}
|
||||||
setCache={cache.update}
|
cache={$cache}
|
||||||
focusOnVisible
|
setCache={cache.update}
|
||||||
gridCoreComponent={SqlDataGridCore}
|
focusOnVisible
|
||||||
/>
|
gridCoreComponent={SqlDataGridCore}
|
||||||
|
/>
|
||||||
|
<svelte:fragment slot="toolstrip">
|
||||||
|
<ToolStripCommandButton command="dataGrid.refresh" />
|
||||||
|
<ToolStripCommandButton command="sqlDataGrid.export" />
|
||||||
|
</svelte:fragment>
|
||||||
|
</ToolStripContainer>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<StatusBarTabItem
|
<StatusBarTabItem
|
||||||
|
@ -95,7 +95,7 @@ function mapItem(item, commands) {
|
|||||||
const command = commands[item.command];
|
const command = commands[item.command];
|
||||||
if (command) {
|
if (command) {
|
||||||
return {
|
return {
|
||||||
text: command.menuName || command.toolbarName || command.name,
|
text: item.text || command.menuName || command.toolbarName || command.name,
|
||||||
keyText: command.keyText || command.keyTextFromGroup,
|
keyText: command.keyText || command.keyTextFromGroup,
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
if (command.getSubCommands) visibleCommandPalette.set(command);
|
if (command.getSubCommands) visibleCommandPalette.set(command);
|
||||||
|
@ -1,6 +1,20 @@
|
|||||||
import { ExtensionsDirectory, QuickExportDefinition } from 'dbgate-types';
|
import { ExtensionsDirectory, QuickExportDefinition } from 'dbgate-types';
|
||||||
import getElectron from './getElectron';
|
import getElectron from './getElectron';
|
||||||
|
|
||||||
|
export function createQuickExportMenuItems(
|
||||||
|
extensions: ExtensionsDirectory,
|
||||||
|
handler: (fmt: QuickExportDefinition) => Function
|
||||||
|
) {
|
||||||
|
const electron = getElectron();
|
||||||
|
if (!electron) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return extensions.quickExports.map(fmt => ({
|
||||||
|
text: fmt.label,
|
||||||
|
onClick: handler(fmt),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
export default function createQuickExportMenu(
|
export default function createQuickExportMenu(
|
||||||
extensions: ExtensionsDirectory,
|
extensions: ExtensionsDirectory,
|
||||||
handler: (fmt: QuickExportDefinition) => Function
|
handler: (fmt: QuickExportDefinition) => Function
|
||||||
@ -11,9 +25,6 @@ export default function createQuickExportMenu(
|
|||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
text: 'Quick export',
|
text: 'Quick export',
|
||||||
submenu: extensions.quickExports.map(fmt => ({
|
submenu: createQuickExportMenuItems(extensions, handler),
|
||||||
text: fmt.label,
|
|
||||||
onClick: handler(fmt),
|
|
||||||
})),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user