Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
added runOnBranchChange event #4108
zadam45ed43642656
diff --git a/bin/tpl/anonymize-database.sql b/bin/tpl/anonymize-database.sqlindex aee335a854..bc2b431d66 100644--- a/bin/tpl/anonymize-database.sql+++ b/bin/tpl/anonymize-database.sql@@ -20,7 +20,7 @@ UPDATE attributes SET name = 'name', value = 'value' WHERE type = 'label''shareRaw', 'shareDisallowRobotIndexing', 'shareIndex', 'displayRelations', 'hideRelations', 'titleTemplate','template', 'toc', 'color', 'keepCurrentHoisting', 'executeButton', 'executeDescription', 'newNotesOnTop','clipperInbox', 'internalLink', 'imageLink', 'relationMapLink', 'includeMapLink', 'runOnNoteCreation',- 'runOnNoteTitleChange', 'runOnNoteChange', 'runOnNoteContentChange', 'runOnNoteDeletion', 'runOnBranchCreation',+ 'runOnNoteTitleChange', 'runOnNoteChange', 'runOnNoteContentChange', 'runOnNoteDeletion', 'runOnBranchCreation', 'runOnBranchChange','runOnBranchDeletion', 'runOnChildNoteCreation', 'runOnAttributeCreation', 'runOnAttributeChange', 'template','inherit', 'widget', 'renderNote', 'shareCss', 'shareJs', 'shareTemplate', 'shareFavicon');UPDATE attributes SET name = 'name' WHERE type = 'relation'@@ -37,7 +37,7 @@ UPDATE attributes SET name = 'name' WHERE type = 'relation''shareRaw', 'shareDisallowRobotIndexing', 'shareIndex', 'displayRelations', 'hideRelations', 'titleTemplate','template', 'toc', 'color', 'keepCurrentHoisting', 'executeButton', 'executeDescription', 'newNotesOnTop','clipperInbox', 'internalLink', 'imageLink', 'relationMapLink', 'includeMapLink', 'runOnNoteCreation',- 'runOnNoteTitleChange', 'runOnNoteChange', 'runOnNoteContentChange', 'runOnNoteDeletion', 'runOnBranchCreation',+ 'runOnNoteTitleChange', 'runOnNoteChange', 'runOnNoteContentChange', 'runOnNoteDeletion', 'runOnBranchCreation', 'runOnBranchChange','runOnBranchDeletion', 'runOnChildNoteCreation', 'runOnAttributeCreation', 'runOnAttributeChange', 'template','inherit', 'widget', 'renderNote', 'shareCss', 'shareJs', 'shareTemplate', 'shareFavicon');UPDATE branches SET prefix = 'prefix' WHERE prefix IS NOT NULL AND prefix != 'recovered';diff --git a/src/public/app/widgets/attribute_widgets/attribute_detail.js b/src/public/app/widgets/attribute_widgets/attribute_detail.jsindex db209e168a..28cdb96f6d 100644--- a/src/public/app/widgets/attribute_widgets/attribute_detail.js+++ b/src/public/app/widgets/attribute_widgets/attribute_detail.js@@ -263,6 +263,7 @@ const ATTR_HELP = {"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.",+ "runOnBranchChange": "executes when a branch is updated.","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).","runOnAttributeCreation": "executes when new attribute is created for the note which defines this relation","runOnAttributeChange": " executes when the attribute is changed of a note which defines this relation. This is triggered also when the attribute is deleted",diff --git a/src/routes/api/branches.js b/src/routes/api/branches.jsindex 0af2ae7a01..87d1d5265e 100644--- a/src/routes/api/branches.js+++ b/src/routes/api/branches.js@@ -10,6 +10,7 @@ const TaskContext = require('../../services/task_context');const branchService = require("../../services/branches");const log = require("../../services/log");const ValidationError = require("../../errors/validation_error");+const eventService = require("../../services/events.js");/*** Code in this file deals with moving and cloning branches. The relationship between note and parent note is unique@@ -144,6 +145,11 @@ function setExpanded(req) {if (branch) {branch.isExpanded = !!expanded;}++ eventService.emit(eventService.ENTITY_CHANGED, {+ entityName: 'branches',+ entity: branch+ });}}diff --git a/src/services/builtin_attributes.js b/src/services/builtin_attributes.jsindex a4049e7758..4a8b410e9f 100644--- a/src/services/builtin_attributes.js+++ b/src/services/builtin_attributes.js@@ -81,6 +81,7 @@ module.exports = [{ type: 'relation', name: 'runOnNoteContentChange', isDangerous: true },{ type: 'relation', name: 'runOnNoteDeletion', isDangerous: true },{ type: 'relation', name: 'runOnBranchCreation', isDangerous: true },+ { type: 'relation', name: 'runOnBranchChange', isDangerous: true },{ type: 'relation', name: 'runOnBranchDeletion', isDangerous: true },{ type: 'relation', name: 'runOnChildNoteCreation', isDangerous: true },{ type: 'relation', name: 'runOnAttributeCreation', isDangerous: true },diff --git a/src/services/handlers.js b/src/services/handlers.jsindex 06cb35abed..6dcb90e845 100644--- a/src/services/handlers.js+++ b/src/services/handlers.js@@ -65,6 +65,12 @@ eventService.subscribe(eventService.ENTITY_CHANGED, ({entityName, entity}) => {if (parentNote?.hasLabel("sorted")) {treeService.sortNotesIfNeeded(parentNote.noteId);}++ const childNote = becca.getNote(entity.noteId);++ if (childNote) {+ runAttachedRelations(childNote, 'runOnBranchChange', entity);+ }}});