diff --git a/src/options/Config.vue b/src/options/Config.vue index 60855d1..5d44703 100644 --- a/src/options/Config.vue +++ b/src/options/Config.vue @@ -4,17 +4,41 @@

Extension Configuration

- Load configuration - - - - +
+ Load configuration + + + + + + +
+ +
+ + + +
+ + + +
@@ -22,7 +46,6 @@
-
@@ -52,6 +75,8 @@ export default { savedConfig: null, extConfigType: 'file', extURL: null, + selectedHost: null, + hosts: [], }; }, @@ -65,6 +90,7 @@ export default { async reload() { const config = await this.loadConfig(); + this.hosts = config.hosts || []; this.config = JSON.stringify(config, null, ' '); this.savedConfig = this.config; }, @@ -121,6 +147,10 @@ export default { this.loading = false; } }, + + async restoreConfig(host) { + this.config = JSON.stringify(await this.getConfig(host), null, ' '); + }, }, created() { @@ -176,7 +206,18 @@ $buttons-height: 5em; margin-bottom: 1em; .loader-head { + display: flex; + flex-direction: row; margin-bottom: 1em; + + .left { + width: 50%; + } + + .right { + width: 50%; + text-align: right; + } } .loader-body { @@ -197,6 +238,10 @@ $buttons-height: 5em; right: 0; } } + +select { + margin-right: 0.5em; +} diff --git a/src/utils.js b/src/utils.js index 4f90a8c..0ad1c70 100644 --- a/src/utils.js +++ b/src/utils.js @@ -71,11 +71,18 @@ export default { if (Array.isArray(action.args)) { args = action.args - .filter(arg => arg.value && arg.value.length) + .filter(arg => arg.value != null && arg.value.length) .reduce((obj, arg) => { obj[arg.name] = arg.value; return obj; }, {}); + } else { + args = Object.entries(args) + .filter(([name, value]) => value != null && value.length) + .reduce((obj, [name, value]) => { + obj[name] = value; + return obj; + }, {}); } Object.keys(args).forEach(name => { @@ -282,6 +289,78 @@ export default { } }, + async backupConfig(host) { + if (typeof host === 'string') { + const hosts = await this.getHosts(); + if (!(host in hosts)) { + this.notify(host, 'No such Platypush host'); + return; + } + + host = hosts[host]; + } + + this.loading = true; + const config = JSON.stringify(await this.loadConfig()); + const basedir = `\${Config.get("workdir")}/webext`; + const filename = `${basedir}/config.json`; + + try { + await this.run( + { + name: 'file.mkdir', + args: { directory: basedir }, + }, + host + ); + + await this.run( + { + name: 'file.write', + args: { + file: filename, + content: config, + }, + }, + host + ); + + this.notify(`Configugration successfully backed up to ${host.name}`, 'Backup successful'); + } finally { + this.loading = false; + } + }, + + async getConfig(host) { + if (typeof host === 'string') { + const hosts = await this.getHosts(); + if (!(host in hosts)) { + this.notify(host, 'No such Platypush host'); + return; + } + + host = hosts[host]; + } + + this.loading = true; + const basedir = `\${Config.get("workdir")}/webext`; + const filename = `${basedir}/config.json`; + + try { + const config = await this.run( + { + name: 'file.read', + args: { file: filename }, + }, + host + ); + + return config; + } finally { + this.loading = false; + } + }, + formToHost(form) { return { name: form.name.value,