From ff5d3a5f0cdd6eb9abd631fc4c31ffbdca3cd828 Mon Sep 17 00:00:00 2001 From: zadam Date: Tue, 9 May 2023 00:05:27 +0200 Subject: [PATCH] import WIP --- src/public/app/layouts/desktop_layout.js | 2 ++ src/public/app/services/branches.js | 2 +- src/public/app/services/import.js | 28 ++++++++++++++++- src/public/app/widgets/dialogs/import.js | 2 +- .../app/widgets/dialogs/upload_attachments.js | 4 +-- .../widgets/type_widgets/attachment_detail.js | 2 ++ .../widgets/type_widgets/attachment_list.js | 10 +++++-- src/routes/api/branches.js | 2 +- src/routes/api/import.js | 26 ++++------------ src/routes/api/notes.js | 2 +- src/routes/routes.js | 4 +-- src/services/import/single.js | 30 ++++++++++++++++++- 12 files changed, 80 insertions(+), 34 deletions(-) diff --git a/src/public/app/layouts/desktop_layout.js b/src/public/app/layouts/desktop_layout.js index afb3ab606..3f3287704 100644 --- a/src/public/app/layouts/desktop_layout.js +++ b/src/public/app/layouts/desktop_layout.js @@ -75,6 +75,7 @@ import CodeButtonsWidget from "../widgets/floating_buttons/code_buttons.js"; import ApiLogWidget from "../widgets/api_log.js"; import HideFloatingButtonsButton from "../widgets/floating_buttons/hide_floating_buttons_button.js"; import ScriptExecutorWidget from "../widgets/ribbon_widgets/script_executor.js"; +import UploadAttachmentsDialog from "../widgets/dialogs/upload_attachments.js"; export default class DesktopLayout { constructor(customWidgets) { @@ -200,6 +201,7 @@ export default class DesktopLayout { .child(new MoveToDialog()) .child(new ImportDialog()) .child(new ExportDialog()) + .child(new UploadAttachmentsDialog()) .child(new MarkdownImportDialog()) .child(new ProtectedSessionPasswordDialog()) .child(new NoteRevisionsDialog()) diff --git a/src/public/app/services/branches.js b/src/public/app/services/branches.js index 74465ea1b..4177f8069 100644 --- a/src/public/app/services/branches.js +++ b/src/public/app/services/branches.js @@ -182,7 +182,7 @@ function makeToast(id, message) { } ws.subscribeToMessages(async message => { - if (message.taskType !== 'delete-notes') { + if (message.taskType !== 'deleteNotes') { return; } diff --git a/src/public/app/services/import.js b/src/public/app/services/import.js index 46548460c..85f197a58 100644 --- a/src/public/app/services/import.js +++ b/src/public/app/services/import.js @@ -54,7 +54,7 @@ function makeToast(id, message) { } ws.subscribeToMessages(async message => { - if (message.taskType !== 'import') { + if (message.taskType !== 'importNotes') { return; } @@ -75,6 +75,32 @@ ws.subscribeToMessages(async message => { } }); +ws.subscribeToMessages(async message => { + if (message.taskType !== 'importAttachments') { + return; + } + + if (message.type === 'taskError') { + toastService.closePersistent(message.taskId); + toastService.showError(message.message); + } else if (message.type === 'taskProgressCount') { + toastService.showPersistent(makeToast(message.taskId, `Import in progress: ${message.progressCount}`)); + } else if (message.type === 'taskSucceeded') { + const toast = makeToast(message.taskId, "Import finished successfully."); + toast.closeAfter = 5000; + + toastService.showPersistent(toast); + + if (message.result.parentNoteId) { + await appContext.tabManager.getActiveContext().setNote(message.result.importedNoteId, { + viewScope: { + viewMode: 'attachments' + } + }); + } + } +}); + export default { uploadFiles }; diff --git a/src/public/app/widgets/dialogs/import.js b/src/public/app/widgets/dialogs/import.js index 0dff47e72..4121b78fb 100644 --- a/src/public/app/widgets/dialogs/import.js +++ b/src/public/app/widgets/dialogs/import.js @@ -21,7 +21,7 @@ const TPL = ` -

Content of the file will be imported as child note(s) into . +

Content of the selected file(s) will be imported as child note(s) into .

diff --git a/src/public/app/widgets/dialogs/upload_attachments.js b/src/public/app/widgets/dialogs/upload_attachments.js index f5d12a124..217ae53bb 100644 --- a/src/public/app/widgets/dialogs/upload_attachments.js +++ b/src/public/app/widgets/dialogs/upload_attachments.js @@ -9,7 +9,7 @@ const TPL = `