fixed upload file

This commit is contained in:
Jan Prochazka 2024-09-16 17:16:54 +02:00
parent a9a5a3491e
commit 88d7e07bea
3 changed files with 56 additions and 36 deletions

View File

@ -68,8 +68,8 @@
import SourceTargetConfig from './SourceTargetConfig.svelte'; import SourceTargetConfig from './SourceTargetConfig.svelte';
export let uploadedFile = undefined; // export let uploadedFile = undefined;
export let openedFile = undefined; // export let openedFile = undefined;
export let previewReaderStore; export let previewReaderStore;
const { values, setFieldValue } = getFormContext(); const { values, setFieldValue } = getFormContext();
@ -98,7 +98,7 @@
} }
}; };
const handleUpload = file => { export function addUploadedFile(file) {
addFilesToSourceList( addFilesToSourceList(
$extensions, $extensions,
[ [
@ -116,26 +116,26 @@
}; };
onMount(() => { onMount(() => {
setUploadListener(handleUpload); setUploadListener(addUploadedFile);
if (uploadedFile) { // if (uploadedFile) {
handleUpload(uploadedFile); // handleUpload(uploadedFile);
} // }
if (openedFile) { // if (openedFile) {
handleUpload(openedFile); // handleUpload(openedFile);
// addFilesToSourceList( // // addFilesToSourceList(
// $extensions, // // $extensions,
// [ // // [
// { // // {
// fileName: openedFile.filePath, // // fileName: openedFile.filePath,
// shortName: openedFile.shortName, // // shortName: openedFile.shortName,
// }, // // },
// ], // // ],
// $values, // // $values,
// values, // // values,
// !sourceList || sourceList.length == 0 ? openedFile.storageType : null, // // !sourceList || sourceList.length == 0 ? openedFile.storageType : null,
// previewSource.set // // previewSource.set
// ); // // );
} // }
return () => { return () => {
setUploadListener(null); setUploadListener(null);

View File

@ -42,22 +42,42 @@
const refreshArchiveFolderRef = createRef(null); const refreshArchiveFolderRef = createRef(null);
const formValues = writable({ const formValues = writable({});
let domConfigurator;
// const formValues = writable({
// sourceStorageType: 'database',
// targetStorageType: getDefaultFileFormat($extensions).storageType,
// targetArchiveFolder: $currentArchive,
// sourceArchiveFolder: $currentArchive,
// ...detectCurrentTarget(),
// ...initialValues,
// });
const { editorState, editorValue, setEditorData } = useEditorData({
tabid,
onInitialData: value => {
$formValues = {
sourceStorageType: 'database', sourceStorageType: 'database',
targetStorageType: getDefaultFileFormat($extensions).storageType, targetStorageType: getDefaultFileFormat($extensions).storageType,
targetArchiveFolder: $currentArchive, targetArchiveFolder: $currentArchive,
sourceArchiveFolder: $currentArchive, sourceArchiveFolder: $currentArchive,
...detectCurrentTarget(), ...detectCurrentTarget(),
...initialValues, ...value,
}); };
const { editorState, editorValue, setEditorData } = useEditorData({ if (uploadedFile) {
tabid, domConfigurator.addUploadedFile(uploadedFile);
onInitialData: value => { }
$formValues = value; if (openedFile) {
domConfigurator.addUploadedFile(openedFile);
}
}, },
}); });
// $: console.log('formValues', $formValues);
$: setEditorData($formValues); $: setEditorData($formValues);
function detectCurrentTarget() { function detectCurrentTarget() {
@ -111,7 +131,7 @@
}; };
const handleGenerateScript = async e => { const handleGenerateScript = async e => {
const values = $formValues; const values = $formValues as any;
const code = await createImpExpScript($extensions, values, undefined, true); const code = await createImpExpScript($extensions, values, undefined, true);
openNewTab( openNewTab(
{ {
@ -125,7 +145,7 @@
const handleExecute = async e => { const handleExecute = async e => {
if (busy) return; if (busy) return;
const values = $formValues; const values = $formValues as any;
busy = true; busy = true;
const script = await createImpExpScript($extensions, values); const script = await createImpExpScript($extensions, values);
executeNumber += 1; executeNumber += 1;
@ -152,7 +172,7 @@
<FormProviderCore values={formValues}> <FormProviderCore values={formValues}>
<HorizontalSplitter initialValue="70%"> <HorizontalSplitter initialValue="70%">
<div class="content" slot="1"> <div class="content" slot="1">
<ImportExportConfigurator {uploadedFile} {openedFile} {previewReaderStore} /> <ImportExportConfigurator bind:this={domConfigurator} {previewReaderStore} />
{#if busy} {#if busy}
<LoadingInfo wrapper message="Processing import/export ..." /> <LoadingInfo wrapper message="Processing import/export ..." />

View File

@ -6,7 +6,7 @@ export function openImportExportTab(editorProps, additionalProps = {}) {
tabComponent: 'ImportExportTab', tabComponent: 'ImportExportTab',
title: 'Import/Export', title: 'Import/Export',
icon: 'img export', icon: 'img export',
...additionalProps, props: additionalProps,
}, },
{ {
editor: editorProps, editor: editorProps,