mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 14:23:58 +00:00
quick export from web
This commit is contained in:
@@ -169,7 +169,7 @@
|
|||||||
{ text: 'Delete', onClick: handleDelete },
|
{ text: 'Delete', onClick: handleDelete },
|
||||||
{ text: 'Rename', onClick: handleRename },
|
{ text: 'Rename', onClick: handleRename },
|
||||||
data.fileType == 'jsonl' &&
|
data.fileType == 'jsonl' &&
|
||||||
createQuickExportMenu($extensions, fmt => async () => {
|
createQuickExportMenu(fmt => async () => {
|
||||||
exportElectronFile(
|
exportElectronFile(
|
||||||
data.fileName,
|
data.fileName,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -412,7 +412,7 @@
|
|||||||
if (menu.divider) return menu;
|
if (menu.divider) return menu;
|
||||||
|
|
||||||
if (menu.isQuickExport) {
|
if (menu.isQuickExport) {
|
||||||
return createQuickExportMenu(getExtensions(), fmt => async () => {
|
return createQuickExportMenu(fmt => async () => {
|
||||||
const coninfo = await getConnectionInfo(data);
|
const coninfo = await getConnectionInfo(data);
|
||||||
exportElectronFile(
|
exportElectronFile(
|
||||||
data.pureName,
|
data.pureName,
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<script lang="ts" context="module">
|
<script lang="ts" context="module">
|
||||||
import { getContext, setContext } from 'svelte';
|
import { getContext, setContext } from 'svelte';
|
||||||
import { extensions } from '../stores';
|
|
||||||
import { createQuickExportMenuItems } from '../utility/createQuickExportMenu';
|
import { createQuickExportMenuItems } from '../utility/createQuickExportMenu';
|
||||||
|
|
||||||
import createRef from '../utility/createRef';
|
import createRef from '../utility/createRef';
|
||||||
@@ -32,7 +31,7 @@
|
|||||||
|
|
||||||
function getExportMenu() {
|
function getExportMenu() {
|
||||||
return [
|
return [
|
||||||
quickExportHandlerRef?.value ? createQuickExportMenuItems($extensions, quickExportHandlerRef?.value) : null,
|
quickExportHandlerRef?.value ? createQuickExportMenuItems(quickExportHandlerRef?.value) : null,
|
||||||
{ divider: true },
|
{ divider: true },
|
||||||
{ command, text: label },
|
{ command, text: label },
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -109,7 +109,7 @@
|
|||||||
import { parseFilter } from 'dbgate-filterparser';
|
import { parseFilter } from 'dbgate-filterparser';
|
||||||
import { scriptToSql } from 'dbgate-sqltree';
|
import { scriptToSql } from 'dbgate-sqltree';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { registerQuickExportHandler } from '../buttons/ToolStripExportButton.svelte';
|
import { registerQuickExportHandler } from '../buttons/ToolStripExportButton.svelte';
|
||||||
import registerCommand from '../commands/registerCommand';
|
import registerCommand from '../commands/registerCommand';
|
||||||
import ErrorInfo from '../elements/ErrorInfo.svelte';
|
import ErrorInfo from '../elements/ErrorInfo.svelte';
|
||||||
import ConfirmNoSqlModal from '../modals/ConfirmNoSqlModal.svelte';
|
import ConfirmNoSqlModal from '../modals/ConfirmNoSqlModal.svelte';
|
||||||
@@ -216,10 +216,10 @@ import { registerQuickExportHandler } from '../buttons/ToolStripExportButton.sve
|
|||||||
|
|
||||||
registerMenu(
|
registerMenu(
|
||||||
{ command: 'collectionDataGrid.openQuery', tag: 'export' },
|
{ command: 'collectionDataGrid.openQuery', tag: 'export' },
|
||||||
{
|
() => ({
|
||||||
...createQuickExportMenu($extensions, quickExportHandler),
|
...createQuickExportMenu(quickExportHandler),
|
||||||
tag: 'export',
|
tag: 'export',
|
||||||
},
|
}),
|
||||||
|
|
||||||
{ command: 'collectionDataGrid.export', tag: 'export' }
|
{ command: 'collectionDataGrid.export', tag: 'export' }
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -131,10 +131,10 @@
|
|||||||
registerQuickExportHandler(quickExportHandler);
|
registerQuickExportHandler(quickExportHandler);
|
||||||
|
|
||||||
registerMenu(
|
registerMenu(
|
||||||
{
|
() => ({
|
||||||
...createQuickExportMenu($extensions, quickExportHandler),
|
...createQuickExportMenu(quickExportHandler),
|
||||||
tag: 'export',
|
tag: 'export',
|
||||||
},
|
}),
|
||||||
{ command: 'jslTableGrid.export', tag: 'export' }
|
{ command: 'jslTableGrid.export', tag: 'export' }
|
||||||
);
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -66,12 +66,11 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { getContext } from 'svelte';
|
import { getContext } from 'svelte';
|
||||||
import { registerQuickExportHandler } from '../buttons/ToolStripExportButton.svelte';
|
import { registerQuickExportHandler } from '../buttons/ToolStripExportButton.svelte';
|
||||||
|
|
||||||
import registerCommand from '../commands/registerCommand';
|
import registerCommand from '../commands/registerCommand';
|
||||||
import ImportExportModal from '../modals/ImportExportModal.svelte';
|
import ImportExportModal from '../modals/ImportExportModal.svelte';
|
||||||
import { showModal } from '../modals/modalTools';
|
import { showModal } from '../modals/modalTools';
|
||||||
import { extensions } from '../stores';
|
|
||||||
import { apiCall } from '../utility/api';
|
import { apiCall } from '../utility/api';
|
||||||
|
|
||||||
import { registerMenu } from '../utility/contextMenu';
|
import { registerMenu } from '../utility/contextMenu';
|
||||||
@@ -202,10 +201,10 @@ import { registerQuickExportHandler } from '../buttons/ToolStripExportButton.sve
|
|||||||
registerMenu(
|
registerMenu(
|
||||||
{ command: 'sqlDataGrid.openActiveChart', tag: 'chart' },
|
{ command: 'sqlDataGrid.openActiveChart', tag: 'chart' },
|
||||||
{ command: 'sqlDataGrid.openQuery', tag: 'export' },
|
{ command: 'sqlDataGrid.openQuery', tag: 'export' },
|
||||||
{
|
() => ({
|
||||||
...createQuickExportMenu($extensions, quickExportHandler),
|
...createQuickExportMenu(quickExportHandler),
|
||||||
tag: 'export',
|
tag: 'export',
|
||||||
},
|
}),
|
||||||
{ command: 'sqlDataGrid.export', tag: 'export' }
|
{ command: 'sqlDataGrid.export', tag: 'export' }
|
||||||
);
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -50,14 +50,11 @@
|
|||||||
import { showSnackbarSuccess } from '../utility/snackbar';
|
import { showSnackbarSuccess } from '../utility/snackbar';
|
||||||
import StatusBarTabItem from '../widgets/StatusBarTabItem.svelte';
|
import StatusBarTabItem from '../widgets/StatusBarTabItem.svelte';
|
||||||
import openNewTab from '../utility/openNewTab';
|
import openNewTab from '../utility/openNewTab';
|
||||||
import { getBoolSettingsValue } from '../settings/settingsTools';
|
|
||||||
import { setContext } from 'svelte';
|
import { setContext } from 'svelte';
|
||||||
import { apiCall } from '../utility/api';
|
import { apiCall } from '../utility/api';
|
||||||
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';
|
|
||||||
import ToolStripExportButton, { createQuickExportHandlerRef } from '../buttons/ToolStripExportButton.svelte';
|
import ToolStripExportButton, { createQuickExportHandlerRef } from '../buttons/ToolStripExportButton.svelte';
|
||||||
|
|
||||||
export let tabid;
|
export let tabid;
|
||||||
|
|||||||
@@ -1,30 +1,27 @@
|
|||||||
import { ExtensionsDirectory, QuickExportDefinition } from 'dbgate-types';
|
import { ExtensionsDirectory, QuickExportDefinition } from 'dbgate-types';
|
||||||
|
import { getExtensions } from '../stores';
|
||||||
import getElectron from './getElectron';
|
import getElectron from './getElectron';
|
||||||
|
|
||||||
export function createQuickExportMenuItems(
|
export function createQuickExportMenuItems(handler: (fmt: QuickExportDefinition) => Function) {
|
||||||
extensions: ExtensionsDirectory,
|
// const electron = getElectron();
|
||||||
handler: (fmt: QuickExportDefinition) => Function
|
// if (!electron) {
|
||||||
) {
|
// return null;
|
||||||
const electron = getElectron();
|
// }
|
||||||
if (!electron) {
|
const extensions = getExtensions();
|
||||||
return null;
|
console.log('extensions', extensions);
|
||||||
}
|
|
||||||
return extensions.quickExports.map(fmt => ({
|
return extensions.quickExports.map(fmt => ({
|
||||||
text: fmt.label,
|
text: fmt.label,
|
||||||
onClick: handler(fmt),
|
onClick: handler(fmt),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function createQuickExportMenu(
|
export default function createQuickExportMenu(handler: (fmt: QuickExportDefinition) => Function) {
|
||||||
extensions: ExtensionsDirectory,
|
// const electron = getElectron();
|
||||||
handler: (fmt: QuickExportDefinition) => Function
|
// if (!electron) {
|
||||||
) {
|
// return { _skip: true };
|
||||||
const electron = getElectron();
|
// }
|
||||||
if (!electron) {
|
|
||||||
return { _skip: true };
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
text: 'Quick export',
|
text: 'Quick export',
|
||||||
submenu: createQuickExportMenuItems(extensions, handler),
|
submenu: createQuickExportMenuItems(handler),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,14 +6,21 @@ import { apiCall, apiOff, apiOn } from './api';
|
|||||||
|
|
||||||
export async function exportElectronFile(dataName, reader, format) {
|
export async function exportElectronFile(dataName, reader, format) {
|
||||||
const electron = getElectron();
|
const electron = getElectron();
|
||||||
const filters = [{ name: format.label, extensions: [format.extension] }];
|
|
||||||
|
|
||||||
const filePath = await electron.showSaveDialog({
|
let filePath;
|
||||||
filters,
|
let pureFileName;
|
||||||
defaultPath: `${dataName}.${format.extension}`,
|
if (electron) {
|
||||||
properties: ['showOverwriteConfirmation'],
|
const filters = [{ name: format.label, extensions: [format.extension] }];
|
||||||
});
|
filePath = electron.showSaveDialog({
|
||||||
if (!filePath) return;
|
filters,
|
||||||
|
defaultPath: `${dataName}.${format.extension}`,
|
||||||
|
properties: ['showOverwriteConfirmation'],
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const resp = await apiCall('files/generate-uploads-file');
|
||||||
|
filePath = resp.filePath;
|
||||||
|
pureFileName = resp.fileName;
|
||||||
|
}
|
||||||
|
|
||||||
const script = new ScriptWriter();
|
const script = new ScriptWriter();
|
||||||
|
|
||||||
@@ -50,6 +57,10 @@ export async function exportElectronFile(dataName, reader, format) {
|
|||||||
apiOff(`runner-done-${runid}`, handleRunnerDone);
|
apiOff(`runner-done-${runid}`, handleRunnerDone);
|
||||||
if (isCanceled) showSnackbarError(`Export ${dataName} canceled`);
|
if (isCanceled) showSnackbarError(`Export ${dataName} canceled`);
|
||||||
else showSnackbarInfo(`Export ${dataName} finished`);
|
else showSnackbarInfo(`Export ${dataName} finished`);
|
||||||
|
|
||||||
|
if (!electron) {
|
||||||
|
window.open(`${resolveApi()}/uploads/get?file=${pureFileName}`, '_blank');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
apiOn(`runner-done-${runid}`, handleRunnerDone);
|
apiOn(`runner-done-${runid}`, handleRunnerDone);
|
||||||
|
|||||||
Reference in New Issue
Block a user