Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
sofyenne committed Oct 9, 2024
1 parent f0a745c commit 1a41b72
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ public class PageEntity implements Serializable {
private String lang;

private PagePropertiesEntity properties;

private boolean extensionDataUpdated;
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public class Page {

private NotePageProperties properties;


public Page(String name) {
this.name = name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -824,8 +824,15 @@ public Response updateNoteById(@Parameter(description = "Note id", required = tr
WikiPageParams noteParams = new WikiPageParams(note_.getWikiType(), note_.getWikiOwner(), newNoteName);
noteService.removeDraftOfNote(noteParams, note.getLang());
}
} else if (note_.isToBePublished()){
note_ = noteService.updateNote(note_, PageUpdateType.PUBLISH, identity);
} else if (note_.isToBePublished()) {
note_ = noteService.updateNote(note_, PageUpdateType.PUBLISH, identity);
} else if (note.isExtensionDataUpdated()) {
note_ = noteService.updateNote(note_, PageUpdateType.EDIT_PAGE_CONTENT_AND_TITLE, identity);
noteService.createVersionOfNote(note_, identity.getUserId());
if (!Utils.ANONYM_IDENTITY.equals(identity.getUserId())) {
WikiPageParams noteParams = new WikiPageParams(note_.getWikiType(), note_.getWikiOwner(), newNoteName);
noteService.removeDraftOfNote(noteParams, note.getLang());
}
} else {
// in this case, the note didnt change on title nor content. As we need the page
// url in front side, we compute it here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ export default {
saveButtonIcon: 'fas fa-save',
translationSwitch: false,
newTranslation: false,
autosaveProcessedFromEditorExtension: false
autosaveProcessedFromEditorExtension: false,
extensionDataUpdated: false
};
},
computed: {
Expand Down Expand Up @@ -252,9 +253,61 @@ export default {
methods: {
processAutoSaveFromEditorExtension(event) {
if (event.detail.processAutoSave) {
this.extensionDataUpdated = true;
this.autosaveProcessedFromEditorExtension = true;
this.draftSavingStatus = this.$t('notes.draft.savingDraftStatus');
this.persistDraftNote(this.fillDraftNote(), true);
clearTimeout(this.saveDraft);
const draftNote = this.fillDraftNote();
if (!draftNote.title) {
draftNote.title = 'Untitled';
}
draftNote.lang = this.selectedLanguage;
if (this.newDraft){
draftNote.id = null;
}
if (draftNote.properties) {
draftNote.properties.draft = true;
if (this.newTranslation && !this.featuredImageUpdated) {
draftNote.properties.featuredImage = null;
}
}
this.$notesService.saveDraftNote(draftNote, this.parentPageId).then(savedDraftNote => {
this.actualNote = {
id: savedDraftNote.id,
name: savedDraftNote.name,
title: savedDraftNote.title,
content: savedDraftNote.content,
author: savedDraftNote.author,
owner: savedDraftNote.owner,
properties: savedDraftNote.properties
};
this.newDraft=false;
savedDraftNote.parentPageId = this.parentPageId;
this.note = savedDraftNote;
localStorage.setItem(`draftNoteId-${this.note.id}-${this.selectedLanguage}`, JSON.stringify(savedDraftNote));
this.newTranslation = false;
}).then(() => {
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);
}).catch(e => {
console.error('Error when creating draft note: ', e);
this.$root.$emit('show-alert', {
type: 'error',
message: this.$t(`notes.message.${e.message}`)
});
});
} else {
this.draftSavingStatus = this.$t('notes.draft.savedDraftStatus');
}
},
editorClosed() {
Expand Down Expand Up @@ -308,7 +361,8 @@ export default {
parentPageId: this.note?.draftPage && this.note?.targetPageId === this.parentPageId ? null : this.parentPageId,
toBePublished: false,
appName: this.appName,
properties: properties
properties: properties,
extensionDataUpdated: this.extensionDataUpdated
};
if (note.id) {
this.updateNote(note);
Expand Down Expand Up @@ -341,6 +395,7 @@ export default {
}).finally(() => {
this.enableClickOnce();
this.removeLocalStorageCurrentDraft(currentDraftId);
this.extensionDataUpdated = false;
});
},
createNote(note) {
Expand Down Expand Up @@ -589,14 +644,6 @@ 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);
Expand All @@ -607,6 +654,7 @@ export default {
});
}
},
displayDraftMessage() {
if (!this.draftNote) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
:placeholder="titlePlaceholder"
type="text"
:maxlength="noteTitleMaxLength + 1"
class="py-0 px-1 mt-5 mb-0">
class="py-0 px-1 mt-5 mb-0"
@input="waitUserTyping()">
</div>
<div class="formInputGroup white overflow-auto flex notes-content-wrapper">
<textarea
Expand All @@ -71,7 +72,7 @@
v-if="editorExtensions.length > 0"
name="NotesRichEditor"
type="notes-editor-extensions"
:params="extensionParams"/>
:params="extensionParams" />
<note-custom-plugins
ref="noteCustomPlugins"
:instance="editor" />
Expand Down Expand Up @@ -105,6 +106,8 @@ export default {
initialized: false,
instanceReady: false,
noteTitleMaxLength: 500,
typingTimer: null,
isUserTyping: false,
editorExtensions: [],
updatingProperties: false,
enablePostKeys: 0,
Expand Down Expand Up @@ -250,19 +253,26 @@ export default {
}
},
computed: {
newEmptyTranslation() {
return !!this.note?.lang && !this.note?.title?.length && !this.note?.content?.length;
},
entityId() {
return this.newEmptyTranslation ? null : this.note?.draftPage ? this.note?.id : this.note?.latestVersionId;
},
extensionParams() {
return {
spaceId: this.getURLQueryParam('spaceId'),
entityId: this.note.id && this.note.id !== 0 && this.note?.draftPage ? this.note.id : this.note.latestVersionId,
entityId: this.entityId,
entityType: this.note.draftPage && 'WIKI_DRAFT_PAGES' || 'WIKI_PAGE_VERSIONS',
lang: this.note.lang,
isEmptyNoteTranslation: (!!this.note.lang || this.note.lang != null) && !this.note?.title && !this.note?.content
isEmptyNoteTranslation: this.newEmptyTranslation
};
},
hasFeaturedImage() {
return !!this.noteObject?.properties?.featuredImage?.id;
},
saveNoteButtonDisabled() {
return this.updatingProperties || this.saveButtonDisabled || this.isUserTyping;
return this.updatingProperties || this.saveButtonDisabled;
},
newPageDraft() {
Expand Down Expand Up @@ -496,6 +506,7 @@ export default {
self.initialized = true;
return;
}
self.waitUserTyping(self);
self.noteObject.content = evt.editor.getData();
self.autoSave();
const removeTreeviewBtn = evt.editor.document.getById( 'remove-treeview' );
Expand Down Expand Up @@ -605,6 +616,14 @@ export default {
return urlParams.get(paramName);
}
},
waitUserTyping(component) {
component ??= this;
clearTimeout(component.typingTimer);
component.isUserTyping = true;
component.typingTimer = setTimeout(function () {
component.isUserTyping = false;
}, 2000);
}
}
};
</script>

0 comments on commit 1a41b72

Please sign in to comment.