renamed workEntity to originEntity

This commit is contained in:
azivner
2018-08-10 13:30:20 +02:00
parent 7ac109e7f7
commit 965dbcbc9a
8 changed files with 24 additions and 24 deletions

View File

@@ -4,14 +4,14 @@ const treeService = require('./tree');
const messagingService = require('./messaging');
const repository = require('./repository');
async function runAttachedRelations(note, relationName, workEntity) {
async function runAttachedRelations(note, relationName, originEntity) {
const attributes = await note.getAttributes();
const runRelations = attributes.filter(relation => relation.type === 'relation' && relation.name === relationName);
for (const relation of runRelations) {
const scriptNote = await relation.getTargetNote();
await scriptService.executeNote(scriptNote, scriptNote, workEntity);
await scriptService.executeNote(scriptNote, scriptNote, originEntity);
}
}

View File

@@ -4,17 +4,17 @@ const repository = require('./repository');
const cls = require('./cls');
const sourceIdService = require('./source_id');
async function executeNote(note, workEntity) {
async function executeNote(note, originEntity) {
if (!note.isJavaScript()) {
return;
}
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) {
// this is the default case, the only exception is when we want to preserve frontend startNote
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
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')) {
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
* 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 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.type = 'code';
@@ -48,7 +48,7 @@ async function executeScript(script, params, startNoteId, currentNoteId, workEnt
const bundle = await getScriptBundle(currentNote);
return await executeBundle(bundle, startNote, workEntity);
return await executeBundle(bundle, startNote, originEntity);
}
async function execute(ctx, script, paramsStr) {

View File

@@ -10,10 +10,10 @@ const config = require('./config');
const repository = require('./repository');
const axios = require('axios');
function ScriptContext(startNote, allNotes, workEntity = null) {
function ScriptContext(startNote, allNotes, originEntity = null) {
this.modules = {};
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 => {
return moduleName => {
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.currentNote = currentNote;
this.workEntity = workEntity;
this.originEntity = originEntity;
this.axios = axios;