From 048e5e0a4e7723981e174825e7359836433646c3 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 2 Jul 2018 22:49:47 +0200 Subject: [PATCH] load oraclize plugin --- src/app/panels/righthand-panel.js | 23 +++++++++++++++++++---- src/app/plugin/pluginManager.js | 5 +++++ src/app/plugin/plugins.js | 8 ++++++++ src/app/tabs/settings-tab.js | 14 ++++++++++---- src/app/tabs/tabbed-menu.js | 11 +++++++++++ 5 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 src/app/plugin/plugins.js diff --git a/src/app/panels/righthand-panel.js b/src/app/panels/righthand-panel.js index 77f389f278..aca26f259b 100644 --- a/src/app/panels/righthand-panel.js +++ b/src/app/panels/righthand-panel.js @@ -16,7 +16,9 @@ const PluginTab = require('../tabs/plugin-tab') const TestTab = require('../tabs/test-tab') const RunTab = require('../tabs/run-tab') const PluginAPI = require('../plugin/pluginAPI') +const plugins = require('../plugin/plugins') +var toolTip = require('../ui/tooltip') const EventManager = remixLib.EventManager const styles = styleguide.chooser() @@ -73,11 +75,24 @@ module.exports = class RighthandPanel { 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) { - 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) + if (self._components.pluginManager.plugins[json.title]) { + self._components.tabbedMenu.removeTabByTitle(json.title) + self._components.pluginManager.unregister(json) + } 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`
` diff --git a/src/app/plugin/pluginManager.js b/src/app/plugin/pluginManager.js index 5492581284..0ea91f1781 100644 --- a/src/app/plugin/pluginManager.js +++ b/src/app/plugin/pluginManager.js @@ -161,6 +161,11 @@ module.exports = class PluginManager { // } }, false) } + unregister (desc) { + const self = this + delete self.plugins[desc.title] + delete self.origins[desc.url] + } register (desc, content) { const self = this self.plugins[desc.title] = {content, origin: desc.url} diff --git a/src/app/plugin/plugins.js b/src/app/plugin/plugins.js new file mode 100644 index 0000000000..68cdb2e31e --- /dev/null +++ b/src/app/plugin/plugins.js @@ -0,0 +1,8 @@ +'use strict' + +module.exports = { + 'oraclize': { + url: 'https://remix-plugin.oraclize.it', + title: 'Oraclize' + } +} diff --git a/src/app/tabs/settings-tab.js b/src/app/tabs/settings-tab.js index ba2d3b0fd5..6b406f86ed 100644 --- a/src/app/tabs/settings-tab.js +++ b/src/app/tabs/settings-tab.js @@ -26,7 +26,8 @@ module.exports = class SettingsTab { compiler: self._components.registry.get('compiler').api, config: self._components.registry.get('config').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 */ el: null, @@ -155,8 +156,9 @@ module.exports = class SettingsTab {
${self._view.pluginInput} - +
+ { onLoadPlugin('oraclize') }} type="button" value="Oraclize" class="${css.pluginLoad}"> ` self._view.config.remixd = yo` @@ -197,14 +199,18 @@ module.exports = class SettingsTab { function onchangeOption (event) { 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 { var json = JSON.parse(self._view.pluginInput.value) } catch (e) { return modal.alert('cannot parse the plugin definition to JSON') } // @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) { styleGuide.switchTheme('dark') diff --git a/src/app/tabs/tabbed-menu.js b/src/app/tabs/tabbed-menu.js index ca9f39de28..69a1b2aa5b 100644 --- a/src/app/tabs/tabbed-menu.js +++ b/src/app/tabs/tabbed-menu.js @@ -46,6 +46,17 @@ module.exports = class TabbedMenu { if (self._view.el) self._view.el.appendChild(self._view.tabs[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) { const self = this return self._view.el.querySelector(`li.${tabClass}`)