From 7feb9727158b2b6efd6d0ec8928f28f6ee8aa2e3 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 29 Jun 2020 20:26:58 +0200 Subject: [PATCH] Support for editing actions and scripts --- src/options/App.vue | 25 +++++++++++++++++--- src/options/LocalCommands.vue | 13 +++++++++++ src/options/Run.vue | 43 +++++++++++++++++++++++++++++++++-- src/popup/App.vue | 12 ++++++---- src/utils.js | 3 +++ 5 files changed, 87 insertions(+), 9 deletions(-) diff --git a/src/options/App.vue b/src/options/App.vue index 74ae528..6037f68 100644 --- a/src/options/App.vue +++ b/src/options/App.vue @@ -5,8 +5,8 @@
- - + +
Select an option from the menu
@@ -14,6 +14,7 @@ diff --git a/src/options/LocalCommands.vue b/src/options/LocalCommands.vue index d70648c..a27cf86 100644 --- a/src/options/LocalCommands.vue +++ b/src/options/LocalCommands.vue @@ -33,6 +33,9 @@ + @@ -88,6 +91,7 @@ export default { components: { PrismEditor }, props: { host: String, + bus: Object, }, data() { @@ -162,6 +166,14 @@ export default { this.hosts = await this.getHosts(); }, + editAction() { + this.bus.$emit('edit-action', this.actions_[this.selectedAction]); + }, + + editScript() { + this.bus.$emit('edit-script', this.scripts[this.selectedAction]); + }, + async removeAction() { if (!this.selectedAction || !(this.selectedAction in this.actions_) || !confirm('Are you sure that you want to remove this action from this device?')) { return; @@ -285,6 +297,7 @@ form { } .icon { + width: 1em; font-size: 1.2em; margin-right: 1.5em; } diff --git a/src/options/Run.vue b/src/options/Run.vue index d5eca12..a2aeb3c 100644 --- a/src/options/Run.vue +++ b/src/options/Run.vue @@ -22,7 +22,15 @@
- +
@@ -100,6 +108,7 @@ :autocomplete-items="categoriesAutocomplete" :disabled="loading" :separators="[',', ';']" + :tags="selectedCategories.map(cat => (typeof cat === 'object' ? cat : { text: cat }))" @tags-changed="tags => (selectedCategories = tags)" placeholder="Categories" /> @@ -114,7 +123,7 @@ Install script on these devices
- +
@@ -143,6 +152,8 @@ export default { mixins: [mixins], props: { host: Object, + selectedAction: Object, + selectedScript: Object, scriptTemplate: { type: String, default: `async (app, host, browser, tab, target, ...args) => { @@ -178,6 +189,7 @@ export default { storedActions: {}, selectedCategory: '', selectedCategories: [], + selectedHosts: null, actionMode: 'request', action: { name: null, @@ -429,6 +441,32 @@ export default { this.action.defaultArgs = {}; } }, + + initAction() { + const action = this.selectedAction || this.selectedScript; + if (!action) { + return; + } + + this.saveMode = true; + this.saveParams.name = action.displayName; + this.saveParams.color = action.color; + this.saveParams.iconClass = action.iconClass; + this.selectedCategories = action.categories; + this.selectedHosts = action.hosts; + + if (this.selectedAction) { + this.actionMode = 'request'; + this.action.name = action.name; + this.action.defaultArgs = Object.entries(action.args).reduce((obj, [name, value]) => { + obj[name] = { value: value }; + return obj; + }, {}); + } else { + this.actionMode = 'script'; + this.script = action.script.toString(); + } + }, }, created() { @@ -436,6 +474,7 @@ export default { this.loadHosts(); this.loadPlugins(); this.loadActions(); + this.initAction(); }, }; diff --git a/src/popup/App.vue b/src/popup/App.vue index d3b7030..680e37c 100644 --- a/src/popup/App.vue +++ b/src/popup/App.vue @@ -1,6 +1,6 @@