create new runOnNoteContentChange event, #3436

This commit is contained in:
zadam
2022-12-18 23:53:47 +01:00
parent e41104208a
commit 5413a1aa79
5 changed files with 28 additions and 5 deletions

View File

@@ -245,7 +245,8 @@ const ATTR_HELP = {
"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)",
"runOnNoteChange": "executes when note is changed (includes note creation as well)",
"runOnNoteContentChange": "executes when note content is changed (includes note creation as well).",
"runOnNoteChange": "executes when note is changed (includes note creation as well). Does not include content changes",
"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.",
"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).",

View File

@@ -19,6 +19,7 @@ export default class ClosePaneButton extends OnClickButtonWidget {
e.stopPropagation();
widget.triggerCommand("closeThisNoteSplit", { ntxId: widget.getClosestNtxId() });
});
})
.class("icon-action");
}
}

View File

@@ -58,6 +58,12 @@ eventService.subscribe([ eventService.ENTITY_CHANGED, eventService.ENTITY_DELETE
}
});
eventService.subscribe(eventService.ENTITY_CHANGED, ({entityName, entity}) => {
if (entityName === 'note_contents') {
runAttachedRelations(entity, 'runOnNoteContentChange', entity);
}
});
eventService.subscribe(eventService.ENTITY_CREATED, ({ entityName, entity }) => {
if (entityName === 'attributes') {
runAttachedRelations(entity.getNote(), 'runOnAttributeCreation', entity);

View File

@@ -204,6 +204,11 @@ function createNewNote(params) {
entity: note
});
eventService.emit(eventService.ENTITY_CREATED, {
entityName: 'note_contents',
entity: note
});
eventService.emit(eventService.ENTITY_CREATED, {
entityName: 'branches',
entity: branch
@@ -444,7 +449,7 @@ function downloadImages(noteId, content) {
// which will get asynchronously downloaded, during that time they keep editing the note
// once the download is finished, the image note representing downloaded image will be used
// to replace the IMG link.
// However there's another flow where user pastes the image and leaves the note before the images
// However, there's another flow where user pastes the image and leaves the note before the images
// are downloaded and the IMG references are not updated. For this occassion we have this code
// which upon the download of all the images will update the note if the links have not been fixed before
@@ -475,6 +480,11 @@ function downloadImages(noteId, content) {
scanForLinks(origNote);
eventService.emit(eventService.ENTITY_CHANGED, {
entityName: 'note_contents',
entity: origNote
});
console.log(`Fixed the image links for note '${noteId}' to the offline saved.`);
}
});
@@ -580,6 +590,11 @@ function updateNoteContent(noteId, content) {
content = saveLinks(note, content);
note.setContent(content);
eventService.emit(eventService.ENTITY_CHANGED, {
entityName: 'note_contents',
entity: note
});
}
/**