seriously. I used Row instead of Col. moron!

This commit is contained in:
Jeff Carr 2025-09-14 05:49:58 -05:00
parent ddea4b6514
commit 48e2465be1
2 changed files with 13 additions and 226 deletions

View File

@ -1,213 +0,0 @@
package zoopb
import (
"time"
"go.wit.com/gui"
"go.wit.com/lib/protobuf/guipb"
"go.wit.com/log"
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
)
func (x *Machines) NewTable(title string) *MachinesTable {
t := new(MachinesTable)
t.x = x
pb := new(guipb.Table)
pb.Title = title
t.pb = pb
return t
}
func (t *MachinesTable) AddStringFunc(title string, f func(*Machine) string) {
t.pb.Order = append(t.pb.Order, title)
sf := new(MachineStringFunc)
sf.title = title
sf.f = f
t.stringFuncs = append(t.stringFuncs, sf)
}
func (t *MachinesTable) AddIntFunc(title string, f func(*Machine) int) {
t.pb.Order = append(t.pb.Order, title)
sf := new(MachineIntFunc)
sf.title = title
sf.f = f
t.intFuncs = append(t.intFuncs, sf)
}
func (t *MachinesTable) AddTimeFunc(title string, f func(*Machine) time.Time) {
t.pb.Order = append(t.pb.Order, title)
sf := new(MachineTimeFunc)
sf.title = title
sf.f = f
t.timeFuncs = append(t.timeFuncs, sf)
}
func (mt *MachinesTable) ShowTable() {
log.Info("zoopb.ShowTable() SENDING TO GUI")
mt.MakeTable()
gui.ShowTable(mt.pb)
}
type MachineStringFunc struct {
title string
f func(*Machine) string
}
type MachineIntFunc struct {
title string
f func(*Machine) int
}
type MachineTimeFunc struct {
title string
f func(*Machine) time.Time
}
type MachinesTable struct {
// gt *gui.NodeTable
pb *guipb.Table
x *Machines
hostnames []string
stringFuncs []*MachineStringFunc
intFuncs []*MachineIntFunc
timeFuncs []*MachineTimeFunc
}
func (mt *MachinesTable) doStringFunc(name string) bool {
for _, sf := range mt.stringFuncs {
if sf.title != name {
continue
}
log.Info("zoopb: found stringfunc name:", name)
r := new(guipb.StringRow)
r.Header = new(guipb.Widget)
r.Header.Name = name
all := mt.x.All()
for all.Scan() {
m := all.Next()
r.Vals = append(r.Vals, sf.f(m))
log.Info("zoopb: adding", name, r.Vals)
}
mt.pb.StringRows = append(mt.pb.StringRows, r)
return true
}
return false
}
func (mt *MachinesTable) doIntFunc(name string) bool {
for _, sf := range mt.intFuncs {
if sf.title != name {
continue
}
log.Info("zoopb: found intfunc name:", name)
r := new(guipb.IntRow)
r.Header = new(guipb.Widget)
r.Header.Name = name
all := mt.x.All()
for all.Scan() {
m := all.Next()
r.Vals = append(r.Vals, int64(sf.f(m)))
log.Info("zoopb: adding", name, r.Vals)
}
mt.pb.IntRows = append(mt.pb.IntRows, r)
return true
}
return false
}
func (mt *MachinesTable) doTimeFunc(name string) bool {
for _, sf := range mt.timeFuncs {
if sf.title != name {
continue
}
log.Info("zoopb: found timefunc name:", name)
r := new(guipb.TimeRow)
r.Header = new(guipb.Widget)
r.Header.Name = name
all := mt.x.All()
for all.Scan() {
m := all.Next()
t := sf.f(m)
r.Vals = append(r.Vals, timestamppb.New(t)) // convert to protobuf time
log.Info("zoopb: adding", name, r.Vals)
}
mt.pb.TimeRows = append(mt.pb.TimeRows, r)
return true
}
return false
}
func (t *MachinesTable) AddHostname() {
// t.pb.Order = append(t.pb.Order, "Hostname")
t.AddStringFunc("Hostname", func(m *zoopb.Machine) string {
return m.Hostname
})
}
func (t *MachinesTable) AddMemory() {
t.pb.Order = append(t.pb.Order, "Memory")
}
func (t *MachinesTable) AddCpus() {
t.pb.Order = append(t.pb.Order, "Cpus")
}
func (mt *MachinesTable) MakeTable() {
for _, name := range mt.pb.Order {
log.Info("zoopb: looking for row name()", name)
switch name {
case "Hostname":
r := new(guipb.StringRow)
r.Header = new(guipb.Widget)
r.Header.Name = name
all := mt.x.All()
for all.Scan() {
m := all.Next()
r.Vals = append(r.Vals, m.Hostname)
log.Info("zoopb: adding", name, r.Vals)
}
mt.pb.StringRows = append(mt.pb.StringRows, r)
continue
case "Cpus":
i := new(guipb.IntRow)
i.Header = new(guipb.Widget)
i.Header.Name = name
all := mt.x.All()
for all.Scan() {
m := all.Next()
i.Vals = append(i.Vals, m.Cpus)
log.Info("zoopb: adding", name, i.Vals)
}
mt.pb.IntRows = append(mt.pb.IntRows, i)
continue
case "Memory":
i := new(guipb.IntRow)
i.Header = new(guipb.Widget)
i.Header.Name = name
all := mt.x.All()
for all.Scan() {
m := all.Next()
i.Vals = append(i.Vals, m.Memory)
log.Info("zoopb: adding", name, i.Vals)
}
mt.pb.IntRows = append(mt.pb.IntRows, i)
continue
default:
// mt.addFuncRow(name)
}
log.Info("zoopb: didn't find name. trying StringFuncs", name)
if mt.doStringFunc(name) {
continue
}
if mt.doIntFunc(name) {
continue
}
if mt.doTimeFunc(name) {
continue
}
}
}

