forge/windowForgePatchsets.go

221 lines
5.0 KiB
Go
Raw Normal View History

2025-02-01 11:57:52 -06:00
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
2025-01-20 02:14:08 -06:00
package main
2025-02-01 11:55:17 -06:00
// this is the "main" patch window. The first one
// then you can dig down and examine the patchsets and the files
2025-01-20 02:14:08 -06:00
import (
2025-01-30 08:48:59 -06:00
"fmt"
"strconv"
2025-01-20 02:14:08 -06:00
"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 09:16:39 -06:00
win *gadgets.BasicWindow // the patches window
stack *gui.Node // the top box set as vertical
grid *gui.Node // the list of available patches
reason *gadgets.BasicEntry // the name of the patchset
submitB *gui.Node // the submit patchet button
psetgrid *gui.Node // the list of each patchset
2025-01-30 09:04:45 -06:00
totalOL *gadgets.OneLiner
dirtyOL *gadgets.OneLiner
readonlyOL *gadgets.OneLiner
rw *gadgets.OneLiner
// checkB *gui.Node
2025-01-30 09:16:39 -06:00
}
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()
}
// you can only have one of these
func (r *patchesWindow) initWindow() {
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
}
r.grid = r.stack.RawGrid()
2025-01-30 09:16:39 -06:00
r.submitPatchesBox()
2025-01-20 02:14:08 -06:00
2025-01-28 18:10:32 -06:00
// update the stats about the repos and patches
2025-01-30 09:16:39 -06:00
r.Update()
2025-01-30 08:48:59 -06:00
}
2025-01-30 09:16:39 -06:00
func (r *patchesWindow) submitPatchesBox() {
// s := new(patchSummary)
group1 := r.stack.NewGroup("Repo Summary")
grid := group1.RawGrid()
2025-01-30 08:48:59 -06:00
2025-01-30 08:59:41 -06:00
// make the header table for repo stats
2025-01-30 09:16:39 -06:00
r.totalOL = gadgets.NewOneLiner(grid, "Total")
grid.NextRow()
r.dirtyOL = gadgets.NewOneLiner(grid, "dirty")
grid.NextRow()
r.readonlyOL = gadgets.NewOneLiner(grid, "read-only")
grid.NextRow()
r.rw = gadgets.NewOneLiner(grid, "r/w")
grid.NextRow()
2025-01-30 08:48:59 -06:00
// now, make the 'widget group' and the buttons at the bottom of the window
2025-01-30 09:16:39 -06:00
group1 = r.stack.NewGroup("Patchset Create")
grid = group1.RawGrid()
2025-01-30 08:48:59 -06:00
2025-01-30 09:16:39 -06:00
grid.NewButton("current patch summary", func() {
r.Update()
2025-01-30 08:48:59 -06:00
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()
})
2025-01-30 09:16:39 -06:00
r.reason = gadgets.NewBasicEntry(grid, "Patchset name:")
r.reason.Custom = func() {
if r.reason.String() != "" {
r.submitB.Enable()
2025-01-30 08:48:59 -06:00
} else {
2025-01-30 09:16:39 -06:00
r.submitB.Disable()
2025-01-30 08:48:59 -06:00
}
}
2025-01-30 09:16:39 -06:00
r.submitB = grid.NewButton("Submit", func() {
pset, err := me.forge.SubmitDevelPatchSet(r.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
r.addPatchsetNew(pset)
})
2025-02-01 11:55:17 -06:00
psets, err := openPatchsets()
if err != nil {
log.Info("Open Patchsets failed", err)
}
grid.NewButton("Update Patchset List", func() {
psets, err = me.forge.GetPatchesets()
if err != nil {
2025-01-30 08:48:59 -06:00
log.Info("Get Patchsets failed", err)
return
2025-02-01 11:55:17 -06:00
}
savePatchsets(psets)
log.Info("got psets len", len(psets.Patchsets))
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
})
2025-02-01 11:55:17 -06:00
// disables the submit button until the user enters a name
2025-01-30 09:16:39 -06:00
r.submitB.Disable()
grid.NextRow()
2025-01-30 19:00:57 -06:00
g := r.stack.NewGroup("Patchset List")
// add the grid
r.psetgrid = g.RawGrid()
2025-02-01 11:55:17 -06:00
// will look in ~/.config/forge for an existing patchset file
// attempt to read in patchsets saved on disk
if psets != nil {
2025-01-30 19:00:57 -06:00
log.Info("got psets len", len(psets.Patchsets))
all := psets.SortByName()
for all.Scan() {
pset := all.Next()
// log.Info("pset name =", pset.Name)
r.addPatchsetNew(pset)
}
}
2025-01-28 13:20:10 -06:00
}
2025-01-30 08:48:59 -06:00
func (r *patchesWindow) addPatchsetNew(pset *forgepb.Patchset) {
r.psetgrid.NewLabel(pset.Name)
r.psetgrid.NewLabel(pset.Comment)
r.psetgrid.NewLabel(pset.GitAuthorName)
2025-02-01 11:55:17 -06:00
ctime := pset.Ctime.AsTime()
stime := ctime.UTC().Format("2006-01-02_15:04:05_UTC")
r.psetgrid.NewLabel(stime)
2025-01-30 19:05:21 -06:00
if pset.State == "BROKEN" {
r.psetgrid.NewLabel("Bad")
} else {
r.psetgrid.NewLabel("Good")
}
2025-01-30 08:48:59 -06:00
var win *patchWindow
2025-01-30 19:19:05 -06:00
r.psetgrid.NewButton("View", func() {
2025-01-29 09:06:19 -06:00
// has the window already been created?
if win != nil {
win.Toggle()
return
}
2025-01-30 08:48:59 -06:00
win = makePatchWindow(pset)
win.Show()
2025-01-28 13:20:10 -06:00
})
r.psetgrid.NextRow()
2025-01-28 13:20:10 -06:00
}
2025-01-30 08:48:59 -06:00
2025-01-30 09:09:47 -06:00
// will update this from the current state of the protobuf
2025-01-30 09:16:39 -06:00
func (r *patchesWindow) Update() {
2025-01-30 08:48:59 -06:00
var total, dirty, readonly, rw int
2025-01-30 09:09:47 -06:00
// figure out the totals
2025-01-30 08:48:59 -06:00
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
}
}
2025-01-30 09:09:47 -06:00
// send the values to the GUI toolkit
2025-01-30 09:16:39 -06:00
r.totalOL.SetText(strconv.Itoa(total) + " repos")
r.dirtyOL.SetText(strconv.Itoa(dirty) + " repos")
r.readonlyOL.SetText(strconv.Itoa(readonly) + " repos")
r.rw.SetText(fmt.Sprintf("%d repos", rw))
2025-01-30 08:48:59 -06:00
}