mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 22:03:58 +00:00
quick export with snackbar info, allows canceling process
This commit is contained in:
@@ -69,7 +69,9 @@
|
|||||||
{/if}
|
{/if}
|
||||||
<div class="snackbar-container">
|
<div class="snackbar-container">
|
||||||
{#each $openedSnackbars as snackbar}
|
{#each $openedSnackbars as snackbar}
|
||||||
<Snackbar {...snackbar} />
|
{#key snackbar.id}
|
||||||
|
<Snackbar {...snackbar} />
|
||||||
|
{/key}
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -77,6 +77,7 @@
|
|||||||
'img error': 'mdi mdi-close-circle color-icon-red',
|
'img error': 'mdi mdi-close-circle color-icon-red',
|
||||||
'img error-inv': 'mdi mdi-close-circle color-icon-inv-red',
|
'img error-inv': 'mdi mdi-close-circle color-icon-inv-red',
|
||||||
'img warn': 'mdi mdi-alert color-icon-gold',
|
'img warn': 'mdi mdi-alert color-icon-gold',
|
||||||
|
'img info': 'mdi mdi-information color-icon-blue',
|
||||||
// 'img statusbar-ok': 'mdi mdi-check-circle color-on-statusbar-green',
|
// 'img statusbar-ok': 'mdi mdi-check-circle color-on-statusbar-green',
|
||||||
|
|
||||||
'img archive': 'mdi mdi-table color-icon-gold',
|
'img archive': 'mdi mdi-table color-icon-gold',
|
||||||
|
|||||||
@@ -47,7 +47,7 @@
|
|||||||
import createActivator, { getActiveComponent } from '../utility/createActivator';
|
import createActivator, { getActiveComponent } from '../utility/createActivator';
|
||||||
import registerCommand from '../commands/registerCommand';
|
import registerCommand from '../commands/registerCommand';
|
||||||
import { registerMenu } from '../utility/contextMenu';
|
import { registerMenu } from '../utility/contextMenu';
|
||||||
import { showSnackbarSuccess } from '../widgets/Snackbar.svelte';
|
import { showSnackbarSuccess } from '../utility/snackbar';
|
||||||
|
|
||||||
export let tabid;
|
export let tabid;
|
||||||
export let conid;
|
export let conid;
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import ScriptWriter from '../impexp/ScriptWriter';
|
import ScriptWriter from '../impexp/ScriptWriter';
|
||||||
import getElectron from './getElectron';
|
import getElectron from './getElectron';
|
||||||
import axiosInstance from '../utility/axiosInstance';
|
import axiosInstance from '../utility/axiosInstance';
|
||||||
|
import socket from '../utility/socket';
|
||||||
|
import { showSnackbar, showSnackbarInfo, showSnackbarError, closeSnackbar } from '../utility/snackbar';
|
||||||
|
|
||||||
export async function exportElectronFile(dataName, reader, format) {
|
export async function exportElectronFile(dataName, reader, format) {
|
||||||
const electron = getElectron();
|
const electron = getElectron();
|
||||||
@@ -18,8 +20,6 @@ export async function exportElectronFile(dataName, reader, format) {
|
|||||||
const sourceVar = script.allocVariable();
|
const sourceVar = script.allocVariable();
|
||||||
script.assign(sourceVar, reader.functionName, reader.props);
|
script.assign(sourceVar, reader.functionName, reader.props);
|
||||||
|
|
||||||
console.log('format.createWriter(filePath, dataName)', format.createWriter(filePath, dataName));
|
|
||||||
|
|
||||||
const targetVar = script.allocVariable();
|
const targetVar = script.allocVariable();
|
||||||
const writer = format.createWriter(filePath, dataName);
|
const writer = format.createWriter(filePath, dataName);
|
||||||
script.assign(targetVar, writer.functionName, writer.props);
|
script.assign(targetVar, writer.functionName, writer.props);
|
||||||
@@ -27,8 +27,30 @@ export async function exportElectronFile(dataName, reader, format) {
|
|||||||
script.copyStream(sourceVar, targetVar);
|
script.copyStream(sourceVar, targetVar);
|
||||||
script.put();
|
script.put();
|
||||||
|
|
||||||
console.log('script.getScript()', script.getScript());
|
|
||||||
|
|
||||||
const resp = await axiosInstance.post('runners/start', { script: script.getScript() });
|
const resp = await axiosInstance.post('runners/start', { script: script.getScript() });
|
||||||
const runid = resp.data.runid;
|
const runid = resp.data.runid;
|
||||||
|
let isCanceled = false;
|
||||||
|
|
||||||
|
const snackId = showSnackbar({
|
||||||
|
message: `Exporting ${dataName}`,
|
||||||
|
icon: 'icon loading',
|
||||||
|
buttons: [
|
||||||
|
{
|
||||||
|
label: 'Cancel',
|
||||||
|
onClick: () => {
|
||||||
|
isCanceled = true;
|
||||||
|
axiosInstance.post('runners/cancel', { runid });
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
function handleRunnerDone() {
|
||||||
|
closeSnackbar(snackId);
|
||||||
|
socket.off(`runner-done-${runid}`, handleRunnerDone);
|
||||||
|
if (isCanceled) showSnackbarError(`Export ${dataName} canceled`);
|
||||||
|
else showSnackbarInfo(`Export ${dataName} finished`);
|
||||||
|
}
|
||||||
|
|
||||||
|
socket.on(`runner-done-${runid}`, handleRunnerDone);
|
||||||
}
|
}
|
||||||
|
|||||||
75
packages/web/src/utility/snackbar.ts
Normal file
75
packages/web/src/utility/snackbar.ts
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
import { openedSnackbars } from '../stores';
|
||||||
|
|
||||||
|
export interface SnackbarButton {
|
||||||
|
label: string;
|
||||||
|
onClick: Function;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SnackbarInfo {
|
||||||
|
message: string;
|
||||||
|
icon?: string;
|
||||||
|
autoClose?: boolean;
|
||||||
|
allowClose?: boolean;
|
||||||
|
buttons?: SnackbarButton[];
|
||||||
|
}
|
||||||
|
|
||||||
|
let lastSnackbarId = 0;
|
||||||
|
|
||||||
|
export function showSnackbar(snackbar: SnackbarInfo): string {
|
||||||
|
lastSnackbarId += 1;
|
||||||
|
const id = lastSnackbarId.toString();
|
||||||
|
openedSnackbars.update(x => [
|
||||||
|
...x,
|
||||||
|
{
|
||||||
|
...snackbar,
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function showSnackbarSuccess(message: string) {
|
||||||
|
showSnackbar({
|
||||||
|
message,
|
||||||
|
icon: 'img ok',
|
||||||
|
allowClose: true,
|
||||||
|
autoClose: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function showSnackbarInfo(message: string) {
|
||||||
|
showSnackbar({
|
||||||
|
message,
|
||||||
|
icon: 'img info',
|
||||||
|
allowClose: true,
|
||||||
|
autoClose: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function showSnackbarError(message: string) {
|
||||||
|
showSnackbar({
|
||||||
|
message,
|
||||||
|
icon: 'img error',
|
||||||
|
allowClose: true,
|
||||||
|
autoClose: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function closeSnackbar(snackId: string) {
|
||||||
|
openedSnackbars.update(x => x.filter(x => x.id != snackId));
|
||||||
|
}
|
||||||
|
// showSnackbar({
|
||||||
|
// icon: 'img ok',
|
||||||
|
// message: 'Test snackbar',
|
||||||
|
// allowClose: true,
|
||||||
|
// });
|
||||||
|
showSnackbar({
|
||||||
|
icon: 'img ok',
|
||||||
|
message: 'Auto close',
|
||||||
|
autoClose: true,
|
||||||
|
});
|
||||||
|
// showSnackbar({
|
||||||
|
// icon: 'img warn',
|
||||||
|
// message: 'Buttons',
|
||||||
|
// buttons: [{ label: 'OK', onClick: () => console.log('OK') }],
|
||||||
|
// });
|
||||||
@@ -1,63 +1,8 @@
|
|||||||
<script lang="ts" context="module">
|
|
||||||
import { openedSnackbars } from '../stores';
|
|
||||||
|
|
||||||
export interface SnackbarButton {
|
|
||||||
label: string;
|
|
||||||
onClick: Function;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SnackbarInfo {
|
|
||||||
message: string;
|
|
||||||
icon?: string;
|
|
||||||
autoClose?: boolean;
|
|
||||||
allowClose?: boolean;
|
|
||||||
buttons?: SnackbarButton[];
|
|
||||||
}
|
|
||||||
|
|
||||||
let lastSnackbarId = 0;
|
|
||||||
|
|
||||||
export function showSnackbar(snackbar: SnackbarInfo) {
|
|
||||||
lastSnackbarId += 1;
|
|
||||||
openedSnackbars.update(x => [
|
|
||||||
...x,
|
|
||||||
{
|
|
||||||
...snackbar,
|
|
||||||
id: lastSnackbarId,
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function showSnackbarSuccess(message: string) {
|
|
||||||
showSnackbar({
|
|
||||||
message,
|
|
||||||
icon: 'img ok',
|
|
||||||
allowClose: true,
|
|
||||||
autoClose: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// showSnackbar({
|
|
||||||
// icon: 'img ok',
|
|
||||||
// message: 'Test snackbar',
|
|
||||||
// allowClose: true,
|
|
||||||
// });
|
|
||||||
// showSnackbar({
|
|
||||||
// icon: 'img ok',
|
|
||||||
// message: 'Auto close',
|
|
||||||
// autoClose: true,
|
|
||||||
// });
|
|
||||||
// showSnackbar({
|
|
||||||
// icon: 'img warn',
|
|
||||||
// message: 'Buttons',
|
|
||||||
// buttons: [{ label: 'OK', onClick: () => console.log('OK') }],
|
|
||||||
// });
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import FontIcon from '../icons/FontIcon.svelte';
|
import FontIcon from '../icons/FontIcon.svelte';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import FormStyledButton from '../elements/FormStyledButton.svelte';
|
import FormStyledButton from '../elements/FormStyledButton.svelte';
|
||||||
|
import { openedSnackbars } from '../stores';
|
||||||
|
|
||||||
export let message;
|
export let message;
|
||||||
export let id;
|
export let id;
|
||||||
|
|||||||
Reference in New Issue
Block a user