From bb017f5967cda1ac6092d5b7a3b57563bc5ae767 Mon Sep 17 00:00:00 2001 From: sofyenne Date: Fri, 4 Oct 2024 18:03:24 +0100 Subject: [PATCH] process auto save from editor extensions --- .../components/NotesEditorDashboard.vue | 25 +++++++++++++------ .../components/NoteFullRichEditor.vue | 19 +++++--------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/notes-webapp/src/main/webapp/vue-app/notes-editor/components/NotesEditorDashboard.vue b/notes-webapp/src/main/webapp/vue-app/notes-editor/components/NotesEditorDashboard.vue index 6b8046de6..06f4e6176 100644 --- a/notes-webapp/src/main/webapp/vue-app/notes-editor/components/NotesEditorDashboard.vue +++ b/notes-webapp/src/main/webapp/vue-app/notes-editor/components/NotesEditorDashboard.vue @@ -129,6 +129,7 @@ export default { saveButtonIcon: 'fas fa-save', translationSwitch: false, newTranslation: false, + autosaveProcessedFromEditorExtension: false }; }, computed: { @@ -195,6 +196,7 @@ export default { document.addEventListener('automatic-translation-extensions-updated', () => { this.refreshTranslationExtensions(); }); + document.addEventListener('note-editor-extensions-data-updated', (evt) => this.processAutoSaveFromEditorExtension(evt)); this.getAvailableLanguages(); window.addEventListener('beforeunload', () => { if (!this.postingNote && this.note.draftPage && this.note.id) { @@ -248,6 +250,13 @@ export default { }); }, methods: { + processAutoSaveFromEditorExtension(event) { + if (event.detail.processAutoSave) { + this.autosaveProcessedFromEditorExtension = true; + this.draftSavingStatus = this.$t('notes.draft.savingDraftStatus'); + this.persistDraftNote(this.fillDraftNote(), true); + } + }, editorClosed() { window.close(); }, @@ -361,13 +370,7 @@ export default { }); }).finally(() => this.enableClickOnce()); }, - autoSave(event) { - if (event?.detail?.processAutoSave) { - //TODO - } - if (event?.detail?.showAutoSaveMessage) { - this.draftSavingStatus = this.$t('notes.draft.savingDraftStatus'); - } + autoSave() { if (this.translationSwitch) { return; } @@ -586,6 +589,14 @@ export default { this.savingDraft = false; setTimeout(() => { this.draftSavingStatus = this.$t('notes.draft.savedDraftStatus'); + if (this.autosaveProcessedFromEditorExtension) { + document.dispatchEvent(new CustomEvent('note-draft-auto-save-done', { + detail: { + draftId: this.note.id + } + })); + } + this.autosaveProcessedFromEditorExtension = false; }, this.autoSaveDelay/2); }).catch(e => { console.error('Error when creating draft note: ', e); diff --git a/notes-webapp/src/main/webapp/vue-app/notes-rich-editor/components/NoteFullRichEditor.vue b/notes-webapp/src/main/webapp/vue-app/notes-rich-editor/components/NoteFullRichEditor.vue index 08b90f769..937de638f 100644 --- a/notes-webapp/src/main/webapp/vue-app/notes-rich-editor/components/NoteFullRichEditor.vue +++ b/notes-webapp/src/main/webapp/vue-app/notes-rich-editor/components/NoteFullRichEditor.vue @@ -219,6 +219,10 @@ export default { }, watch: { 'noteObject.title': function(newVal, oldVal) { + if (newVal && newVal.length > this.noteTitleMaxLength) { + this.displayNoteTitleMaxLengthCheckAlert(); + this.noteObject.title = oldVal; + } this.displayNoteTitleMaxLengthCheckAlert(newVal, oldVal); this.updateData(); }, @@ -247,12 +251,13 @@ export default { }, computed: { extensionParams() { + console.log(this.note); return { spaceId: this.getURLQueryParam('spaceId'), entityId: this.note.draftPage && this.note?.id || this.note.latestVersionId, entityType: this.note.draftPage && 'WIKI_DRAFT_PAGES' || 'WIKI_PAGE_VERSIONS', lang: this.note.lang, - isEmptyNoteTranslation: this.note?.lang && this.note?.title && this.note?.content + isEmptyNoteTranslation: this.note.lang != null && !this.note?.title && !this.note?.content }; }, hasFeaturedImage() { @@ -285,14 +290,8 @@ export default { document.addEventListener('note-custom-plugins', this.openCustomPluginsDrawer); document.addEventListener('notes-editor-extensions-updated', this.refreshEditorExtensions); - document.addEventListener('editor-extensions-data-start-updating', (event) => this.handleEditorExtensionDataUpdated(event)); - document.addEventListener('editor-extensions-data-updated', (event) => this.handleEditorExtensionDataUpdated(event)); - }, methods: { - handleEditorExtensionDataUpdated(event) { - this.autoSave(event.detail); - }, metadataUpdated(properties) { this.updatingProperties = true; this.noteObject.properties = properties; @@ -575,12 +574,6 @@ export default { isImageDrawerClosed() { return this.$refs.featuredImageDrawer.isClosed(); }, - openPublicationDrawer() { - this.$refs.editorPublicationDrawer.open(this.noteObject); - }, - publicationDrawerClosed() { - this.enablePostKeys ++; - }, openMetadataDrawer() { this.$refs.editorMetadataDrawer.open(this.noteObject); },