This commit is contained in:
wh1te909
2022-03-10 00:57:55 +00:00
parent 47a382b805
commit 6f760f5d4f
34 changed files with 386 additions and 288 deletions

View File

@@ -84,7 +84,7 @@
<v-ace-editor
v-model:value="formScript.script_body"
class="col-8"
:lang="formScript.shell === 'cmd' ? 'batchfile' : formScript.shell"
:lang="lang"
:theme="$q.dark.isActive ? 'tomorrow_night_eighties' : 'tomorrow'"
:style="{ height: `${maximized ? '87vh' : '64vh'}` }"
wrap
@@ -127,7 +127,7 @@
<script>
// composable imports
import { ref, computed, onMounted } from "vue";
import { ref, computed, watch, onMounted } from "vue";
import { useQuasar, useDialogPluginComponent } from "quasar";
import { saveScript, editScript, downloadScript } from "@/api/scripts";
import { useAgentDropdown } from "@/composables/agents";
@@ -142,6 +142,7 @@ import { VAceEditor } from "vue3-ace-editor";
import "ace-builds/src-noconflict/mode-powershell";
import "ace-builds/src-noconflict/mode-python";
import "ace-builds/src-noconflict/mode-batchfile";
import "ace-builds/src-noconflict/mode-sh";
import "ace-builds/src-noconflict/theme-tomorrow_night_eighties";
import "ace-builds/src-noconflict/theme-tomorrow";
@@ -185,6 +186,16 @@ export default {
const loading = ref(false);
const agentLoading = ref(false);
// watch(script.value, (newValue, oldValue) => {
// if (!props.script && script.value.script_body === "") {
// if (newValue.shell === "shell") {
// script.value.script_body = "#!/bin/bash\n\n# don't forget to include the shebang above!\n\n";
// } else if (newValue.shell === "python") {
// script.value.script_body = "#!/usr/bin/python3\n\n# don't forget to include the shebang above!\n\n";
// }
// }
// });
const title = computed(() => {
if (props.script) {
return props.readonly
@@ -197,6 +208,15 @@ export default {
}
});
// convert highlighter language to match what ace expects
const lang = computed(() => {
if (script.value.shell === "cmd") return "batchfile";
else if (script.value.shell === "powershell") return "powershell";
else if (script.value.shell === "python") return "python";
else if (script.value.shell === "shell") return "sh";
else return "";
});
// get code if editing or cloning script
if (props.script)
downloadScript(script.value.id, { with_snippets: props.readonly }).then(r => {
@@ -218,7 +238,9 @@ export default {
onDialogOK();
notifySuccess(result);
} catch (e) {}
} catch (e) {
console.error(e);
}
loading.value = false;
}
@@ -248,6 +270,7 @@ export default {
agentOptions,
agent,
agentLoading,
lang,
// non-reactive data
shellOptions,

View File

@@ -106,6 +106,9 @@
<q-icon v-else-if="props.node.shell === 'cmd'" name="mdi-microsoft-windows" color="primary">
<q-tooltip> Batch </q-tooltip>
</q-icon>
<q-icon v-else-if="props.node.shell === 'shell'" name="mdi-bash" color="primary">
<q-tooltip> Shell </q-tooltip>
</q-icon>
<span class="q-pl-xs text-weight-bold">{{ props.node.name }}</span>
<span class="q-pl-xs">{{ props.node.description }}</span>
@@ -289,6 +292,9 @@
<q-icon v-else-if="props.row.shell === 'cmd'" name="mdi-microsoft-windows" color="primary" size="sm">
<q-tooltip> Batch </q-tooltip>
</q-icon>
<q-icon v-else-if="props.row.shell === 'shell'" size="sm" name="mdi-bash" color="primary">
<q-tooltip> Shell </q-tooltip>
</q-icon>
</q-td>
<!-- name -->
<q-td>

View File

@@ -40,7 +40,7 @@
<v-ace-editor
v-model:value="formSnippet.code"
:lang="formSnippet.shell === 'cmd' ? 'batchfile' : formSnippet.shell"
:lang="lang"
:theme="$q.dark.isActive ? 'tomorrow_night_eighties' : 'tomorrow'"
:style="{ height: `${maximized ? '80vh' : '70vh'}` }"
wrap
@@ -70,6 +70,7 @@ import { VAceEditor } from "vue3-ace-editor";
import "ace-builds/src-noconflict/mode-powershell";
import "ace-builds/src-noconflict/mode-python";
import "ace-builds/src-noconflict/mode-batchfile";
import "ace-builds/src-noconflict/mode-sh";
import "ace-builds/src-noconflict/theme-tomorrow_night_eighties";
import "ace-builds/src-noconflict/theme-tomorrow";
@@ -104,6 +105,15 @@ export default {
}
});
// convert highlighter language to match what ace expects
const lang = computed(() => {
if (snippet.value.shell === "cmd") return "batchfile";
else if (snippet.value.shell === "powershell") return "powershell";
else if (snippet.value.shell === "python") return "python";
else if (snippet.value.shell === "shell") return "sh";
else return "";
});
async function submitForm() {
loading.value = true;
try {
@@ -121,6 +131,7 @@ export default {
// reactive data
formSnippet: snippet.value,
maximized,
lang,
loading,
// non-reactive data

View File

@@ -72,6 +72,9 @@
<q-icon v-else-if="props.row.shell === 'cmd'" name="mdi-microsoft-windows" color="primary" size="sm">
<q-tooltip> Batch </q-tooltip>
</q-icon>
<q-icon v-else-if="props.row.shell === 'shell'" name="mdi-bash" color="primary">
<q-tooltip> Shell </q-tooltip>
</q-icon>
</q-td>
<!-- name -->
<q-td>{{ props.row.name }}</q-td>

View File

@@ -34,11 +34,11 @@
<q-file
label="Script Upload"
v-model="file"
hint="Supported file types: .ps1, .bat, .py"
hint="Supported file types: .ps1, .bat, .py, .sh"
filled
dense
counter
accept=".ps1, .bat, .py"
accept=".ps1, .bat, .py, .sh"
>
<template v-slot:prepend>
<q-icon name="attach_file" />