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