virtigo/windowDropletCreate.go

125 lines
2.7 KiB
Go

// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main
// An app to submit patches for the 30 GO GUI repos
import (
"fmt"
"strconv"
"go.wit.com/gui"
"go.wit.com/lib/gadgets"
"go.wit.com/lib/protobuf/virtpb"
"go.wit.com/log"
)
func (admin *adminT) createDropletWindow() *gadgets.GenericWindow {
d := new(virtpb.Droplet)
win := gadgets.NewGenericWindow("Create Droplet "+d.Hostname, "settings")
win.Custom = func() {
log.Warn("edit window close")
}
grid := win.Group.RawGrid()
var save *gui.Node
grid.NewLabel("name")
name := grid.NewTextbox("new2.wit.com")
d.Hostname = "new2.wit.com"
name.SetText(d.Hostname)
name.Custom = func() {
if d.Hostname == name.String() {
return
}
d.Hostname = name.String()
log.Info("changed droplet name to", d.Hostname)
save.Enable()
}
grid.NextRow()
mem := gadgets.NewBasicEntry(grid, "memory (GB)")
mem.SetText("16")
d.Memory = int64(16 * 1024 * 2024 * 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()
}
grid.NextRow() // each entry is on it's own row
cpus := gadgets.NewBasicEntry(grid, "cpus")
cpus.SetText("4")
d.Cpus = int64(4)
cpus.Custom = func() {
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.NextRow() // each entry is on it's own row
grid.NewButton("dump pb.FormatTEXT()", func() {
t := d.FormatTEXT()
log.Info(t)
})
save = grid.NewButton("postEvent() EDIT", func() {
log.Info("save droplet changes here")
e := new(virtpb.Event)
e.Etype = virtpb.EventType_EDIT
e.Droplet = d
if err := admin.postEvent(e); err != nil {
log.Info("event edit err", err)
} else {
log.Info("admin.postEvent() worked (?)")
}
})
save = grid.NewButton("postEvent() ADD", func() {
log.Info("save droplet changes here")
e := new(virtpb.Event)
e.Etype = virtpb.EventType_ADD
e.Droplet = d
if err := admin.postEvent(e); err != nil {
log.Info("event edit err", err)
} else {
log.Info("admin.postEvent() worked (?)")
}
})
// save.Disable()
return win
}