395 lines
8.5 KiB
Go
395 lines
8.5 KiB
Go
// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
|
|
// This file was autogenerated with autogenpb v0.0.79 2025-09-01_01:52:08_UTC
|
|
// go install go.wit.com/apps/autogenpb@latest
|
|
//
|
|
// define which structs (messages) you want to use in the .proto file
|
|
// Then sort.pb.go and marshal.pb.go files are autogenerated
|
|
//
|
|
// autogenpb uses it and has an example .proto file with instructions
|
|
//
|
|
|
|
package chatpb
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"go.wit.com/gui"
|
|
"go.wit.com/lib/protobuf/guipb"
|
|
"go.wit.com/log"
|
|
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
|
|
)
|
|
|
|
// START GUI
|
|
|
|
func (x *Books) NewTable(title string) *BooksTable {
|
|
t := new(BooksTable)
|
|
t.x = x
|
|
pb := new(guipb.Table)
|
|
pb.Title = title
|
|
t.pb = pb
|
|
return t
|
|
}
|
|
|
|
func (t *BooksTable) AddStringFunc(title string, f func(*Book) string) *BookStringFunc {
|
|
t.pb.Order = append(t.pb.Order, title)
|
|
|
|
sf := new(BookStringFunc)
|
|
sf.title = title
|
|
sf.f = f
|
|
sf.order = t.order
|
|
t.order += 1
|
|
t.stringFuncs = append(t.stringFuncs, sf)
|
|
return sf
|
|
}
|
|
|
|
func (t *BooksTable) AddButtonFunc(title string, f func(*Book) string) *BookButtonFunc {
|
|
t.pb.Order = append(t.pb.Order, title)
|
|
|
|
sf := new(BookButtonFunc)
|
|
sf.title = title
|
|
sf.f = f
|
|
sf.order = t.order
|
|
t.order += 1
|
|
t.buttonFuncs = append(t.buttonFuncs, sf)
|
|
return sf
|
|
}
|
|
|
|
func (t *BooksTable) AddIntFunc(title string, f func(*Book) int) *BookIntFunc {
|
|
t.pb.Order = append(t.pb.Order, title)
|
|
|
|
sf := new(BookIntFunc)
|
|
sf.title = title
|
|
sf.f = f
|
|
sf.order = t.order
|
|
t.order += 1
|
|
t.intFuncs = append(t.intFuncs, sf)
|
|
return sf
|
|
}
|
|
|
|
func (t *BooksTable) AddTimeFunc(title string, f func(*Book) time.Time) *BookTimeFunc {
|
|
t.pb.Order = append(t.pb.Order, title)
|
|
|
|
sf := new(BookTimeFunc)
|
|
sf.title = title
|
|
sf.f = f
|
|
sf.order = t.order
|
|
t.order += 1
|
|
t.timeFuncs = append(t.timeFuncs, sf)
|
|
return sf
|
|
}
|
|
|
|
func (sf *BookStringFunc) SetTitle(title string) {
|
|
sf.title = title
|
|
}
|
|
func (sf *BookIntFunc) SetTitle(title string) {
|
|
sf.title = title
|
|
}
|
|
func (sf *BookTimeFunc) SetTitle(title string) {
|
|
sf.title = title
|
|
}
|
|
|
|
func (mt *BooksTable) SetParent(p *gui.Node) {
|
|
mt.parent = p
|
|
}
|
|
|
|
func (mt *BooksTable) ShowTable() {
|
|
// log.Info("ShowTable() SENDING TO GUI")
|
|
mt.MakeTable()
|
|
mt.parent.ShowTable(mt.pb)
|
|
}
|
|
|
|
type BookStringFunc struct {
|
|
title string
|
|
f func(*Book) string
|
|
Custom func(*Book)
|
|
order int
|
|
}
|
|
|
|
type BookButtonFunc struct {
|
|
title string
|
|
f func(*Book) string
|
|
Custom func(*Book)
|
|
order int
|
|
}
|
|
|
|
type BookIntFunc struct {
|
|
title string
|
|
f func(*Book) int
|
|
Custom func(*Book)
|
|
order int
|
|
}
|
|
|
|
type BookTimeFunc struct {
|
|
title string
|
|
f func(*Book) time.Time
|
|
Custom func(*Book)
|
|
order int
|
|
}
|
|
|
|
type BooksTable struct {
|
|
pb *guipb.Table
|
|
parent *gui.Node
|
|
x *Books
|
|
hostnames []string
|
|
stringFuncs []*BookStringFunc
|
|
intFuncs []*BookIntFunc
|
|
timeFuncs []*BookTimeFunc
|
|
buttonFuncs []*BookButtonFunc
|
|
CustomFunc func(*Book)
|
|
order int
|
|
}
|
|
|
|
func (mt *BooksTable) doStringFunc(name string) bool {
|
|
for _, sf := range mt.stringFuncs {
|
|
if sf.title != name {
|
|
continue
|
|
}
|
|
// log.Info("chatpb: found stringfunc name:", name)
|
|
r := new(guipb.StringRow)
|
|
r.Header = new(guipb.Widget)
|
|
r.Header.Name = name
|
|
for m := range mt.x.IterAll() {
|
|
r.Vals = append(r.Vals, sf.f(m))
|
|
// log.Info("chatpb: adding", name, r.Vals)
|
|
}
|
|
mt.pb.StringRows = append(mt.pb.StringRows, r)
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (mt *BooksTable) doButtonFunc(name string) bool {
|
|
for _, sf := range mt.buttonFuncs {
|
|
if sf.title != name {
|
|
continue
|
|
}
|
|
// log.Info("chatpb: found stringfunc name:", name)
|
|
r := new(guipb.ButtonRow)
|
|
r.Header = new(guipb.Widget)
|
|
r.Header.Name = name
|
|
for m := range mt.x.IterAll() {
|
|
r.Vals = append(r.Vals, sf.f(m))
|
|
// log.Info("chatpb: adding", name, r.Vals)
|
|
}
|
|
mt.pb.ButtonRows = append(mt.pb.ButtonRows, r)
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (mt *BooksTable) doIntFunc(name string) bool {
|
|
for _, sf := range mt.intFuncs {
|
|
if sf.title != name {
|
|
continue
|
|
}
|
|
// log.Info("chatpb: found intfunc name:", name)
|
|
r := new(guipb.IntRow)
|
|
r.Header = new(guipb.Widget)
|
|
r.Header.Name = name
|
|
for m := range mt.x.IterAll() {
|
|
r.Vals = append(r.Vals, int64(sf.f(m)))
|
|
// log.Info("chatpb: adding", name, r.Vals)
|
|
}
|
|
mt.pb.IntRows = append(mt.pb.IntRows, r)
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (mt *BooksTable) doTimeFunc(name string) bool {
|
|
for _, sf := range mt.timeFuncs {
|
|
if sf.title != name {
|
|
continue
|
|
}
|
|
// log.Info("chatpb: found timefunc name:", name)
|
|
r := new(guipb.TimeRow)
|
|
r.Header = new(guipb.Widget)
|
|
r.Header.Name = name
|
|
for m := range mt.x.IterAll() {
|
|
t := sf.f(m)
|
|
r.Vals = append(r.Vals, timestamppb.New(t)) // convert to protobuf time
|
|
// log.Info("chatpb: adding", name, r.Vals)
|
|
}
|
|
mt.pb.TimeRows = append(mt.pb.TimeRows, r)
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (mt *BooksTable) MakeTable() {
|
|
for _, name := range mt.pb.Order {
|
|
// log.Info("chatpb: looking for row name()", name)
|
|
if mt.doStringFunc(name) {
|
|
continue
|
|
}
|
|
if mt.doIntFunc(name) {
|
|
continue
|
|
}
|
|
if mt.doTimeFunc(name) {
|
|
continue
|
|
}
|
|
if mt.doButtonFunc(name) {
|
|
continue
|
|
}
|
|
}
|
|
}
|
|
|
|
func (t *BooksTable) AddUuid() *BookStringFunc {
|
|
sf := t.AddStringFunc("Uuid", func(m *Book) string {
|
|
return m.Uuid
|
|
})
|
|
return sf
|
|
}
|
|
|
|
func (t *BooksTable) AddTitle() *BookStringFunc {
|
|
sf := t.AddStringFunc("Title", func(m *Book) string {
|
|
return m.Title
|
|
})
|
|
return sf
|
|
}
|
|
|
|
func (t *BooksTable) AddContent() *BookStringFunc {
|
|
sf := t.AddStringFunc("Content", func(m *Book) string {
|
|
return m.Content
|
|
})
|
|
return sf
|
|
}
|
|
func (mt *BooksTable) NewUuid() {
|
|
mt.pb.Uuid = uuid.New().String()
|
|
}
|
|
|
|
// START TABLE UPDATE
|
|
func (mt *BooksTable) todoUpdate() {
|
|
for _, name := range mt.pb.Order {
|
|
// log.Info("Bookpb: trying to update row()", name)
|
|
if mt.updateStringFunc(name) {
|
|
continue
|
|
}
|
|
if mt.updateTimeFunc(name) {
|
|
continue
|
|
}
|
|
/*
|
|
if mt.updateIntFunc(name) {
|
|
continue
|
|
}
|
|
*/
|
|
}
|
|
// mt.dumpStringFunc("Hostname")
|
|
mt.parent.UpdateTable(mt.pb)
|
|
}
|
|
|
|
func (mt *BooksTable) dumpStringFunc(name string) {
|
|
for i, r := range mt.pb.StringRows {
|
|
// log.Info("could use", i, r.Header.Name, "for name =", name)
|
|
if r.Header.Name == name {
|
|
log.Info("dump Strings row", i, r.Header.Name, r.Vals)
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
func (mt *BooksTable) updateStringFunc(name string) bool {
|
|
// log.Info("LOOKING FOR STRING row", name)
|
|
var found *guipb.StringRow
|
|
for _, r := range mt.pb.StringRows {
|
|
// log.Info("could use", i, r.Header.Name, "for name =", name)
|
|
if r.Header.Name == name {
|
|
// log.Info("found row", i, r.Header.Name)
|
|
found = r
|
|
break
|
|
}
|
|
}
|
|
if found == nil {
|
|
log.Info("did not find string row", name)
|
|
return false
|
|
}
|
|
for _, sf := range mt.stringFuncs {
|
|
if sf.title != name {
|
|
continue
|
|
}
|
|
// log.Info("Bookpb: starting", name, found.Vals)
|
|
for i, _ := range found.Vals {
|
|
tmp := sf.f(mt.x.Books[i])
|
|
if tmp == "www.wit.com" {
|
|
log.Info("virtpb: FOUND WWW", i)
|
|
tmp = "new.www"
|
|
}
|
|
found.Vals[i] = tmp
|
|
}
|
|
// log.Info("Bookpb: ending", name, found.Vals)
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (mt *BooksTable) updateTimeFunc(name string) bool {
|
|
log.Info("LOOKING FOR TIME row", name)
|
|
var found *guipb.TimeRow
|
|
for i, r := range mt.pb.TimeRows {
|
|
// log.Info("could use", i, r.Header.Name, "for name =", name)
|
|
if r.Header.Name == name {
|
|
log.Info("found row", i, r.Header.Name)
|
|
found = r
|
|
break
|
|
}
|
|
}
|
|
if found == nil {
|
|
log.Info("did not find time row", name)
|
|
return false
|
|
}
|
|
for _, sf := range mt.timeFuncs {
|
|
if sf.title != name {
|
|
continue
|
|
}
|
|
// log.Info("updateTimeFunc() has row len =", len(mt.x.Books))
|
|
// log.Info("virtpb: starting", name, found.Vals)
|
|
for i, _ := range found.Vals {
|
|
newt := sf.f(mt.x.Books[i])
|
|
found.Vals[i] = timestamppb.New(newt) // convert to protobuf time
|
|
}
|
|
// log.Info("virtpb: ending", name, found.Vals)
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (mt *BooksTable) Delete() {
|
|
if mt == nil {
|
|
log.Info("mt == nil table already deleted")
|
|
return
|
|
}
|
|
// log.Info("table Delete here")
|
|
mt.parent.DeleteTable(mt.pb)
|
|
}
|
|
|
|
func (mt *BooksTable) booksCustom(w *guipb.Widget) {
|
|
row := mt.x.Books[w.Location.Y-1]
|
|
// log.Info("got to booksCustom() with", w.Location.X, w.Location.Y-1)
|
|
|
|
for _, sf := range mt.buttonFuncs {
|
|
if sf.order == int(w.Location.X) {
|
|
// log.Info("found order", sf.order)
|
|
if sf.Custom != nil {
|
|
log.Info("doing Custom() func for button")
|
|
sf.Custom(row)
|
|
return
|
|
}
|
|
}
|
|
}
|
|
mt.CustomFunc(row)
|
|
}
|
|
|
|
func (mt *BooksTable) Custom(f func(*Book)) {
|
|
mt.pb.RegisterCustom(mt.booksCustom)
|
|
mt.CustomFunc = f
|
|
}
|
|
|
|
func (mt *BooksTable) GetUuid() string {
|
|
return mt.pb.Uuid
|
|
}
|
|
|
|
// END TABLE UPDATE
|
|
|
|
// END GUI
|