diff --git a/client/src/app/features/recipes/recipe-details/recipe-list/recipe-list.component.html b/client/src/app/features/recipes/recipe-details/recipe-list/recipe-list.component.html index 356935a..dab44e1 100644 --- a/client/src/app/features/recipes/recipe-details/recipe-list/recipe-list.component.html +++ b/client/src/app/features/recipes/recipe-details/recipe-list/recipe-list.component.html @@ -5,6 +5,45 @@ + diff --git a/client/src/app/shared/helpers/debugger.ts b/client/src/app/shared/helpers/debugger.ts index 12bda80..701b8a3 100644 --- a/client/src/app/shared/helpers/debugger.ts +++ b/client/src/app/shared/helpers/debugger.ts @@ -35,6 +35,28 @@ export class Debugger { "!tb get:: - get value of variable in angular", "!tb fn:: <...args> - execute the function with args", ]; + + exposeVarsToJs = (var_map: any) => { + let varMap = var_map as any; + + Object.keys(varMap).forEach((key: string) => { + let value = ""; + try { + value = JSON.stringify(varMap[key] as any); + } catch(e) { + this.output.push(e); + return; + } + console.log("exporting", value); + if(value != ""){ + let evalCmd = "window."+key+" = "+value+";"; + let evalResult = eval(evalCmd); + // + // this.output.push(evalResult); + } + }); + } + // evaluate eval(comp: any) { let enableCommand = document.getElementById('command-enable') as any; @@ -52,6 +74,8 @@ export class Debugger { declPrefixFlag = true; } else if(line == "tbs;"){ declPrefixFlag = false; + // export all stored + this.exposeVarsToJs(holdon); } // this.output.push(line); @@ -91,32 +115,69 @@ export class Debugger { if(cmd.startsWith("fn::")){ let execFn = cmd.substring(4); + if(cmd.includes("!tb")){ + execFn = cmd; + } // get some args let args = execFn.split(' '); execFn = args[0]; - if(args[1].includes("Var::") || args[1].includes("var::")){ - args[1] = holdon[args[1].split("::")[1]] - } - if(args[1].includes(',')){ - args = args[1].split(','); - } else { - args = [args[1]]; + if(args.length > 1){ + if(args[1].includes("Var::") || args[1].includes("var::")){ + args[1] = holdon[args[1].split("::")[1]] + } + if(args[1].includes(',')){ + args = args[1].split(','); + } else { + args = [args[1]]; + } } console.log("args>", args); // try exec class function try{ - - let res = (comp as any)[execFn].apply("", args); - console.log("res>",res); - this.output.push(res); + if(args.length > 1){ + let res = (comp as any)[execFn].apply("", args); + console.log("res>",res); + this.output.push(res); + } else { + let res = (comp as any)[execFn]; + console.log("res>",res); + this.output.push(res); + } } catch (e) { this.output.push(e); } } else if(cmd.startsWith("get::")){ let getter = cmd.substring(5); - this.output.push(JSON.stringify(comp[getter])); + + if(cmd.includes("->")){ + let arrowSpl = cmd.split("->"); + getter = arrowSpl[0].trim().substring(5); + console.log(arrowSpl); + try { + let test_val = JSON.stringify(comp[getter]); + } catch(e){ + this.output.push(e); + this.output.push("\nSee console log for actual value"); + console.log(comp[getter]); + } + + let assignTo = arrowSpl[1].trim(); + holdon[assignTo] = comp[getter]; + console.log("getter",getter,"assign",comp[getter],"to",assignTo); + + } else { + try { + this.output.push(JSON.stringify(comp[getter])); + } catch(e){ + this.output.push(e); + this.output.push("\nSee console log for actual value"); + console.log(comp[getter]); + } + } + + } else if(cmd.startsWith("var::")){ let varname = cmd.substring(5); this.output.push(JSON.stringify(holdon[varname])); @@ -125,6 +186,12 @@ export class Debugger { break; } + if(line.startsWith("!tb")){ + let varMap = holdon as Map; + if(varMap.size > 0){ + this.exposeVarsToJs(holdon); + } + } } else if (!line.startsWith("//") && line != ""){ if(!line.startsWith("window") && !line.startsWith("let") && !line.startsWith("var")){