Skip to content

Commit

Permalink
Workflow WIP
Browse files Browse the repository at this point in the history
Started working on workflows, several changes to script definitions made. In other news, changed default results pagination to All, made scripts table more responsive by hiding icons on extra small devices
  • Loading branch information
megastary committed Jul 13, 2020
1 parent d333992 commit 1cc14a7
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 62 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lazy-admin",
"version": "0.2.4",
"version": "0.2.5",
"description": "GUI for PowerShell scripts to simplify day to day IT tasks.",
"productName": "Lazy Admin",
"cordovaId": "eu.houby-studio.lazy-admin",
Expand All @@ -18,7 +18,7 @@
"electron-log": "^4.1.1",
"electron-updater": "^4.3.1",
"node-powershell": "^4.0.0",
"quasar": "^1.12.8",
"quasar": "^1.12.11",
"regedit": "^3.0.3",
"vue-clipboard2": "^0.3.1",
"vue-i18n": "^8.0.0",
Expand Down
10 changes: 7 additions & 3 deletions scripts-definitions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Possible values for definitions file:
* icon: name of icon, if omitted, powershell icon is used
* returns: type of the result, which application should expect after command is executed
* insidePsSession: whether command should be run in Remote PSSession or locally
* usesLoggedUser: whether command utilizes $CredentialObject or $LazySession created upon logging in. May be ommited when insidePsSession is true
* confirm: before executing the command, ask user for confirmation
* friendlyName: provided in languages you want to support, this is displayed to user to get better idea what the command might do
* description: provided in languages you want to support, this is displayed to user to best describe what the command might do
Expand Down Expand Up @@ -111,6 +112,7 @@ This is only example, there are many possibilities how to write definitions.
"icon": "{icon-name}",
"returns": "{returnType}",
"insidePsSession": {Boolean},
"usesLoggedUser": {Boolean},
"friendlyName": "{friendlyName}",
"description": "{Description}",
"parameters": [
Expand Down Expand Up @@ -143,8 +145,10 @@ This is only example, there are many possibilities how to write definitions.
"workflow": [
{
"passedParameters": [
"parameter": "{parameterName}",
"propertyName": "{propertyName}"
{
"parameter": "{parameterName}",
"propertyName": "{propertyName}"
}
],
"parameters": [
{
Expand All @@ -160,7 +164,7 @@ This is only example, there are many possibilities how to write definitions.
},
{
"commandBlock": "{Verb-Noun {{parameterName}}}",
"passthru": {Boolean},
"passthru": {single|multiple|none},
"confirm": {Boolean}
}
]
Expand Down
55 changes: 54 additions & 1 deletion 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.0",
"version": "0.1.1",
"icon": "mdi-powershell",
"displayName": {
"default": "Base commands",
Expand Down Expand Up @@ -265,6 +265,59 @@
}
],
"commandBlock": "Write-Output \"String:{{String}}`nNumber:{{Number}}`nSwitch:{{Switch}}`nBoolean:{{Boolean}}`nScriptBlock:{{ScriptBlock}}\""
},
{
"commandName": "Get-CommandExamples",
"type": "workflow",
"icon": "mdi-checkbox-multiple-marked",
"returns": "PSObject",
"id": "Name",
"insidePsSession": false,
"friendlyName": {
"default": "Get examples for command",
"en-us": "Get examples for command",
"cs-cz": "Získat příklady pro příkaz"
},
"description": {
"default": "Example workflow, which obtains list of matching commands based on first query, then gets examples for selected one.",
"en-us": "Example workflow, which obtains list of matching commands based on first query, then gets examples for selected one.",
"cs-cz": "Ukázkové workflow, které získá seznam odpovídajících příkazů na základě prvního dotazu, následně získá příklady pro zvolený příkaz."
},
"parameters": [
{
"parameter": "Name",
"format": "-Name \"*{{Name}}*\"",
"required": true,
"type": "String",
"hint": {
"default": "Supply name of command",
"en-us": "Supply name of the command",
"cs-cz": "Zadejte název příkazu"
}
}
],
"commandBlock": "Get-Command {{Name}} | Select-Object Name, @{n='Type';e={$_.CommandType.ToString()}} | ConvertTo-Json -Compress",
"workflow": [
{
"passedParameters": [
{
"parameter": "Name",
"propertyName": "Name"
}
],
"parameters": [
{
"parameter": "{parameterName}",
"required": true,
"type": "{inputType}",
"hint": "{hint}"
}
],
"commandBlock": "{Verb-Noun {{parameterName}}}",
"passthru": "single",
"confirm": false
}
]
}
]
}
Expand Down
44 changes: 34 additions & 10 deletions src/pages/ScriptsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
<q-card class="full-width">
<q-card-section>
<div class="text-h6">
<q-icon :name="currentCommand.icon ? currentCommand.icon : 'mdi-powershell'"></q-icon> {{ $t('results', { commandName: currentCommand.commandName }) }}
<q-icon :name="currentCommand.icon ? currentCommand.icon : 'mdi-powershell'"></q-icon> {{ $t('results', { commandName: currentCommand.commandName }) }} {{ currentCommand.workflow ? 'Workflow' : '' }}
</div>
</q-card-section>
<q-card-section>
Expand All @@ -122,7 +122,10 @@
<q-table
:data="results.output"
:columns="resultsColumns"
row-key="name"
:pagination.sync="outputPagination"
:selection="resultsTableSelection"
:selected.sync="resultsSelected"
:row-key="results.id ? results.id : 'id'"
>
</q-table>
</div>
Expand Down Expand Up @@ -191,7 +194,7 @@
:data="scriptsArray"
:columns="scriptsColumns"
:filter="searchText"
:pagination.sync="pagination"
:pagination.sync="scriptsPagination"
row-key="parameter"
hide-bottom
hide-header
Expand Down Expand Up @@ -301,8 +304,10 @@ export default {
data () {
return {
currentCommand: {}, // User click "Execute" on datatable, chosen command is set to this object, which gets rendered with dialog
currentWorkflowIndex: 0, // Index of currently workflow step to run
returnParams: {}, // User defined parameters from Command Dialog
results: {}, // Command result object displayed in Results Dialog
resultsSelected: [], // Array of selected objects from Results Dialog
displayCommandDiag: false,
displayHelpDiag: false,
displayResultsDiag: false,
Expand All @@ -314,18 +319,22 @@ export default {
'Switch': ['q-toggle', false]
},
scriptsColumns: [
{ name: 'icon', align: 'center', label: 'Icon', field: row => row.icon, sortable: true },
{ name: 'icon', align: 'center', label: 'Icon', field: row => row.icon, sortable: true, classes: 'gt-xs' },
{ name: 'commandName', required: true, label: 'Command Name', align: 'left', field: row => row.commandName, format: val => `${val}`, sortable: true },
{ name: 'friendlyName', label: 'Friendly Name', align: 'left', field: row => row.friendlyName ? row.friendlyName[(this.$i18n.locale)] ? row.friendlyName[(this.$i18n.locale)] : row.friendlyName['default'] : '', format: val => `${val}`, sortable: true, classes: 'hidden' },
{ name: 'description', align: 'left', label: 'Description', field: row => row.description ? row.description[(this.$i18n.locale)] ? row.description[(this.$i18n.locale)] : row.description.default : '', sortable: true, classes: 'gt-sm' },
{ name: 'spacer', align: 'center', label: 'Spacer', field: '', sortable: false, classes: 'full-width' },
{ name: 'favorite', align: 'center', label: 'Icon', field: 'star', sortable: true },
{ name: 'help', align: 'center', label: 'Icon', field: 'help', sortable: true },
{ name: 'favorite', align: 'center', label: 'Icon', field: 'star', sortable: true, classes: 'gt-xs' },
{ name: 'help', align: 'center', label: 'Icon', field: 'help', sortable: true, classes: 'gt-xs' },
{ name: 'execute', label: 'Execute', field: 'Execute', sortable: true, sort: (a, b) => parseInt(a, 10) - parseInt(b, 10) }
],
pagination: {
scriptsPagination: {
// all records per page
rowsPerPage: 0
},
outputPagination: {
// all records per page, user may change that via GUI
rowsPerPage: 0
}
}
},
Expand Down Expand Up @@ -361,6 +370,19 @@ export default {
}
return columns
}
},
resultsTableSelection: {
get () {
if (this.currentCommand.workflow) {
if (this.currentCommand.workflow[this.currentWorkflowIndex].passthru) {
return this.currentCommand.workflow[this.currentWorkflowIndex].passthru
} else {
return 'none'
}
} else {
return 'none'
}
}
}
},
methods: {
Expand Down Expand Up @@ -502,12 +524,12 @@ export default {
for (let i = 0; i < this.currentCommand.parameters.length; i++) {
let param = this.currentCommand.parameters[i]
let input = this.returnParams[param.parameter]
console.log('Checking input: ', input)
// console.log('Checking input: ', input)
if (input) {
console.log('input is here!')
// console.log('input is here!')
// If parameter has additional text format, insert it
if (param.format) {
console.log('format is here!')
// console.log('format is here!')
resultCommand = resultCommand.replace(`{{${param.parameter}}}`, `${param.format}`)
}
// If parameter was supplied, insert param in place of template variable
Expand All @@ -527,6 +549,7 @@ export default {
this.$pwsh.shell.addCommand(resultCommand)
}
this.$pwsh.shell.invoke().then(output => {
// console.log('Command results: ', output)
// Code block to handle PowerShell return data
let data
let params
Expand All @@ -546,6 +569,7 @@ export default {
error: params.error,
returnType: 'object',
params: params,
id: this.currentCommand.id,
output: dataArray
}
} catch (error) {
Expand Down
Loading

0 comments on commit 1cc14a7

Please sign in to comment.