From 2e3534dfb7ddd40525dba16d18e5256beef76111 Mon Sep 17 00:00:00 2001 From: zadam Date: Tue, 18 Feb 2020 22:16:20 +0100 Subject: [PATCH] small fixes --- src/entities/note.js | 2 +- src/public/javascripts/widgets/note_detail.js | 9 ++++++--- src/public/javascripts/widgets/note_type.js | 12 ++++++++++-- src/public/javascripts/widgets/tab_aware_widget.js | 6 ++++++ 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/entities/note.js b/src/entities/note.js index 3336f377a..c110479d3 100644 --- a/src/entities/note.js +++ b/src/entities/note.js @@ -36,7 +36,7 @@ const RELATION_DEFINITION = 'relation-definition'; class Note extends Entity { static get entityName() { return "notes"; } static get primaryKeyName() { return "noteId"; } - static get hashedProperties() { return ["noteId", "title", "type", "isProtected", "isDeleted", "deleteId"]; } + static get hashedProperties() { return ["noteId", "title", "type", "mime", "isProtected", "isDeleted", "deleteId"]; } /** * @param row - object containing database row from "notes" table diff --git a/src/public/javascripts/widgets/note_detail.js b/src/public/javascripts/widgets/note_detail.js index 0c4085dd1..7145a6daa 100644 --- a/src/public/javascripts/widgets/note_detail.js +++ b/src/public/javascripts/widgets/note_detail.js @@ -101,6 +101,7 @@ export default class NoteDetailWidget extends TabAwareWidget { this.toggle(true); this.type = await this.getWidgetType(); + this.mime = this.note.mime; if (!(this.type in this.typeWidgets)) { const clazz = typeWidgetClasses[this.type]; @@ -218,10 +219,12 @@ export default class NoteDetailWidget extends TabAwareWidget { } async entitiesReloadedEvent({loadResults}) { - // we should test what happens when the loaded note is deleted + // FIXME: we should test what happens when the loaded note is deleted - if (loadResults.isNoteContentReloaded(this.noteId, this.componentId)) { - this.refreshWithNote(this.note, this.notePath); + if (loadResults.isNoteContentReloaded(this.noteId, this.componentId) + || (loadResults.isNoteReloaded(this.noteId, this.componentId) && (this.type !== await this.getWidgetType() || this.mime !== this.note.mime))) { + + this.handleEvent('noteTypeMimeChanged', {noteId: this.noteId}); } } diff --git a/src/public/javascripts/widgets/note_type.js b/src/public/javascripts/widgets/note_type.js index f3383d8c0..d33e26d17 100644 --- a/src/public/javascripts/widgets/note_type.js +++ b/src/public/javascripts/widgets/note_type.js @@ -118,6 +118,10 @@ export default class NoteTypeWidget extends TabAwareWidget { } async save(type, mime) { + if (type === this.note.type && mime === this.note.mime) { + return; + } + if (type !== this.note.type && !await this.confirmChangeIfContent()) { return; } @@ -125,8 +129,6 @@ export default class NoteTypeWidget extends TabAwareWidget { await server.put('notes/' + this.noteId + '/type/' + encodeURIComponent(type) + '/mime/' + encodeURIComponent(mime)); - - this.update(); } async confirmChangeIfContent() { @@ -139,4 +141,10 @@ export default class NoteTypeWidget extends TabAwareWidget { const confirmDialog = await import("../dialogs/confirm.js"); return await confirmDialog.confirm("It is not recommended to change note type when note content is not empty. Do you want to continue anyway?"); } + + async entitiesReloadedEvent({loadResults}) { + if (loadResults.isNoteReloaded(this.noteId, this.componentId)) { + this.refresh(); + } + } } \ No newline at end of file diff --git a/src/public/javascripts/widgets/tab_aware_widget.js b/src/public/javascripts/widgets/tab_aware_widget.js index 333c21c09..df94d0115 100644 --- a/src/public/javascripts/widgets/tab_aware_widget.js +++ b/src/public/javascripts/widgets/tab_aware_widget.js @@ -36,6 +36,12 @@ export default class TabAwareWidget extends BasicWidget { } } + noteTypeMimeChangedEvent({noteId}) { + if (this.noteId === noteId) { + this.refresh(); + } + } + noteSwitched() { this.refresh(); }