From 241c7746c2cc6555828d99c2c0af0eb7b438705b Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Wed, 10 Nov 2021 18:04:00 +0100 Subject: [PATCH] rename archive file --- packages/api/src/controllers/archive.js | 6 ++++++ packages/web/src/appobj/ArchiveFileAppObject.svelte | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/packages/api/src/controllers/archive.js b/packages/api/src/controllers/archive.js index 9bf911f6..e8fead0a 100644 --- a/packages/api/src/controllers/archive.js +++ b/packages/api/src/controllers/archive.js @@ -84,6 +84,12 @@ module.exports = { socket.emitChanged(`archive-files-changed-${folder}`); }, + renameFile_meta: 'post', + async renameFile({ folder, file, newFile }) { + await fs.rename(path.join(resolveArchiveFolder(folder), `${file}.jsonl`), path.join(resolveArchiveFolder(folder), `${newFile}.jsonl`)); + socket.emitChanged(`archive-files-changed-${folder}`); + }, + deleteFolder_meta: 'post', async deleteFolder({ folder }) { if (!folder) throw new Error('Missing folder parameter'); diff --git a/packages/web/src/appobj/ArchiveFileAppObject.svelte b/packages/web/src/appobj/ArchiveFileAppObject.svelte index 208f126d..a0a0a69d 100644 --- a/packages/web/src/appobj/ArchiveFileAppObject.svelte +++ b/packages/web/src/appobj/ArchiveFileAppObject.svelte @@ -67,9 +67,21 @@ import openNewTab from '../utility/openNewTab'; import AppObjectCore from './AppObjectCore.svelte'; import getConnectionLabel from '../utility/getConnectionLabel'; + import InputTextModal from '../modals/InputTextModal.svelte'; export let data; + const handleRename = () => { + showModal(InputTextModal, { + value: data.file, + label: 'New file name', + header: 'Rename file', + onConfirm: newFile => { + axiosInstance.post('archive/rename-file', { file: data.fileName, folder: data.folderName, newFile }); + }, + }); + }; + const handleDelete = () => { axiosInstance.post('archive/delete-file', { file: data.fileName, folder: data.folderName }); }; @@ -115,6 +127,7 @@ data.fileType == 'jsonl' && { text: 'Open (readonly)', onClick: handleOpenRead }, data.fileType == 'jsonl' && { text: 'Open in free table editor', onClick: handleOpenWrite }, { text: 'Delete', onClick: handleDelete }, + { text: 'Rename', onClick: handleRename }, data.fileType == 'jsonl' && createQuickExportMenu($extensions, fmt => async () => { exportElectronFile(