bugy / script-server

Web UI for your scripts with execution management
Other
1.61k stars 249 forks source link

Request Dynamic Parameters #476

Open dwestness opened 3 years ago

dwestness commented 3 years ago

I would like to request the ability to define dynamic parameter sets.

For example, Only display parameter #3 if user has selected applicable value first for parameter #2 for instance.

bugy commented 3 years ago

Hi @dwestness, how many dynamic parameters do you have? And are they free-text or list values? You might have a look at:

dwestness commented 3 years ago

Thanks @bugy for pointing me in this direction. I had overlooked the option for dynamic includes here. I was able to get it working for my immediate needs perfectly.

For this use case i have a list parameter in main with options for "Add, Remove, Query" and have another parameter that becomes available whenever either "Add" or "Remove" is chosen and not available when "Query" is selected.

For this I had to create 2 include JSON files to support the ${PARAMETER_NAME} variable (one Add.JSON and one Remove.JSON) for the target. The files are identical in this case. Does that seem like the right way to go about it?

bugy commented 3 years ago

Yes, this seems the only way for now

agail commented 3 years ago

For this use case i have a list parameter in main with options for "Add, Remove, Query" and have another parameter that becomes available whenever either "Add" or "Remove" is chosen and not available when "Query" is selected.

For this I had to create 2 include JSON files to support the ${PARAMETER_NAME} variable (one Add.JSON and one Remove.JSON) for the target. The files are identical in this case. Does that seem like the right way to go about it?

@dwestness sounds like something I'm trying to achieve as well. Care to share an example?

sbalakrishna commented 1 year ago

@dwestness , I am unable to understand how to use this feature. Can you explain me clearly with an example?

bugy commented 1 year ago

@agail @sbalakrishna for the usecase above, script json should config smth like:

{
  "include": "${Parameter name}.json"
}

And then create 2 json files (identical to each other), Add.json and Query.json (according to possible values). Both of these jsons should have body like:

{
  "parameters": [
    {
       "name": "query text"
    }
  ]
}
agail commented 1 year ago

@agail @sbalakrishna for the usecase above, script json should config smth like:

{
  "include": "${Parameter name}.json"
}

And then create 2 json files (identical to each other), Add.json and Query.json (according to possible values). Both of these jsons should have body like:

{
  "parameters": [
    {
       "name": "query text"
    }
  ]
}

@bugy I must have a thick skull, all these includes are very confusing to me. I guess it's easy when you know how, but I've been at it for a couple of hours, a small tutorial would be nice.

For example, in UI I wish to have three fields: [device] [action] [node] Device is a list with predefined values; device1 and device2 Action is a list with predefined values; on and off Node should be populated with the values of selected [device]. The field Node newer show up, is that how its supposed to work or am I missing something? Running most recent dev docker image

mockup.json

{
  "name": "Dynamic select",
  "script_path": "bash -x -c \"echo ${@};env\"",
  "include": "${PARAM_DEVICE}.json",
  "parameters": [
    {
      "name": "device",
      "type": "list",
      "values": [
        "device1",
        "device2"
      ]
    },
    {
      "name": "action",
      "type": "list",
      "values": [
        "on",
        "off"
      ]
    }
  ]
}

device1.json

{
  "parameters": [
    {
      "name": "nodes",
      "type": "list",
      "constant": false,
      "values": {
        "script": "scripts/test/mockup.sh device1 list",
        "shell": false
      }
    }
  ]
}
bugy commented 1 year ago

Hi @agail you don't need to use include feature, this is needed when you want to add or remove a parameter dynamically. This is what the ticket's author was asking You just need dynamic values, so remove the include section and the file, and move the node parameter to the main json And then replace "device 1" in values with ${device}. I'm not sure, why you were using PARAM_DEVICE

agail commented 1 year ago

Hi @agail you don't need to use include feature, this is needed when you want to add or remove a parameter dynamically. This is what the ticket's author was asking You just need dynamic values, so remove the include section and the file, and move the node parameter to the main json And then replace "device 1" in values with ${device}. I'm not sure, why you were using PARAM_DEVICE

Thanks for the quick reply @bugy, I'm slowly getting the grasp of it. Since I apparently misunderstood the whole include thing, I thought I had to use the PARAM-variables produced. Without knowing the named PARAM to use, listing them with env at script execution would let med identify them. Completely wrong, obviously ;)

+ env
PYTHONUNBUFFERED=1
HOSTNAME=test-script-srv
[snip]
PARAM_ACTION=on
PARAM_DEVICE=device1
bugy commented 1 year ago

Yeah, parameters are resolved before env variables are available