mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	renamed workEntity to originEntity
This commit is contained in:
		| @@ -1,14 +1,14 @@ | |||||||
| import ScriptContext from "./script_context.js"; | import ScriptContext from "./script_context.js"; | ||||||
| import server from "./server.js"; | import server from "./server.js"; | ||||||
|  |  | ||||||
| async function getAndExecuteBundle(noteId, workEntity = null) { | async function getAndExecuteBundle(noteId, originEntity = null) { | ||||||
|     const bundle = await server.get('script/bundle/' + noteId); |     const bundle = await server.get('script/bundle/' + noteId); | ||||||
|  |  | ||||||
|     await executeBundle(bundle, workEntity); |     await executeBundle(bundle, originEntity); | ||||||
| } | } | ||||||
|  |  | ||||||
| async function executeBundle(bundle, workEntity) { | async function executeBundle(bundle, originEntity) { | ||||||
|     const apiContext = ScriptContext(bundle.note, bundle.allNotes, workEntity); |     const apiContext = ScriptContext(bundle.note, bundle.allNotes, originEntity); | ||||||
|  |  | ||||||
|     return await (function () { |     return await (function () { | ||||||
|         return eval(`const apiContext = this; (async function() { ${bundle.script}\r\n})()`); |         return eval(`const apiContext = this; (async function() { ${bundle.script}\r\n})()`); | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ import utils from './utils.js'; | |||||||
| import infoService from './info.js'; | import infoService from './info.js'; | ||||||
| import linkService from './link.js'; | import linkService from './link.js'; | ||||||
|  |  | ||||||
| function ScriptApi(startNote, currentNote, workEntity = null) { | function ScriptApi(startNote, currentNote, originEntity = null) { | ||||||
|     const $pluginButtons = $("#plugin-buttons"); |     const $pluginButtons = $("#plugin-buttons"); | ||||||
|  |  | ||||||
|     async function activateNote(notePath) { |     async function activateNote(notePath) { | ||||||
| @@ -44,8 +44,8 @@ function ScriptApi(startNote, currentNote, workEntity = null) { | |||||||
|             params: prepareParams(params), |             params: prepareParams(params), | ||||||
|             startNoteId: startNote.noteId, |             startNoteId: startNote.noteId, | ||||||
|             currentNoteId: currentNote.noteId, |             currentNoteId: currentNote.noteId, | ||||||
|             workEntityName: workEntity ? workEntity.constructor.tableName() : null |             originEntityName: originEntity ? originEntity.constructor.tableName() : null, | ||||||
|             workEntityId: workEntity ? workEntity.noteId : null |             originEntityId: originEntity ? originEntity.noteId : null | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|         return ret.executionResult; |         return ret.executionResult; | ||||||
| @@ -54,7 +54,7 @@ function ScriptApi(startNote, currentNote, workEntity = null) { | |||||||
|     return { |     return { | ||||||
|         startNote: startNote, |         startNote: startNote, | ||||||
|         currentNote: currentNote, |         currentNote: currentNote, | ||||||
|         workEntity: workEntity, |         originEntity: originEntity, | ||||||
|         addButtonToToolbar, |         addButtonToToolbar, | ||||||
|         activateNote, |         activateNote, | ||||||
|         getInstanceName: () => window.glob.instanceName, |         getInstanceName: () => window.glob.instanceName, | ||||||
|   | |||||||
| @@ -1,13 +1,13 @@ | |||||||
| import ScriptApi from './script_api.js'; | import ScriptApi from './script_api.js'; | ||||||
| import utils from './utils.js'; | import utils from './utils.js'; | ||||||
|  |  | ||||||
| function ScriptContext(startNote, allNotes, workEntity = null) { | function ScriptContext(startNote, allNotes, originEntity = null) { | ||||||
|     const modules = {}; |     const modules = {}; | ||||||
|  |  | ||||||
|     return { |     return { | ||||||
|         modules: modules, |         modules: modules, | ||||||
|         notes: utils.toObject(allNotes, note => [note.noteId, note]), |         notes: utils.toObject(allNotes, note => [note.noteId, note]), | ||||||
|         apis: utils.toObject(allNotes, note => [note.noteId, ScriptApi(startNote, note, workEntity)]), |         apis: utils.toObject(allNotes, note => [note.noteId, ScriptApi(startNote, note, originEntity)]), | ||||||
|         require: moduleNoteIds => { |         require: moduleNoteIds => { | ||||||
|             return moduleName => { |             return moduleName => { | ||||||
|                 const candidates = allNotes.filter(note => moduleNoteIds.includes(note.noteId)); |                 const candidates = allNotes.filter(note => moduleNoteIds.includes(note.noteId)); | ||||||
|   | |||||||
| @@ -6,7 +6,7 @@ const repository = require('../../services/repository'); | |||||||
|  |  | ||||||
| async function exec(req) { | async function exec(req) { | ||||||
|     const result = await scriptService.executeScript(req.body.script, req.body.params, req.body.startNoteId, |     const result = await scriptService.executeScript(req.body.script, req.body.params, req.body.startNoteId, | ||||||
|         req.body.currentNoteId, req.body.workEntityName, req.body.workEntityId); |         req.body.currentNoteId, req.body.originEntityName, req.body.originEntityId); | ||||||
|  |  | ||||||
|     return { executionResult: result }; |     return { executionResult: result }; | ||||||
| } | } | ||||||
|   | |||||||
										
											Binary file not shown.
										
									
								
							| @@ -4,14 +4,14 @@ const treeService = require('./tree'); | |||||||
| const messagingService = require('./messaging'); | const messagingService = require('./messaging'); | ||||||
| const repository = require('./repository'); | const repository = require('./repository'); | ||||||
|  |  | ||||||
| async function runAttachedRelations(note, relationName, workEntity) { | async function runAttachedRelations(note, relationName, originEntity) { | ||||||
|     const attributes = await note.getAttributes(); |     const attributes = await note.getAttributes(); | ||||||
|     const runRelations = attributes.filter(relation => relation.type === 'relation' && relation.name === relationName); |     const runRelations = attributes.filter(relation => relation.type === 'relation' && relation.name === relationName); | ||||||
|  |  | ||||||
|     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, workEntity); |         await scriptService.executeNote(scriptNote, scriptNote, originEntity); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -4,17 +4,17 @@ const repository = require('./repository'); | |||||||
| const cls = require('./cls'); | const cls = require('./cls'); | ||||||
| const sourceIdService = require('./source_id'); | const sourceIdService = require('./source_id'); | ||||||
|  |  | ||||||
| async function executeNote(note, workEntity) { | async function executeNote(note, originEntity) { | ||||||
|     if (!note.isJavaScript()) { |     if (!note.isJavaScript()) { | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     const bundle = await getScriptBundle(note); |     const bundle = await getScriptBundle(note); | ||||||
|  |  | ||||||
|     await executeBundle(bundle, note, workEntity); |     await executeBundle(bundle, note, originEntity); | ||||||
| } | } | ||||||
|  |  | ||||||
| async function executeBundle(bundle, startNote, workEntity = null) { | async function executeBundle(bundle, startNote, originEntity = null) { | ||||||
|     if (!startNote) { |     if (!startNote) { | ||||||
|         // this is the default case, the only exception is when we want to preserve frontend startNote |         // this is the default case, the only exception is when we want to preserve frontend startNote | ||||||
|         startNote = bundle.note; |         startNote = bundle.note; | ||||||
| @@ -23,7 +23,7 @@ async function executeBundle(bundle, startNote, workEntity = null) { | |||||||
|     // last \r\n is necessary if script contains line comment on its last line |     // last \r\n is necessary if script contains line comment on its last line | ||||||
|     const script = "async function() {\r\n" + bundle.script + "\r\n}"; |     const script = "async function() {\r\n" + bundle.script + "\r\n}"; | ||||||
|  |  | ||||||
|     const ctx = new ScriptContext(startNote, bundle.allNotes, workEntity); |     const ctx = new ScriptContext(startNote, bundle.allNotes, originEntity); | ||||||
|  |  | ||||||
|     if (await bundle.note.hasLabel('manualTransactionHandling')) { |     if (await bundle.note.hasLabel('manualTransactionHandling')) { | ||||||
|         return await execute(ctx, script, ''); |         return await execute(ctx, script, ''); | ||||||
| @@ -37,10 +37,10 @@ async function executeBundle(bundle, startNote, workEntity = null) { | |||||||
|  * This method preserves frontend startNode - that's why we start execution from currentNote and override |  * This method preserves frontend startNode - that's why we start execution from currentNote and override | ||||||
|  * bundle's startNote. |  * bundle's startNote. | ||||||
|  */ |  */ | ||||||
| async function executeScript(script, params, startNoteId, currentNoteId, workEntityName, workEntityId) { | async function executeScript(script, params, startNoteId, currentNoteId, originEntityName, originEntityId) { | ||||||
|     const startNote = await repository.getNote(startNoteId); |     const startNote = await repository.getNote(startNoteId); | ||||||
|     const currentNote = await repository.getNote(currentNoteId); |     const currentNote = await repository.getNote(currentNoteId); | ||||||
|     const workEntity = await repository.getEntityFromName(workEntityName, workEntityId); |     const originEntity = await repository.getEntityFromName(originEntityName, originEntityId); | ||||||
|  |  | ||||||
|     currentNote.content = `return await (${script}\r\n)(${getParams(params)})`; |     currentNote.content = `return await (${script}\r\n)(${getParams(params)})`; | ||||||
|     currentNote.type = 'code'; |     currentNote.type = 'code'; | ||||||
| @@ -48,7 +48,7 @@ async function executeScript(script, params, startNoteId, currentNoteId, workEnt | |||||||
|  |  | ||||||
|     const bundle = await getScriptBundle(currentNote); |     const bundle = await getScriptBundle(currentNote); | ||||||
|  |  | ||||||
|     return await executeBundle(bundle, startNote, workEntity); |     return await executeBundle(bundle, startNote, originEntity); | ||||||
| } | } | ||||||
|  |  | ||||||
| async function execute(ctx, script, paramsStr) { | async function execute(ctx, script, paramsStr) { | ||||||
|   | |||||||
| @@ -10,10 +10,10 @@ const config = require('./config'); | |||||||
| const repository = require('./repository'); | const repository = require('./repository'); | ||||||
| const axios = require('axios'); | const axios = require('axios'); | ||||||
|  |  | ||||||
| function ScriptContext(startNote, allNotes, workEntity = null) { | function ScriptContext(startNote, allNotes, originEntity = null) { | ||||||
|     this.modules = {}; |     this.modules = {}; | ||||||
|     this.notes = utils.toObject(allNotes, note => [note.noteId, note]); |     this.notes = utils.toObject(allNotes, note => [note.noteId, note]); | ||||||
|     this.apis = utils.toObject(allNotes, note => [note.noteId, new ScriptApi(startNote, note, workEntity)]); |     this.apis = utils.toObject(allNotes, note => [note.noteId, new ScriptApi(startNote, note, originEntity)]); | ||||||
|     this.require = moduleNoteIds => { |     this.require = moduleNoteIds => { | ||||||
|         return moduleName => { |         return moduleName => { | ||||||
|             const candidates = allNotes.filter(note => moduleNoteIds.includes(note.noteId)); |             const candidates = allNotes.filter(note => moduleNoteIds.includes(note.noteId)); | ||||||
| @@ -28,10 +28,10 @@ function ScriptContext(startNote, allNotes, workEntity = null) { | |||||||
|     }; |     }; | ||||||
| } | } | ||||||
|  |  | ||||||
| function ScriptApi(startNote, currentNote, workEntity) { | function ScriptApi(startNote, currentNote, originEntity) { | ||||||
|     this.startNote = startNote; |     this.startNote = startNote; | ||||||
|     this.currentNote = currentNote; |     this.currentNote = currentNote; | ||||||
|     this.workEntity = workEntity; |     this.originEntity = originEntity; | ||||||
|  |  | ||||||
|     this.axios = axios; |     this.axios = axios; | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user