From 16fef783445180aecb4525ae4ed29225de8a8ba8 Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 14 Jun 2020 10:49:37 +0200 Subject: [PATCH] add API method to force refresh of included notes, closes #1106 --- src/public/app/services/frontend_script_api.js | 9 ++++++++- .../widgets/type_widgets/abstract_text_type_widget.js | 10 +++++++++- src/public/app/widgets/type_widgets/editable_text.js | 4 ++++ src/public/app/widgets/type_widgets/read_only_text.js | 4 ++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/public/app/services/frontend_script_api.js b/src/public/app/services/frontend_script_api.js index 3b8c37a56..b557eae41 100644 --- a/src/public/app/services/frontend_script_api.js +++ b/src/public/app/services/frontend_script_api.js @@ -403,6 +403,13 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain * @method */ this.waitUntilSynced = ws.waitForMaxKnownSyncId; + + /** + * This will refresh all currently opened notes which have included note specified in the parameter + * + * @param includedNoteId - noteId of the included note + */ + this.refreshIncludedNote = includedNoteId => appContext.triggerEvent('refreshIncludedNote', {noteId: includedNoteId}); } -export default FrontendScriptApi; \ No newline at end of file +export default FrontendScriptApi; diff --git a/src/public/app/widgets/type_widgets/abstract_text_type_widget.js b/src/public/app/widgets/type_widgets/abstract_text_type_widget.js index 43099b952..54f44ccfb 100644 --- a/src/public/app/widgets/type_widgets/abstract_text_type_widget.js +++ b/src/public/app/widgets/type_widgets/abstract_text_type_widget.js @@ -62,4 +62,12 @@ export default class AbstractTextTypeWidget extends TypeWidget { $el.text(title); } -} \ No newline at end of file + + refreshIncludedNote($container, noteId) { + if ($container) { + $container.find(`section[data-note-id="${noteId}"]`).each((_, el) => { + this.loadIncludedNote(noteId, $(el)); + }); + } + } +} diff --git a/src/public/app/widgets/type_widgets/editable_text.js b/src/public/app/widgets/type_widgets/editable_text.js index cb5ab2737..1a4f8a1e0 100644 --- a/src/public/app/widgets/type_widgets/editable_text.js +++ b/src/public/app/widgets/type_widgets/editable_text.js @@ -257,4 +257,8 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget { this.textEditor.model.insertContent(imageElement, this.textEditor.model.document.selection); } ); } + + async refreshIncludedNoteEvent({noteId}) { + this.refreshIncludedNote(this.$editor, noteId); + } } diff --git a/src/public/app/widgets/type_widgets/read_only_text.js b/src/public/app/widgets/type_widgets/read_only_text.js index 9e7641414..21a37c016 100644 --- a/src/public/app/widgets/type_widgets/read_only_text.js +++ b/src/public/app/widgets/type_widgets/read_only_text.js @@ -81,4 +81,8 @@ export default class ReadOnlyTextTypeWidget extends AbstractTextTypeWidget { this.loadIncludedNote(noteId, $(el)); }); } + + async refreshIncludedNoteEvent({noteId}) { + this.refreshIncludedNote(this.$content, noteId); + } }