Add TTL input

This commit is contained in:
Ivan Danyliuk 2018-10-24 19:37:31 +02:00
parent 1f8ac9b3b7
commit 276e2ec3b8
No known key found for this signature in database
GPG Key ID: 97ED33CE024E1DBF
3 changed files with 33 additions and 8 deletions

View File

@ -184,7 +184,8 @@ func (p *Page) startSimulation() error {
}()
backend := p.simulationWidget.Address()
sim, err := p.runSimulation(backend)
ttl := p.simulationWidget.TTL()
sim, err := p.runSimulation(backend, ttl)
if err != nil {
return err
}

View File

@ -28,8 +28,8 @@ type SimulationRequest struct {
// runSimulation starts whisper message propagation simulation,
// remotely talking to simulation backend with given address.
func (p *Page) runSimulation(address string) (*Simulation, error) {
buf, err := p.newPOSTSimulationRequest()
func (p *Page) runSimulation(address string, ttl int) (*Simulation, error) {
buf, err := p.newPOSTSimulationRequest(ttl)
if err != nil {
return nil, fmt.Errorf("Internal error. See console output.")
}
@ -53,10 +53,10 @@ func (p *Page) runSimulation(address string) (*Simulation, error) {
// newPOSTSimulationRequest generates SimulationReqeust and
// prepares it as io.Reader for usage with http.Post.
func (p *Page) newPOSTSimulationRequest() (io.Reader, error) {
func (p *Page) newPOSTSimulationRequest(ttl int) (io.Reader, error) {
req := SimulationRequest{
SenderIdx: 0,
TTL: 10,
TTL: ttl,
MsgSize: 400,
Network: p.currentNetworkJSON(),
}

View File

@ -1,6 +1,8 @@
package widgets
import (
"fmt"
"github.com/gopherjs/vecty"
"github.com/gopherjs/vecty/elem"
"github.com/gopherjs/vecty/event"
@ -53,8 +55,19 @@ func (s *Simulation) Render() vecty.ComponentOrHTML {
),
vecty.Class("input", "is-small"),
prop.Value(s.address),
vecty.Attribute("placehoder", "backend url"),
event.Input(s.onEditInput),
event.Input(s.onAddressChange),
),
),
),
InputField("TTL:", "Message time to live value (in seconds)",
elem.Input(
vecty.Markup(
vecty.MarkupIf(s.inProgress,
vecty.Attribute("disabled", "true"),
),
vecty.Class("input", "is-small"),
prop.Value(fmt.Sprint(s.ttl)),
event.Input(s.onTTLChange),
),
),
),
@ -99,17 +112,28 @@ func (s *Simulation) Render() vecty.ComponentOrHTML {
)
}
func (s *Simulation) onEditInput(event *vecty.Event) {
func (s *Simulation) onAddressChange(event *vecty.Event) {
value := event.Target.Get("value").String()
s.address = value
}
func (s *Simulation) onTTLChange(event *vecty.Event) {
value := event.Target.Get("value").Int()
s.ttl = value
}
// Address returns the current backend address.
func (s *Simulation) Address() string {
return s.address
}
// TTL returns the current TTL value.
func (s *Simulation) TTL() int {
return s.ttl
}
func (s *Simulation) onSimulateClick(e *vecty.Event) {
go func() {
s.errMsg = ""