Skip to content

Commit fdb43f3

Browse files
committed
Fixed bugs with confirm dialog, added history saving
1 parent 0c45bf2 commit fdb43f3

File tree

8 files changed

+208
-153
lines changed

8 files changed

+208
-153
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lazy-admin",
3-
"version": "0.3.4",
3+
"version": "0.3.5",
44
"description": "GUI for PowerShell scripts to simplify day to day IT tasks.",
55
"productName": "Lazy Admin",
66
"cordovaId": "eu.houby-studio.lazy-admin",
@@ -17,6 +17,7 @@
1717
"axios": "^0.19.2",
1818
"electron-log": "^4.1.1",
1919
"electron-updater": "^4.3.1",
20+
"lodash": "^4.17.19",
2021
"node-powershell": "^4.0.0",
2122
"quasar": "^1.12.13",
2223
"regedit": "^3.0.3",

src/pages/ScriptsPage.vue

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
:rules="param.required ? [ val => val && val.length > 0 || $t('requiredField') ] : [] "
8181
:hint="`${param.required ? $t('requiredParam') : $t('optionalParam') } | ${param.type} | ${param.hint ? param.hint[language] || param.hint['default'] : ''}`"
8282
:type="paramType[param.type][1]"
83-
@keyup.enter="$event.target.nextElementSibling.focus()"
83+
@keydown.enter.prevent
8484
filled
8585
clearable
8686
lazy-rules
@@ -297,7 +297,10 @@
297297
no-backdrop-dismiss
298298
>
299299
<q-card class="full-width">
300-
<q-form autofocus>
300+
<q-form
301+
autofocus
302+
@submit="executeCommand"
303+
>
301304
<q-card-section>
302305
<div class="text-h6">
303306
<q-icon
@@ -330,7 +333,6 @@
330333
<q-btn
331334
v-close-popup
332335
:label="$t('launch')"
333-
@click="executeCommand"
334336
flat
335337
type="submit"
336338
/>
@@ -432,6 +434,7 @@ import { exportFile } from 'quasar'
432434
import { mapGetters } from 'vuex'
433435
import { QMarkdown } from '@quasar/quasar-ui-qmarkdown'
434436
import Prism from 'vue-prismjs'
437+
import _ from 'lodash'
435438
import 'src/assets/prism_tomorrowlight.css'
436439
const childProcess = require('child_process')
437440
@@ -471,7 +474,7 @@ export default {
471474
returnParamsPaginate: 1, // In multiple selection workflows allows parameters for each selection
472475
resultCommand: '', // Command ready to be executed, that is variables replaced for user set parameters
473476
results: {}, // Command result object displayed in Results Dialog
474-
resultsSelected: { '0': [] }, // Array of selected objects from Results Dialog
477+
resultsSelected: [[]], // Array of selected objects from Results Dialog
475478
resultsFilter: '', // Filter for results table
476479
externalHelpFile: '', // Holds Help text loaded from external source
477480
displayCommandDiag: false, // Visibility state for command dialog
@@ -502,7 +505,7 @@ export default {
502505
}
503506
},
504507
computed: {
505-
...mapGetters('lazystore', ['getLanguage', 'getSearch', 'getScriptsArray', 'getDefinitions', 'getCommandMaximized', 'getAlwaysConfirm']),
508+
...mapGetters('lazystore', ['getLanguage', 'getSearch', 'getScriptsArray', 'getDefinitions', 'getCommandMaximized', 'getAlwaysConfirm', 'getHistoryLength', 'getHistory']),
506509
language: function () {
507510
return this.getLanguage
508511
},
@@ -526,6 +529,18 @@ export default {
526529
alwaysConfirm: function () {
527530
return this.getAlwaysConfirm
528531
},
532+
historyLength: function () {
533+
return this.getHistoryLength
534+
},
535+
history: {
536+
get () {
537+
return this.getHistory
538+
},
539+
set (val) {
540+
let history = _.cloneDeep(val)
541+
this.$store.dispatch('lazystore/setHistory', history)
542+
}
543+
},
529544
resultsColumns: {
530545
get () {
531546
let columns = [
@@ -662,7 +677,7 @@ export default {
662677
this.returnParams = {} // User defined parameters from Command Dialog
663678
this.returnParamsPaginate = 1 // In multiple selection workflows allows parameters for each selection
664679
this.results = {} // Command result object displayed in Results Dialog
665-
this.resultsSelected = { '0': [] } // Array of selected objects from Results Dialog
680+
this.resultsSelected = [[]] // Array of selected objects from Results Dialog
666681
this.resultsFilter = '' // Filter for results table
667682
},
668683
// If user needs to stop PowerShell execution for whatever reason, he can smash Esc to kill process and launch new one.
@@ -807,21 +822,14 @@ export default {
807822
}
808823
},
809824
executeCommand () {
810-
// this.resultsSelected = [] // Clear variable as we do not need it anymore
811-
// TODO: Above move to preexecute command, so user can see it and edit it before running
812825
this.toggleLoading(true)
813-
// TODO: Save command to history
814826
this.$pwsh.shell.clear().then(() => {
815827
if (this.currentCommand.insidePsSession) {
816-
// if (this.resultCommand.match(/(\r\n|\n|\r)/gm)) {
817-
// console.log('multiline!')
818-
// }
819828
this.$pwsh.shell.addCommand(`Invoke-Command -Session $Global:LazyAdminPSSession -ScriptBlock {${this.resultCommand}}`)
820829
} else {
821830
this.$pwsh.shell.addCommand(this.resultCommand)
822831
}
823832
this.$pwsh.shell.invoke().then(output => {
824-
// console.log('Command results: ', output)
825833
// Code block to handle PowerShell return data
826834
let data
827835
let params
@@ -858,6 +866,16 @@ export default {
858866
output: output.trim()
859867
}
860868
}
869+
// Save to history
870+
this.history = {
871+
currentCommand: this.currentCommand,
872+
currentCommandMaster: this.currentCommandMaster,
873+
currentWorkflowIndex: this.currentWorkflowIndex,
874+
resultCommand: this.resultCommand,
875+
returnParams: this.returnParams,
876+
returnParamsPaginate: this.returnParamsPaginate,
877+
results: this.results
878+
}
861879
this.displayResultsDiag = true
862880
this.toggleLoading()
863881
}).catch(error => {

src/pages/SettingsPage.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<template>
22
<q-page class="row justify-center items-center">
33
<div class="column">
4-
<q-card class="full-width">
4+
<q-card
5+
class="full-width"
6+
square
7+
bordered
8+
>
59
<q-card-section>
610
<q-toolbar-title class="text-h2 text-center">
711
{{ $t('settings') }}

src/store/lazystore/actions.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,23 @@ export async function setUpdateProgress ({ commit }, updateProgress) {
7272
export async function setAlwaysConfirm ({ commit }, alwaysConfirm) {
7373
commit('SET_ALWAYSCONFIRM', alwaysConfirm)
7474
}
75+
76+
// Commit mutation to set history length - Accessed in SettingsPage.vue
77+
export async function setHistoryLength ({ commit }, historyLength) {
78+
commit('SET_HISTORYLENGTH', historyLength)
79+
}
80+
81+
// Commit mutation to set history dialog visibility - Accessed in FullLayout.vue
82+
export async function setHistoryVisible ({ commit }, historyVisible) {
83+
commit('SET_HISTORYVISIBLE', historyVisible)
84+
}
85+
86+
// Commit mutation to set history - Accessed in ScriptsPage.vue
87+
export async function setHistory ({ commit, state }, history) {
88+
// const newHistory = state.history
89+
// newHistory.unshift(history)
90+
// if (newHistory.length > this.historyLength) {
91+
// newHistory.length = this.historyLength
92+
// }
93+
commit('SET_HISTORY', history)
94+
}

src/store/lazystore/getters.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ export function getAlwaysConfirm (state) {
4646
return state.always_confirm
4747
}
4848

49+
export function getHistoryLength (state) {
50+
return state.history_length
51+
}
52+
53+
export function getHistoryVisible (state) {
54+
return state.history_visible
55+
}
56+
57+
export function getHistory (state) {
58+
return state.history
59+
}
60+
4961
// Dynamically build array of scripts to display in ScriptsPage.vue page
5062
export function getScriptsArray (state) {
5163
try {

src/store/lazystore/mutations.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,15 @@ export const SET_UPDATEPROGRESS = (state, value) => {
5454
export const SET_ALWAYSCONFIRM = (state, value) => {
5555
state.always_confirm = value
5656
}
57+
58+
export const SET_HISTORYLENGTH = (state, value) => {
59+
state.history_length = value
60+
}
61+
62+
export const SET_HISTORYVISIBLE = (state, value) => {
63+
state.history_visible = value
64+
}
65+
66+
export const SET_HISTORY = (state, value) => {
67+
state.history.unshift(value)
68+
}

src/store/lazystore/state.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export default function () {
1313
definitions_update_in_progress: false, // Are definitions update in progress?
1414
restart_required: false, // Is application restart required? (To install updates)
1515
update_progress: '', // Update Progress message
16-
always_confirm: false // Should confirmation dialog be always displayed regardless script definition
16+
always_confirm: false, // Should confirmation dialog be always displayed regardless script definition
17+
history_length: 100, // How many commands should be saved
18+
history_visible: false, // Is history dialog window visible?
19+
history: [] // Array holding previous commands
1720
}
1821
}

0 commit comments

Comments
 (0)