Skip to content

Commit

Permalink
Added support for default values in params
Browse files Browse the repository at this point in the history
  • Loading branch information
megastary committed Aug 1, 2020
1 parent b89488e commit 6a987b3
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lazy-admin",
"version": "0.4.0",
"version": "0.4.1",
"description": "GUI for PowerShell scripts to simplify day to day IT tasks.",
"productName": "Lazy Admin",
"cordovaId": "eu.houby-studio.lazy-admin",
Expand Down
1 change: 1 addition & 0 deletions scripts-definitions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ This is only example, there are many possibilities how to write definitions.
{
"parameter": "${parameterName}",
"format": "some format ${parameterName}",
"value": "some default value",
"required": ${Boolean},
"type": "${inputType}",
"hint": "${hint}"
Expand Down
31 changes: 27 additions & 4 deletions scripts-definitions/base-module-example.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"base-module-example": {
"version": "0.1.4",
"version": "0.1.5",
"icon": "mdi-powershell",
"displayName": {
"default": "Base commands",
Expand Down Expand Up @@ -402,7 +402,14 @@
"passedParamName": "Name"
}
],
"parameters": [],
"parameters": [
{
"parameter": "Dummy",
"value": "For test purposes",
"required": false,
"type": "String"
}
],
"commandBlock": "Stop-Process {{Id}} -Force; if ($?) {Write-Output \"Process {{Name}} killed succesfully\"}"
}
]
Expand Down Expand Up @@ -491,6 +498,7 @@
{
"parameter": "SampleString",
"format": "-SampleString \"*{{SampleString}}*\"",
"value": "something",
"required": false,
"type": "String",
"hint": {
Expand All @@ -502,6 +510,7 @@
{
"parameter": "SambleNumber",
"format": "-SambleNumber \"*{{SambleNumber}}*\"",
"value": 666,
"required": false,
"type": "Number",
"hint": {
Expand All @@ -524,6 +533,7 @@
{
"parameter": "SampleSwitch",
"format": "-SampleSwitch",
"value": false,
"required": false,
"type": "Switch",
"hint": {
Expand Down Expand Up @@ -557,6 +567,7 @@
{
"parameter": "Name",
"format": "-Name \"*{{Name}}*\"",
"value": "notepad",
"required": true,
"type": "String",
"hint": {
Expand Down Expand Up @@ -588,8 +599,20 @@
"joinFormat": " and "
}
],
"parameters": [],
"commandBlock": "Write-Output 'You have selected processes with Ids {{Id}} and names {{Name}}.'"
"parameters": [
{
"parameter": "Note",
"value": "Just for fun",
"required": true,
"type": "String",
"hint": {
"default": "Supply note to command.",
"en-us": "Supply note to command.",
"cs-cz": "Zadejte poznámku k příkazu."
}
}
],
"commandBlock": "Write-Output 'You have selected processes with Ids {{Id}} and names {{Name}}. You also noted: {{Note}}'"
},
{
"acceptsParams": "single",
Expand Down
26 changes: 26 additions & 0 deletions src/pages/ScriptsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,20 @@ export default {
showCommandDiag (commandCtx) {
this.currentCommand = commandCtx
this.currentCommandMaster = commandCtx
// Loop through parameterSets and their parameters to set default values for each parameter
let parametersSetsNum = 1
if (this.resultsSelected[this.currentWorkflowIndex - 1]) {
if (this.resultsSelected[this.currentWorkflowIndex - 1].length > 1) {
parametersSetsNum = this.resultsSelected[this.currentWorkflowIndex - 1].length
}
}
for (let paramSetIndex = 1; paramSetIndex <= parametersSetsNum; paramSetIndex++) {
for (let i = 0; i < this.currentCommand.parameters.length; i++) {
let param = this.currentCommand.parameters[i]
this.$set(this.returnParams, [`${paramSetIndex}__${param.parameter}`], param.value)
// this.returnParams[`${paramSetIndex}__${param.parameter}`] = param.value
}
}
this.displayCommandDiag = !this.displayCommandDiag
},
historyShowCommandDiag (commandCtx) {
Expand Down Expand Up @@ -864,6 +878,18 @@ export default {
this.returnParams['1__' + this.currentCommandMaster.workflow[this.currentWorkflowIndex].passedParameters[passedParamsIndex].parameter] = parameterString
}
}
// Loop through parameterSets and their parameters to set default values for each parameter
let parametersSetsNum = 1
if (this.resultsSelected[this.currentWorkflowIndex].length > 1) {
parametersSetsNum = this.resultsSelected[this.currentWorkflowIndex].length
}
for (let paramSetIndex = 1; paramSetIndex <= parametersSetsNum; paramSetIndex++) {
for (let i = 0; i < this.currentCommand.parameters.length; i++) {
let param = this.currentCommand.parameters[i]
this.$set(this.returnParams, [`${paramSetIndex}__${param.parameter}`], param.value)
// this.returnParams[`${paramSetIndex}__${param.parameter}`] = param.value
}
}
if (this.currentCommand.joinParamsAsString) { this.resultsSelected[this.currentWorkflowIndex] = [] } // clear resultsSelected to make command dialog behave in single input mode
this.currentWorkflowIndex++
// Reactivity solution how to add keys to object https://vuejs.org/v2/guide/reactivity.html#Change-Detection-Caveats
Expand Down

0 comments on commit 6a987b3

Please sign in to comment.