handle error for local plugin

pull/1/head
Grandschtroumpf 6 years ago committed by yann300
parent 1e17d8c476
commit 8dd5315775
  1. 14
      src/app/components/local-plugin.js
  2. 14
      src/app/components/plugin-manager-component.js

@ -12,8 +12,16 @@ module.exports = class LocalPlugin {
open (plugins) { open (plugins) {
this.profile = JSON.parse(localStorage.getItem('plugins/local')) || { notifications: {} } this.profile = JSON.parse(localStorage.getItem('plugins/local')) || { notifications: {} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const onValidation = () => {
try {
const profile = this.create()
resolve(profile)
} catch (err) {
reject(err)
}
}
modalDialog('Local Plugin', this.form(plugins), modalDialog('Local Plugin', this.form(plugins),
{ fn: () => resolve(this.create()) }, { fn: () => onValidation() },
{ fn: () => resolve() } { fn: () => resolve() }
) )
}) })
@ -94,7 +102,7 @@ module.exports = class LocalPlugin {
return yo` return yo`
<form id="local-plugin-form" onsubmit="${e => this.validate(e)}"> <form id="local-plugin-form" onsubmit="${e => this.validate(e)}">
<div class="form-group"> <div class="form-group">
<label for="plugin-name">Plugin Name</label> <label for="plugin-name">Plugin Name <small>(required)</small></label>
<input class="form-control" onchange="${e => this.updateName(e)}" value="${name}" id="plugin-name" placeholder="Should be camelCase"> <input class="form-control" onchange="${e => this.updateName(e)}" value="${name}" id="plugin-name" placeholder="Should be camelCase">
</div> </div>
<div class="form-group"> <div class="form-group">
@ -102,7 +110,7 @@ module.exports = class LocalPlugin {
<input class="form-control" onchange="${e => this.updateDisplayName(e)}" value="${displayName}" id="plugin-displayname" placeholder="Name in the header"> <input class="form-control" onchange="${e => this.updateDisplayName(e)}" value="${displayName}" id="plugin-displayname" placeholder="Name in the header">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="plugin-url">Url</label> <label for="plugin-url">Url <small>(required)</small></label>
<input class="form-control" onchange="${e => this.updateUrl(e)}" value="${url}" id="plugin-url" placeholder="ex: https://localhost:8000"> <input class="form-control" onchange="${e => this.updateUrl(e)}" value="${url}" id="plugin-url" placeholder="ex: https://localhost:8000">
</div> </div>
<div class="form-group"> <div class="form-group">

@ -104,11 +104,15 @@ class PluginManagerComponent {
* Add a local plugin to the list of plugins * Add a local plugin to the list of plugins
*/ */
async openLocalPlugin () { async openLocalPlugin () {
const profile = await this.localPlugin.open(this.store.getAll()) try {
if (!profile) return const profile = await this.localPlugin.open(this.store.getAll())
const resolveLocaton = (iframe) => this.appManager.resolveLocation(profile, iframe) if (!profile) return
const api = new Plugin(profile, { resolveLocaton }) const resolveLocaton = (iframe) => this.appManager.resolveLocation(profile, iframe)
this.appManager.init([{profile, api}]) const api = new Plugin(profile, { resolveLocaton })
this.appManager.init([{profile, api}])
} catch (err) {
console.log(`Cannot create Plugin : ${err.message}`)
}
} }
render () { render () {

Loading…
Cancel
Save