aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/util/Scripting.ts26
-rw-r--r--src/client/views/nodes/ScriptingBox.tsx57
2 files changed, 42 insertions, 41 deletions
diff --git a/src/client/util/Scripting.ts b/src/client/util/Scripting.ts
index bb0681ea7..e6cf50de3 100644
--- a/src/client/util/Scripting.ts
+++ b/src/client/util/Scripting.ts
@@ -63,13 +63,12 @@ export namespace Scripting {
n = first;
obj = second;
} else {
- obj = [first];
- obj.push(second);
+ obj = first;
+ n = first.name;
+ _scriptingDescriptions[n] = second;
if (third !== undefined) {
- obj.push(third);
+ _scriptingParams[n] = third;
}
- console.log("are we here");
- n = first.name;
}
} else if (first && typeof first.name === "string") {
n = first.name;
@@ -82,7 +81,6 @@ export namespace Scripting {
} else if (_scriptingGlobals.hasOwnProperty(n)) {
throw new Error(`Global with name ${n} is already registered, choose another name`);
}
- console.log(n);
_scriptingGlobals[n] = obj;
}
@@ -97,6 +95,12 @@ export namespace Scripting {
export function removeGlobal(name: string) {
if (getGlobals().includes(name)) {
delete _scriptingGlobals[name];
+ if (_scriptingDescriptions[name]){
+ delete _scriptingDescriptions[name];
+ }
+ if (_scriptingParams[name]){
+ delete _scriptingParams[name];
+ }
return true;
}
return false;
@@ -118,6 +122,14 @@ export namespace Scripting {
export function getGlobalObj() {
return _scriptingGlobals;
}
+
+ export function getDescriptions(){
+ return _scriptingDescriptions;
+ }
+
+ export function getParameters(){
+ return _scriptingParams;
+ }
}
export function scriptingGlobal(constructor: { new(...args: any[]): any }) {
@@ -126,6 +138,8 @@ export function scriptingGlobal(constructor: { new(...args: any[]): any }) {
const _scriptingGlobals: { [name: string]: any } = {};
let scriptingGlobals: { [name: string]: any } = _scriptingGlobals;
+const _scriptingDescriptions: { [name: string]: any } = {};
+const _scriptingParams: { [name: string]: any } = {};
function Run(script: string | undefined, customParams: string[], diagnostics: any[], originalScript: string, options: ScriptOptions): CompileResult {
const errors = diagnostics.filter(diag => diag.category === ts.DiagnosticCategory.Error);
diff --git a/src/client/views/nodes/ScriptingBox.tsx b/src/client/views/nodes/ScriptingBox.tsx
index 161ca88e9..60cd02678 100644
--- a/src/client/views/nodes/ScriptingBox.tsx
+++ b/src/client/views/nodes/ScriptingBox.tsx
@@ -40,8 +40,12 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent<FieldViewProps, Sc
@observable private _function: boolean = false;
@observable private _hovered: boolean = false;
@observable private _spaced: boolean = false;
+
@observable private _scriptKeys: any = Scripting.getGlobals();
@observable private _scriptGlobals: any = Scripting.getGlobalObj();
+ @observable private _scriptingDescriptions: any = Scripting.getDescriptions();
+ @observable private _scriptingParams: any = Scripting.getParameters();
+
@observable private _currWord: string = "";
@observable private _suggestions: string[] = [];
@@ -73,26 +77,6 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent<FieldViewProps, Sc
set compileParams(value) { this.dataDoc[this.props.fieldKey + "-params"] = new List<string>(value); }
- // WORK ON THIS
- // in: global, description, params
- @computed get _descriptions() {
- const descrip: string[] = [];
- this._scriptKeys.forEach((element: any) => {
- const result = this._scriptGlobals[element];
- descrip.push(this.getValue(result, true));
- });
- return descrip;
- }
-
- @computed get _scriptParams() {
- const params: string[] = [];
- this._scriptKeys.forEach((element: any) => {
- const result = this._scriptGlobals[element];
- params.push(this.getValue(result, false));
- });
- return params;
- }
-
getValue(result: any, descrip: boolean) {
let value = "";
if (typeof result === "object") {
@@ -113,7 +97,6 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent<FieldViewProps, Sc
return value;
}
-
@action
componentDidMount() {
this.rawScript = ScriptCast(this.dataDoc[this.props.fieldKey])?.script?.originalScript ?? this.rawScript;
@@ -250,18 +233,22 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent<FieldViewProps, Sc
return false;
}
+ if (this.functionName.indexOf(".") > 0) {
+ this._errorMessage = "Name can not include '.'";
+ return false;
+ }
+
this.dataDoc.name = this.functionName;
this.dataDoc.description = this.functionDescription;
//this.dataDoc.parameters = this.compileParams;
this.dataDoc.script = this.rawScript;
- //ScriptManager.Instance.deleteScript(this.dataDoc);
ScriptManager.Instance.addScript(this.dataDoc);
- console.log("created");
-
this._scriptKeys = Scripting.getGlobals();
this._scriptGlobals = Scripting.getGlobalObj();
+ this._scriptingDescriptions = Scripting.getDescriptions();
+ this._scriptingParams = Scripting.getParameters();
}
// overlays document numbers (ex. d32) over all documents when clicked on
@@ -487,16 +474,14 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent<FieldViewProps, Sc
const scriptString = this.rawScript.slice(0, pos - 2);
this._currWord = scriptString.split(" ")[scriptString.split(" ").length - 1];
this._suggestions = [];
- const index = this._scriptKeys.indexOf(this._currWord);
- const params = StrCast(this._scriptParams[index]);
+ const params = StrCast(this._scriptingParams[this._currWord]);
this._suggestions.push(params);
return (this._suggestions);
}
getDescription(value: string) {
- const index = this._scriptKeys.indexOf(value);
- const descrip = this._descriptions[index];
+ const descrip = this._scriptingDescriptions[value];
let display = "";
if (descrip !== undefined) {
if (descrip.length > 0) {
@@ -507,12 +492,11 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent<FieldViewProps, Sc
}
getParams(value: string) {
- const index = this._scriptKeys.indexOf(value);
- const descrip = this._scriptParams[index];
+ const params = this._scriptingParams[value];
let display = "";
- if (descrip !== undefined) {
- if (descrip.length > 0) {
- display = descrip;
+ if (params !== undefined) {
+ if (params.length > 0) {
+ display = params;
}
}
return display;
@@ -547,8 +531,11 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent<FieldViewProps, Sc
} else {
func = firstScript.slice(indexS + 1, firstScript.length + 1);
}
- const indexF = this._scriptKeys.indexOf(func);
- return this._scriptParams[indexF];
+ if (this._scriptingParams[func]) {
+ return this._scriptingParams[func];
+ } else {
+ return "";
+ }
}
@action