From 7fe5c354f1cb1460c0db47d524d21613cefde6ac Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Thu, 11 Nov 2021 16:04:51 +0100 Subject: [PATCH] copy saved file --- packages/api/src/controllers/files.js | 8 ++++++++ packages/web/src/appobj/SavedFileAppObject.svelte | 12 ++++++++++++ packages/web/src/charts/ChartEditor.svelte | 8 +++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/api/src/controllers/files.js b/packages/api/src/controllers/files.js index 2e31e499..1b14e58a 100644 --- a/packages/api/src/controllers/files.js +++ b/packages/api/src/controllers/files.js @@ -58,6 +58,14 @@ module.exports = { socket.emitChanged(`all-files-changed`); }, + copy_meta: 'post', + async copy({ folder, file, newFile }) { + if (!hasPermission(`files/${folder}/write`)) return; + await fs.copyFile(path.join(filesdir(), folder, file), path.join(filesdir(), folder, newFile)); + socket.emitChanged(`files-changed-${folder}`); + socket.emitChanged(`all-files-changed`); + }, + load_meta: 'post', async load({ folder, file, format }) { if (folder.startsWith('archive:')) { diff --git a/packages/web/src/appobj/SavedFileAppObject.svelte b/packages/web/src/appobj/SavedFileAppObject.svelte index fc7a365f..d434db8a 100644 --- a/packages/web/src/appobj/SavedFileAppObject.svelte +++ b/packages/web/src/appobj/SavedFileAppObject.svelte @@ -104,6 +104,7 @@ return [ handler?.tabComponent && { text: 'Open', onClick: openTab }, hasPermission(`files/${data.folder}/write`) && { text: 'Rename', onClick: handleRename }, + hasPermission(`files/${data.folder}/write`) && { text: 'Create copy', onClick: handleCopy }, hasPermission(`files/${data.folder}/write`) && { text: 'Delete', onClick: handleDelete }, folder == 'markdown' && { text: 'Show page', onClick: showMarkdownPage }, ]; @@ -129,6 +130,17 @@ }); }; + const handleCopy = () => { + showModal(InputTextModal, { + value: data.file, + label: 'New file name', + header: 'Rename file', + onConfirm: newFile => { + axiosInstance.post('files/copy', { ...data, newFile }); + }, + }); + }; + async function openTab() { const resp = await axiosInstance.post('files/load', { folder, file: data.file, format: handler.format }); diff --git a/packages/web/src/charts/ChartEditor.svelte b/packages/web/src/charts/ChartEditor.svelte index ed0c92c3..1b130f19 100644 --- a/packages/web/src/charts/ChartEditor.svelte +++ b/packages/web/src/charts/ChartEditor.svelte @@ -19,6 +19,7 @@ import { loadChartData, loadChartStructure } from './chartDataLoader'; import DataChart from './DataChart.svelte'; import _ from 'lodash'; + import ErrorInfo from '../elements/ErrorInfo.svelte'; export let data; export let configStore; @@ -47,6 +48,7 @@ const columns = await loadChartStructure(driver, conid, database, sql); availableColumnNames = columns; } catch (err) { + console.error(err); error = err.message; } }; @@ -151,7 +153,11 @@ - + {#if error} + + {:else} + + {/if}