WIP
This commit is contained in:
parent
ee6ca9e341
commit
1066ae2032
5 changed files with 150 additions and 75 deletions
|
@ -6,7 +6,6 @@
|
||||||
<NewHost @add="addHost" v-if="selectedTab === 'add'" />
|
<NewHost @add="addHost" v-if="selectedTab === 'add'" />
|
||||||
<Config v-else-if="selectedTab === 'config'" @reload="reload" />
|
<Config v-else-if="selectedTab === 'config'" @reload="reload" />
|
||||||
<LocalCommands :host="selectedHost" v-else-if="selectedHost && selectedHostOption === 'localProc'" />
|
<LocalCommands :host="selectedHost" v-else-if="selectedHost && selectedHostOption === 'localProc'" />
|
||||||
<RemoteCommands v-else-if="selectedHost && selectedHostOption === 'remoteProc'" />
|
|
||||||
<Run :host="hosts[selectedHost]" v-else-if="selectedHost && selectedHostOption === 'run'" />
|
<Run :host="hosts[selectedHost]" v-else-if="selectedHost && selectedHostOption === 'run'" />
|
||||||
<EditHost :host="hosts[selectedHost]" @save="editHost" @remove="removeHost" v-else-if="selectedHost" />
|
<EditHost :host="hosts[selectedHost]" @save="editHost" @remove="removeHost" v-else-if="selectedHost" />
|
||||||
<div class="none" v-else>Select an option from the menu</div>
|
<div class="none" v-else>Select an option from the menu</div>
|
||||||
|
@ -20,7 +19,6 @@ import Menu from './Menu';
|
||||||
import NewHost from './NewHost';
|
import NewHost from './NewHost';
|
||||||
import EditHost from './EditHost';
|
import EditHost from './EditHost';
|
||||||
import LocalCommands from './LocalCommands';
|
import LocalCommands from './LocalCommands';
|
||||||
import RemoteCommands from './RemoteCommands';
|
|
||||||
import Config from './Config';
|
import Config from './Config';
|
||||||
import Run from './Run';
|
import Run from './Run';
|
||||||
|
|
||||||
|
@ -32,7 +30,6 @@ export default {
|
||||||
NewHost,
|
NewHost,
|
||||||
EditHost,
|
EditHost,
|
||||||
LocalCommands,
|
LocalCommands,
|
||||||
RemoteCommands,
|
|
||||||
Config,
|
Config,
|
||||||
Run,
|
Run,
|
||||||
},
|
},
|
||||||
|
|
|
@ -39,13 +39,9 @@ export default {
|
||||||
hostOptions() {
|
hostOptions() {
|
||||||
return {
|
return {
|
||||||
localProc: {
|
localProc: {
|
||||||
displayName: 'Local Actions',
|
displayName: 'Stored Actions',
|
||||||
iconClass: 'fas fa-puzzle-piece',
|
iconClass: 'fas fa-puzzle-piece',
|
||||||
},
|
},
|
||||||
remoteProc: {
|
|
||||||
displayName: 'Remote Procedures',
|
|
||||||
iconClass: 'fas fa-database',
|
|
||||||
},
|
|
||||||
run: {
|
run: {
|
||||||
displayName: 'Run Action',
|
displayName: 'Run Action',
|
||||||
iconClass: 'fas fa-play',
|
iconClass: 'fas fa-play',
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
<template>
|
|
||||||
<div class="page remote-procedures">
|
|
||||||
<h2>Procedures stored on the server</h2>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import mixins from '../utils';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'RemoteCommands',
|
|
||||||
mixins: [mixins],
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<!-- vim:sw=2:ts=2:et: -->
|
|
|
@ -2,9 +2,21 @@
|
||||||
<div class="page run">
|
<div class="page run">
|
||||||
<h2>Run a command on {{ host.name }}</h2>
|
<h2>Run a command on {{ host.name }}</h2>
|
||||||
|
|
||||||
|
<div class="mode-selector">
|
||||||
|
Action mode
|
||||||
|
|
||||||
|
<div class="buttons">
|
||||||
|
<input type="radio" value="request" id="_request" v-model="actionMode" />
|
||||||
|
<label for="_request"> Request</label>
|
||||||
|
<input type="radio" value="script" id="_script" v-model="actionMode" />
|
||||||
|
<label for="_script"> Script</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="actionMode === 'request'">
|
||||||
<div class="help">
|
<div class="help">
|
||||||
<a href="https://platypush.readthedocs.io/en/latest/plugins.html" target="_blank">Plugins reference</a>. Use <tt>$URL$</tt> as argument value to denote the current
|
<a href="https://platypush.readthedocs.io/en/latest/plugins.html" target="_blank">Plugins reference</a>. Use <tt>$URL$</tt> as argument value to denote the current
|
||||||
URL.
|
URL. You can also call remotely stored procedure through <tt>procedure.<procedure_name></tt>.
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form ref="runForm" @submit.prevent="runAction">
|
<form ref="runForm" @submit.prevent="runAction">
|
||||||
|
@ -56,8 +68,22 @@
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
<form class="save-form" ref="saveForm" @submit.prevent="storeAction" v-if="saveMode">
|
<div v-else>
|
||||||
|
<form ref="runForm" @submit.prevent="runScript">
|
||||||
|
<textarea v-model="script" />
|
||||||
|
|
||||||
|
<div class="row buttons">
|
||||||
|
<button type="button" @click="saveMode = true" :disabled="loading || !(action.name && action.name.length && action.name in actions)" v-if="!saveMode">
|
||||||
|
<i class="fas fa-save" /> Save Action
|
||||||
|
</button>
|
||||||
|
<button type="submit" :disabled="loading"><i class="fas fa-play" /> Run</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form class="save-form" ref="scriptForm" @submit.prevent="storeAction" v-if="saveMode">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<input type="text" name="displayName" placeholder="Action display name" />
|
<input type="text" name="displayName" placeholder="Action display name" />
|
||||||
</div>
|
</div>
|
||||||
|
@ -106,12 +132,18 @@ export default {
|
||||||
return {
|
return {
|
||||||
plugins: {},
|
plugins: {},
|
||||||
pluginsLoading: false,
|
pluginsLoading: false,
|
||||||
|
procedures: {},
|
||||||
saveMode: false,
|
saveMode: false,
|
||||||
actionResponse: null,
|
actionResponse: null,
|
||||||
actionError: null,
|
actionError: null,
|
||||||
hosts: {},
|
hosts: {},
|
||||||
|
script: `(browser, window, document) => {
|
||||||
|
// Do something
|
||||||
|
}`,
|
||||||
|
actionMode: 'request',
|
||||||
action: {
|
action: {
|
||||||
name: null,
|
name: null,
|
||||||
|
script: null,
|
||||||
args: [],
|
args: [],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -119,12 +151,26 @@ export default {
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
actions() {
|
actions() {
|
||||||
return Object.values(this.plugins).reduce((obj, plugin) => {
|
let plugins = {};
|
||||||
|
let procedures = {};
|
||||||
|
|
||||||
|
if (this.plugins) {
|
||||||
|
plugins = Object.values(this.plugins).reduce((obj, plugin) => {
|
||||||
return Object.values(plugin.actions).reduce((obj, action) => {
|
return Object.values(plugin.actions).reduce((obj, action) => {
|
||||||
obj[plugin.name + '.' + action.name] = action;
|
obj[plugin.name + '.' + action.name] = action;
|
||||||
return obj;
|
return obj;
|
||||||
}, obj);
|
}, obj);
|
||||||
}, {});
|
}, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.procedures) {
|
||||||
|
procedures = Object.entries(this.procedures).reduce((obj, [name, args]) => {
|
||||||
|
obj['procedure.' + name] = args;
|
||||||
|
return obj;
|
||||||
|
}, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
return { ...plugins, ...procedures };
|
||||||
},
|
},
|
||||||
|
|
||||||
filteredActions() {
|
filteredActions() {
|
||||||
|
@ -183,6 +229,11 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async runScript() {
|
||||||
|
this.loading = true;
|
||||||
|
console.log(this.script);
|
||||||
|
},
|
||||||
|
|
||||||
addActionArgument() {
|
addActionArgument() {
|
||||||
this.action.args.push({
|
this.action.args.push({
|
||||||
name: '',
|
name: '',
|
||||||
|
@ -203,11 +254,40 @@ export default {
|
||||||
},
|
},
|
||||||
this.host
|
this.host
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.procedures = await this.run({ name: 'inspect.get_procedures' }, this.host);
|
||||||
} finally {
|
} finally {
|
||||||
this.pluginsLoading = false;
|
this.pluginsLoading = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async storeScript(event) {
|
||||||
|
const saveForm = event.target;
|
||||||
|
const displayName = saveForm.displayName.value.trim();
|
||||||
|
const iconClass = saveForm.iconClass.value.trim();
|
||||||
|
const hosts = [...saveForm.querySelectorAll('input[data-type="host"]:checked')].map(el => el.value);
|
||||||
|
|
||||||
|
if (!displayName.length) {
|
||||||
|
this.notify('Please specify an action name', 'No action name provided');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hosts.length) {
|
||||||
|
this.notify('Please specify at least one device where the action should run', 'No devices provided');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const script = {
|
||||||
|
type: this.actionMode,
|
||||||
|
displayName: displayName,
|
||||||
|
iconClass: iconClass,
|
||||||
|
hosts: hosts,
|
||||||
|
script: this.script,
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log(script);
|
||||||
|
},
|
||||||
|
|
||||||
async storeAction(event) {
|
async storeAction(event) {
|
||||||
const saveForm = event.target;
|
const saveForm = event.target;
|
||||||
const displayName = saveForm.displayName.value.trim();
|
const displayName = saveForm.displayName.value.trim();
|
||||||
|
@ -225,11 +305,12 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
const action = {
|
const action = {
|
||||||
|
type: this.actionMode,
|
||||||
displayName: displayName,
|
displayName: displayName,
|
||||||
iconClass: iconClass,
|
iconClass: iconClass,
|
||||||
|
hosts: hosts,
|
||||||
name: this.action.name,
|
name: this.action.name,
|
||||||
args: this.getActionArgs(),
|
args: this.getActionArgs(),
|
||||||
hosts: hosts,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
await this.saveAction(action);
|
await this.saveAction(action);
|
||||||
|
@ -254,6 +335,23 @@ export default {
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
.mode-selector {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
margin: 1em 0;
|
||||||
|
|
||||||
|
.buttons {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
margin-left: 1em;
|
||||||
|
|
||||||
|
input[type='radio'] {
|
||||||
|
margin-left: 1em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.help {
|
.help {
|
||||||
margin-bottom: 1em;
|
margin-bottom: 1em;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ export default {
|
||||||
async run(action, host) {
|
async run(action, host) {
|
||||||
const url = (host.ssl ? 'https' : 'http') + '://' + host.address + ':' + host.port + '/execute';
|
const url = (host.ssl ? 'https' : 'http') + '://' + host.address + ':' + host.port + '/execute';
|
||||||
const config = {};
|
const config = {};
|
||||||
let args = action.args;
|
let args = action.args || {};
|
||||||
if (Array.isArray(action.args)) {
|
if (Array.isArray(action.args)) {
|
||||||
args = action.args
|
args = action.args
|
||||||
.filter(arg => arg.value && arg.value.length)
|
.filter(arg => arg.value && arg.value.length)
|
||||||
|
|
Loading…
Reference in a new issue