mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	fixed runOnAttributeChange event
This commit is contained in:
		| @@ -10,18 +10,22 @@ const Option = require('../entities/option'); | |||||||
| const repository = require('../services/repository'); | const repository = require('../services/repository'); | ||||||
|  |  | ||||||
| const TABLE_NAME_TO_ENTITY = { | const TABLE_NAME_TO_ENTITY = { | ||||||
|     "attributes": Attribute.constructor, |     "attributes": Attribute, | ||||||
|     "images": Image.constructor, |     "images": Image, | ||||||
|     "note_images": NoteImage.constructor, |     "note_images": NoteImage, | ||||||
|     "branches": Branch.constructor, |     "branches": Branch, | ||||||
|     "notes": Note.constructor, |     "notes": Note, | ||||||
|     "note_revisions": NoteRevision.constructor, |     "note_revisions": NoteRevision, | ||||||
|     "recent_notes": RecentNote.constructor, |     "recent_notes": RecentNote, | ||||||
|     "options": Option.constructor, |     "options": Option, | ||||||
|     "api_tokens": ApiToken.constructor, |     "api_tokens": ApiToken | ||||||
| }; | }; | ||||||
|  |  | ||||||
| function getEntityFromTableName(tableName) { | function getEntityFromTableName(tableName) { | ||||||
|  |     if (!(tableName in TABLE_NAME_TO_ENTITY)) { | ||||||
|  |         throw new Error(`Entity for table ${tableName} not found!`); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     return TABLE_NAME_TO_ENTITY[tableName]; |     return TABLE_NAME_TO_ENTITY[tableName]; | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -44,7 +44,7 @@ function ScriptApi(startNote, currentNote, originEntity = null) { | |||||||
|             params: prepareParams(params), |             params: prepareParams(params), | ||||||
|             startNoteId: startNote.noteId, |             startNoteId: startNote.noteId, | ||||||
|             currentNoteId: currentNote.noteId, |             currentNoteId: currentNote.noteId, | ||||||
|             originEntityName: originEntity ? originEntity.constructor.tableName() : null, |             originEntityName: originEntity ? originEntity.constructor.tableName : null, | ||||||
|             originEntityId: originEntity ? originEntity.noteId : null |             originEntityId: originEntity ? originEntity.noteId : null | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -14,7 +14,7 @@ async function exec(req) { | |||||||
| async function run(req) { | async function run(req) { | ||||||
|     const note = await repository.getNote(req.params.noteId); |     const note = await repository.getNote(req.params.noteId); | ||||||
|  |  | ||||||
|     const result = await scriptService.executeNote(req, note); |     const result = await scriptService.executeNote(note, note); | ||||||
|  |  | ||||||
|     return { executionResult: result }; |     return { executionResult: result }; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -19,7 +19,8 @@ const BUILTIN_ATTRIBUTES = [ | |||||||
|  |  | ||||||
|     // relation names |     // relation names | ||||||
|     { type: 'relation', name: 'runOnNoteView' }, |     { type: 'relation', name: 'runOnNoteView' }, | ||||||
|     { type: 'relation', name: 'runOnNoteTitleChange' } |     { type: 'relation', name: 'runOnNoteTitleChange' }, | ||||||
|  |     { type: 'relation', name: 'runOnAttributeChange' } | ||||||
| ]; | ]; | ||||||
|  |  | ||||||
| async function getNotesWithLabel(name, value) { | async function getNotesWithLabel(name, value) { | ||||||
|   | |||||||
| @@ -11,7 +11,7 @@ async function runAttachedRelations(note, relationName, originEntity) { | |||||||
|     for (const relation of runRelations) { |     for (const relation of runRelations) { | ||||||
|         const scriptNote = await relation.getTargetNote(); |         const scriptNote = await relation.getTargetNote(); | ||||||
|  |  | ||||||
|         await scriptService.executeNote(scriptNote, scriptNote, originEntity); |         await scriptService.executeNote(scriptNote, originEntity); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -273,8 +273,6 @@ eventService.subscribe(eventService.ENTITY_CHANGED, async ({entityName, entityId | |||||||
|             const hideLabel = await repository.getEntity(`SELECT * FROM attributes WHERE isDeleted = 0 AND type = 'label'  |             const hideLabel = await repository.getEntity(`SELECT * FROM attributes WHERE isDeleted = 0 AND type = 'label'  | ||||||
|                                  AND name = 'archived' AND noteId = ?`, [attribute.noteId]); |                                  AND name = 'archived' AND noteId = ?`, [attribute.noteId]); | ||||||
|  |  | ||||||
|             console.log(hideLabel); |  | ||||||
|  |  | ||||||
|             if (hideLabel) { |             if (hideLabel) { | ||||||
|                 archived[attribute.noteId] = hideLabel.isInheritable ? 1 : 0; |                 archived[attribute.noteId] = hideLabel.isInheritable ? 1 : 0; | ||||||
|             } |             } | ||||||
|   | |||||||
| @@ -10,9 +10,9 @@ async function setEntityConstructor(constructor) { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function getEntityFromName(entityName, entityId) { | async function getEntityFromName(entityName, entityId) { | ||||||
|     const entityConstructor = entityConstructor.getEntityFromTableName(entityName); |     const constructor = entityConstructor.getEntityFromTableName(entityName); | ||||||
|  |  | ||||||
|     return await getEntity(`SELECT * FROM ${entityConstructor.tableName()} WHERE ${entityConstructor.primaryKeyName()} = ?`, [entityId]); |     return await getEntity(`SELECT * FROM ${constructor.tableName} WHERE ${constructor.primaryKeyName} = ?`, [entityId]); | ||||||
| } | } | ||||||
|  |  | ||||||
| async function getEntities(query, params = []) { | async function getEntities(query, params = []) { | ||||||
|   | |||||||
| @@ -17,7 +17,7 @@ async function runNotesWithLabel(runAttrValue) { | |||||||
|           AND notes.isDeleted = 0`, [runAttrValue]); |           AND notes.isDeleted = 0`, [runAttrValue]); | ||||||
|  |  | ||||||
|     for (const note of notes) { |     for (const note of notes) { | ||||||
|         scriptService.executeNote(note); |         scriptService.executeNote(note, note); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user