mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-27 20:46:00 +00:00
export html file both from web page and electron
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
|
||||
import contextMenu, { getContextMenu, registerMenu } from '../utility/contextMenu';
|
||||
import createActivator, { getActiveComponent } from '../utility/createActivator';
|
||||
import { saveFileToDisk } from '../utility/exportElectronFile';
|
||||
import resolveApi from '../utility/resolveApi';
|
||||
|
||||
export let data;
|
||||
@@ -60,17 +61,18 @@
|
||||
});
|
||||
|
||||
export async function exportChart() {
|
||||
const resp = await axiosInstance.post('files/export-chart', {
|
||||
title,
|
||||
config: {
|
||||
type,
|
||||
data,
|
||||
options,
|
||||
},
|
||||
image: domChart.toDataURL(),
|
||||
saveFileToDisk(async filePath => {
|
||||
await axiosInstance.post('files/export-chart', {
|
||||
title,
|
||||
filePath,
|
||||
config: {
|
||||
type,
|
||||
data,
|
||||
options,
|
||||
},
|
||||
image: domChart.toDataURL(),
|
||||
});
|
||||
});
|
||||
|
||||
window.open(`${resolveApi()}/uploads/get?file=${resp.data}`, '_blank');
|
||||
}
|
||||
|
||||
registerMenu({ command: 'chart.export', tag: 'export' });
|
||||
|
||||
@@ -156,6 +156,7 @@
|
||||
import { changeTab } from '../utility/common';
|
||||
import contextMenu, { getContextMenu, registerMenu } from '../utility/contextMenu';
|
||||
import createActivator, { getActiveComponent } from '../utility/createActivator';
|
||||
import { saveFileToDisk } from '../utility/exportElectronFile';
|
||||
import { useArchiveFolders, useConnectionInfo, useDatabaseInfo } from '../utility/metadataLoaders';
|
||||
import resolveApi from '../utility/resolveApi';
|
||||
import { showSnackbarSuccess } from '../utility/snackbar';
|
||||
@@ -212,14 +213,15 @@
|
||||
}));
|
||||
|
||||
export async function showReport() {
|
||||
const resp = await axiosInstance.post('database-connections/generate-db-diff-report', {
|
||||
sourceConid: $values?.sourceConid,
|
||||
sourceDatabase: $values?.sourceDatabase,
|
||||
targetConid: $values?.targetConid,
|
||||
targetDatabase: $values?.targetDatabase,
|
||||
saveFileToDisk(async filePath => {
|
||||
await axiosInstance.post('database-connections/generate-db-diff-report', {
|
||||
filePath,
|
||||
sourceConid: $values?.sourceConid,
|
||||
sourceDatabase: $values?.sourceDatabase,
|
||||
targetConid: $values?.targetConid,
|
||||
targetDatabase: $values?.targetDatabase,
|
||||
});
|
||||
});
|
||||
|
||||
window.open(`${resolveApi()}/uploads/get?file=${resp.data}`, '_blank');
|
||||
}
|
||||
|
||||
export function swap() {
|
||||
|
||||
@@ -3,6 +3,7 @@ import getElectron from './getElectron';
|
||||
import axiosInstance from '../utility/axiosInstance';
|
||||
import socket from '../utility/socket';
|
||||
import { showSnackbar, showSnackbarInfo, showSnackbarError, closeSnackbar } from '../utility/snackbar';
|
||||
import resolveApi from './resolveApi';
|
||||
|
||||
export async function exportElectronFile(dataName, reader, format) {
|
||||
const electron = getElectron();
|
||||
@@ -54,3 +55,27 @@ export async function exportElectronFile(dataName, reader, format) {
|
||||
|
||||
socket.on(`runner-done-${runid}`, handleRunnerDone);
|
||||
}
|
||||
|
||||
export async function saveFileToDisk(
|
||||
filePathFunc,
|
||||
options: any = { formatLabel: 'HTML page', formatExtension: 'html' }
|
||||
) {
|
||||
const { formatLabel, formatExtension } = options;
|
||||
const electron = getElectron();
|
||||
|
||||
if (electron) {
|
||||
const filters = [{ name: formatLabel, extensions: [formatExtension] }];
|
||||
const filePath = electron.remote.dialog.showSaveDialogSync(electron.remote.getCurrentWindow(), {
|
||||
filters,
|
||||
defaultPath: `file.${formatExtension}`,
|
||||
properties: ['showOverwriteConfirmation'],
|
||||
});
|
||||
if (!filePath) return;
|
||||
await filePathFunc(filePath);
|
||||
electron.shell.openExternal('file:///' + filePath);
|
||||
} else {
|
||||
const resp = await axiosInstance.get('files/generate-uploads-file');
|
||||
await filePathFunc(resp.data.filePath);
|
||||
window.open(`${resolveApi()}/uploads/get?file=${resp.data.fileName}`, '_blank');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user