diff --git a/src/common.scss b/src/common.scss index 388ba73..00eff98 100644 --- a/src/common.scss +++ b/src/common.scss @@ -49,4 +49,24 @@ form { } } +.hidden { + display: none !important; +} + +.code { + padding: 1em; + white-space: pre-wrap; + font-family: monospace; + border: 1px dotted rgba(0, 0, 0, 0.8); + border-radius: 1em; + + &.response { + background: rgba(200, 255, 200, 0.3); + } + + &.error { + background: rgba(255, 200, 200, 0.3); + } +} + // vim:sw=2:ts=2:et: diff --git a/src/options/App.vue b/src/options/App.vue index 3ea8e60..8a7c2e5 100644 --- a/src/options/App.vue +++ b/src/options/App.vue @@ -5,7 +5,7 @@
- + diff --git a/src/options/Config.vue b/src/options/Config.vue index de18007..5cbac50 100644 --- a/src/options/Config.vue +++ b/src/options/Config.vue @@ -9,7 +9,7 @@ - +
diff --git a/src/options/LocalCommands.vue b/src/options/LocalCommands.vue index 5019b20..3527aa1 100644 --- a/src/options/LocalCommands.vue +++ b/src/options/LocalCommands.vue @@ -1,6 +1,49 @@ @@ -10,7 +53,166 @@ import mixins from '../utils'; export default { name: 'LocalCommands', mixins: [mixins], + props: { + host: String, + }, + + data() { + return { + hosts: {}, + actions_: {}, + selectedAction: null, + response: null, + error: null, + }; + }, + + computed: { + actionsByHost() { + return Object.entries(this.actions_).reduce((obj, [name, action]) => { + const hosts = action.hosts || []; + for (const host of hosts) { + if (!(host in obj)) { + obj[host] = {}; + } + + obj[host][name] = action; + } + + return obj; + }, {}); + }, + + actions() { + return this.host ? this.actionsByHost[this.host] : this.actions_; + }, + }, + + methods: { + async loadActions() { + this.actions_ = await this.getActions(); + }, + + async loadHosts() { + this.hosts = await this.getHosts(); + }, + + 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; + } + + const action = this.actions_[this.selectedAction]; + const hostIndex = action.hosts.indexOf(this.host); + if (hostIndex < 0) { + return; + } + + action.hosts.splice(hostIndex, 1); + if (action.hosts.length === 0) { + delete this.actions_[this.selectedAction]; + } else { + this.actions_[this.selectedAction] = action; + } + + await this.saveActions(this.actions_); + await this.loadActions(); + }, + + async runAction() { + if (!(this.selectedAction && this.host && this.selectedAction in this.actions)) { + return; + } + + const action = this.actions[this.selectedAction]; + this.error = null; + + try { + this.response = await this.run(action, this.hosts[this.host]); + } catch (e) { + this.error = e.message; + } + }, + + toggleSelectedAction(name) { + this.response = null; + this.error = null; + this.selectedAction = this.selectedAction === name ? null : name; + }, + }, + + created() { + this.loadHosts(); + this.loadActions(); + }, }; + + diff --git a/src/options/Menu.vue b/src/options/Menu.vue index 4186303..d7df9d8 100644 --- a/src/options/Menu.vue +++ b/src/options/Menu.vue @@ -1,6 +1,12 @@ + + + + + + diff --git a/src/options/Run.vue b/src/options/Run.vue index 30e72e2..30ef392 100644 --- a/src/options/Run.vue +++ b/src/options/Run.vue @@ -66,6 +66,14 @@
+
+
+ Install action on these devices +
+ + +
+
@@ -80,15 +88,20 @@