mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
export html file both from web page and electron
This commit is contained in:
parent
b9da035a97
commit
d2299ab926
50
app/file.html
Normal file
50
app/file.html
Normal file
File diff suppressed because one or more lines are too long
BIN
app/file.html.png
Normal file
BIN
app/file.html.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 148 KiB |
@ -339,16 +339,15 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
generateDbDiffReport_meta: 'post',
|
generateDbDiffReport_meta: 'post',
|
||||||
async generateDbDiffReport({ sourceConid, sourceDatabase, targetConid, targetDatabase }) {
|
async generateDbDiffReport({ filePath, sourceConid, sourceDatabase, targetConid, targetDatabase }) {
|
||||||
const unifiedDiff = await this.getUnifiedDiff({ sourceConid, sourceDatabase, targetConid, targetDatabase });
|
const unifiedDiff = await this.getUnifiedDiff({ sourceConid, sourceDatabase, targetConid, targetDatabase });
|
||||||
|
|
||||||
const diffJson = parse(unifiedDiff);
|
const diffJson = parse(unifiedDiff);
|
||||||
// $: diffHtml = html(diffJson, { outputFormat: 'side-by-side', drawFileList: false });
|
// $: diffHtml = html(diffJson, { outputFormat: 'side-by-side', drawFileList: false });
|
||||||
const diffHtml = html(diffJson, { outputFormat: 'side-by-side' });
|
const diffHtml = html(diffJson, { outputFormat: 'side-by-side' });
|
||||||
|
|
||||||
const fileName = `${uuidv1()}.html`;
|
await fs.writeFile(filePath, diff2htmlPage(diffHtml));
|
||||||
await fs.writeFile(path.join(uploadsdir(), fileName), diff2htmlPage(diffHtml));
|
|
||||||
|
|
||||||
return fileName;
|
return true;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -117,20 +117,29 @@ module.exports = {
|
|||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
|
|
||||||
exportChart_meta: 'post',
|
generateUploadsFile_meta: 'get',
|
||||||
async exportChart({ title, config, image }) {
|
async generateUploadsFile() {
|
||||||
const fileName = `${uuidv1()}.html`;
|
const fileName = `${uuidv1()}.html`;
|
||||||
|
return {
|
||||||
|
fileName,
|
||||||
|
filePath: path.join(uploadsdir(), fileName),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
exportChart_meta: 'post',
|
||||||
|
async exportChart({ filePath, title, config, image }) {
|
||||||
|
const fileName = path.parse(filePath).base;
|
||||||
const imageFile = `${fileName}.png`;
|
const imageFile = `${fileName}.png`;
|
||||||
const html = getChartExport(title, config, imageFile);
|
const html = getChartExport(title, config, imageFile);
|
||||||
await fs.writeFile(path.join(uploadsdir(), fileName), html);
|
await fs.writeFile(filePath, html);
|
||||||
if (image) {
|
if (image) {
|
||||||
const index = image.indexOf('base64,');
|
const index = image.indexOf('base64,');
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
const data = image.substr(index + 'base64,'.length);
|
const data = image.substr(index + 'base64,'.length);
|
||||||
const buf = Buffer.from(data, 'base64');
|
const buf = Buffer.from(data, 'base64');
|
||||||
await fs.writeFile(path.join(uploadsdir(), imageFile), buf);
|
await fs.writeFile(filePath + '.png', buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fileName;
|
return true;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
import contextMenu, { getContextMenu, registerMenu } from '../utility/contextMenu';
|
import contextMenu, { getContextMenu, registerMenu } from '../utility/contextMenu';
|
||||||
import createActivator, { getActiveComponent } from '../utility/createActivator';
|
import createActivator, { getActiveComponent } from '../utility/createActivator';
|
||||||
|
import { saveFileToDisk } from '../utility/exportElectronFile';
|
||||||
import resolveApi from '../utility/resolveApi';
|
import resolveApi from '../utility/resolveApi';
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
@ -60,17 +61,18 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
export async function exportChart() {
|
export async function exportChart() {
|
||||||
const resp = await axiosInstance.post('files/export-chart', {
|
saveFileToDisk(async filePath => {
|
||||||
title,
|
await axiosInstance.post('files/export-chart', {
|
||||||
config: {
|
title,
|
||||||
type,
|
filePath,
|
||||||
data,
|
config: {
|
||||||
options,
|
type,
|
||||||
},
|
data,
|
||||||
image: domChart.toDataURL(),
|
options,
|
||||||
|
},
|
||||||
|
image: domChart.toDataURL(),
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
window.open(`${resolveApi()}/uploads/get?file=${resp.data}`, '_blank');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
registerMenu({ command: 'chart.export', tag: 'export' });
|
registerMenu({ command: 'chart.export', tag: 'export' });
|
||||||
|
@ -156,6 +156,7 @@
|
|||||||
import { changeTab } from '../utility/common';
|
import { changeTab } from '../utility/common';
|
||||||
import contextMenu, { getContextMenu, registerMenu } from '../utility/contextMenu';
|
import contextMenu, { getContextMenu, registerMenu } from '../utility/contextMenu';
|
||||||
import createActivator, { getActiveComponent } from '../utility/createActivator';
|
import createActivator, { getActiveComponent } from '../utility/createActivator';
|
||||||
|
import { saveFileToDisk } from '../utility/exportElectronFile';
|
||||||
import { useArchiveFolders, useConnectionInfo, useDatabaseInfo } from '../utility/metadataLoaders';
|
import { useArchiveFolders, useConnectionInfo, useDatabaseInfo } from '../utility/metadataLoaders';
|
||||||
import resolveApi from '../utility/resolveApi';
|
import resolveApi from '../utility/resolveApi';
|
||||||
import { showSnackbarSuccess } from '../utility/snackbar';
|
import { showSnackbarSuccess } from '../utility/snackbar';
|
||||||
@ -212,14 +213,15 @@
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
export async function showReport() {
|
export async function showReport() {
|
||||||
const resp = await axiosInstance.post('database-connections/generate-db-diff-report', {
|
saveFileToDisk(async filePath => {
|
||||||
sourceConid: $values?.sourceConid,
|
await axiosInstance.post('database-connections/generate-db-diff-report', {
|
||||||
sourceDatabase: $values?.sourceDatabase,
|
filePath,
|
||||||
targetConid: $values?.targetConid,
|
sourceConid: $values?.sourceConid,
|
||||||
targetDatabase: $values?.targetDatabase,
|
sourceDatabase: $values?.sourceDatabase,
|
||||||
|
targetConid: $values?.targetConid,
|
||||||
|
targetDatabase: $values?.targetDatabase,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
window.open(`${resolveApi()}/uploads/get?file=${resp.data}`, '_blank');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function swap() {
|
export function swap() {
|
||||||
|
@ -3,6 +3,7 @@ import getElectron from './getElectron';
|
|||||||
import axiosInstance from '../utility/axiosInstance';
|
import axiosInstance from '../utility/axiosInstance';
|
||||||
import socket from '../utility/socket';
|
import socket from '../utility/socket';
|
||||||
import { showSnackbar, showSnackbarInfo, showSnackbarError, closeSnackbar } from '../utility/snackbar';
|
import { showSnackbar, showSnackbarInfo, showSnackbarError, closeSnackbar } from '../utility/snackbar';
|
||||||
|
import resolveApi from './resolveApi';
|
||||||
|
|
||||||
export async function exportElectronFile(dataName, reader, format) {
|
export async function exportElectronFile(dataName, reader, format) {
|
||||||
const electron = getElectron();
|
const electron = getElectron();
|
||||||
@ -54,3 +55,27 @@ export async function exportElectronFile(dataName, reader, format) {
|
|||||||
|
|
||||||
socket.on(`runner-done-${runid}`, handleRunnerDone);
|
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');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user