From d8d1f9f5fbc1cc4bfa605d94d1cf6ae73d0bb5fe Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 25 Mar 2019 18:08:41 +0100 Subject: [PATCH 1/3] status API --- .../components/vertical-icons-component.js | 59 ++++++++++++++++--- src/app/editor/contextualListener.js | 3 +- src/app/staticanalysis/staticAnalysisView.js | 1 + src/app/tabs/analysis-tab.js | 9 +++ src/app/tabs/compile-tab.js | 4 ++ 5 files changed, 68 insertions(+), 8 deletions(-) diff --git a/src/app/components/vertical-icons-component.js b/src/app/components/vertical-icons-component.js index e81c34c068..2e0dbc98e9 100644 --- a/src/app/components/vertical-icons-component.js +++ b/src/app/components/vertical-icons-component.js @@ -11,33 +11,72 @@ class VerticalIconComponent { this.events = new EventEmitter() this.icons = {} this.iconKind = {} + this.iconStatus = {} this.name = name this.store.event.on('activate', (name) => { - const { profile } = this.store.getOne(name) - if (!profile.icon) return - if (profile.location === this.name || !profile.location) { - this.addIcon(profile) + const api = this.store.getOne(name) + if (!api.profile.icon) return + if (api.profile.location === this.name || !api.profile.location) { + this.addIcon(api.profile) + this.listenOnStatus(api) } }) this.store.event.on('deactivate', (name) => { const api = this.store.getOne(name) - if (api && this.icons[name]) this.removeIcon(api.profile) + if (api && this.icons[name]) { + this.removeIcon(api.profile) + this.stopListenOnStatus(api) + } }) this.store.event.on('add', (api) => { }) this.store.event.on('remove', (api) => { }) } + stopListenOnStatus (api) { + if (!api.events) return + let fn = this.iconStatus[api.profile.name] + if (fn) { + api.events.unregister('setStatus', fn) + delete this.iconStatus[api.profile.name] + } + } + + listenOnStatus (api) { + if (!api.events) return + const fn = (status) => { + this.setIconStatus(api.profile.name, status) + } + this.iconStatus[api.profile.name] = fn + api.events.on('setStatus', this.iconStatus[api.profile.name]) + } + /** * Add an icon to the map * @param {ModuleProfile} profile The profile of the module */ addIcon ({kind, name, icon}) { this.icons[name] = yo`
${name}
` - this.iconKind[kind || 'other'].appendChild(this.icons[name]) } + /** + * Set a new status for the @arg name + * @param {name} + * @param {status} + */ + setIconStatus (name, status) { + const el = this.icons[name] + if (!el) return + let statusEl = el.querySelector('i') + if (statusEl) { + el.removeChild(statusEl) + } + if (status.key) { + el.appendChild(yo``) + } + } + /** * Remove an icon from the map * @param {ModuleProfile} profile The profile of the module @@ -136,6 +175,7 @@ const css = csjs` width: 36px; height: 36px; padding: 3px; + position: relative; } .icon img { width: 28px; @@ -152,9 +192,14 @@ const css = csjs` border-radius: 8px; padding-top: 1px; padding-left: 1px; -} + } .icon[title='settings'] { position: absolute; bottom: 0; } + .status { + position: absolute; + bottom: 0; + right: 0; + } ` diff --git a/src/app/editor/contextualListener.js b/src/app/editor/contextualListener.js index dcbc60077c..7673e1d7d9 100644 --- a/src/app/editor/contextualListener.js +++ b/src/app/editor/contextualListener.js @@ -69,6 +69,7 @@ class ContextualListener { this.currentPosition = cursorPosition return } + this._stopHighlighting() this.currentPosition = cursorPosition this.currentFile = file if (compilationResult && compilationResult.data && compilationResult.data.sources[file]) { @@ -78,7 +79,7 @@ class ContextualListener { this._highlightExpressions(nodes[nodes.length - 1], compilationResult) } this.event.trigger('contextChanged', [nodes]) - } else this._stopHighlighting() + } } _buildIndex (compilationResult, source) { diff --git a/src/app/staticanalysis/staticAnalysisView.js b/src/app/staticanalysis/staticAnalysisView.js index e00676a4ea..699387b61a 100644 --- a/src/app/staticanalysis/staticAnalysisView.js +++ b/src/app/staticanalysis/staticAnalysisView.js @@ -125,6 +125,7 @@ staticAnalysisView.prototype.run = function () { }) } else { warningContainer.html('No compiled AST available') + self.event.trigger('staticAnaysisWarning', [0]) } } diff --git a/src/app/tabs/analysis-tab.js b/src/app/tabs/analysis-tab.js index 390082c84c..aadaba6975 100644 --- a/src/app/tabs/analysis-tab.js +++ b/src/app/tabs/analysis-tab.js @@ -4,12 +4,14 @@ var EventManager = require('../../lib/events') var css = require('./styles/analysis-tab-styles') import { ApiFactory } from 'remix-plugin' +import { EventEmitter } from 'events' class AnalysisTab extends ApiFactory { constructor (registry) { super() this.event = new EventManager() + this.events = new EventEmitter() this.registry = registry } @@ -27,6 +29,13 @@ class AnalysisTab extends ApiFactory { render () { var staticanalysis = new StaticAnalysis() + staticanalysis.event.register('staticAnaysisWarning', (count) => { + if (count) { + this.events.emit('setStatus', {key: 'exclamation-triangle', title: count + ' warnings', type: 'warning'}) + } else { + this.events.emit('setStatus', {key: 'check', title: 'no warning', type: 'success'}) + } + }) this.registry.put({api: staticanalysis, name: 'staticanalysis'}) if (this.el) return this.el diff --git a/src/app/tabs/compile-tab.js b/src/app/tabs/compile-tab.js index f87d43f61a..4bdd386b16 100644 --- a/src/app/tabs/compile-tab.js +++ b/src/app/tabs/compile-tab.js @@ -79,6 +79,7 @@ class CompileTab extends ApiFactory { if (this._view.errorContainer) { this._view.errorContainer.innerHTML = '' } + this.events.emit('setStatus', {key: 'spinner', title: 'compiling...', type: 'info'}) }) this.fileManager.events.on('currentFileChanged', (name) => { @@ -88,6 +89,7 @@ class CompileTab extends ApiFactory { if (success) { // forwarding the event to the appManager infra this.events.emit('compilationFinished', source.target, source, 'soljson', data) + this.events.emit('setStatus', {key: 'check', title: 'compilation successful', type: 'success'}) // Store the contracts this.data.contractsDetails = {} this.compiler.visitContracts((contract) => { @@ -97,6 +99,8 @@ class CompileTab extends ApiFactory { this.compiler.getSource(contract.file) ) }) + } else { + this.events.emit('setStatus', {key: 'exclamation', title: 'compilation failed', type: 'danger'}) } // Update contract Selection let contractMap = {} From 0fcf3ac3df1689b5113cdbb75e20a0882d89a24c Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 26 Mar 2019 12:19:10 +0100 Subject: [PATCH 2/3] check for special char --- src/app/components/vertical-icons-component.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/app/components/vertical-icons-component.js b/src/app/components/vertical-icons-component.js index 2e0dbc98e9..bf9ac34605 100644 --- a/src/app/components/vertical-icons-component.js +++ b/src/app/components/vertical-icons-component.js @@ -1,5 +1,6 @@ var yo = require('yo-yo') var csjs = require('csjs-inject') +var helper = require('../../lib/helper') const EventEmitter = require('events') @@ -62,8 +63,8 @@ class VerticalIconComponent { /** * Set a new status for the @arg name - * @param {name} - * @param {status} + * @param {String} name + * @param {Object} status */ setIconStatus (name, status) { const el = this.icons[name] @@ -73,7 +74,10 @@ class VerticalIconComponent { el.removeChild(statusEl) } if (status.key) { - el.appendChild(yo``) + let key = helper.checkSpecialChars(status.key) ? '' : status.key + let type = helper.checkSpecialChars(status.type) ? '' : status.type + let title = helper.checkSpecialChars(status.title) ? '' : status.title + el.appendChild(yo``) } } From 38cd56ca1a3d5f57aa064c50f08b1f768c06c0aa Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 26 Mar 2019 12:37:43 +0100 Subject: [PATCH 3/3] rename event --- src/app/components/vertical-icons-component.js | 4 ++-- src/app/tabs/analysis-tab.js | 4 ++-- src/app/tabs/compile-tab.js | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/app/components/vertical-icons-component.js b/src/app/components/vertical-icons-component.js index bf9ac34605..bc0ecdb00d 100644 --- a/src/app/components/vertical-icons-component.js +++ b/src/app/components/vertical-icons-component.js @@ -38,7 +38,7 @@ class VerticalIconComponent { if (!api.events) return let fn = this.iconStatus[api.profile.name] if (fn) { - api.events.unregister('setStatus', fn) + api.events.remove('statusChanged', fn) delete this.iconStatus[api.profile.name] } } @@ -49,7 +49,7 @@ class VerticalIconComponent { this.setIconStatus(api.profile.name, status) } this.iconStatus[api.profile.name] = fn - api.events.on('setStatus', this.iconStatus[api.profile.name]) + api.events.on('statusChanged', this.iconStatus[api.profile.name]) } /** diff --git a/src/app/tabs/analysis-tab.js b/src/app/tabs/analysis-tab.js index aadaba6975..2b663cf594 100644 --- a/src/app/tabs/analysis-tab.js +++ b/src/app/tabs/analysis-tab.js @@ -31,9 +31,9 @@ class AnalysisTab extends ApiFactory { var staticanalysis = new StaticAnalysis() staticanalysis.event.register('staticAnaysisWarning', (count) => { if (count) { - this.events.emit('setStatus', {key: 'exclamation-triangle', title: count + ' warnings', type: 'warning'}) + this.events.emit('statusChanged', {key: 'exclamation-triangle', title: count + ' warnings', type: 'warning'}) } else { - this.events.emit('setStatus', {key: 'check', title: 'no warning', type: 'success'}) + this.events.emit('statusChanged', {key: 'check', title: 'no warning', type: 'success'}) } }) this.registry.put({api: staticanalysis, name: 'staticanalysis'}) diff --git a/src/app/tabs/compile-tab.js b/src/app/tabs/compile-tab.js index 4bdd386b16..764a0442b6 100644 --- a/src/app/tabs/compile-tab.js +++ b/src/app/tabs/compile-tab.js @@ -79,7 +79,7 @@ class CompileTab extends ApiFactory { if (this._view.errorContainer) { this._view.errorContainer.innerHTML = '' } - this.events.emit('setStatus', {key: 'spinner', title: 'compiling...', type: 'info'}) + this.events.emit('statusChanged', {key: 'spinner', title: 'compiling...', type: 'info'}) }) this.fileManager.events.on('currentFileChanged', (name) => { @@ -89,7 +89,7 @@ class CompileTab extends ApiFactory { if (success) { // forwarding the event to the appManager infra this.events.emit('compilationFinished', source.target, source, 'soljson', data) - this.events.emit('setStatus', {key: 'check', title: 'compilation successful', type: 'success'}) + this.events.emit('statusChanged', {key: 'check', title: 'compilation successful', type: 'success'}) // Store the contracts this.data.contractsDetails = {} this.compiler.visitContracts((contract) => { @@ -100,7 +100,7 @@ class CompileTab extends ApiFactory { ) }) } else { - this.events.emit('setStatus', {key: 'exclamation', title: 'compilation failed', type: 'danger'}) + this.events.emit('statusChanged', {key: 'exclamation', title: 'compilation failed', type: 'danger'}) } // Update contract Selection let contractMap = {}