View File

@ -283,7 +283,7 @@ func guiStringFuncs(w io.Writer, ZOOPB string, FRUITS string, FRUIT string) {
fmt.Fprintln(w, " continue")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, " // log.Info(\""+ZOOPB+": found stringfunc name:\", name)")
fmt.Fprintln(w, " r := new(guipb.StringRow)")
fmt.Fprintln(w, " r := new(guipb.StringCol)")
fmt.Fprintln(w, " r.Header = new(guipb.Widget)")
fmt.Fprintln(w, " r.Header.Name = name")
@ -297,7 +297,7 @@ func guiStringFuncs(w io.Writer, ZOOPB string, FRUITS string, FRUIT string) {
fmt.Fprintln(w, " r.Vals = append(r.Vals, sf.f(m))")
fmt.Fprintln(w, " // log.Info(\""+ZOOPB+": adding\", name, r.Vals)")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, " mt.pb.StringRows = append(mt.pb.StringRows, r)")
fmt.Fprintln(w, " mt.pb.StringCols = append(mt.pb.StringCols, r)")
fmt.Fprintln(w, " return true")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, " return false")
@ -309,14 +309,14 @@ func guiStringFuncs(w io.Writer, ZOOPB string, FRUITS string, FRUIT string) {
fmt.Fprintln(w, " continue")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, " // log.Info(\""+ZOOPB+": found stringfunc name:\", name)")
fmt.Fprintln(w, " r := new(guipb.ButtonRow)")
fmt.Fprintln(w, " r := new(guipb.ButtonCol)")
fmt.Fprintln(w, " r.Header = new(guipb.Widget)")
fmt.Fprintln(w, " r.Header.Name = name")
fmt.Fprintln(w, " for m := range mt.x.IterAll() {")
fmt.Fprintln(w, " r.Vals = append(r.Vals, sf.f(m))")
fmt.Fprintln(w, " // log.Info(\""+ZOOPB+": adding\", name, r.Vals)")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, " mt.pb.ButtonRows = append(mt.pb.ButtonRows, r)")
fmt.Fprintln(w, " mt.pb.ButtonCols = append(mt.pb.ButtonCols, r)")
fmt.Fprintln(w, " return true")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, " return false")
@ -328,14 +328,14 @@ func guiStringFuncs(w io.Writer, ZOOPB string, FRUITS string, FRUIT string) {
fmt.Fprintln(w, " continue")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, " // log.Info(\""+ZOOPB+": found intfunc name:\", name)")
fmt.Fprintln(w, " r := new(guipb.IntRow)")
fmt.Fprintln(w, " r := new(guipb.IntCol)")
fmt.Fprintln(w, " r.Header = new(guipb.Widget)")
fmt.Fprintln(w, " r.Header.Name = name")
fmt.Fprintln(w, " for m := range mt.x.IterAll() {")
fmt.Fprintln(w, " r.Vals = append(r.Vals, int64(sf.f(m)))")
fmt.Fprintln(w, " // log.Info(\""+ZOOPB+": adding\", name, r.Vals)")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, " mt.pb.IntRows = append(mt.pb.IntRows, r)")
fmt.Fprintln(w, " mt.pb.IntCols = append(mt.pb.IntCols, r)")
fmt.Fprintln(w, " return true")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, " return false")
@ -347,7 +347,7 @@ func guiStringFuncs(w io.Writer, ZOOPB string, FRUITS string, FRUIT string) {
fmt.Fprintln(w, " continue")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, " // log.Info(\""+ZOOPB+": found timefunc name:\", name)")
fmt.Fprintln(w, " r := new(guipb.TimeRow)")
fmt.Fprintln(w, " r := new(guipb.TimeCol)")
fmt.Fprintln(w, " r.Header = new(guipb.Widget)")
fmt.Fprintln(w, " r.Header.Name = name")
fmt.Fprintln(w, " for m := range mt.x.IterAll() {")
@ -355,7 +355,7 @@ func guiStringFuncs(w io.Writer, ZOOPB string, FRUITS string, FRUIT string) {
fmt.Fprintln(w, " r.Vals = append(r.Vals, timestamppb.New(t)) // convert to protobuf time")
fmt.Fprintln(w, " // log.Info(\""+ZOOPB+": adding\", name, r.Vals)")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, " mt.pb.TimeRows = append(mt.pb.TimeRows, r)")
fmt.Fprintln(w, " mt.pb.TimeCols = append(mt.pb.TimeCols, r)")
fmt.Fprintln(w, " return true")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, " return false")
@ -437,7 +437,7 @@ func guiUpdate(w io.Writer, FRUITS string, FRUIT string) {
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "")
fmt.Fprintln(w, "func (mt *"+FRUITS+"Table) dumpStringFunc(name string) {")
fmt.Fprintln(w, " for i, r := range mt.pb.StringRows {")
fmt.Fprintln(w, " for i, r := range mt.pb.StringCols {")
fmt.Fprintln(w, " // log.Info(\"could use\", i, r.Header.Name, \"for name =\", name)")
fmt.Fprintln(w, " if r.Header.Name == name {")
fmt.Fprintln(w, " log.Info(\"dump Strings row\", i, r.Header.Name, r.Vals)")
@ -448,8 +448,8 @@ func guiUpdate(w io.Writer, FRUITS string, FRUIT string) {
fmt.Fprintln(w, "")
fmt.Fprintln(w, "func (mt *"+FRUITS+"Table) updateStringFunc(name string) bool {")
fmt.Fprintln(w, " // log.Info(\"LOOKING FOR STRING row\", name)")
fmt.Fprintln(w, " var found *guipb.StringRow")
fmt.Fprintln(w, " for _, r := range mt.pb.StringRows {")
fmt.Fprintln(w, " var found *guipb.StringCol")
fmt.Fprintln(w, " for _, r := range mt.pb.StringCols {")
fmt.Fprintln(w, " // log.Info(\"could use\", i, r.Header.Name, \"for name =\", name)")
fmt.Fprintln(w, " if r.Header.Name == name {")
fmt.Fprintln(w, " // log.Info(\"found row\", i, r.Header.Name)")
@ -482,8 +482,8 @@ func guiUpdate(w io.Writer, FRUITS string, FRUIT string) {
fmt.Fprintln(w, "")
fmt.Fprintln(w, "func (mt *"+FRUITS+"Table) updateTimeFunc(name string) bool {")
fmt.Fprintln(w, " log.Info(\"LOOKING FOR TIME row\", name)")
fmt.Fprintln(w, " var found *guipb.TimeRow")
fmt.Fprintln(w, " for i, r := range mt.pb.TimeRows {")
fmt.Fprintln(w, " var found *guipb.TimeCol")
fmt.Fprintln(w, " for i, r := range mt.pb.TimeCols {")
fmt.Fprintln(w, " // log.Info(\"could use\", i, r.Header.Name, \"for name =\", name)")
fmt.Fprintln(w, " if r.Header.Name == name {")
fmt.Fprintln(w, " log.Info(\"found row\", i, r.Header.Name)")