From 9c84c87730796b5da0c7e3e83e58006d73a969c1 Mon Sep 17 00:00:00 2001 From: anika-ahluwalia Date: Wed, 22 Apr 2020 18:37:09 -0500 Subject: added to parameters UI, changed error display --- src/client/views/nodes/ScriptingBox.scss | 36 +++++++-- src/client/views/nodes/ScriptingBox.tsx | 129 +++++++++++++++++++++++++------ 2 files changed, 134 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/client/views/nodes/ScriptingBox.scss b/src/client/views/nodes/ScriptingBox.scss index 25fbd3f35..761a54e42 100644 --- a/src/client/views/nodes/ScriptingBox.scss +++ b/src/client/views/nodes/ScriptingBox.scss @@ -11,22 +11,42 @@ flex-direction: column; height: calc(100% - 30px); + .scriptingBox-wrapper { + height: 100%; + width: 100%; + display: flex; + flex-direction: row; + justify-content: center; - .scriptingBox-errorMessage { - overflow: auto; - } - - .scripting-params { - background: "beige"; - } .scriptingBox-textArea { - width: 100%; + flex: 70; + width: 70%; + height: 100%; + box-sizing: border-box; + resize: none; + padding: 7px; + flex-grow: 100%; + } + + .scriptingBox-plist { + flex: 30; + width: 30%; height: 100%; box-sizing: border-box; resize: none; padding: 7px; + flex-grow: 100%; } + } + + .scriptingBox-errorMessage { + overflow: auto; + } + + .scripting-params { + background: "beige"; + } } .scriptingBox-toolbar { diff --git a/src/client/views/nodes/ScriptingBox.tsx b/src/client/views/nodes/ScriptingBox.tsx index a5d55018b..0d6f688c8 100644 --- a/src/client/views/nodes/ScriptingBox.tsx +++ b/src/client/views/nodes/ScriptingBox.tsx @@ -19,18 +19,23 @@ const ScriptingSchema = createSchema({}); type ScriptingDocument = makeInterface<[typeof ScriptingSchema, typeof documentSchema]>; const ScriptingDocument = makeInterface(ScriptingSchema, documentSchema); + @observer export class ScriptingBox extends ViewBoxAnnotatableComponent(ScriptingDocument) { + protected multiTouchDisposer?: InteractionUtils.MultiTouchEventDisposer | undefined; + rowProps: any; public static LayoutString(fieldStr: string) { return FieldView.LayoutString(ScriptingBox, fieldStr); } _overlayDisposer?: () => void; @observable private _errorMessage: string = ""; + @observable private paramNum: number = -1; @computed get rawScript() { return StrCast(this.dataDoc[this.props.fieldKey + "-rawScript"], StrCast(this.layoutDoc[this.props.fieldKey + "-rawScript"])); } @computed get compileParams() { return Cast(this.dataDoc[this.props.fieldKey + "-params"], listSpec("string"), Cast(this.layoutDoc[this.props.fieldKey + "-params"], listSpec("string"), [])); } set rawScript(value) { this.dataDoc[this.props.fieldKey + "-rawScript"] = value; } + set compileParams(value) { this.dataDoc[this.props.fieldKey + "-params"] = value; } @action @@ -49,22 +54,65 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent { + for (const entry of error) { + this._errorMessage = this._errorMessage + " " + entry.messageText; + } + } + @action onCompile = () => { + // const params = this.compileParams.reduce((o: ScriptParam, p: string) => { o[p] = "any"; return o; }, {} as ScriptParam); + // const result = CompileScript(this.rawScript, { + // editable: true, + // transformer: DocumentIconContainer.getTransformer(), + // params, + // typecheck: false + // }); + // this._errorMessage = isCompileError(result) ? result.errors.map(e => e.messageText).join("\n") : ""; + // return this.dataDoc[this.props.fieldKey] = result.compiled ? new ScriptField(result) : undefined; const params = this.compileParams.reduce((o: ScriptParam, p: string) => { o[p] = "any"; return o; }, {} as ScriptParam); const result = CompileScript(this.rawScript, { - editable: true, - transformer: DocumentIconContainer.getTransformer(), + editable: false, + transformer: undefined, params, - typecheck: false + typecheck: true }); - this._errorMessage = isCompileError(result) ? result.errors.map(e => e.messageText).join("\n") : ""; - return this.dataDoc[this.props.fieldKey] = result.compiled ? new ScriptField(result) : undefined; + this._errorMessage = ""; + if (result.compiled) { + this._errorMessage = ""; + this.props.Document.data = new ScriptField(result); + } + else { + this.onError(result.errors); + } + this.props.Document.documentText = this.rawScript; } @action onRun = () => { - this.onCompile()?.script.run({}, err => this._errorMessage = err.map((e: any) => e.messageText).join("\n")); + const params = this.compileParams.reduce((o: ScriptParam, p: string) => { o[p] = "any"; return o; }, {} as ScriptParam); + const result = CompileScript(this.rawScript, { + editable: false, + transformer: undefined, + params, + typecheck: true + }); + this._errorMessage = ""; + if (result.compiled) { + // this automatically saves + result.run({}, (err: any) => { + this._errorMessage = ""; + this.onError(err); + }); + this.props.Document.data = new ScriptField(result); + } + else { + this.onError(result.errors); + } + this.props.Document.documentText = this.rawScript; + //this.onCompile()?.script.run({}, err => this._errorMessage = err.map((e: any) => e.messageText).join("\n")); } onFocus = () => { @@ -72,16 +120,50 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent, { x: 0, y: 0 }); } + keyPressed(event: { key: string; }) { + if (event.key === "Enter") { + + } + } + render() { + //this.compileParams = new List(); + const params = ""} - SetValue={value => { this.compileParams = new List(value.split(" ").filter(s => s !== " ")); return true; }} + SetValue={value => { + if (value !== "" && value !== " ") { + this.paramNum++; + const par = this.compileParams; + this.compileParams = new List(value.split(";").filter(s => s !== " ")); + this.compileParams.push.apply(this.compileParams, par); + return true; + } + return false; + }} />; + + const listParams = this.compileParams.map((parameter) => + parameter} + SetValue={value => { + if (value !== "" && value !== " ") { + parameter = value; + } return false; + }} + /> + ); + return (
this.props.isSelected(true) && e.stopPropagation()} > - -