aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/ScriptingBox.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/ScriptingBox.tsx')
-rw-r--r--src/client/views/nodes/ScriptingBox.tsx39
1 files changed, 30 insertions, 9 deletions
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<FieldViewProps, Sc
this.dataDoc.documentText = this.rawScript;
this.dataDoc.data = result.compiled ? new ScriptField(result) : undefined;
this.onError(result.compiled ? undefined : result.errors);
+ if (result.compiled) {
+ return true;
+ } else {
+ return false;
+ }
}
// checks if the script compiles and then runs the script
@action
onRun = () => {
- 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.<var>
- 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.<var>
+ 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<FieldViewProps, Sc
this._applied = false;
}
+ @action
+ onSave = () => {
+ 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<FieldViewProps, Sc
renderScriptingTools() {
const buttonStyle = "scriptingBox-button" + (this.rootDoc.layoutKey === "layout_onClick" ? "third" : "");
return <div className="scriptingBox-toolbar">
- <button className={buttonStyle} onPointerDown={e => { this.onCompile(); e.stopPropagation(); }}>Compile</button>
- <button className={buttonStyle} onPointerDown={e => { this.onApply(); e.stopPropagation(); }}>Apply</button>
+ <button className={buttonStyle} style={{ width: "33%" }} onPointerDown={e => { this.onCompile(); e.stopPropagation(); }}>Compile</button>
+ <button className={buttonStyle} style={{ width: "33%" }} onPointerDown={e => { this.onApply(); e.stopPropagation(); }}>Apply</button>
+ <button className={buttonStyle} style={{ width: "33%" }} onPointerDown={e => { this.onSave(); e.stopPropagation(); }}>Save</button>
+
{this.rootDoc.layoutKey !== "layout_onClick" ? (null) :
<button className={buttonStyle} onPointerDown={e => { this.onFinish(); e.stopPropagation(); }}>Finish</button>}
</div>;