From f2281a2102d5821d337029a9f36395b955f3ec80 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 29 Jan 2025 09:06:19 -0600 Subject: start a 'view patch' window --- send.go | 21 ++++++++ windowPatches.go | 28 ++++++++-- windowPatchesSubmit.go | 120 +++++++++++++++++++++++++++++++++++++++++ windowPatchesSummary.go | 140 ------------------------------------------------ windowViewPatch.go | 114 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 279 insertions(+), 144 deletions(-) create mode 100644 windowPatchesSubmit.go delete mode 100644 windowPatchesSummary.go create mode 100644 windowViewPatch.go diff --git a/send.go b/send.go index 745426a..6067baf 100644 --- a/send.go +++ b/send.go @@ -96,7 +96,28 @@ func doRegister(newurl string) error { return nil } +// gets the patch +// todo: move to forgepb func getPatch(pbfile string) (*forgepb.Patchset, error) { + url := me.urlbase + "/patchsetget?filename=" + pbfile + log.Info("getPatch() url", url) + body, err := me.forge.HttpPost(url, nil) + if err != nil { + log.Info("httpPost() failed:", err) + return nil, err + } + log.Info("getPatch() len(body)", len(body)) + var pset *forgepb.Patchset + pset = new(forgepb.Patchset) + err = pset.Unmarshal(body) + if err != nil { + log.Info("Unmarshal failed", err) + return nil, err + } + return pset, nil +} + +func savePatch(pbfile string) (*forgepb.Patchset, error) { url := me.urlbase + "/patchsetget?filename=" + pbfile log.Info("getPatch() url", url) body, err := me.forge.HttpPost(url, nil) diff --git a/windowPatches.go b/windowPatches.go index ad14e7f..4839f3d 100644 --- a/windowPatches.go +++ b/windowPatches.go @@ -13,14 +13,15 @@ import ( ) type patchesWindow struct { - 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 + 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 } func (r *patchesWindow) Hidden() bool { @@ -84,6 +85,7 @@ func (r *patchesWindow) initWindow() { // add the grid r.setgrid = g.NewGrid("", 0, 0) r.setlist = make(map[string]*forgepb.Patchset) + r.setwin = make(map[string]*patchWindow) // query for current patchsets lines, err := listPatches() @@ -108,12 +110,30 @@ func (r *patchesWindow) addPatchset(line string) { r.setgrid.NewLabel(subject) r.setgrid.NewLabel(author) r.setgrid.NewButton("Download", func() { + pset, err := savePatch(name) + if err != nil { + log.Info(name, "failed to download", err) + return + } + r.setlist[name] = pset + }) + r.setgrid.NewButton("View", func() { + // has the window already been created? + win := r.setwin[name] + if win != nil { + win.Toggle() + log.Info("TRYING TO TOGGLE WINDOW") + return + } + + // get the patch and make the window pset, err := getPatch(name) if err != nil { log.Info(name, "failed to download", err) return } r.setlist[name] = pset + r.setwin[name] = makePatchWindow(pset) }) r.setgrid.NewButton("Dump", func() { pset := r.setlist[name] diff --git a/windowPatchesSubmit.go b/windowPatchesSubmit.go new file mode 100644 index 0000000..518e7e1 --- /dev/null +++ b/windowPatchesSubmit.go @@ -0,0 +1,120 @@ +package main + +import ( + "fmt" + "strconv" + + "go.wit.com/gui" + "go.wit.com/lib/gadgets" + "go.wit.com/log" +) + +type patchSummary struct { + 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 + totalUserPatches *gui.Node + totalDevelPatches *gui.Node + totalMasterPatches *gui.Node + fileCount *gui.Node + unknownOL *gadgets.BasicEntry + unknownSubmitB *gui.Node + reason *gadgets.BasicEntry + submitB *gui.Node + // allp []*repolist.Patch +} + +func (r *patchesWindow) submitPatchesBox(box *gui.Node) *patchSummary { + s := new(patchSummary) + group1 := box.NewGroup("Patch Summary") + s.grid = group1.RawGrid() + + s.totalOL = gadgets.NewOneLiner(s.grid, "Total") + _ = s.grid.NewLabel("total changes") + _ = s.grid.NewLabel("user to devel") + s.grid.NextRow() + + s.dirtyOL = gadgets.NewOneLiner(s.grid, "dirty") + _ = s.grid.NewLabel("") // skip a column + s.totalUserRepos = s.grid.NewLabel("x go repos") + s.grid.NextRow() + + s.readonlyOL = gadgets.NewOneLiner(s.grid, "read-only") + _ = s.grid.NewLabel("") // skip a column + s.totalUserPatches = s.grid.NewLabel("x patches") + s.grid.NextRow() + + s.rw = gadgets.NewOneLiner(s.grid, "r/w") + _ = s.grid.NewLabel("") // skip a column + s.fileCount = s.grid.NewLabel("x files") + s.grid.NextRow() + + group1 = box.NewGroup("PatchSet Create") + s.grid = group1.RawGrid() + + s.grid.NewButton("update patch summary", func() { + s.Update() + }) + + s.reason = gadgets.NewBasicEntry(s.grid, "set 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()) + if err != nil { + log.Info(err) + return + } + line := "somedate " + s.reason.String() + " Author: me" + pset.GitAuthorEmail + me.patchWin.addPatchset(line) + }) + + // disable these until there are not dirty repos + // s.reason.Disable() + s.submitB.Disable() + s.grid.NextRow() + return s +} + +// does not run any commands +func (s *patchSummary) Update() { + var total, dirty, readonly, rw int + var userT int // , develT, masterT int + // 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)) + + s.totalUserRepos.SetText(strconv.Itoa(userT) + " repos") +} diff --git a/windowPatchesSummary.go b/windowPatchesSummary.go deleted file mode 100644 index 5be64f7..0000000 --- a/windowPatchesSummary.go +++ /dev/null @@ -1,140 +0,0 @@ -package main - -import ( - "fmt" - "strconv" - - "go.wit.com/gui" - "go.wit.com/lib/gadgets" - "go.wit.com/log" -) - -type patchSummary struct { - 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 - totalUserPatches *gui.Node - totalDevelPatches *gui.Node - totalMasterPatches *gui.Node - fileCount *gui.Node - unknownOL *gadgets.BasicEntry - unknownSubmitB *gui.Node - reason *gadgets.BasicEntry - submitB *gui.Node - // allp []*repolist.Patch -} - -func (r *patchesWindow) submitPatchesBox(box *gui.Node) *patchSummary { - s := new(patchSummary) - group1 := box.NewGroup("Patch Summary") - s.grid = group1.RawGrid() - - s.totalOL = gadgets.NewOneLiner(s.grid, "Total") - _ = s.grid.NewLabel("total changes") - _ = s.grid.NewLabel("user to devel") - s.grid.NextRow() - - s.dirtyOL = gadgets.NewOneLiner(s.grid, "dirty") - _ = s.grid.NewLabel("") // skip a column - s.totalUserRepos = s.grid.NewLabel("x go repos") - s.grid.NextRow() - - s.readonlyOL = gadgets.NewOneLiner(s.grid, "read-only") - _ = s.grid.NewLabel("") // skip a column - s.totalUserPatches = s.grid.NewLabel("x patches") - s.grid.NextRow() - - s.rw = gadgets.NewOneLiner(s.grid, "r/w") - _ = s.grid.NewLabel("") // skip a column - s.fileCount = s.grid.NewLabel("x files") - s.grid.NextRow() - - group1 = box.NewGroup("PatchSet Create") - s.grid = group1.RawGrid() - - s.grid.NewButton("update patch summary", func() { - s.Update() - }) - - s.reason = gadgets.NewBasicEntry(s.grid, "set 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()) - if err != nil { - log.Info(err) - return - } - line := "somedate " + s.reason.String() + " Author: me" + pset.GitAuthorEmail - me.patchWin.addPatchset(line) - }) - - /* - s.grid.NewButton("Apply Latest Patchset", func() { - lastp := lastPatch() - pset, err := getPatch(lastp) - if err != nil { - return - } - if _, _, _, err := IsEverythingOnDevel(); err != nil { - log.Info("You can only apply patches to the devel branch") - return - } - if IsAnythingDirty() { - log.Info("You can't apply patches when repos are dirty") - me.forge.PrintHumanTable(me.found) - return - } - applyPatchset(pset) - }) - */ - - // disable these until there are not dirty repos - // s.reason.Disable() - s.submitB.Disable() - s.grid.NextRow() - return s -} - -// does not run any commands -func (s *patchSummary) Update() { - var total, dirty, readonly, rw int - var userT int // , develT, masterT int - // 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)) - - s.totalUserRepos.SetText(strconv.Itoa(userT) + " repos") -} diff --git a/windowViewPatch.go b/windowViewPatch.go new file mode 100644 index 0000000..a59baa7 --- /dev/null +++ b/windowViewPatch.go @@ -0,0 +1,114 @@ +package main + +import ( + "strings" + "sync" + + "go.wit.com/lib/gadgets" + "go.wit.com/lib/protobuf/forgepb" + + "go.wit.com/gui" +) + +type patchWindow struct { + 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 + pset *forgepb.Patchset // the patchset in question +} + +// todo: autogenerate these or make them standared 'gui' package functions +// make this an go interface somehow + +// is the window hidden right now? +func (w *patchWindow) Hidden() bool { + return w.win.Hidden() +} + +// switches between the window being visable or hidden on the desktop +func (w *patchWindow) Toggle() { + if w.Hidden() { + w.Show() + } else { + w.Hide() + } +} + +// hides the window completely +func (w *patchWindow) Show() { + w.win.Show() +} + +func (w *patchWindow) Hide() { + w.win.Hide() +} + +// should be the first box/widget in the window +// greys out the window to the user +func (w *patchWindow) Disable() { + w.stack.Disable() +} + +func (w *patchWindow) Enable() { + w.stack.Enable() +} + +// you can only have one of these +func makePatchWindow(pset *forgepb.Patchset) *patchWindow { + pw := new(patchWindow) + + // sync.Once() + pw.win = gadgets.RawBasicWindow("Patcheset for") + pw.win.Make() + + pw.stack = pw.win.Box().NewBox("bw vbox", false) + // me.reposwin.Draw() + pw.win.Custom = func() { + // sets the hidden flag to false so Toggle() works + pw.win.Hide() + } + + grid := pw.stack.NewGrid("", 0, 0) + + grid.NewLabel(pset.GitAuthorName) + + /* + r.shelf = r.initGroup() + group1 := r.stack.NewGroup("stuff") + vbox := group1.Box() + vbox.Vertical() + */ + + g := pw.stack.NewGroup("PatchSet List") + + // add the patch grid + g.NewGrid("", 0, 0) + + /* + for i, line := range lines { + log.Info(i, line) + r.addFile(line) + } + */ + return pw +} + +func (r *patchWindow) addPatchset(line string) { + parts := strings.Split(line, "Author:") + author := parts[1] + parts = strings.Fields(parts[0]) + name := parts[0] + subject := strings.Join(parts[1:], " ") + r.setgrid.NewLabel(name) + r.setgrid.NewLabel(subject) + r.setgrid.NewLabel(author) + r.setgrid.NewButton("Download", func() { + }) + r.setgrid.NewButton("Apply", func() { + }) + r.setgrid.NextRow() +} -- cgit v1.2.3