77 >
88 <q-card
99 class =" q-dialog-plugin"
10- :style =" { 'min-width': ! ret ? '40vw ' : '70vw ' }"
10+ :style =" { 'min-width': ret || streamOutput ? '70vw ' : '40vw ' }"
1111 >
1212 <q-bar >
1313 Send command on {{ agent.hostname }}
8282 ]"
8383 />
8484 </q-card-section >
85- <q-card-section >
85+ <q-card-section class = " q-pb-xs " >
8686 <q-input
8787 v-model =" state.cmd"
8888 outlined
9292 :rules =" [(val) => !!val || '*Required']"
9393 />
9494 </q-card-section >
95- <q-card-actions align =" right" >
96- <q-btn flat dense push label =" Cancel" v-close-popup />
97- <q-btn
98- :loading =" loading"
99- flat
100- dense
101- push
102- label =" Send"
103- color =" primary"
104- type =" submit"
105- />
95+ <q-card-actions align =" between" >
96+ <q-toggle v-model =" useStreaming" label =" Stream Output" />
97+ <div >
98+ <q-btn flat dense push label =" Cancel" v-close-popup />
99+ <q-btn
100+ :loading =" loading"
101+ flat
102+ dense
103+ push
104+ label =" Send"
105+ color =" primary"
106+ type =" submit"
107+ />
108+ </div >
106109 </q-card-actions >
107110 <q-card-section v-if =" ret !== null"
108111 ><script-output-copy-clip label =" Output" :data =" ret" /> <q-separator
114117 >
115118 <pre >{{ ret }}</pre >
116119 </q-card-section >
120+ <q-card-section v-if =" showStream" class =" q-py-xs" >
121+ <command-stream
122+ :key =" `${runId}`"
123+ :agent-id =" agent.agent_id"
124+ :cmd =" streamCmd"
125+ :shell =" state.shell"
126+ :timeout =" state.timeout"
127+ @updateOutput =" (val) => (streamOutput = val)"
128+ @streamLoaded =" loading = false"
129+ @streamClosed =" loading = false"
130+ />
131+ </q-card-section >
117132 </q-form >
118133 </q-card >
119134 </q-dialog >
120135</template >
121136
122137<script >
123138// composition imports
124- import { ref } from " vue" ;
139+ import { ref , nextTick } from " vue" ;
125140import { useDialogPluginComponent } from " quasar" ;
126141import { sendAgentCommand } from " @/api/agents" ;
127142import { cmdPlaceholder } from " @/composables/agents" ;
128143import { runAsUserToolTip } from " @/constants/constants" ;
129144
130145import ScriptOutputCopyClip from " @/components/scripts/ScriptOutputCopyClip.vue" ;
146+ import CommandStream from " @/components/agents/CommandStream.vue" ;
131147
132148export default {
133149 name: " SendCommand" ,
134150 components: {
135151 ScriptOutputCopyClip,
152+ CommandStream,
136153 },
137154 emits: [... useDialogPluginComponent .emits ],
138155 props: {
139156 agent: ! Object ,
140157 },
141158 setup (props ) {
142- // setup quasar dialog plugin
143159 const { dialogRef , onDialogHide } = useDialogPluginComponent ();
144160
145- // run command logic
146161 const state = ref ({
147162 shell: props .agent .plat === " windows" ? " cmd" : " /bin/bash" ,
148163 cmd: null ,
@@ -153,10 +168,30 @@ export default {
153168
154169 const loading = ref (false );
155170 const ret = ref (null );
171+ const useStreaming = ref (false );
172+ const showStream = ref (false );
173+ const streamOutput = ref (" " );
174+ const streamCmd = ref (" " );
175+ const streamShell = ref (" " );
176+ const streamTimeout = ref (30 );
177+ const runId = ref (0 );
156178
157179 async function submit () {
158180 loading .value = true ;
159181 ret .value = null ;
182+ streamOutput .value = " " ;
183+ showStream .value = false ;
184+
185+ if (useStreaming .value ) {
186+ streamCmd .value = state .value .cmd ;
187+ streamShell .value = state .value .shell ;
188+ streamTimeout .value = state .value .timeout ;
189+ await nextTick ();
190+ runId .value ++ ;
191+ showStream .value = true ;
192+ return ;
193+ }
194+
160195 try {
161196 ret .value = await sendAgentCommand (props .agent .agent_id , state .value );
162197 } catch (e) {
@@ -167,20 +202,21 @@ export default {
167202
168203 return {
169204 // reactive data
205+ dialogRef,
206+ onDialogHide,
170207 state,
171208 loading,
172209 ret,
173-
174- // non reactivete data
175- runAsUserToolTip,
176-
177- // methods
210+ useStreaming,
211+ streamOutput,
212+ showStream,
213+ streamCmd,
214+ streamShell,
215+ streamTimeout,
216+ runId,
178217 submit,
218+ runAsUserToolTip,
179219 cmdPlaceholder,
180-
181- // quasar dialog
182- dialogRef,
183- onDialogHide,
184220 };
185221 },
186222};
0 commit comments