From b21aeae569c3ebcf2538918a13cf64b9d4c8bade Mon Sep 17 00:00:00 2001 From: anika-ahluwalia Date: Mon, 8 Jun 2020 10:57:59 -0500 Subject: adding ScriptManager and saving --- src/client/views/nodes/ScriptingBox.tsx | 39 +++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 9 deletions(-) (limited to 'src/client/views') diff --git a/src/client/views/nodes/ScriptingBox.tsx b/src/client/views/nodes/ScriptingBox.tsx index 149640c07..6f94ae8f9 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({}); @@ -184,23 +185,30 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent { - this.onCompile(); - const bindings: { [name: string]: any } = {}; - this.paramsNames.forEach(key => bindings[key] = this.dataDoc[key]); - // binds vars so user doesnt have to refer to everything as self. - ScriptCast(this.dataDoc.data, null)?.script.run({ self: this.rootDoc, this: this.layoutDoc, ...bindings }, this.onError); + if (this.onCompile()) { + const bindings: { [name: string]: any } = {}; + this.paramsNames.forEach(key => bindings[key] = this.dataDoc[key]); + // binds vars so user doesnt have to refer to everything as self. + ScriptCast(this.dataDoc.data, null)?.script.run({ self: this.rootDoc, this: this.layoutDoc, ...bindings }, this.onError); + } } // checks if the script compiles and switches to applied UI @action onApply = () => { - this.onCompile(); - this._applied = true; + if (this.onCompile()) { + this._applied = true; + } } @action @@ -208,6 +216,17 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent { + if (this.onCompile()) { + this.dataDoc.funcName = "testingTitle"; + this.dataDoc.descripition = "description test"; + ScriptManager.Instance.addScript(this.dataDoc); + } else { + this._errorMessage = "Can not save script, does not compile"; + } + } + // overlays document numbers (ex. d32) over all documents when clicked on onFocus = () => { this._overlayDisposer?.(); @@ -653,8 +672,10 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent - - + + + + {this.rootDoc.layoutKey !== "layout_onClick" ? (null) : } ; -- cgit v1.2.3-70-g09d2