mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 22:26:01 +00:00
report progress for quick exports
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
import { ScriptWriter, ScriptWriterJson } from 'dbgate-tools';
|
||||
import getElectron from './getElectron';
|
||||
import { showSnackbar, showSnackbarInfo, showSnackbarError, closeSnackbar } from '../utility/snackbar';
|
||||
import {
|
||||
showSnackbar,
|
||||
showSnackbarInfo,
|
||||
showSnackbarError,
|
||||
closeSnackbar,
|
||||
updateSnackbarProgressMessage,
|
||||
} from '../utility/snackbar';
|
||||
import resolveApi, { resolveApiHeaders } from './resolveApi';
|
||||
import { apiCall, apiOff, apiOn } from './api';
|
||||
import { normalizeExportColumnMap } from '../impexp/createImpExpScript';
|
||||
@@ -70,9 +76,17 @@ async function runImportExportScript({ script, runningMessage, canceledMessage,
|
||||
],
|
||||
});
|
||||
|
||||
function handleRunnerProgress(data) {
|
||||
const rows = data.writtenRowsCount || data.readRowCount;
|
||||
if (rows) {
|
||||
updateSnackbarProgressMessage(snackId, `${rows} rows processed`);
|
||||
}
|
||||
}
|
||||
|
||||
function handleRunnerDone() {
|
||||
closeSnackbar(snackId);
|
||||
apiOff(`runner-done-${runid}`, handleRunnerDone);
|
||||
apiOff(`runner-progress-${runid}`, handleRunnerProgress);
|
||||
if (isCanceled) {
|
||||
showSnackbarError(canceledMessage);
|
||||
} else {
|
||||
@@ -82,6 +96,7 @@ async function runImportExportScript({ script, runningMessage, canceledMessage,
|
||||
}
|
||||
|
||||
apiOn(`runner-done-${runid}`, handleRunnerDone);
|
||||
apiOn(`runner-progress-${runid}`, handleRunnerProgress);
|
||||
}
|
||||
|
||||
export async function saveExportedFile(filters, defaultPath, extension, dataName, getScript: (filaPath: string) => {}) {
|
||||
@@ -141,7 +156,7 @@ function generateQuickExportScript(
|
||||
script.assignValue(colmapVar, colmap);
|
||||
}
|
||||
|
||||
script.copyStream(sourceVar, targetVar, colmapVar);
|
||||
script.copyStream(sourceVar, targetVar, colmapVar, 'data');
|
||||
script.endLine();
|
||||
|
||||
return script.getScript();
|
||||
|
||||
@@ -8,6 +8,7 @@ export interface SnackbarButton {
|
||||
|
||||
export interface SnackbarInfo {
|
||||
message: string;
|
||||
progressMessage?: string;
|
||||
icon?: string;
|
||||
autoClose?: boolean;
|
||||
allowClose?: boolean;
|
||||
@@ -59,6 +60,11 @@ export function showSnackbarError(message: string) {
|
||||
export function closeSnackbar(snackId: string) {
|
||||
openedSnackbars.update(x => x.filter(x => x.id != snackId));
|
||||
}
|
||||
|
||||
export function updateSnackbarProgressMessage(snackId: string, progressMessage: string) {
|
||||
openedSnackbars.update(x => x.map(x => (x.id === snackId ? { ...x, progressMessage } : x)));
|
||||
}
|
||||
|
||||
// showSnackbar({
|
||||
// icon: 'img ok',
|
||||
// message: 'Test snackbar',
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
export let autoClose = false;
|
||||
export let allowClose = false;
|
||||
export let buttons = [];
|
||||
export let progressMessage = null;
|
||||
|
||||
function handleClose() {
|
||||
openedSnackbars.update(x => x.filter(x => x.id != id));
|
||||
@@ -25,6 +26,11 @@
|
||||
<FontIcon {icon} />
|
||||
{message}
|
||||
</div>
|
||||
{#if progressMessage}
|
||||
<div class="progress-message">
|
||||
{progressMessage}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if allowClose}
|
||||
<div class="close" on:click={handleClose}>
|
||||
@@ -83,4 +89,10 @@
|
||||
.button {
|
||||
margin: 5px;
|
||||
}
|
||||
|
||||
.progress-message {
|
||||
color: var(--theme-font-3);
|
||||
margin: 10px;
|
||||
margin-left: 30px;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user