diff options
| author | Jeff Carr <[email protected]> | 2025-02-20 09:39:58 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-02-20 09:39:58 -0600 |
| commit | 8f6f85e51cc4dcc1ba4636e35a2369f92002bdd7 (patch) | |
| tree | 0895deeda83c1eb5cc34455bc95c6d2669cb9045 /machine.gui.go | |
| parent | 705800fb23a87bfa4fc71956fbe18cee411e3a2d (diff) | |
Diffstat (limited to 'machine.gui.go')
| -rw-r--r-- | machine.gui.go | 209 |
1 files changed, 0 insertions, 209 deletions
diff --git a/machine.gui.go b/machine.gui.go deleted file mode 100644 index 8a5572f..0000000 --- a/machine.gui.go +++ /dev/null @@ -1,209 +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 (t *MachinesTable) AddHostname() { - t.pb.Order = append(t.pb.Order, "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) 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 (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 - } - } -} - -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 -} |
