From 3e6e77119a0ace5bddd59b58338edd4fa866055c Mon Sep 17 00:00:00 2001 From: anika-ahluwalia Date: Tue, 9 Jun 2020 17:39:35 -0500 Subject: moving things around to find bug --- src/client/util/ScriptManager.ts | 6 ++++-- src/client/util/Scripting.ts | 13 ++++++------ src/client/views/nodes/ScriptingBox.tsx | 35 +++++++++++++++++++++++++++++++-- 3 files changed, 44 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/client/util/ScriptManager.ts b/src/client/util/ScriptManager.ts index 72d134800..6c90f43eb 100644 --- a/src/client/util/ScriptManager.ts +++ b/src/client/util/ScriptManager.ts @@ -32,11 +32,13 @@ export class ScriptManager { } public addScript(scriptDoc: Doc): boolean { + console.log("in add script method"); const scriptList = ScriptManager.Instance.getAllScripts(); scriptList.push(scriptDoc); if (ScriptManager.Instance.ScriptManagerDoc) { ScriptManager.Instance.ScriptManagerDoc.data = new List(scriptList); ScriptManager.addScriptToGlobals(scriptDoc); + console.log("script added"); return true; } return false; @@ -63,7 +65,7 @@ export class ScriptManager { const params = Cast(scriptDoc.compileParams, listSpec("string"), []); const p = params.reduce((o: ScriptParam, p: string) => { o[p] = "any"; return o; }, {} as ScriptParam); const f = new Function(...Array.from(Object.keys(p)), StrCast(scriptDoc.rawScript)); - + let parameters = "("; params.forEach((element: string, i: number) => { if (i === params.length - 1) { @@ -72,7 +74,7 @@ export class ScriptManager { parameters = parameters + element + ", "; } }); - + if (parameters === "(") { Scripting.addGlobal(f, StrCast(scriptDoc.description), "", StrCast(scriptDoc.funcName)); } else { diff --git a/src/client/util/Scripting.ts b/src/client/util/Scripting.ts index 237027c03..b34bf0406 100644 --- a/src/client/util/Scripting.ts +++ b/src/client/util/Scripting.ts @@ -57,23 +57,24 @@ export namespace Scripting { let n: any; let obj: any; + console.log("adding global"); + if (second !== undefined) { if (typeof first === "string") { + console.log("name first"); n = first; obj = second; } else { obj = [first]; obj.push(second); - if (third) { - //if (third.indexOf("(") > 0) { + if (third !== undefined) { obj.push(third); - //} else { - //n = third; - //} } - if (fourth) { + if (fourth !== undefined) { + console.log("WE SHOULD BE HERE"); n = fourth; } else { + console.log("HOW DID WE GET HERE"); n = first.name; } } diff --git a/src/client/views/nodes/ScriptingBox.tsx b/src/client/views/nodes/ScriptingBox.tsx index e07704c19..c2581240b 100644 --- a/src/client/views/nodes/ScriptingBox.tsx +++ b/src/client/views/nodes/ScriptingBox.tsx @@ -22,6 +22,7 @@ const _global = (window /* browser */ || global /* node */) as any; import ReactTextareaAutocomplete from "@webscopeio/react-textarea-autocomplete"; import "@webscopeio/react-textarea-autocomplete/style.css"; +//import { ScriptManager } from "../../util/ScriptManager"; const ScriptingSchema = createSchema({}); @@ -252,8 +253,38 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent { o[p] = "any"; return o; }, {} as ScriptParam); + //const f = new Function(...Array.from(Object.keys(p)), this.rawScript); + + const paramNames = this.compileParams.reduce((o: string, p: string) => { + if (this.compileParams.indexOf(p) === this.compileParams.length - 1) { + o = o + p.split(":")[0].trim(); + } else { + o = o + p.split(":")[0].trim() + ","; + } + return o; + }, "" as string); + const f = new Function(paramNames, this.rawScript); + + let parameters = "("; + this.compileParams.forEach((element: string, i: number) => { + if (i === this.compileParams.length - 1) { + parameters = parameters + element + ")"; + } else { + parameters = parameters + element + ", "; + } + }); + + console.log(this.functionName); + + if (parameters === "(") { + Scripting.addGlobal(f, this.dataDoc.description, "", this.functionName); + } else { + Scripting.addGlobal(f, this.dataDoc.description, parameters, this.functionName); + } console.log("created"); } -- cgit v1.2.3-70-g09d2