mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
fix running of runOnNoteCreation hook, #3219
This commit is contained in:
parent
867f7f3f59
commit
c1127ec429
@ -240,15 +240,15 @@ const ATTR_HELP = {
|
|||||||
"keyboardShortcut": "Defines a keyboard shortcut which will immediately jump to this note. Example: 'ctrl+alt+e'. Requires frontend reload for the change to take effect."
|
"keyboardShortcut": "Defines a keyboard shortcut which will immediately jump to this note. Example: 'ctrl+alt+e'. Requires frontend reload for the change to take effect."
|
||||||
},
|
},
|
||||||
"relation": {
|
"relation": {
|
||||||
"runOnNoteCreation": "executes when note is created on backend",
|
"runOnNoteCreation": "executes when note is created on backend. Use this relation if you want to run the script for all notes created under a specific subtree. In that case, create it on the subtree root note and make it inheritable. A new note created within the subtree (any depth) will trigger the script.",
|
||||||
|
"runOnChildNoteCreation": "executes when new note is created under the note where this relation is defined",
|
||||||
"runOnNoteTitleChange": "executes when note title is changed (includes note creation as well)",
|
"runOnNoteTitleChange": "executes when note title is changed (includes note creation as well)",
|
||||||
"runOnNoteChange": "executes when note is changed (includes note creation as well)",
|
"runOnNoteChange": "executes when note is changed (includes note creation as well)",
|
||||||
"runOnNoteDeletion": "executes when note is being deleted",
|
"runOnNoteDeletion": "executes when note is being deleted",
|
||||||
"runOnBranchCreation": "executes when a branch is created. Branch is a link between parent note and child note and is created e.g. when cloning or moving note.",
|
"runOnBranchCreation": "executes when a branch is created. Branch is a link between parent note and child note and is created e.g. when cloning or moving note.",
|
||||||
"runOnBranchDeletion": "executes when a branch is deleted. Branch is a link between parent note and child note and is deleted e.g. when moving note (old branch/link is deleted).",
|
"runOnBranchDeletion": "executes when a branch is deleted. Branch is a link between parent note and child note and is deleted e.g. when moving note (old branch/link is deleted).",
|
||||||
"runOnChildNoteCreation": "executes when new note is created under this note",
|
"runOnAttributeCreation": "executes when new attribute is created for the note which defines this relation",
|
||||||
"runOnAttributeCreation": "executes when new attribute is created under this note",
|
"runOnAttributeChange": " executes when the attribute is changed of a note which defines this relation. This is triggered also when the attribute is deleted",
|
||||||
"runOnAttributeChange": "executes when attribute is changed under this note",
|
|
||||||
"template": "attached note's attributes will be inherited even without parent-child relationship. See template for details.",
|
"template": "attached note's attributes will be inherited even without parent-child relationship. See template for details.",
|
||||||
"renderNote": 'notes of type "render HTML note" will be rendered using a code note (HTML or script) and it is necessary to point using this relation to which note should be rendered',
|
"renderNote": 'notes of type "render HTML note" will be rendered using a code note (HTML or script) and it is necessary to point using this relation to which note should be rendered',
|
||||||
"widget": "target of this relation will be executed and rendered as a widget in the sidebar",
|
"widget": "target of this relation will be executed and rendered as a widget in the sidebar",
|
||||||
|
@ -40,6 +40,10 @@ function disableEntityEvents() {
|
|||||||
namespace.set('disableEntityEvents', true);
|
namespace.set('disableEntityEvents', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function enableEntityEvents() {
|
||||||
|
namespace.set('disableEntityEvents', false);
|
||||||
|
}
|
||||||
|
|
||||||
function isEntityEventsDisabled() {
|
function isEntityEventsDisabled() {
|
||||||
return !!namespace.get('disableEntityEvents');
|
return !!namespace.get('disableEntityEvents');
|
||||||
}
|
}
|
||||||
@ -83,6 +87,7 @@ module.exports = {
|
|||||||
getComponentId,
|
getComponentId,
|
||||||
getLocalNowDateTime,
|
getLocalNowDateTime,
|
||||||
disableEntityEvents,
|
disableEntityEvents,
|
||||||
|
enableEntityEvents,
|
||||||
isEntityEventsDisabled,
|
isEntityEventsDisabled,
|
||||||
reset,
|
reset,
|
||||||
getAndClearEntityChangeIds,
|
getAndClearEntityChangeIds,
|
||||||
|
@ -33,10 +33,6 @@ function getNewNotePosition(parentNoteId) {
|
|||||||
return maxNotePos + 10;
|
return maxNotePos + 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
function triggerChildNoteCreated(childNote, parentNote) {
|
|
||||||
eventService.emit(eventService.CHILD_NOTE_CREATED, { childNote, parentNote });
|
|
||||||
}
|
|
||||||
|
|
||||||
function triggerNoteTitleChanged(note) {
|
function triggerNoteTitleChanged(note) {
|
||||||
eventService.emit(eventService.NOTE_TITLE_CHANGED, note);
|
eventService.emit(eventService.NOTE_TITLE_CHANGED, note);
|
||||||
}
|
}
|
||||||
@ -140,7 +136,18 @@ function createNewNote(params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return sql.transactional(() => {
|
return sql.transactional(() => {
|
||||||
const note = new Note({
|
let note, branch, isEntityEventsDisabled;
|
||||||
|
|
||||||
|
try {
|
||||||
|
isEntityEventsDisabled = cls.isEntityEventsDisabled();
|
||||||
|
|
||||||
|
if (!isEntityEventsDisabled) {
|
||||||
|
// it doesn't make sense to run note creation events on a partially constructed note, so
|
||||||
|
// defer them until note creation is completed
|
||||||
|
cls.disableEntityEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
note = new Note({
|
||||||
noteId: params.noteId, // optionally can force specific noteId
|
noteId: params.noteId, // optionally can force specific noteId
|
||||||
title: params.title,
|
title: params.title,
|
||||||
isProtected: !!params.isProtected,
|
isProtected: !!params.isProtected,
|
||||||
@ -150,7 +157,7 @@ function createNewNote(params) {
|
|||||||
|
|
||||||
note.setContent(params.content);
|
note.setContent(params.content);
|
||||||
|
|
||||||
const branch = new Branch({
|
branch = new Branch({
|
||||||
branchId: params.branchId,
|
branchId: params.branchId,
|
||||||
noteId: note.noteId,
|
noteId: note.noteId,
|
||||||
parentNoteId: params.parentNoteId,
|
parentNoteId: params.parentNoteId,
|
||||||
@ -158,6 +165,14 @@ function createNewNote(params) {
|
|||||||
prefix: params.prefix,
|
prefix: params.prefix,
|
||||||
isExpanded: !!params.isExpanded
|
isExpanded: !!params.isExpanded
|
||||||
}).save();
|
}).save();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (!isEntityEventsDisabled) {
|
||||||
|
// re-enable entity events only if there were previously enabled
|
||||||
|
// (they can be disabled in case of import)
|
||||||
|
cls.enableEntityEvents();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
scanForLinks(note);
|
scanForLinks(note);
|
||||||
|
|
||||||
@ -175,7 +190,21 @@ function createNewNote(params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
triggerNoteTitleChanged(note);
|
triggerNoteTitleChanged(note);
|
||||||
triggerChildNoteCreated(note, parentNote);
|
|
||||||
|
eventService.emit(eventService.ENTITY_CREATED, {
|
||||||
|
entityName: 'notes',
|
||||||
|
entity: note
|
||||||
|
});
|
||||||
|
|
||||||
|
eventService.emit(eventService.ENTITY_CREATED, {
|
||||||
|
entityName: 'branches',
|
||||||
|
entity: branch
|
||||||
|
});
|
||||||
|
|
||||||
|
eventService.emit(eventService.CHILD_NOTE_CREATED, {
|
||||||
|
childNote: note,
|
||||||
|
parentNote: parentNote
|
||||||
|
});
|
||||||
|
|
||||||
log.info(`Created new note '${note.noteId}', branch '${branch.branchId}' of type '${note.type}', mime '${note.mime}'`);
|
log.info(`Created new note '${note.noteId}', branch '${branch.branchId}' of type '${note.type}', mime '${note.mime}'`);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user