gitpb/repo.gui.pb.go

363 lines
8.4 KiB
Go

// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
// This file was autogenerated with autogenpb v0.5.3-11-g737c5b7 2025.09.16_2337
// 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 gitpb
import (
"time"
"github.com/google/uuid"
"go.wit.com/gui"
"go.wit.com/lib/protobuf/guipb"
"go.wit.com/log"
"google.golang.org/protobuf/proto"
anypb "google.golang.org/protobuf/types/known/anypb"
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
"google.golang.org/protobuf/types/known/wrapperspb"
)
// START GUI
func (x *Repos) NewTable(title string) *ReposTable {
t := new(ReposTable)
t.x = x
pb := new(guipb.Table)
pb.Title = title
t.pb = pb
return t
}
// force the application to choose the type of data. this allows the GUI plugin to be smarter
func (t *ReposTable) AddStringFunc(title string, f func(*Repo) string) *RepoAnyFunc {
t.pb.Order = append(t.pb.Order, title)
sf := new(RepoAnyFunc)
sf.title = title
sf.f = func(x *Repo) any {
return f(x)
}
sf.attr = new(guipb.ColAttr)
sf.attr.Width = int32(sf.Width)
sf.attr.Type = guipb.ColAttr_STRING
t.anyFuncs = append(t.anyFuncs, sf)
return sf
}
// force the application to choose the type of data. this allows the GUI plugin to be smarter
func (t *ReposTable) AddButtonFunc(title string, f func(*Repo) string) *RepoAnyFunc {
t.pb.Order = append(t.pb.Order, title)
sf := new(RepoAnyFunc)
sf.title = title
sf.f = func(x *Repo) any {
return f(x)
}
sf.attr = new(guipb.ColAttr)
sf.attr.Width = int32(sf.Width)
sf.attr.Type = guipb.ColAttr_STRING
sf.attr.Click = true
t.anyFuncs = append(t.anyFuncs, sf)
return sf
}
// force the application to choose the type of data. this allows the GUI plugin to be smarter
func (t *ReposTable) AddIntFunc(title string, f func(*Repo) int) *RepoAnyFunc {
t.pb.Order = append(t.pb.Order, title)
sf := new(RepoAnyFunc)
sf.title = title
sf.f = func(x *Repo) any {
return f(x)
}
sf.attr = new(guipb.ColAttr)
sf.attr.Width = int32(sf.Width)
sf.attr.Type = guipb.ColAttr_INT
t.anyFuncs = append(t.anyFuncs, sf)
return sf
}
// force the application to choose the type of data. this allows the GUI plugin to be smarter
func (t *ReposTable) AddTimeFunc(title string, f func(*Repo) time.Time) *RepoAnyFunc {
t.pb.Order = append(t.pb.Order, title)
sf := new(RepoAnyFunc)
sf.title = title
sf.f = func(x *Repo) any {
return f(x)
}
sf.attr = new(guipb.ColAttr)
sf.attr.Width = int32(sf.Width)
sf.attr.Type = guipb.ColAttr_TIME
// t.timeFuncs = append(t.timeFuncs, sf)
t.anyFuncs = append(t.anyFuncs, sf)
return sf
}
func (sf *RepoAnyFunc) SetTitle(title string) {
sf.title = title
}
func (mt *ReposTable) SetParent(p *gui.Node) {
mt.parent = p
}
func (mt *ReposTable) ShowTable() {
// log.Info("ShowTable() SENDING TO GUI")
mt.MakeTable()
mt.parent.ShowTable(mt.pb)
}
type RepoAnyFunc struct {
title string
f func(*Repo) any
Custom func(*Repo)
Width int
attr *guipb.ColAttr
}
type ReposTable struct {
pb *guipb.Table
parent *gui.Node
x *Repos
hostnames []string
anyFuncs []*RepoAnyFunc
CustomFunc func(*Repo)
}
func (mt *ReposTable) doAnyFuncNew(sf *RepoAnyFunc) bool {
r := new(guipb.AnyCol)
r.Header = new(guipb.Widget)
r.Header.Name = sf.title
r.Attr = proto.Clone(sf.attr).(*guipb.ColAttr)
for m := range mt.x.IterAll() {
t := sf.f(m)
switch r.Attr.Type {
case guipb.ColAttr_STRING:
// anyProto, err := anypb.New(tsProto)
stringValue := wrapperspb.String(t.(string))
anyProto, err := anypb.New(stringValue)
_ = err // do something with err someday (?)
r.Vals = append(r.Vals, anyProto)
// return col.Vals[row] true
case guipb.ColAttr_INT:
var finalInt int
finalInt = t.(int)
intVal := wrapperspb.Int32(int32(finalInt))
anyProto, _ := anypb.New(intVal)
r.Vals = append(r.Vals, anyProto)
case guipb.ColAttr_DURATION:
case guipb.ColAttr_TIME:
var goTime time.Time
goTime = t.(time.Time)
tsProto := timestamppb.New(goTime)
anyProto, err := anypb.New(tsProto)
_ = err // do something with err someday (?)
r.Vals = append(r.Vals, anyProto)
default:
log.Info("cell unhandled type", r.Attr.Type)
}
// cellTime := r.Vals[row]
// s := shell.FormatDuration(time.Since(cellTime.AsTime()))
}
mt.pb.AnyCols = append(mt.pb.AnyCols, r)
return true
}
func (mt *ReposTable) MakeTable() {
for _, sf := range mt.anyFuncs {
mt.doAnyFuncNew(sf)
}
}
func (t *ReposTable) AddNamespace() *RepoAnyFunc {
sf := t.AddStringFunc("Namespace", func(m *Repo) string {
return m.Namespace
})
return sf
}
func (t *ReposTable) AddFullPath() *RepoAnyFunc {
sf := t.AddStringFunc("FullPath", func(m *Repo) string {
return m.FullPath
})
return sf
}
func (t *ReposTable) AddMasterBranchName() *RepoAnyFunc {
sf := t.AddStringFunc("MasterBranchName", func(m *Repo) string {
return m.MasterBranchName
})
return sf
}
func (t *ReposTable) AddDevelBranchName() *RepoAnyFunc {
sf := t.AddStringFunc("DevelBranchName", func(m *Repo) string {
return m.DevelBranchName
})
return sf
}
func (t *ReposTable) AddUserBranchName() *RepoAnyFunc {
sf := t.AddStringFunc("UserBranchName", func(m *Repo) string {
return m.UserBranchName
})
return sf
}
func (t *ReposTable) AddURL() *RepoAnyFunc {
sf := t.AddStringFunc("URL", func(m *Repo) string {
return m.URL
})
return sf
}
func (t *ReposTable) AddCurrentBranchName() *RepoAnyFunc {
sf := t.AddStringFunc("CurrentBranchName", func(m *Repo) string {
return m.CurrentBranchName
})
return sf
}
func (t *ReposTable) AddCurrentBranchVersion() *RepoAnyFunc {
sf := t.AddStringFunc("CurrentBranchVersion", func(m *Repo) string {
return m.CurrentBranchVersion
})
return sf
}
func (t *ReposTable) AddLastTag() *RepoAnyFunc {
sf := t.AddStringFunc("LastTag", func(m *Repo) string {
return m.LastTag
})
return sf
}
func (t *ReposTable) AddTargetVersion() *RepoAnyFunc {
sf := t.AddStringFunc("TargetVersion", func(m *Repo) string {
return m.TargetVersion
})
return sf
}
func (t *ReposTable) AddDesc() *RepoAnyFunc {
sf := t.AddStringFunc("Desc", func(m *Repo) string {
return m.Desc
})
return sf
}
func (t *ReposTable) AddStateChange() *RepoAnyFunc {
sf := t.AddStringFunc("StateChange", func(m *Repo) string {
return m.StateChange
})
return sf
}
func (t *ReposTable) AddMasterVersion() *RepoAnyFunc {
sf := t.AddStringFunc("MasterVersion", func(m *Repo) string {
return m.MasterVersion
})
return sf
}
func (t *ReposTable) AddDevelVersion() *RepoAnyFunc {
sf := t.AddStringFunc("DevelVersion", func(m *Repo) string {
return m.DevelVersion
})
return sf
}
func (t *ReposTable) AddUserVersion() *RepoAnyFunc {
sf := t.AddStringFunc("UserVersion", func(m *Repo) string {
return m.UserVersion
})
return sf
}
func (t *ReposTable) AddState() *RepoAnyFunc {
sf := t.AddStringFunc("State", func(m *Repo) string {
return m.State
})
return sf
}
func (t *ReposTable) AddMasterHash() *RepoAnyFunc {
sf := t.AddStringFunc("MasterHash", func(m *Repo) string {
return m.MasterHash
})
return sf
}
func (t *ReposTable) AddDevelHash() *RepoAnyFunc {
sf := t.AddStringFunc("DevelHash", func(m *Repo) string {
return m.DevelHash
})
return sf
}
func (mt *ReposTable) NewUuid() {
mt.pb.Uuid = uuid.New().String()
}
// START TABLE UPDATE (doesn't work yet)
func (mt *ReposTable) dumpStringFunc(name string) {
for i, r := range mt.pb.StringCols {
// 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 *ReposTable) Delete() {
if mt == nil {
log.Info("mt == nil table already deleted")
return
}
// log.Info("table Delete here")
mt.parent.DeleteTable(mt.pb)
}
func (mt *ReposTable) reposCustom(w *guipb.Widget) {
row := mt.x.Repos[w.Location.Y-1]
// log.Info("got to reposCustom() with", w.Location.X, w.Location.Y-1)
for i, sf := range mt.anyFuncs {
if i == int(w.Location.X) {
if sf.Custom != nil {
log.Info("doing Custom() func for button")
sf.Custom(row)
return
}
}
}
mt.CustomFunc(row)
}
func (mt *ReposTable) Custom(f func(*Repo)) {
mt.pb.RegisterCustom(mt.reposCustom)
mt.CustomFunc = f
}
func (mt *ReposTable) GetUuid() string {
return mt.pb.Uuid
}
// END TABLE UPDATE
// END GUI