mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-28 15:16:00 +00:00
quick export WIP
This commit is contained in:
7
packages/types/extensions.d.ts
vendored
7
packages/types/extensions.d.ts
vendored
@@ -33,9 +33,16 @@ export interface PluginDefinition {
|
|||||||
content: any;
|
content: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface QuickExportDefinition {
|
||||||
|
label: string;
|
||||||
|
createWriter: (fileName: string) => { functionName: string; props: any };
|
||||||
|
extension: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ExtensionsDirectory {
|
export interface ExtensionsDirectory {
|
||||||
plugins: PluginDefinition[];
|
plugins: PluginDefinition[];
|
||||||
fileFormats: FileFormatDefinition[];
|
fileFormats: FileFormatDefinition[];
|
||||||
|
quickExports: QuickExportDefinition[];
|
||||||
drivers: EngineDriver[];
|
drivers: EngineDriver[];
|
||||||
themes: ThemeDefinition[];
|
themes: ThemeDefinition[];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script lang="ts" context="module">
|
<script lang="ts" context="module">
|
||||||
export const extractKey = ({ schemaName, pureName }) => (schemaName ? `${schemaName}.${pureName}` : pureName);
|
export const extractKey = ({ schemaName, pureName }) => (schemaName ? `${schemaName}.${pureName}` : pureName);
|
||||||
export const createMatcher = ({ pureName }) => filter => filterName(filter, pureName);
|
export const createMatcher = ({ pureName }) => filter => filterName(filter, pureName);
|
||||||
|
const electron = getElectron();
|
||||||
|
|
||||||
const icons = {
|
const icons = {
|
||||||
tables: 'img table',
|
tables: 'img table',
|
||||||
@@ -50,6 +51,10 @@
|
|||||||
label: 'Export',
|
label: 'Export',
|
||||||
isExport: true,
|
isExport: true,
|
||||||
},
|
},
|
||||||
|
electron && {
|
||||||
|
label: 'Quick export',
|
||||||
|
isQuickExport: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: 'Open in free table editor',
|
label: 'Open in free table editor',
|
||||||
isOpenFreeTable: true,
|
isOpenFreeTable: true,
|
||||||
@@ -112,6 +117,10 @@
|
|||||||
label: 'Export',
|
label: 'Export',
|
||||||
isExport: true,
|
isExport: true,
|
||||||
},
|
},
|
||||||
|
electron && {
|
||||||
|
label: 'Quick export',
|
||||||
|
isQuickExport: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: 'Open in free table editor',
|
label: 'Open in free table editor',
|
||||||
isOpenFreeTable: true,
|
isOpenFreeTable: true,
|
||||||
@@ -169,6 +178,10 @@
|
|||||||
label: 'Export',
|
label: 'Export',
|
||||||
isExport: true,
|
isExport: true,
|
||||||
},
|
},
|
||||||
|
electron && {
|
||||||
|
label: 'Quick export',
|
||||||
|
isQuickExport: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: 'Open in free table editor',
|
label: 'Open in free table editor',
|
||||||
isOpenFreeTable: true,
|
isOpenFreeTable: true,
|
||||||
@@ -265,6 +278,10 @@
|
|||||||
label: 'Export',
|
label: 'Export',
|
||||||
isExport: true,
|
isExport: true,
|
||||||
},
|
},
|
||||||
|
electron && {
|
||||||
|
label: 'Quick export',
|
||||||
|
isQuickExport: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
divider: true,
|
divider: true,
|
||||||
},
|
},
|
||||||
@@ -311,6 +328,7 @@
|
|||||||
{ forceNewTab }
|
{ forceNewTab }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
@@ -326,7 +344,9 @@
|
|||||||
import { findEngineDriver } from 'dbgate-tools';
|
import { findEngineDriver } from 'dbgate-tools';
|
||||||
import uuidv1 from 'uuid/v1';
|
import uuidv1 from 'uuid/v1';
|
||||||
import SqlGeneratorModal from '../modals/SqlGeneratorModal.svelte';
|
import SqlGeneratorModal from '../modals/SqlGeneratorModal.svelte';
|
||||||
import getConnectionLabel from '../utility/getConnectionLabel';
|
import getConnectionLabel from '../utility/getConnectionLabel';
|
||||||
|
import getElectron from '../utility/getElectron';
|
||||||
|
import { exportElectronFile } from '../utility/exportElectronFile';
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
|
|
||||||
@@ -370,100 +390,105 @@ import getConnectionLabel from '../utility/getConnectionLabel';
|
|||||||
|
|
||||||
function createMenu() {
|
function createMenu() {
|
||||||
const { objectTypeField } = data;
|
const { objectTypeField } = data;
|
||||||
return menus[objectTypeField].map(menu => {
|
return menus[objectTypeField]
|
||||||
if (menu.divider) return menu;
|
.filter(x => x)
|
||||||
return {
|
.map(menu => {
|
||||||
text: menu.label,
|
if (menu.divider) return menu;
|
||||||
onClick: async () => {
|
return {
|
||||||
if (menu.isExport) {
|
text: menu.label,
|
||||||
showModal(ImportExportModal, {
|
onClick: async () => {
|
||||||
initialValues: {
|
if (menu.isExport) {
|
||||||
sourceStorageType: 'database',
|
showModal(ImportExportModal, {
|
||||||
sourceConnectionId: data.conid,
|
initialValues: {
|
||||||
sourceDatabaseName: data.database,
|
sourceStorageType: 'database',
|
||||||
sourceSchemaName: data.schemaName,
|
sourceConnectionId: data.conid,
|
||||||
sourceList: [data.pureName],
|
sourceDatabaseName: data.database,
|
||||||
},
|
sourceSchemaName: data.schemaName,
|
||||||
});
|
sourceList: [data.pureName],
|
||||||
} else if (menu.isOpenFreeTable) {
|
},
|
||||||
const coninfo = await getConnectionInfo(data);
|
});
|
||||||
openNewTab({
|
} else if (menu.isQuickExport) {
|
||||||
title: data.pureName,
|
exportElectronFile(data);
|
||||||
icon: 'img free-table',
|
} else if (menu.isOpenFreeTable) {
|
||||||
tabComponent: 'FreeTableTab',
|
const coninfo = await getConnectionInfo(data);
|
||||||
props: {
|
openNewTab({
|
||||||
initialArgs: {
|
title: data.pureName,
|
||||||
functionName: 'tableReader',
|
icon: 'img free-table',
|
||||||
props: {
|
tabComponent: 'FreeTableTab',
|
||||||
connection: {
|
props: {
|
||||||
...coninfo,
|
initialArgs: {
|
||||||
database: data.database,
|
functionName: 'tableReader',
|
||||||
|
props: {
|
||||||
|
connection: {
|
||||||
|
...coninfo,
|
||||||
|
database: data.database,
|
||||||
|
},
|
||||||
|
schemaName: data.schemaName,
|
||||||
|
pureName: data.pureName,
|
||||||
},
|
},
|
||||||
schemaName: data.schemaName,
|
|
||||||
pureName: data.pureName,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
});
|
} else if (menu.isActiveChart) {
|
||||||
} else if (menu.isActiveChart) {
|
const driver = await getDriver();
|
||||||
const driver = await getDriver();
|
const dmp = driver.createDumper();
|
||||||
const dmp = driver.createDumper();
|
dmp.put('^select * from %f', data);
|
||||||
dmp.put('^select * from %f', data);
|
openNewTab(
|
||||||
openNewTab(
|
{
|
||||||
{
|
title: data.pureName,
|
||||||
title: data.pureName,
|
icon: 'img chart',
|
||||||
icon: 'img chart',
|
tabComponent: 'ChartTab',
|
||||||
tabComponent: 'ChartTab',
|
props: {
|
||||||
props: {
|
conid: data.conid,
|
||||||
conid: data.conid,
|
database: data.database,
|
||||||
database: data.database,
|
},
|
||||||
},
|
},
|
||||||
},
|
{
|
||||||
{
|
editor: {
|
||||||
editor: {
|
config: { chartType: 'bar' },
|
||||||
config: { chartType: 'bar' },
|
sql: dmp.s,
|
||||||
sql: dmp.s,
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else if (menu.isQueryDesigner) {
|
||||||
|
openNewTab(
|
||||||
|
{
|
||||||
|
title: 'Query #',
|
||||||
|
icon: 'img query-design',
|
||||||
|
tabComponent: 'QueryDesignTab',
|
||||||
|
props: {
|
||||||
|
conid: data.conid,
|
||||||
|
database: data.database,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
{
|
||||||
);
|
editor: {
|
||||||
} else if (menu.isQueryDesigner) {
|
tables: [
|
||||||
openNewTab(
|
{
|
||||||
{
|
...data,
|
||||||
title: 'Query #',
|
designerId: uuidv1(),
|
||||||
icon: 'img query-design',
|
left: 50,
|
||||||
tabComponent: 'QueryDesignTab',
|
top: 50,
|
||||||
props: {
|
},
|
||||||
conid: data.conid,
|
],
|
||||||
database: data.database,
|
},
|
||||||
},
|
}
|
||||||
},
|
);
|
||||||
{
|
} else if (menu.sqlGeneratorProps) {
|
||||||
editor: {
|
showModal(SqlGeneratorModal, {
|
||||||
tables: [
|
initialObjects: [data],
|
||||||
{
|
initialConfig: menu.sqlGeneratorProps,
|
||||||
...data,
|
conid: data.conid,
|
||||||
designerId: uuidv1(),
|
database: data.database,
|
||||||
left: 50,
|
});
|
||||||
top: 50,
|
} else {
|
||||||
},
|
openDatabaseObjectDetail(menu.tab, menu.scriptTemplate, data, menu.forceNewTab, menu.initialData);
|
||||||
],
|
}
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
);
|
});
|
||||||
} else if (menu.sqlGeneratorProps) {
|
|
||||||
showModal(SqlGeneratorModal, {
|
|
||||||
initialObjects: [data],
|
|
||||||
initialConfig: menu.sqlGeneratorProps,
|
|
||||||
conid: data.conid,
|
|
||||||
database: data.database,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
openDatabaseObjectDetail(menu.tab, menu.scriptTemplate, data, menu.forceNewTab, menu.initialData);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<AppObjectCore
|
<AppObjectCore
|
||||||
|
|||||||
@@ -40,18 +40,26 @@
|
|||||||
function buildDrivers(plugins) {
|
function buildDrivers(plugins) {
|
||||||
const res = [];
|
const res = [];
|
||||||
for (const { content } of plugins) {
|
for (const { content } of plugins) {
|
||||||
// if (content.driver) res.push(content.driver);
|
|
||||||
if (content.drivers) res.push(...content.drivers);
|
if (content.drivers) res.push(...content.drivers);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildQuickExports(plugins) {
|
||||||
|
const res = [];
|
||||||
|
for (const { content } of plugins) {
|
||||||
|
if (content.quickExports) res.push(...content.quickExports);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
export function buildExtensions(plugins) {
|
export function buildExtensions(plugins) {
|
||||||
const extensions = {
|
const extensions = {
|
||||||
plugins,
|
plugins,
|
||||||
fileFormats: buildFileFormats(plugins),
|
fileFormats: buildFileFormats(plugins),
|
||||||
themes: buildThemes(plugins),
|
themes: buildThemes(plugins),
|
||||||
drivers: buildDrivers(plugins),
|
drivers: buildDrivers(plugins),
|
||||||
|
quickExports: buildQuickExports(plugins),
|
||||||
};
|
};
|
||||||
return extensions;
|
return extensions;
|
||||||
}
|
}
|
||||||
|
|||||||
29
packages/web/src/utility/exportElectronFile.ts
Normal file
29
packages/web/src/utility/exportElectronFile.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import { showModal } from '../modals/modalTools';
|
||||||
|
import { get } from 'svelte/store';
|
||||||
|
import newQuery from '../query/newQuery';
|
||||||
|
import ImportExportModal from '../modals/ImportExportModal.svelte';
|
||||||
|
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() {
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -43,4 +43,29 @@ const fileFormat = {
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
fileFormats: [fileFormat],
|
fileFormats: [fileFormat],
|
||||||
|
|
||||||
|
quickExports: [
|
||||||
|
{
|
||||||
|
label: 'CSV file',
|
||||||
|
extension: 'csv',
|
||||||
|
createWriter: (fileName) => ({
|
||||||
|
functionName: 'writer',
|
||||||
|
props: {
|
||||||
|
fileName,
|
||||||
|
delimiter: ',',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'CSV file (semicolor separated)',
|
||||||
|
extension: 'csv',
|
||||||
|
createWriter: (fileName) => ({
|
||||||
|
functionName: 'writer',
|
||||||
|
props: {
|
||||||
|
fileName,
|
||||||
|
delimiter: ';',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -64,5 +64,18 @@ const fileFormat = {
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
fileFormats: [fileFormat],
|
fileFormats: [fileFormat],
|
||||||
|
quickExports: [
|
||||||
|
{
|
||||||
|
label: 'MS Excel',
|
||||||
|
extension: 'xlsx',
|
||||||
|
createWriter: (fileName) => ({
|
||||||
|
functionName: 'writer',
|
||||||
|
props: {
|
||||||
|
fileName,
|
||||||
|
sheetName: 'data',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
],
|
||||||
initialize,
|
initialize,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user