From cdc4bbfda1265740eb1a34fbb58ae8525d878d16 Mon Sep 17 00:00:00 2001 From: sadnub Date: Fri, 9 Jul 2021 18:47:28 -0400 Subject: [PATCH] added script cloning functionality --- src/components/ScriptManager.vue | 108 ++++----- .../modals/scripts/ScriptFormModal.vue | 29 ++- .../modals/scripts/ScriptUploadModal.vue | 224 ++++++++++-------- 3 files changed, 183 insertions(+), 178 deletions(-) diff --git a/src/components/ScriptManager.vue b/src/components/ScriptManager.vue index 67a6bc6..f1a2d63 100644 --- a/src/components/ScriptManager.vue +++ b/src/components/ScriptManager.vue @@ -20,7 +20,7 @@ New Script - + @@ -30,30 +30,6 @@ - - - -
@@ -333,17 +309,13 @@ import ScriptFormModal from "@/components/modals/scripts/ScriptFormModal"; export default { name: "ScriptManager", - components: { ScriptUploadModal }, mixins: [mixins], data() { return { scripts: [], - selectedScript: {}, - showScriptUploadModal: false, search: "", tableView: true, expanded: [], - selected: null, pagination: { rowsPerPage: 0, sortBy: "favorite", @@ -405,7 +377,6 @@ export default { }, methods: { getScripts() { - this.clearRow(); this.$axios .get("/scripts/scripts/") .then(r => { @@ -416,9 +387,6 @@ export default { setShowCommunityScripts(show) { this.$store.dispatch("setShowCommunityScripts", show); }, - clearRow() { - this.selectedScript = {}; - }, viewCode(script) { this.$q.dialog({ component: ScriptFormModal, @@ -478,9 +446,6 @@ export default { return false; } }, - rowSelectedClass(id) { - if (this.selectedScript.id === id) return this.$q.dark.isActive ? "highlight-dark" : "highlight"; - }, favoriteText(isFavorite) { return isFavorite ? "Remove as Favorite" : "Add as Favorite"; }, @@ -513,16 +478,34 @@ export default { }, setTableView(view) { this.tableView = view; - this.selectedScript = {}; - this.selected = null; this.expanded = []; }, - nodeSelected(nodeid) { - if (nodeid) { - this.selectedScript = this.$refs.folderTree.getNodeByKey(nodeid); - } else { - this.selectedScript = {}; - } + cloneScript(script) { + this.$q + .dialog({ + component: ScriptFormModal, + componentProps: { + script: script, + categories: this.categories, + readonly: false, + clone: true, + }, + }) + .onOk(() => { + this.getScripts(); + }); + }, + uploadScript() { + this.$q + .dialog({ + component: ScriptUploadModal, + componentProps: { + categories: this.categories, + }, + }) + .onOk(() => { + this.getScripts(); + }); }, }, computed: { @@ -539,9 +522,6 @@ export default { }); return list; }, - isRowSelected() { - return this.selectedScript.id !== null && this.selectedScript.id !== undefined; - }, tree() { if (this.tableView || this.visibleScripts.length === 0) { return []; diff --git a/src/components/modals/scripts/ScriptFormModal.vue b/src/components/modals/scripts/ScriptFormModal.vue index fae828d..a7cea40 100644 --- a/src/components/modals/scripts/ScriptFormModal.vue +++ b/src/components/modals/scripts/ScriptFormModal.vue @@ -136,7 +136,14 @@ export default { props: { script: Object, categories: !Array, - readonly: Boolean, + readonly: { + type: Boolean, + default: false, + }, + clone: { + type: Boolean, + default: false, + }, }, data() { return { @@ -164,7 +171,7 @@ export default { submit() { this.$q.loading.show(); - if (!!this.script) { + if (this.script && !this.clone) { this.$axios .put(`/scripts/${this.script.id}/script/`, this.localScript) .then(r => { @@ -247,8 +254,12 @@ export default { return this.localScript.favorite ? "star" : "star_outline"; }, title() { - if (!!this.script) { - return this.readonly ? `Viewing ${this.script.name}` : `Editing ${this.script.name}`; + if (this.script) { + return this.readonly + ? `Viewing ${this.script.name}` + : this.clone + ? `Copying ${this.script.name}` + : `Editing ${this.script.name}`; } else { return "Adding new script"; } @@ -264,14 +275,14 @@ export default { }, }, mounted() { - if (!!this.script) { - this.localScript.id = this.script.id; - this.localScript.name = this.script.name; + if (this.script) { + this.localScript.id = this.clone ? null : this.script.id; + this.localScript.name = this.clone ? "Copy of " + this.script.name : this.script.name; this.localScript.description = this.script.description; - this.localScript.favorite = this.script.favorite; + this.localScript.favorite = this.clone ? false : this.script.favorite; this.localScript.shell = this.script.shell; this.localScript.category = this.script.category; - this.localScript.script_type = this.script.script_type; + this.localScript.script_type = this.clone ? "userdefined" : this.script.script_type; this.localScript.default_timeout = this.script.default_timeout; this.localScript.args = this.script.args; this.getCode(); diff --git a/src/components/modals/scripts/ScriptUploadModal.vue b/src/components/modals/scripts/ScriptUploadModal.vue index 4c089b5..65cd92c 100644 --- a/src/components/modals/scripts/ScriptUploadModal.vue +++ b/src/components/modals/scripts/ScriptUploadModal.vue @@ -1,107 +1,109 @@ \ No newline at end of file