pull/1/head
Grandschtroumpf 6 years ago committed by yann300
parent fe4ba66b2f
commit 66931ebc8a
  1. 28
      src/app/components/local-plugin.js
  2. 3
      src/app/components/plugin-manager-component.js

@ -3,27 +3,25 @@ const modalDialog = require('../ui/modaldialog')
module.exports = class LocalPlugin {
constructor() {}
/**
* Open a modal to create a local plugin
* @param {{profile: any, api: any}[]} plugins The list of the plugins in the store
* @returns {Promise<{api: any, profile: any}>} A promise with the new plugin profile
*/
open(plugins) {
open (plugins) {
this.profile = JSON.parse(localStorage.getItem('plugins/local')) || { notifications: {} }
return new Promise((res, rej) => {
return new Promise((resolve, reject) => {
modalDialog('Local Plugin', this.form(plugins),
{ fn:() => res(this.create()) },
{ fn: () => rej() }
{ fn: () => resolve(this.create()) },
{ fn: () => resolve() }
)
})
})
}
/**
* Create the object to add to the plugin-list
*/
create() {
create () {
const profile = {
...this.profile,
icon: 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPHN2ZyB3aWR0aD0iMTc5MiIgaGVpZ2h0PSIxNzkyIiB2aWV3Qm94PSIwIDAgMTc5MiAxNzkyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik0xMjYyIDEwNzVxLTM3IDEyMS0xMzggMTk1dC0yMjggNzQtMjI4LTc0LTEzOC0xOTVxLTgtMjUgNC00OC41dDM4LTMxLjVxMjUtOCA0OC41IDR0MzEuNSAzOHEyNSA4MCA5Mi41IDEyOS41dDE1MS41IDQ5LjUgMTUxLjUtNDkuNSA5Mi41LTEyOS41cTgtMjYgMzItMzh0NDktNCAzNyAzMS41IDQgNDguNXptLTQ5NC00MzVxMCA1My0zNy41IDkwLjV0LTkwLjUgMzcuNS05MC41LTM3LjUtMzcuNS05MC41IDM3LjUtOTAuNSA5MC41LTM3LjUgOTAuNSAzNy41IDM3LjUgOTAuNXptNTEyIDBxMCA1My0zNy41IDkwLjV0LTkwLjUgMzcuNS05MC41LTM3LjUtMzcuNS05MC41IDM3LjUtOTAuNSA5MC41LTM3LjUgOTAuNSAzNy41IDM3LjUgOTAuNXptMjU2IDI1NnEwLTEzMC01MS0yNDguNXQtMTM2LjUtMjA0LTIwNC0xMzYuNS0yNDguNS01MS0yNDguNSA1MS0yMDQgMTM2LjUtMTM2LjUgMjA0LTUxIDI0OC41IDUxIDI0OC41IDEzNi41IDIwNCAyMDQgMTM2LjUgMjQ4LjUgNTEgMjQ4LjUtNTEgMjA0LTEzNi41IDEzNi41LTIwNCA1MS0yNDguNXptMTI4IDBxMCAyMDktMTAzIDM4NS41dC0yNzkuNSAyNzkuNS0zODUuNSAxMDMtMzg1LjUtMTAzLTI3OS41LTI3OS41LTEwMy0zODUuNSAxMDMtMzg1LjUgMjc5LjUtMjc5LjUgMzg1LjUtMTAzIDM4NS41IDEwMyAyNzkuNSAyNzkuNSAxMDMgMzg1LjV6Ii8+PC9zdmc+',
@ -42,7 +40,7 @@ module.exports = class LocalPlugin {
* @param {string} pluginName The name of the plugin
* @param {string} eventName The name of the event to listen on
*/
toggleNotification(e, pluginName, eventName) {
toggleNotification (e, pluginName, eventName) {
const {checked} = e.target
if (checked) {
if (!this.profile.notifications[pluginName]) this.profile.notifications[pluginName] = []
@ -53,15 +51,15 @@ module.exports = class LocalPlugin {
}
}
updateName({target}) {
updateName ({target}) {
this.profile.name = target.value
}
updateUrl({target}) {
updateUrl ({target}) {
this.profile.url = target.value
}
updateDisplayName({target}) {
updateDisplayName ({target}) {
this.profile.displayName = target.value
}
@ -70,7 +68,7 @@ module.exports = class LocalPlugin {
* @param {string} plugin The name of the plugin
* @param {string} event The name of the event exposed by the plugin
*/
notificationCheckbox(plugin, event) {
notificationCheckbox (plugin, event) {
const notifications = this.profile.notifications || {}
const checkbox = notifications[plugin] && notifications[plugin].includes(event)
? yo`<input type="checkbox" checked onchange="${e => this.toggleNotification(e, plugin, event)}">`
@ -85,7 +83,7 @@ module.exports = class LocalPlugin {
* The form to create a local plugin
* @param {Profile[]} plugins Liste of profile of the plugins
*/
form(plugins = []) {
form (plugins = []) {
const name = this.profile.name || ''
const url = this.profile.url || ''
const displayName = this.profile.displayName || ''
@ -114,4 +112,4 @@ module.exports = class LocalPlugin {
</div>
</form>`
}
}
}

@ -103,8 +103,9 @@ class PluginManagerComponent {
/**
* Add a local plugin to the list of plugins
*/
async openLocalPlugin() {
async openLocalPlugin () {
const profile = await this.localPlugin.open(this.store.getAll())
if (!profile) return
const resolveLocaton = (iframe) => this.appManager.resolveLocation(profile, iframe)
const api = new Plugin(profile, { resolveLocaton })
this.appManager.init([{profile, api}])

Loading…
Cancel
Save