Archi Forum

Archi Plug-ins => jArchi => Topic started by: dvenetas on March 22, 2021, 13:07:27 PM

Title: Get user input on script run
Post by: dvenetas on March 22, 2021, 13:07:27 PM
Hello!,

Can we accept user input in Archi console when we run a script?

Nashorn readLine() function seems to not be working:

Script Error: javax.script.ScriptException: ReferenceError: "readline" is not defined in file:/D:/projects/archi-script/scripts/restclient.ajs at line number 61
Script Error: javax.script.ScriptException: ReferenceError: "readLine" is not defined in file:/D:/projects/archi-script/scripts/restclient.ajs at line number 61

Also:
    console.log("Give user");
    var buffer = new java.io.BufferedReader(new java.io.InputStreamReader(java.lang.System.in));
    var uname = buffer.readLine();

throws:
    Script Error: java.lang.RuntimeException: java.io.IOException: The handle is invalid

Is there a way to get user to provide input at runtime?
Title: Re: Get user input on script run
Post by: Phil Beauvoir on March 22, 2021, 13:15:33 PM
Hi, the console is for output only.

Please take time to read through the wiki. This section concerns the console and user input:

https://github.com/archimatetool/archi-scripting-plugin/wiki/The-Console%2C-Dialogs-and-Other-Utilities
Title: Re: Get user input on script run
Post by: dvenetas on March 22, 2021, 13:22:10 PM
Thank you!! hadn't seen this part.
Title: Re: Get user input on script run
Post by: René on March 25, 2021, 09:27:38 AM
Are there any other ways for input during run?

var name = window.prompt("Please enter your name", "Default Name");

I ask for checkboxes, comboboxes, etc.
Title: Re: Get user input on script run
Post by: Phil Beauvoir on March 25, 2021, 09:29:59 AM
Quote from: René on March 25, 2021, 09:27:38 AM
Are there any other ways for input during run?

var name = window.prompt("Please enter your name", "Default Name");

I ask for checkboxes, comboboxes, etc.

Have a look at this topic - https://forum.archimatetool.com/index.php?topic=843.0
Title: Re: Get user input on script run
Post by: Jean-Baptiste Sarrodie on March 25, 2021, 10:02:37 AM
Hi,

FWIW, I'm working on a small JS library to address this need. The goal is to make it easy to describe the dialog UI, then "run" it and get a data structure (JSON) as a result.

I'll share it as soon as possible, but don't expect something ready before one or two months.

Regards,

JB
Title: Re: Get user input on script run
Post by: mohitd on November 07, 2022, 18:28:36 PM
Quote from: Jean-Baptiste Sarrodie on March 25, 2021, 10:02:37 AMHi,

FWIW, I'm working on a small JS library to address this need. The goal is to make it easy to describe the dialog UI, then "run" it and get a data structure (JSON) as a result.

I'll share it as soon as possible, but don't expect something ready before one or two months.

Regards,

JB

Hello Jean-Baptiste Sarrodie,

Can you please direct me to where the JS library is? The things discussed in this thread are exactly what I am looking for. Thanks!

Regards,
Mohit
Title: Re: Get user input on script run
Post by: Jean-Baptiste Sarrodie on November 07, 2022, 19:10:33 PM
Hi,

Quote from: mohitd on November 07, 2022, 18:28:36 PMCan you please direct me to where the JS library is? The things discussed in this thread are exactly what I am looking for. Thanks!

Unfortunately, I wasn't able to finish this library.

Maybe this experiment made by Thomas Rohde could help you: https://gist.github.com/ThomasRohde/73d250bcf8e27bf76d7b7f92977f7c83

Regards,

JB
Title: Re: Get user input on script run
Post by: Thomas Rohde on November 08, 2022, 13:26:48 PM
I have created a forms library for easy modelling of web forms using JSON schemas.

The library uses the JSON Form library (https://github.com/jsonform/jsonform/). Go there to fetch the library and dependencies.

JArchi library gist (https://gist.github.com/ThomasRohde/2287bb69346283f89e963d429d1d9195) (show_form.js), including an example application.
Title: Re: Get user input on script run
Post by: Thomas Rohde on November 12, 2022, 07:20:19 AM
I have reworked my forms utility to use JSON Editor (https://github.com/json-editor/json-editor) instead.

This library gives more control over grids, and integrates a number of useful editors.

The gist is here (https://gist.github.com/ThomasRohde/342b8551428ad56f6c9b2233e7fa4878).

The gist has two examples, including a handy editor for documentation properties, which allows easy editing of Markdown, ready for another script to publish to Confluence.

Form1.pngmarkdown.png