From 6a987b318162132e3e93011a09688ac1fd4b72da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=A0indel=C3=A1=C5=99?= <25355950+megastary@users.noreply.github.com> Date: Sat, 1 Aug 2020 22:36:21 +0200 Subject: [PATCH] Added support for default values in params --- package.json | 2 +- scripts-definitions/README.md | 1 + scripts-definitions/base-module-example.json | 31 +++++++++++++++++--- src/pages/ScriptsPage.vue | 26 ++++++++++++++++ 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index f9ccabd..a27555d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts-definitions/README.md b/scripts-definitions/README.md index f51227e..a5b4299 100644 --- a/scripts-definitions/README.md +++ b/scripts-definitions/README.md @@ -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}" diff --git a/scripts-definitions/base-module-example.json b/scripts-definitions/base-module-example.json index b673ca4..48feff6 100644 --- a/scripts-definitions/base-module-example.json +++ b/scripts-definitions/base-module-example.json @@ -1,6 +1,6 @@ { "base-module-example": { - "version": "0.1.4", + "version": "0.1.5", "icon": "mdi-powershell", "displayName": { "default": "Base commands", @@ -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\"}" } ] @@ -491,6 +498,7 @@ { "parameter": "SampleString", "format": "-SampleString \"*{{SampleString}}*\"", + "value": "something", "required": false, "type": "String", "hint": { @@ -502,6 +510,7 @@ { "parameter": "SambleNumber", "format": "-SambleNumber \"*{{SambleNumber}}*\"", + "value": 666, "required": false, "type": "Number", "hint": { @@ -524,6 +533,7 @@ { "parameter": "SampleSwitch", "format": "-SampleSwitch", + "value": false, "required": false, "type": "Switch", "hint": { @@ -557,6 +567,7 @@ { "parameter": "Name", "format": "-Name \"*{{Name}}*\"", + "value": "notepad", "required": true, "type": "String", "hint": { @@ -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", diff --git a/src/pages/ScriptsPage.vue b/src/pages/ScriptsPage.vue index 4dc8652..2b2c83e 100644 --- a/src/pages/ScriptsPage.vue +++ b/src/pages/ScriptsPage.vue @@ -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) { @@ -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