@ -4,15 +4,52 @@ var style = require('./styles/basicStyles')
var ui = require ( '../helpers/ui' )
var ui = require ( '../helpers/ui' )
var yo = require ( 'yo-yo' )
var yo = require ( 'yo-yo' )
function ButtonNavigator ( _traceManager ) {
function ButtonNavigator ( _parent , _ traceManager ) {
this . event = new EventManager ( )
this . event = new EventManager ( )
this . intoBackDisabled = true
this . intoBackDisabled = true
this . overBackDisabled = true
this . overBackDisabled = true
this . intoForwardDisabled = true
this . intoForwardDisabled = true
this . overForwardDisabled = true
this . overForwardDisabled = true
this . nextCallDisabled = true
this . nextCallDisabled = true
this . jumpOutDisabled = true
this . traceManager = _traceManager
this . traceManager = _traceManager
this . currentCall = null
this . revertionPoint = null
_parent . event . register ( 'indexChanged' , this , ( index ) => {
if ( index < 0 ) return
if ( _parent . currentStepIndex !== index ) return
this . traceManager . buildCallPath ( index , ( error , callsPath ) => {
if ( error ) {
console . log ( error )
resetWarning ( this )
} else {
this . currentCall = callsPath [ callsPath . length - 1 ]
if ( this . currentCall . reverted ) {
this . revertionPoint = this . currentCall . return
this . view . querySelector ( '#reverted' ) . style . display = 'block'
this . view . querySelector ( '#reverted #outofgas' ) . style . display = this . currentCall . outOfGas ? 'inline' : 'none'
this . view . querySelector ( '#reverted #parenthasthrown' ) . style . display = 'none'
} else {
var k = callsPath . length - 2
while ( k > 0 ) {
var parent = callsPath [ k ]
if ( parent . reverted ) {
this . revertionPoint = parent . return
this . view . querySelector ( '#reverted' ) . style . display = 'block'
this . view . querySelector ( '#reverted #parenthasthrown' ) . style . display = parent ? 'inline' : 'none'
this . view . querySelector ( '#reverted #outofgas' ) . style . display = 'none'
return
}
k --
}
resetWarning ( this )
}
}
} )
} )
this . view
this . view
}
}
@ -32,6 +69,15 @@ ButtonNavigator.prototype.render = function () {
< / b u t t o n >
< / b u t t o n >
< button id = 'nextcall' title = 'step next call' class = 'fa fa-chevron-right' style = $ { ui . formatCss ( style . button ) } onclick = $ { function ( ) { self . event . trigger ( 'jumpNextCall' ) } } disabled = $ { this . nextCallDisabled } >
< button id = 'nextcall' title = 'step next call' class = 'fa fa-chevron-right' style = $ { ui . formatCss ( style . button ) } onclick = $ { function ( ) { self . event . trigger ( 'jumpNextCall' ) } } disabled = $ { this . nextCallDisabled } >
< / b u t t o n >
< / b u t t o n >
< button id = 'jumpout' title = 'jump out' class = 'fa fa-share' style = $ { ui . formatCss ( style . button ) } onclick = $ { function ( ) { self . event . trigger ( 'jumpOut' ) } } disabled = $ { this . jumpOutDisabled } >
< / b u t t o n >
< div id = 'reverted' style = "display:none" >
< button id = 'jumptoexception' title = 'jump to exception' class = 'fa fa-exclamation-triangle' style = $ { ui . formatCss ( style . button ) } onclick = $ { function ( ) { self . event . trigger ( 'jumpToException' , [ self . revertionPoint ] ) } } disabled = $ { this . jumpOutDisabled } >
< / b u t t o n >
< span > State changes made during this call will be reverted . < / s p a n >
< span id = 'outofgas' style = "display:none" > This call will run out of gas . < / s p a n >
< span id = 'parenthasthrown' style = "display:none" > The parent call will throw an exception < / s p a n >
< / d i v >
< / d i v > `
< / d i v > `
if ( ! this . view ) {
if ( ! this . view ) {
this . view = view
this . view = view
@ -45,6 +91,8 @@ ButtonNavigator.prototype.reset = function () {
this . intoForwardDisabled = true
this . intoForwardDisabled = true
this . overForwardDisabled = true
this . overForwardDisabled = true
this . nextCallDisabled = true
this . nextCallDisabled = true
this . jumpOutDisabled = true
resetWarning ( this )
}
}
ButtonNavigator . prototype . stepChanged = function ( step ) {
ButtonNavigator . prototype . stepChanged = function ( step ) {
@ -53,7 +101,6 @@ ButtonNavigator.prototype.stepChanged = function (step) {
if ( ! this . traceManager ) {
if ( ! this . traceManager ) {
this . intoForwardDisabled = true
this . intoForwardDisabled = true
this . overForwardDisabled = true
this . overForwardDisabled = true
this . nextCallDisabled = true
} else {
} else {
var self = this
var self = this
this . traceManager . getLength ( function ( error , length ) {
this . traceManager . getLength ( function ( error , length ) {
@ -63,7 +110,10 @@ ButtonNavigator.prototype.stepChanged = function (step) {
} else {
} else {
self . intoForwardDisabled = step >= length - 1
self . intoForwardDisabled = step >= length - 1
self . overForwardDisabled = step >= length - 1
self . overForwardDisabled = step >= length - 1
self . nextCallDisabled = step >= length - 1
var nextCall = self . traceManager . findNextCall ( step )
self . nextCallDisabled = nextCall === step
var stepOut = self . traceManager . findStepOut ( step )
self . jumpOutDisabled = stepOut === step
}
}
self . updateAll ( )
self . updateAll ( )
} )
} )
@ -77,6 +127,8 @@ ButtonNavigator.prototype.updateAll = function () {
this . updateDisabled ( 'overforward' , this . overForwardDisabled )
this . updateDisabled ( 'overforward' , this . overForwardDisabled )
this . updateDisabled ( 'intoforward' , this . intoForwardDisabled )
this . updateDisabled ( 'intoforward' , this . intoForwardDisabled )
this . updateDisabled ( 'nextcall' , this . nextCallDisabled )
this . updateDisabled ( 'nextcall' , this . nextCallDisabled )
this . updateDisabled ( 'jumpout' , this . jumpOutDisabled )
this . updateDisabled ( 'jumptoexception' , this . jumpOutDisabled )
}
}
ButtonNavigator . prototype . updateDisabled = function ( id , disabled ) {
ButtonNavigator . prototype . updateDisabled = function ( id , disabled ) {
@ -87,4 +139,10 @@ ButtonNavigator.prototype.updateDisabled = function (id, disabled) {
}
}
}
}
function resetWarning ( self ) {
self . view . querySelector ( '#reverted #outofgas' ) . style . display = 'none'
self . view . querySelector ( '#reverted #parenthasthrown' ) . style . display = 'none'
self . view . querySelector ( '#reverted' ) . style . display = 'none'
}
module . exports = ButtonNavigator
module . exports = ButtonNavigator