summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--machine.gui.go117
1 files changed, 95 insertions, 22 deletions
diff --git a/machine.gui.go b/machine.gui.go
index 5bd4501..8a5572f 100644
--- a/machine.gui.go
+++ b/machine.gui.go
@@ -1,9 +1,12 @@
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 {
@@ -24,14 +27,37 @@ func (t *MachinesTable) AddStringFunc(title string, f func(*Machine) string) {
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 (t *MachinesTable) AddHostname() {
- log.Info("zoopb: GOT TO AddHostname()")
t.pb.Order = append(t.pb.Order, "Hostname")
- t.pb.Order = append(t.pb.Order, "Cpus")
+}
+
+func (t *MachinesTable) AddMemory() {
t.pb.Order = append(t.pb.Order, "Memory")
}
-func (mt *MachinesTable) doStringFunc(name string) {
+func (t *MachinesTable) AddCpus() {
+ t.pb.Order = append(t.pb.Order, "Cpus")
+}
+
+func (mt *MachinesTable) doStringFunc(name string) bool {
for _, sf := range mt.stringFuncs {
if sf.title != name {
continue
@@ -47,8 +73,52 @@ func (mt *MachinesTable) doStringFunc(name string) {
log.Info("zoopb: adding", name, r.Vals)
}
mt.pb.StringRows = append(mt.pb.StringRows, r)
- return
+ 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 (mt *MachinesTable) MakeTable() {
@@ -95,24 +165,17 @@ func (mt *MachinesTable) MakeTable() {
// mt.addFuncRow(name)
}
log.Info("zoopb: didn't find name. trying StringFuncs", name)
- mt.doStringFunc(name)
- }
-}
-
-/*
-func (mt *MachinesTable) addRow(name string) {
- i := new(guipb.IntRow)
- i.Header = new(guipb.Widget)
- i.Header.Name = "Memories"
- all := t.x.All()
- for all.Scan() {
- m := all.Next()
- i.Vals = append(i.Vals, m.Memory)
- log.Info("zoopb: adding cpus", i.Vals)
+ if mt.doStringFunc(name) {
+ continue
+ }
+ if mt.doIntFunc(name) {
+ continue
+ }
+ if mt.doTimeFunc(name) {
+ continue
+ }
}
- t.pb.IntRows = append(t.pb.IntRows, i)
}
-*/
func (mt *MachinesTable) ShowTable() {
log.Info("zoopb.ShowTable() SENDING TO GUI")
@@ -125,12 +188,22 @@ type MachineStringFunc struct {
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
- // columns []*gui.NodeColumn
- // order []*gui.NodeColumn
+ intFuncs []*MachineIntFunc
+ timeFuncs []*MachineTimeFunc
}