From 6e055a4953c55f297626e75796698e51bb83a150 Mon Sep 17 00:00:00 2001 From: anika-ahluwalia Date: Wed, 20 May 2020 15:03:35 -0500 Subject: added booleans and drop down choices for params, fixed deleting and modifying params --- src/client/views/nodes/ScriptingBox.tsx | 168 +++++++++++++++++++++++++++++--- 1 file changed, 156 insertions(+), 12 deletions(-) (limited to 'src/client/views/nodes/ScriptingBox.tsx') diff --git a/src/client/views/nodes/ScriptingBox.tsx b/src/client/views/nodes/ScriptingBox.tsx index f84b996ab..55525ee41 100644 --- a/src/client/views/nodes/ScriptingBox.tsx +++ b/src/client/views/nodes/ScriptingBox.tsx @@ -15,10 +15,10 @@ import { OverlayView } from "../OverlayView"; import { DocumentIconContainer, DocumentIcon } from "./DocumentIcon"; import { List } from "../../../fields/List"; import { DragManager } from "../../util/DragManager"; -import { Doc } from "../../../fields/Doc"; -import { Dropdown } from "prosemirror-menu"; -import { isNumber } from "util"; import { faSearch, faKaaba } from "@fortawesome/free-solid-svg-icons"; +import { undoBatch } from "../../util/UndoManager"; +import { Utils } from "../../../Utils"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; const ScriptingSchema = createSchema({}); type ScriptingDocument = makeInterface<[typeof ScriptingSchema, typeof documentSchema]>; @@ -40,11 +40,14 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent e.stopPropagation(); + set compileParams(value) { this.dataDoc[this.props.fieldKey + "-params"] = value; } @action @@ -197,9 +200,37 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent { this.compileParams.splice(num, 1); - // delete from fields, delete from _paramNames, _paramTypes, _paramValues + const name = this._paramsNames[this._paramsNames.length - num - 1]; + this.props.Document[name] = undefined; + this._paramsNames.splice(this._paramsNames.length - num - 1, 1); + this._paramsTypes.splice(this._paramsTypes.length - num - 1, 1); + this._paramsValues.splice(this._paramsValues.length - num - 1, 1); + } + + @undoBatch + viewChanged = (e: React.ChangeEvent) => { + //@ts-ignore + this.document._viewType = e.target.selectedOptions[0].value; + } + + @action + selected = (val: string, index: number, name: string) => { + this.stopPropagation; + this.props.Document[name] = val; + this._paramsValues[index] = val; } + @action + toggleCollapse = (num: number) => { + console.log("hello"); + if (this._paramsCollapsed[num]) { + this._paramsCollapsed[num] = false; + } else { + this._paramsCollapsed[num] = true; + } + } + + render() { const params = this.onDrop(e, de, i)} SetValue={value => { if (value !== "" && value !== " ") { - this.compileParams[i] = value; - parameter = value; - return true; + const parameter = value.split(":"); + if (parameter[1] !== undefined) { + if (parameter[1].trim() === "Doc" || parameter[1].trim() === "string" + || parameter[1].split("|")[1] || parameter[1].trim() === "number" + || parameter[1].trim() === "boolean") { + + if ((!!!this._paramsNames.includes(parameter[0].trim()) && + this.props.Document[parameter[0].trim()] === undefined) || parameter[0].trim() === this._paramsNames[this._paramsNames.length - i - 1]) { + this._errorMessage = ""; + this._paramsNames[this._paramsNames.length - i - 1] = parameter[0].trim(); + this._paramsTypes[this._paramsTypes.length - i - 1] = parameter[1].trim(); + this._paramsValues[this._paramsValues.length - i - 1] = "undefined"; + this.compileParams[i] = value; + return true; + + } else { + this._errorMessage = "this name has already been used"; + return false; + } + } else { + this._errorMessage = "this type is not supported"; + return false; + } + } else { + this._errorMessage = "must set type of parameter"; + return false; + } } else { this.onDelete(i); return true; @@ -348,8 +405,7 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent {parameter + ":" + this._paramsTypes[i] + " = "} -
+
{parameter + ":" + this._paramsTypes[i] + " = "}
-
+
: null} + {this._paramsTypes[i].split("|")[1] ?
+
+
+ {parameter + ":" + this._paramsTypes[i] + " = "} +
+ +
+
+ +
+
+ +
+
+
+
+
+
: null} + + {this._paramsTypes[i] === "boolean" ?
+
+
+ {parameter + ":" + this._paramsTypes[i] + " = "} +
+
+ StrCast(this._paramsValues[i])} + SetValue={value => { + runInAction(() => { + if (value !== "" && value !== " ") { + if (value.trim() === "true") { + console.log("hello"); + this._errorMessage = ""; + // does not set this + this.props.Document[parameter] = true; + // sets this + this._paramsValues[i] = "true"; + return true; + } else { + if (value.trim() === "false") { + this._errorMessage = ""; + this.props.Document[parameter] = false; + this._paramsValues[i] = "false"; + return true; + } else { + this._errorMessage = "not a boolean"; + return false; + } + } + } else { + return false; + } + }); + return true; + }} + /> +
+
+
: null} -- cgit v1.2.3-70-g09d2