mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-28 16:26: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">
|
||||||
@@ -327,6 +345,8 @@
|
|||||||
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,7 +390,9 @@ import getConnectionLabel from '../utility/getConnectionLabel';
|
|||||||
|
|
||||||
function createMenu() {
|
function createMenu() {
|
||||||
const { objectTypeField } = data;
|
const { objectTypeField } = data;
|
||||||
return menus[objectTypeField].map(menu => {
|
return menus[objectTypeField]
|
||||||
|
.filter(x => x)
|
||||||
|
.map(menu => {
|
||||||
if (menu.divider) return menu;
|
if (menu.divider) return menu;
|
||||||
return {
|
return {
|
||||||
text: menu.label,
|
text: menu.label,
|
||||||
@@ -385,6 +407,8 @@ import getConnectionLabel from '../utility/getConnectionLabel';
|
|||||||
sourceList: [data.pureName],
|
sourceList: [data.pureName],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
} else if (menu.isQuickExport) {
|
||||||
|
exportElectronFile(data);
|
||||||
} else if (menu.isOpenFreeTable) {
|
} else if (menu.isOpenFreeTable) {
|
||||||
const coninfo = await getConnectionInfo(data);
|
const coninfo = await getConnectionInfo(data);
|
||||||
openNewTab({
|
openNewTab({
|
||||||
@@ -464,6 +488,7 @@ import getConnectionLabel from '../utility/getConnectionLabel';
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
</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