forge/windowPatches.go

237 lines
5.6 KiB
Go
Raw Normal View History

2025-01-20 02:14:08 -06:00
package main
import (
2025-01-30 08:48:59 -06:00
"fmt"
"strconv"
2025-01-20 02:14:08 -06:00
"sync"
"go.wit.com/lib/gadgets"
2025-01-30 08:48:59 -06:00
"go.wit.com/lib/protobuf/forgepb"
2025-01-20 02:14:08 -06:00
"go.wit.com/log"
"go.wit.com/gui"
)
type patchesWindow struct {
2025-01-30 06:21:26 -06:00
once sync.Once // only init() the window once
win *gadgets.BasicWindow // the patches window
stack *gui.Node // the top box set as vertical
shelf *gui.Node // the first box in the stack, set as horizontal
grid *gui.Node // the list of available patches
summary *patchSummary // summary of current patches
setgrid *gui.Node // the list of each patchset
// setlist map[string]*forgepb.Patchset // a map of the patch names to the protobuf
// setwin map[string]*patchWindow // a map of the patch names to the protobuf
2025-01-20 02:14:08 -06:00
}
func (r *patchesWindow) Hidden() bool {
return r.win.Hidden()
}
func (r *patchesWindow) Toggle() {
if r.Hidden() {
r.Show()
} else {
2025-01-20 02:30:31 -06:00
r.Hide()
2025-01-20 02:14:08 -06:00
}
}
func (r *patchesWindow) Show() {
r.win.Show()
}
func (r *patchesWindow) Hide() {
r.win.Hide()
}
func (r *patchesWindow) Disable() {
2025-01-20 02:50:07 -06:00
r.stack.Disable()
2025-01-20 02:14:08 -06:00
}
func (r *patchesWindow) Enable() {
2025-01-20 02:50:07 -06:00
r.stack.Enable()
2025-01-20 02:14:08 -06:00
}
// you can only have one of these
func (r *patchesWindow) initWindow() {
// sync.Once()
2025-01-20 02:50:07 -06:00
r.win = gadgets.RawBasicWindow("Forge Patchesets")
2025-01-20 02:14:08 -06:00
r.win.Make()
2025-01-20 02:50:07 -06:00
r.stack = r.win.Box().NewBox("bw vbox", false)
2025-01-20 02:14:08 -06:00
// me.reposwin.Draw()
r.win.Custom = func() {
2025-01-20 02:50:07 -06:00
log.Warn("Patchset Window close. setting hidden=true")
2025-01-20 02:30:31 -06:00
// sets the hidden flag to false so Toggle() works
r.win.Hide()
2025-01-20 02:14:08 -06:00
}
2025-01-20 03:18:44 -06:00
r.grid = r.stack.NewGrid("", 0, 0)
2025-01-28 18:10:32 -06:00
/*
r.shelf = r.initGroup()
group1 := r.stack.NewGroup("stuff")
vbox := group1.Box()
vbox.Vertical()
*/
2025-01-28 13:20:10 -06:00
r.summary = r.submitPatchesBox(r.stack)
2025-01-20 02:14:08 -06:00
2025-01-28 18:10:32 -06:00
// update the stats about the repos and patches
r.summary.Update()
2025-01-20 02:14:08 -06:00
2025-01-30 08:48:59 -06:00
g := r.stack.NewGroup("Patchset List")
2025-01-20 02:14:08 -06:00
2025-01-28 18:10:32 -06:00
// add the grid
r.setgrid = g.NewGrid("", 0, 0)
2025-01-30 08:48:59 -06:00
}
type patchSummary struct {
2025-01-30 08:54:13 -06:00
grid *gui.Node
updateB *gui.Node
docsB *gui.Node
gitPushB *gui.Node
gitPullB *gui.Node
checkB *gui.Node
totalOL *gadgets.OneLiner
dirtyOL *gadgets.OneLiner
readonlyOL *gadgets.OneLiner
rw *gadgets.OneLiner
totalPatchesOL *gadgets.OneLiner
// totalUserRepos *gui.Node
// totalDevelRepos *gui.Node
// totalMasterRepos *gui.Node
2025-01-30 08:48:59 -06:00
// totalUserPatches *gui.Node
2025-01-30 08:54:13 -06:00
// totalDevelPatches *gui.Node
// totalMasterPatches *gui.Node
2025-01-30 08:48:59 -06:00
// fileCount *gui.Node
unknownOL *gadgets.BasicEntry
unknownSubmitB *gui.Node
reason *gadgets.BasicEntry
submitB *gui.Node
// allp []*repolist.Patch
}
2025-01-30 06:21:26 -06:00
2025-01-30 08:48:59 -06:00
func (r *patchesWindow) submitPatchesBox(box *gui.Node) *patchSummary {
s := new(patchSummary)
group1 := box.NewGroup("Repo Summary")
s.grid = group1.RawGrid()
s.totalOL = gadgets.NewOneLiner(s.grid, "Total")
s.grid.NextRow()
s.dirtyOL = gadgets.NewOneLiner(s.grid, "dirty")
2025-01-30 08:54:13 -06:00
// _ = s.grid.NewLabel("") // skip a column
// s.totalUserRepos = s.grid.NewLabel("x go repos")
2025-01-30 08:48:59 -06:00
s.grid.NextRow()
s.readonlyOL = gadgets.NewOneLiner(s.grid, "read-only")
2025-01-30 08:54:13 -06:00
// _ = s.grid.NewLabel("") // skip a column
2025-01-30 08:48:59 -06:00
s.grid.NextRow()
s.rw = gadgets.NewOneLiner(s.grid, "r/w")
2025-01-30 08:54:13 -06:00
// _ = s.grid.NewLabel("") // skip a column
2025-01-30 08:48:59 -06:00
s.grid.NextRow()
group1 = box.NewGroup("Patchset Create")
s.grid = group1.RawGrid()
s.grid.NewButton("current patch summary", func() {
s.Update()
pset, err := me.forge.MakeDevelPatchSet("current patches")
if err != nil {
log.Info("patchset creation failed", err)
return
}
if pset == nil {
log.Info("you have no current patches")
return
}
win := makePatchWindow(pset)
win.Show()
})
s.reason = gadgets.NewBasicEntry(s.grid, "Patchset name:")
s.reason.Custom = func() {
if s.reason.String() != "" {
s.submitB.Enable()
} else {
s.submitB.Disable()
}
}
s.submitB = s.grid.NewButton("Submit", func() {
pset, err := me.forge.SubmitDevelPatchSet(s.reason.String())
2025-01-30 06:21:26 -06:00
if err != nil {
log.Info(err)
return
2025-01-29 09:43:42 -06:00
}
2025-01-30 08:48:59 -06:00
// line := "somedate " + s.reason.String() + " Author: me" + pset.GitAuthorEmail
r.addPatchsetNew(pset)
})
2025-01-30 08:54:13 -06:00
s.grid.NewButton("Get Patchset List", func() {
2025-01-30 08:48:59 -06:00
if psets, err := me.forge.GetPatchesets(); err != nil {
log.Info("Get Patchsets failed", err)
return
} else {
log.Info("got psets len", len(psets.Patchsets))
// all := psets.All()
all := psets.SortByName()
for all.Scan() {
pset := all.Next()
r.addPatchsetNew(pset)
2025-01-30 06:21:26 -06:00
}
}
2025-01-30 08:48:59 -06:00
})
s.submitB.Disable()
s.grid.NextRow()
return s
2025-01-28 13:20:10 -06:00
}
2025-01-30 08:48:59 -06:00
func (r *patchesWindow) addPatchsetNew(pset *forgepb.Patchset) {
r.setgrid.NewLabel(pset.Name)
r.setgrid.NewLabel(pset.Comment)
r.setgrid.NewLabel(pset.GitAuthorName)
2025-01-30 08:48:59 -06:00
var win *patchWindow
2025-01-29 09:06:19 -06:00
r.setgrid.NewButton("View", func() {
// has the window already been created?
if win != nil {
2025-01-30 08:48:59 -06:00
// it has been already created. just show it
2025-01-29 09:06:19 -06:00
win.Toggle()
log.Info("TRYING TO TOGGLE WINDOW")
return
}
2025-01-30 08:48:59 -06:00
win = makePatchWindow(pset)
win.Show()
2025-01-28 13:20:10 -06:00
})
r.setgrid.NextRow()
}
2025-01-30 08:48:59 -06:00
// does not run any commands
func (s *patchSummary) Update() {
var total, dirty, readonly, rw int
2025-01-30 08:54:13 -06:00
// var userT int // , develT, masterT int
2025-01-30 08:48:59 -06:00
// var userP, develP, masterP int
// broken after move to forge protobuf
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
total += 1
if repo.IsDirty() {
dirty += 1
}
if me.forge.Config.IsReadOnly(repo.GetGoPath()) {
readonly += 1
} else {
rw += 1
}
}
s.totalOL.SetText(strconv.Itoa(total) + " repos")
s.dirtyOL.SetText(strconv.Itoa(dirty) + " repos")
s.readonlyOL.SetText(strconv.Itoa(readonly) + " repos")
s.rw.SetText(fmt.Sprintf("%d repos", rw))
2025-01-30 08:54:13 -06:00
// s.totalUserRepos.SetText(strconv.Itoa(userT) + " repos")
2025-01-30 08:48:59 -06:00
}