mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-21 18:46:00 +00:00
quick exports - basic skeleton working
This commit is contained in:
@@ -47,15 +47,15 @@
|
||||
{
|
||||
divider: true,
|
||||
},
|
||||
electron && {
|
||||
label: 'Quick export',
|
||||
isQuickExport: true,
|
||||
functionName: 'tableReader',
|
||||
},
|
||||
{
|
||||
label: 'Export',
|
||||
isExport: true,
|
||||
},
|
||||
// electron &&
|
||||
{
|
||||
label: 'Quick export',
|
||||
isQuickExport: true,
|
||||
},
|
||||
{
|
||||
label: 'Open in free table editor',
|
||||
isOpenFreeTable: true,
|
||||
@@ -114,14 +114,14 @@
|
||||
{
|
||||
divider: true,
|
||||
},
|
||||
{
|
||||
label: 'Export',
|
||||
isExport: true,
|
||||
},
|
||||
electron && {
|
||||
label: 'Quick export',
|
||||
isQuickExport: true,
|
||||
},
|
||||
{
|
||||
label: 'Export',
|
||||
isExport: true,
|
||||
},
|
||||
{
|
||||
label: 'Open in free table editor',
|
||||
isOpenFreeTable: true,
|
||||
@@ -175,14 +175,14 @@
|
||||
{
|
||||
divider: true,
|
||||
},
|
||||
{
|
||||
label: 'Export',
|
||||
isExport: true,
|
||||
},
|
||||
electron && {
|
||||
label: 'Quick export',
|
||||
isQuickExport: true,
|
||||
},
|
||||
{
|
||||
label: 'Export',
|
||||
isExport: true,
|
||||
},
|
||||
{
|
||||
label: 'Open in free table editor',
|
||||
isOpenFreeTable: true,
|
||||
@@ -275,14 +275,14 @@
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Export',
|
||||
isExport: true,
|
||||
},
|
||||
electron && {
|
||||
label: 'Quick export',
|
||||
isQuickExport: true,
|
||||
},
|
||||
{
|
||||
label: 'Export',
|
||||
isExport: true,
|
||||
},
|
||||
{
|
||||
divider: true,
|
||||
},
|
||||
@@ -399,16 +399,26 @@
|
||||
if (menu.isQuickExport) {
|
||||
return {
|
||||
text: menu.label,
|
||||
submenu: [
|
||||
{
|
||||
text: 'CSV file',
|
||||
isQuickExport: true,
|
||||
submenu: $extensions.quickExports.map(fmt => ({
|
||||
text: fmt.label,
|
||||
onClick: async () => {
|
||||
const coninfo = await getConnectionInfo(data);
|
||||
exportElectronFile(
|
||||
data.pureName,
|
||||
{
|
||||
functionName: menu.functionName,
|
||||
props: {
|
||||
connection: {
|
||||
..._.omit(coninfo, ['_id', 'displayName']),
|
||||
..._.pick(data, ['database']),
|
||||
},
|
||||
..._.pick(data, ['pureName', 'schemaName']),
|
||||
},
|
||||
},
|
||||
fmt
|
||||
);
|
||||
},
|
||||
{
|
||||
text: 'Excel',
|
||||
isQuickExport: true,
|
||||
},
|
||||
],
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -425,8 +435,6 @@
|
||||
sourceList: [data.pureName],
|
||||
},
|
||||
});
|
||||
} else if (menu.isQuickExport) {
|
||||
exportElectronFile(data);
|
||||
} else if (menu.isOpenFreeTable) {
|
||||
const coninfo = await getConnectionInfo(data);
|
||||
openNewTab({
|
||||
@@ -511,6 +519,7 @@
|
||||
|
||||
<AppObjectCore
|
||||
{...$$restProps}
|
||||
module={$$props.module}
|
||||
{data}
|
||||
title={data.schemaName ? `${data.schemaName}.${data.pureName}` : data.pureName}
|
||||
icon={icons[data.objectTypeField]}
|
||||
|
||||
@@ -68,6 +68,7 @@
|
||||
export let items;
|
||||
export let top;
|
||||
export let left;
|
||||
export let onCloseParent;
|
||||
|
||||
let element;
|
||||
|
||||
@@ -90,6 +91,7 @@
|
||||
return;
|
||||
}
|
||||
dispatch('close');
|
||||
if (onCloseParent) onCloseParent();
|
||||
if (item.onClick) item.onClick();
|
||||
}
|
||||
|
||||
@@ -106,14 +108,23 @@
|
||||
$: compacted = _.compact(extracted.map(x => mapItem(x, $commandsCustomized)));
|
||||
$: filtered = compacted.filter(x => !x.disabled || !x.hideDisabled);
|
||||
|
||||
const handleClickOutside = event => {
|
||||
// if (element && !element.contains(event.target) && !event.defaultPrevented) {
|
||||
if (event.target.closest('ul.dropDownMenuMarker')) return;
|
||||
|
||||
dispatch('close');
|
||||
};
|
||||
|
||||
onMount(() => {
|
||||
document.addEventListener('mousedown', handleClickOutside, true);
|
||||
return () => {
|
||||
document.removeEventListener('mousedown', handleClickOutside, true);
|
||||
};
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<ul
|
||||
style={`left: ${left}px; top: ${top}px`}
|
||||
use:clickOutside
|
||||
on:clickOutside={() => dispatch('close')}
|
||||
bind:this={element}
|
||||
>
|
||||
<ul class="dropDownMenuMarker" style={`left: ${left}px; top: ${top}px`} bind:this={element}>
|
||||
{#each filtered as item}
|
||||
{#if item.divider}
|
||||
<li class="divider" />
|
||||
@@ -141,7 +152,14 @@
|
||||
{/each}
|
||||
</ul>
|
||||
{#if submenuItem?.submenu}
|
||||
<svelte:self items={submenuItem?.submenu} {...submenuOffset} />
|
||||
<svelte:self
|
||||
items={submenuItem?.submenu}
|
||||
{...submenuOffset}
|
||||
onCloseParent={() => {
|
||||
if (onCloseParent) onCloseParent();
|
||||
dispatch('close');
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
|
||||
@@ -1,29 +1,34 @@
|
||||
import { showModal } from '../modals/modalTools';
|
||||
import { get } from 'svelte/store';
|
||||
import newQuery from '../query/newQuery';
|
||||
import ImportExportModal from '../modals/ImportExportModal.svelte';
|
||||
import ScriptWriter from '../impexp/ScriptWriter';
|
||||
import getElectron from './getElectron';
|
||||
import { currentDatabase, extensions } from '../stores';
|
||||
import { getUploadListener } from './uploadFiles';
|
||||
import axiosInstance from '../utility/axiosInstance';
|
||||
import { getDatabaseFileLabel } from './getConnectionLabel';
|
||||
|
||||
function getFileFormatFilters(extensions) {
|
||||
return extensions.quickExports.map(x => ({ name: x.label, extensions: [x.extension] }));
|
||||
}
|
||||
|
||||
export async function exportElectronFile() {
|
||||
export async function exportElectronFile(dataName, reader, format) {
|
||||
const electron = getElectron();
|
||||
const ext = get(extensions);
|
||||
const filters = getFileFormatFilters(ext);
|
||||
console.log('FLT', filters);
|
||||
electron.remote.dialog
|
||||
.showSaveDialog(electron.remote.getCurrentWindow(), {
|
||||
filters,
|
||||
})
|
||||
.then(filePaths => {
|
||||
console.log('filePaths ASYNC2', filePaths);
|
||||
const filePath = filePaths && filePaths[0];
|
||||
console.log('filePath', filePath);
|
||||
});
|
||||
const filters = [{ name: format.label, extensions: [format.extension] }];
|
||||
|
||||
const filePath = electron.remote.dialog.showSaveDialogSync(electron.remote.getCurrentWindow(), {
|
||||
filters,
|
||||
defaultPath: `${dataName}.${format.extension}`,
|
||||
properties: ['showOverwriteConfirmation'],
|
||||
});
|
||||
if (!filePath) return;
|
||||
|
||||
const script = new ScriptWriter();
|
||||
|
||||
const sourceVar = script.allocVariable();
|
||||
script.assign(sourceVar, reader.functionName, reader.props);
|
||||
|
||||
console.log('format.createWriter(filePath, dataName)', format.createWriter(filePath, dataName));
|
||||
|
||||
const targetVar = script.allocVariable();
|
||||
const writer = format.createWriter(filePath, dataName);
|
||||
script.assign(targetVar, writer.functionName, writer.props);
|
||||
|
||||
script.copyStream(sourceVar, targetVar);
|
||||
script.put();
|
||||
|
||||
console.log('script.getScript()', script.getScript());
|
||||
|
||||
const resp = await axiosInstance.post('runners/start', { script: script.getScript() });
|
||||
const runid = resp.data.runid;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user