More stuff added

This commit is contained in:
Fabio Manganiello 2020-06-16 01:43:04 +02:00
parent a6892d244e
commit 2a6ac58c6d
7 changed files with 178 additions and 134 deletions

View file

@ -9,7 +9,7 @@
"48": "icons/icon-48.png", "48": "icons/icon-48.png",
"64": "icons/icon-64.png" "64": "icons/icon-64.png"
}, },
"permissions": ["activeTab", "storage", "notifications", "<all_urls>"], "permissions": ["activeTab", "storage", "notifications", "clipboardRead", "clipboardWrite", "<all_urls>"],
"browser_action": { "browser_action": {
"default_title": "platypush", "default_title": "platypush",

View file

@ -1,27 +1,14 @@
<template> <template>
<div class="container"> <div class="container">
<Menu <Menu :hosts="hosts" :selectedTab="selectedTab" :selectedHost="selectedHost" :selectedHostOption="selectedHostOption" @select="select" />
:hosts="hosts"
:selectedHost="selectedHost"
:selectedHostOption="selectedHostOption"
:isAddHost="isAddHost"
:isBackupMode="isBackupMode"
:isRestoreMode="isRestoreMode"
@select-host="selectHost"
@select-host-option="selectHostOption"
@select-add-host="selectAddHost"
@select-backup-mode="selectBackupMode"
@select-restore-mode="selectRestoreMode"
/>
<div class="body"> <div class="body">
<NewHost @add="addHost" v-if="isAddHost" /> <NewHost @add="addHost" v-if="selectedTab === 'add'" />
<Backup v-else-if="isBackupMode" /> <Config v-else-if="selectedTab === 'config'" />
<Restore v-else-if="isRestoreMode" /> <LocalCommands v-else-if="selectedTab === 'host' && selectedHostOption === 'localProc'" />
<LocalCommands v-else-if="selectedHost && selectedHostOption === 'localProc'" /> <RemoteCommands v-else-if="selectedTab === 'host' && selectedHostOption === 'remoteProc'" />
<RemoteCommands v-else-if="selectedHost && selectedHostOption === 'remoteProc'" /> <Run :host="hosts[selectedHost]" v-else-if="selectedTab === 'host' && selectedHostOption === 'run'" />
<Run :host="hosts[selectedHost]" v-else-if="selectedHost && selectedHostOption === 'run'" /> <EditHost :host="hosts[selectedHost]" @save="editHost" @remove="removeHost" v-else-if="selectedTab === 'host'" />
<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>
</div> </div>
</div> </div>
@ -34,8 +21,7 @@ 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 RemoteCommands from './RemoteCommands';
import Backup from './Backup'; import Config from './Config';
import Restore from './Restore';
import Run from './Run'; import Run from './Run';
export default { export default {
@ -47,54 +33,24 @@ export default {
EditHost, EditHost,
LocalCommands, LocalCommands,
RemoteCommands, RemoteCommands,
Backup, Config,
Restore,
Run, Run,
}, },
data() { data() {
return { return {
hosts: {}, hosts: {},
selectedTab: null,
selectedHost: null, selectedHost: null,
selectedHostOption: null, selectedHostOption: null,
isAddHost: false,
isBackupMode: false,
isRestoreMode: false,
}; };
}, },
methods: { methods: {
selectHost(i) { select(tab, host, hostOption) {
this.selectedHost = i; this.selectedTab = tab;
this.selectedHostOption = null; this.selectedHost = host;
this.isAddHost = false; this.selectedHostOption = hostOption;
this.isBackupMode = false;
this.isRestoreMode = false;
},
selectHostOption(option) {
this.selectedHostOption = option;
},
selectAddHost() {
this.selectedHost = null;
this.isAddHost = true;
this.isBackupMode = false;
this.isRestoreMode = false;
},
selectBackupMode() {
this.selectedHost = null;
this.isAddHost = false;
this.isBackupMode = true;
this.isRestoreMode = false;
},
selectRestoreMode() {
this.selectedHost = null;
this.isAddHost = false;
this.isBackupMode = false;
this.isRestoreMode = true;
}, },
async addHost(form) { async addHost(form) {

View file

@ -1,32 +0,0 @@
<template>
<div class="page backup">
<h2>Backup the current configuration</h2>
<div class="container">
<textarea v-text="loading ? 'Loading...' : config" :disabled="loading" />
</div>
</div>
</template>
<script>
import mixins from '../utils';
export default {
name: 'Backup',
mixins: [mixins],
data() {
return {
config: {},
};
},
created() {
const self = this;
this.loadConfig().then(config => {
self.config = config;
});
},
};
</script>
<!-- vim:sw=2:ts=2:et: -->

141
src/options/Config.vue Normal file
View file

@ -0,0 +1,141 @@
<template>
<div class="page backup">
<h2>Extension Configuration</h2>
<div class="container">
<form class="loader" ref="loader" @submit.prevent="loadURL">
<div class="head">
Load configuration
<input type="radio" id="_file" value="file" v-model="extConfigType" />
<label for="_file">From file</label>
<input type="radio" id="_url" value="url" v-model="extConfigType" />
<label for="_file">From URL</label>
</div>
<div class="body">
<input type="file" name="file" placeholder="Configuration file" accept="application/json, text/x-json, text/plain" @change="uploadFile" v-if="extConfigType === 'file'" />
<input type="text" name="url" placeholder="Configuration URL" v-model="extURL" v-if="extConfigType === 'url'" />
<input type="submit" value="Load" v-if="extConfigType === 'url'" />
</div>
</form>
<form class="content" ref="content" @submit.prevent="save">
<div class="textarea">
<textarea ref="text" v-model="config" v-text="loading ? 'Loading...' : config" @focus="onFocus" :disabled="loading" />
</div>
<div class="buttons">
<button type="button" :disabled="savedConfig === config" @click="reload"><i class="fas fa-undo" /> &nbsp; Undo</button>
<button type="submit" :disabled="savedConfig === config"><i class="fas fa-save" /> &nbsp; Save</button>
</div>
</form>
</div>
</div>
</template>
<script>
import mixins from '../utils';
export default {
name: 'Backup',
mixins: [mixins],
data() {
return {
config: null,
savedConfig: null,
extConfigType: 'file',
extURL: null,
};
},
methods: {
onFocus(event) {
event.target.select();
document.execCommand('copy');
event.target.selectionStart = event.target.selectionEnd = 0;
this.notify('Configuration copied to the clipboard');
},
async reload() {
const config = await this.loadConfig();
this.config = JSON.stringify(config, null, ' ');
this.savedConfig = this.config;
},
save(event) {},
uploadFile(event) {
if (!(event.target.files && event.target.files.length)) {
return;
}
const self = this;
const reader = new FileReader();
this.loading = true;
reader.onload = evt => {
self.config = evt.target.result;
self.loading = false;
};
reader.onerror = evt => {
this.notify(reader.error, 'Could not read the file');
self.loading = false;
};
reader.readAsText(event.target.files[0]);
},
loadURL(event) {
console.log(event);
},
},
created() {
this.reload();
},
};
</script>
<style lang="scss" scoped>
textarea,
.loader {
width: 60%;
min-width: 30em;
max-width: 50em;
}
textarea {
height: 50em;
max-height: 80vh;
overflow: auto;
}
.loader {
margin-bottom: 1em;
.head {
margin-bottom: 1em;
}
.body {
display: flex;
align-items: center;
position: relative;
}
[type='text'] {
width: 80%;
min-width: 10em;
max-width: 40em;
margin: 0;
}
[type='submit'] {
position: absolute;
right: 0;
}
}
</style>
<!-- vim:sw=2:ts=2:et: -->

View file

@ -1,17 +1,21 @@
<template> <template>
<ul class="menu"> <ul class="menu">
<li class="host" v-for="(host, hostname) in hosts" :key="hostname" :class="{ selected: hostname === selectedHost }" @click="$emit('select-host', hostname)"> <li class="host" v-for="(host, hostname) in hosts" :key="hostname" :class="{ selected: hostname === selectedHost }" @click="$emit('select', 'host', hostname)">
<i class="fas fa-hdd" /> &nbsp; {{ host.name }} <i class="fas fa-hdd" /> &nbsp; {{ host.name }}
<ul class="host-menu" v-if="hostname === selectedHost"> <ul class="host-menu" v-if="hostname === selectedHost">
<li v-for="(option, name) in hostOptions" :key="name" :class="{ selected: selectedHostOption === name }" @click.stop="$emit('select-host-option', name)"> <li
v-for="(option, optionName) in hostOptions"
:key="optionName"
:class="{ selected: selectedHostOption === optionName }"
@click.stop="$emit('select', 'host', hostname, optionName)"
>
<i :class="option.iconClass" /> &nbsp; {{ option.displayName }} <i :class="option.iconClass" /> &nbsp; {{ option.displayName }}
</li> </li>
</ul> </ul>
</li> </li>
<li class="add" :class="{ selected: isAddHost }" @click="$emit('select-add-host')"><i class="fas fa-plus" /> &nbsp; Add Device</li> <li class="add" :class="{ selected: selectedTab === 'add' }" @click="$emit('select', 'add')"><i class="fas fa-plus" /> &nbsp; Add Device</li>
<li class="backup" :class="{ selected: isBackupMode }" @click="$emit('select-backup-mode')"><i class="fas fa-save" /> &nbsp; Backup Configuration</li> <li class="config" :class="{ selected: selectedTab === 'config' }" @click="$emit('select', 'config')"><i class="fas fa-cog" /> &nbsp; Configuration</li>
<li class="restore" :class="{ selected: isRestoreMode }" @click="$emit('select-restore-mode')"><i class="fas fa-window-restore" /> &nbsp; Restore Configuration</li>
</ul> </ul>
</template> </template>
@ -20,11 +24,9 @@ export default {
name: 'Menu', name: 'Menu',
props: { props: {
hosts: Object, hosts: Object,
selectedTab: String,
selectedHost: String, selectedHost: String,
selectedHostOption: String, selectedHostOption: String,
isAddHost: Boolean,
isBackupMode: Boolean,
isRestoreMode: Boolean,
}, },
computed: { computed: {

View file

@ -1,29 +0,0 @@
<template>
<div class="page restore">
<h2>Load configuration from a previous backup</h2>
<div class="container">
<textarea v-text="loading ? 'Loading...' : config" :disabled="loading" />
</div>
</div>
</template>
<script>
import mixins from '../utils';
export default {
name: 'Restore',
mixins: [mixins],
data() {
return {
config: {},
};
},
created() {
this.config = this.loadConfig();
},
};
</script>
<!-- vim:sw=2:ts=2:et: -->

View file

@ -8,7 +8,7 @@ export default {
}, },
methods: { methods: {
notify(message, title) { notify(message, title = 'platypush') {
browser.notifications.create({ browser.notifications.create({
type: 'basic', type: 'basic',
title: title, title: title,
@ -128,11 +128,17 @@ export default {
}, },
async loadConfig() { async loadConfig() {
this.loading = true;
try {
const [hosts, actions] = await Promise.all([this.getHosts(), this.getActions()]); const [hosts, actions] = await Promise.all([this.getHosts(), this.getActions()]);
return { return {
hosts: hosts, hosts: hosts,
actions: actions, actions: actions,
}; };
} finally {
this.loading = false;
}
}, },
formToHost(form) { formToHost(form) {