load oraclize plugin

pull/3094/head
yann300 6 years ago
parent be6a09cb07
commit 048e5e0a4e
  1. 23
      src/app/panels/righthand-panel.js
  2. 5
      src/app/plugin/pluginManager.js
  3. 8
      src/app/plugin/plugins.js
  4. 14
      src/app/tabs/settings-tab.js
  5. 11
      src/app/tabs/tabbed-menu.js

@ -16,7 +16,9 @@ const PluginTab = require('../tabs/plugin-tab')
const TestTab = require('../tabs/test-tab') const TestTab = require('../tabs/test-tab')
const RunTab = require('../tabs/run-tab') const RunTab = require('../tabs/run-tab')
const PluginAPI = require('../plugin/pluginAPI') const PluginAPI = require('../plugin/pluginAPI')
const plugins = require('../plugin/plugins')
var toolTip = require('../ui/tooltip')
const EventManager = remixLib.EventManager const EventManager = remixLib.EventManager
const styles = styleguide.chooser() const styles = styleguide.chooser()
@ -73,11 +75,24 @@ module.exports = class RighthandPanel {
self.loadPlugin(json) self.loadPlugin(json)
}) })
self.event.register('plugin-name-loadRequest', name => {
if (plugins[name]) {
self.loadPlugin(plugins[name])
} else {
toolTip('unknown plugin ' + name)
}
})
self.loadPlugin = function (json) { self.loadPlugin = function (json) {
var tab = new PluginTab(json) if (self._components.pluginManager.plugins[json.title]) {
var content = tab.render() self._components.tabbedMenu.removeTabByTitle(json.title)
self._components.tabbedMenu.addTab(json.title, json.title + ' plugin', content) self._components.pluginManager.unregister(json)
self._components.pluginManager.register(json, content) } else {
var tab = new PluginTab(json)
var content = tab.render()
self._components.tabbedMenu.addTab(json.title, json.title + ' plugin', content)
self._components.pluginManager.register(json, content)
}
} }
self._view.dragbar = yo`<div id="dragbar" class=${css.dragbar}></div>` self._view.dragbar = yo`<div id="dragbar" class=${css.dragbar}></div>`

@ -161,6 +161,11 @@ module.exports = class PluginManager {
// } // }
}, false) }, false)
} }
unregister (desc) {
const self = this
delete self.plugins[desc.title]
delete self.origins[desc.url]
}
register (desc, content) { register (desc, content) {
const self = this const self = this
self.plugins[desc.title] = {content, origin: desc.url} self.plugins[desc.title] = {content, origin: desc.url}

@ -0,0 +1,8 @@
'use strict'
module.exports = {
'oraclize': {
url: 'https://remix-plugin.oraclize.it',
title: 'Oraclize'
}
}

@ -26,7 +26,8 @@ module.exports = class SettingsTab {
compiler: self._components.registry.get('compiler').api, compiler: self._components.registry.get('compiler').api,
config: self._components.registry.get('config').api, config: self._components.registry.get('config').api,
editorPanel: self._components.registry.get('editorpanel').api, editorPanel: self._components.registry.get('editorpanel').api,
editor: self._components.registry.get('editor').api editor: self._components.registry.get('editor').api,
righthandpanel: self._components.registry.get('righthandpanel').api
} }
self._view = { /* eslint-disable */ self._view = { /* eslint-disable */
el: null, el: null,
@ -155,8 +156,9 @@ module.exports = class SettingsTab {
</div> </div>
<div> <div>
${self._view.pluginInput} ${self._view.pluginInput}
<input onclick=${onloadPlugin} type="button" value="Load" class="${css.pluginLoad}"> <input onclick=${onloadPluginJson} type="button" value="Load" class="${css.pluginLoad}">
</div> </div>
<input onclick=${() => { onLoadPlugin('oraclize') }} type="button" value="Oraclize" class="${css.pluginLoad}">
</div> </div>
</div>` </div>`
self._view.config.remixd = yo` self._view.config.remixd = yo`
@ -197,14 +199,18 @@ module.exports = class SettingsTab {
function onchangeOption (event) { function onchangeOption (event) {
self._deps.config.set('settings/always-use-vm', !self._deps.config.get('settings/always-use-vm')) self._deps.config.set('settings/always-use-vm', !self._deps.config.get('settings/always-use-vm'))
} }
function onloadPlugin (event) { function onLoadPlugin (name) {
// @TODO: BAD! REFACTOR: no module should trigger events of another modules emitter
self._deps.righthandpanel.event.trigger('plugin-name-loadRequest', [name])
}
function onloadPluginJson (event) {
try { try {
var json = JSON.parse(self._view.pluginInput.value) var json = JSON.parse(self._view.pluginInput.value)
} catch (e) { } catch (e) {
return modal.alert('cannot parse the plugin definition to JSON') return modal.alert('cannot parse the plugin definition to JSON')
} }
// @TODO: BAD! REFACTOR: no module should trigger events of another modules emitter // @TODO: BAD! REFACTOR: no module should trigger events of another modules emitter
self._events.rhp.trigger('plugin-loadRequest', [json]) self._deps.righthandpanel.event.trigger('plugin-loadRequest', [json])
} }
function onswitch2darkTheme (event) { function onswitch2darkTheme (event) {
styleGuide.switchTheme('dark') styleGuide.switchTheme('dark')

@ -46,6 +46,17 @@ module.exports = class TabbedMenu {
if (self._view.el) self._view.el.appendChild(self._view.tabs[title]) if (self._view.el) self._view.el.appendChild(self._view.tabs[title])
if (self._view.viewport) self._view.viewport.appendChild(self._view.contents[title]) if (self._view.viewport) self._view.viewport.appendChild(self._view.contents[title])
} }
removeTabByTitle (title) {
const self = this
if (self._view.tabs[title]) {
self._view.tabs[title].parentNode.removeChild(self._view.tabs[title])
}
if (self._view.contents[title]) {
self._view.contents[title].parentNode.removeChild(self._view.contents[title])
}
delete self._view.contents[title]
delete self._view.tabs[title]
}
getTabByClass (tabClass) { getTabByClass (tabClass) {
const self = this const self = this
return self._view.el.querySelector(`li.${tabClass}`) return self._view.el.querySelector(`li.${tabClass}`)

Loading…
Cancel
Save