diff --git a/windowDropletEdit.go b/windowDropletEdit.go index 5435e8d..20247b7 100644 --- a/windowDropletEdit.go +++ b/windowDropletEdit.go @@ -7,6 +7,7 @@ package main import ( "fmt" + "strconv" "go.wit.com/gui" "go.wit.com/lib/gadgets" @@ -28,7 +29,12 @@ func (admin *adminT) editDropletWindow(d *virtpb.Droplet) *gadgets.GenericWindow name := grid.NewTextbox("something") name.SetText(d.Hostname) name.Custom = func() { - log.Info("changed droplet name") + if d.Hostname == name.String() { + return + } + d.Hostname = name.String() + log.Info("changed droplet name to", d.Hostname) + save.Enable() } grid.NextRow() @@ -36,15 +42,42 @@ func (admin *adminT) editDropletWindow(d *virtpb.Droplet) *gadgets.GenericWindow mem.SetText(fmt.Sprintf("%d", d.Memory/(1024*1024*1024))) grid.NextRow() mem.Custom = func() { + newmem, err := strconv.Atoi(mem.String()) + if err != nil { + log.Info("mem value error", mem.String(), err) + mem.SetText(fmt.Sprintf("%d", d.Memory/(1024*1024*1024))) + return + } + if newmem < 1 { + log.Info("mem can not be < 1") + mem.SetText(fmt.Sprintf("%d", d.Memory/(1024*1024*1024))) + return + } + d.Memory = int64(newmem * (1024 * 2024 * 1024)) + log.Info("changed mem value. new val =", d.Memory) + save.Enable() - log.Info("changed mem value. new val =", mem.String()) } cpus := gadgets.NewBasicEntry(grid, "cpus") cpus.SetText(fmt.Sprintf("%d", d.Cpus)) grid.NextRow() cpus.Custom = func() { - log.Info("changed cpus value") + newcpu, err := strconv.Atoi(cpus.String()) + if err != nil { + log.Info("cpus value error", cpus.String(), err) + cpus.SetText(fmt.Sprintf("%d", d.Cpus)) + return + } + if newcpu < 1 { + log.Info("cpus can not be < 1") + cpus.SetText(fmt.Sprintf("%d", d.Cpus)) + return + } + d.Cpus = int64(newcpu) + log.Info("changed cpus value. new val =", d.Cpus) + + save.Enable() } grid.NewLabel("hypervisor") @@ -54,6 +87,8 @@ func (admin *adminT) editDropletWindow(d *virtpb.Droplet) *gadgets.GenericWindow hyper.AddText("farm05") if d.Current != nil { hyper.SetText(d.Current.Hypervisor) + } else { + hyper.SetText("farm03") } grid.NextRow() @@ -66,11 +101,14 @@ func (admin *adminT) editDropletWindow(d *virtpb.Droplet) *gadgets.GenericWindow e := new(virtpb.Event) e.Etype = virtpb.EventType_EDIT - e.Droplet = new(virtpb.Droplet) - e.Droplet.Uuid = d.Uuid - e.Droplet.Cpus = 4 - e.Droplet.Memory = 8 * (1024 * 1024 * 1024) - e.Droplet.Hostname = name.String() + e.Droplet = d + /* + e.Droplet = new(virtpb.Droplet) + e.Droplet.Uuid = d.Uuid + e.Droplet.Cpus = 4 + e.Droplet.Memory = 8 * (1024 * 1024 * 1024) + e.Droplet.Hostname = name.String() + */ if err := admin.postEvent(e); err != nil { log.Info("event edit err", err)