diff --git a/src/public/app/entities/note_short.js b/src/public/app/entities/note_short.js index 2b1dbf610..f68547eb7 100644 --- a/src/public/app/entities/note_short.js +++ b/src/public/app/entities/note_short.js @@ -170,6 +170,16 @@ class NoteShort { * @returns {Attribute[]} all note's attributes, including inherited ones */ getAttributes(type, name) { + return this.__filterAttrs(this.__getCachedAttributes([]), type, name); + } + + __getCachedAttributes(path) { + // notes/clones cannot form tree cycles, it is possible to create attribute inheritance cycle via templates + // when template instance is a parent of template itself + if (path.includes(this.noteId)) { + return []; + } + if (!(this.noteId in noteAttributeCache)) { const ownedAttributes = this.getOwnedAttributes(); @@ -177,11 +187,13 @@ class NoteShort { ownedAttributes ]; + const newPath = [...path, this.noteId]; + for (const templateAttr of ownedAttributes.filter(oa => oa.type === 'relation' && oa.name === 'template')) { const templateNote = this.treeCache.notes[templateAttr.value]; - if (templateNote) { - attrArrs.push(templateNote.getAttributes()); + if (templateNote && templateNote.noteId !== this.noteId) { + attrArrs.push(templateNote.__getCachedAttributes(newPath)); } } @@ -189,7 +201,7 @@ class NoteShort { for (const parentNote of this.getParentNotes()) { // these virtual parent-child relationships are also loaded into frontend tree cache if (parentNote.type !== 'search') { - attrArrs.push(parentNote.getInheritableAttributes()); + attrArrs.push(parentNote.__getInheritableAttributes(newPath)); } } } @@ -197,7 +209,7 @@ class NoteShort { noteAttributeCache.attributes[this.noteId] = attrArrs.flat(); } - return this.__filterAttrs(noteAttributeCache.attributes[this.noteId], type, name); + return noteAttributeCache.attributes[this.noteId]; } __filterAttrs(attributes, type, name) { @@ -212,8 +224,8 @@ class NoteShort { } } - getInheritableAttributes() { - const attrs = this.getAttributes(); + __getInheritableAttributes(path) { + const attrs = this.__getCachedAttributes(path); return attrs.filter(attr => attr.isInheritable); } @@ -460,4 +472,4 @@ class NoteShort { } } -export default NoteShort; \ No newline at end of file +export default NoteShort; diff --git a/src/public/app/services/main_tree_executors.js b/src/public/app/services/main_tree_executors.js index a365393f3..9a8306fad 100644 --- a/src/public/app/services/main_tree_executors.js +++ b/src/public/app/services/main_tree_executors.js @@ -34,7 +34,7 @@ export default class MainTreeExecutors extends Component { return; } - const {note} = await noteCreateService.createNote(activeNote.noteId, { + await noteCreateService.createNote(activeNote.noteId, { isProtected: activeNote.isProtected, saveSelection: false }); @@ -56,4 +56,4 @@ export default class MainTreeExecutors extends Component { saveSelection: false }); } -} \ No newline at end of file +} diff --git a/src/public/app/services/tab_context.js b/src/public/app/services/tab_context.js index 9d46e2f6d..920a186f3 100644 --- a/src/public/app/services/tab_context.js +++ b/src/public/app/services/tab_context.js @@ -73,7 +73,7 @@ class TabContext extends Component { protectedSessionHolder.touchProtectedSessionIfNecessary(this.note); if (triggerSwitchEvent) { - this.triggerEvent('tabNoteSwitched', { + await this.triggerEvent('tabNoteSwitched', { tabContext: this, notePath: this.notePath }); @@ -127,4 +127,4 @@ class TabContext extends Component { } } -export default TabContext; \ No newline at end of file +export default TabContext; diff --git a/src/public/app/services/tab_manager.js b/src/public/app/services/tab_manager.js index da333f5f1..fd29172d4 100644 --- a/src/public/app/services/tab_manager.js +++ b/src/public/app/services/tab_manager.js @@ -203,7 +203,7 @@ export default class TabManager extends Component { if (activate) { this.activateTab(tabContext.tabId, false); - this.triggerEvent('tabNoteSwitchedAndActivated', { + await this.triggerEvent('tabNoteSwitchedAndActivated', { tabContext, notePath: tabContext.notePath // resolved note path }); diff --git a/src/public/app/widgets/collapsible_widgets/note_info.js b/src/public/app/widgets/collapsible_widgets/note_info.js index a22837006..12a613fd8 100644 --- a/src/public/app/widgets/collapsible_widgets/note_info.js +++ b/src/public/app/widgets/collapsible_widgets/note_info.js @@ -34,9 +34,8 @@ const TPL = `