summaryrefslogtreecommitdiff
path: root/windowNewPatchsets.go
blob: 484fa2f4c8a67422319a147598e05e1fb598517d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

import (
	"fmt"
	"sync"

	"go.wit.com/gui"
	"go.wit.com/lib/gadgets"
	"go.wit.com/lib/protobuf/forgepb"
	"go.wit.com/log"
)

type stdPatchsetTableWin struct {
	sync.Mutex
	win    *gadgets.GenericWindow  // the machines gui window
	box    *gui.Node               // the machines gui parent box widget
	TB     *forgepb.PatchsetsTable // the gui table buffer
	update bool                    // if the window should be updated
}

func (w *stdPatchsetTableWin) Toggle() {
	if w == nil {
		return
	}
	if w.win == nil {
		return
	}
	w.win.Toggle()
}

func makePatchsetsWin() *stdPatchsetTableWin {
	dwin := new(stdPatchsetTableWin)
	dwin.win = gadgets.NewGenericWindow("forge current patchsets", "who is squirreling around?")
	dwin.win.Custom = func() {
		log.Info("test delete window here")
	}
	grid := dwin.win.Group.RawGrid()

	grid.NewButton("reload current patches", func() {
		psets, err := me.forge.GetPatchesets()
		if err != nil {
			log.Info("Get Patchsets failed", err)
			return
		}
		savePatchsets(psets)
		dwin.doPatchsetsTable(psets)
	})

	grid.NewButton("analyse patchsets", func() {
		psets, err := openPatchsets()
		if err != nil {
			log.Info("Open Patchsets failed", err)
			return
		}
		all := psets.All()
		for all.Scan() {
			pset := all.Next()
			log.Info("What is up with?", pset.Name)
		}
	})

	// make a box at the bottom of the window for the protobuf table
	dwin.box = dwin.win.Bottom.Box().SetProgName("TBOX")

	// load and show the current patch sets
	psets, err := openPatchsets()
	if err != nil {
		log.Info("Open Patchsets failed", err)
		return dwin
	}
	dwin.doPatchsetsTable(psets)

	return dwin
}

func (dwin *stdPatchsetTableWin) doPatchsetsTable(currentPatchsets *forgepb.Patchsets) {
	dwin.Lock()
	defer dwin.Unlock()
	if dwin.TB != nil {
		dwin.TB.Delete()
		dwin.TB = nil
	}

	// display the protobuf
	dwin.TB = AddPatchsetsPB(dwin.box, currentPatchsets)
	f := func(pset *forgepb.Patchset) {
		log.Info("Triggered. do something here", pset.Name)
		// m.Enabled = true
		win := makePatchWindow(pset)
		win.Show()
	}
	dwin.TB.Custom(f)
}

func AddPatchsetsPB(tbox *gui.Node, pb *forgepb.Patchsets) *forgepb.PatchsetsTable {
	t := pb.NewTable("PatchsetsPB")
	t.NewUuid()
	t.SetParent(tbox)

	testf := func(p *forgepb.Patchset) string {
		/*
			ctime := p.Ctime.AsTime()
			s := ctime.Format("2006/01/02 15:04")
			log.Info("test button", s, p.Name)
		*/
		return "test"
	}
	t.AddButtonFunc("test", testf)

	butf := func(p *forgepb.Patchset) string {
		/*
			ctime := p.Ctime.AsTime()
			s := ctime.Format("2006/01/02 15:04")
			log.Info("view button", s, p.Name)
		*/
		return "view"
	}
	t.AddButtonFunc("view", butf)

	t.AddStringFunc("#", func(p *forgepb.Patchset) string {
		return fmt.Sprintf("%d", p.Patches.Len())
	})

	t.AddName()
	t.AddComment()

	ctimef := func(p *forgepb.Patchset) string {
		ctime := p.Ctime.AsTime()
		return ctime.Format("2006/01/02 15:04")
	}
	t.AddStringFunc("ctime", ctimef)

	/*
		etimef := func(e *forgepb.Patchset) string {
			etime := e.Etime.AsTime()
			s := etime.Format("2006/01/02 15:04")
			if strings.HasPrefix(s, "1970/") {
				// just show a blank if it's not set
				return ""
			}
			return s
		}
		t.AddStringFunc("etime", etimef)
	*/

	t.AddStringFunc("Author", func(p *forgepb.Patchset) string {
		return fmt.Sprintf("%s <%s>", p.GitAuthorName, p.GitAuthorEmail)
	})

	t.AddUuid()

	t.ShowTable()
	return t
}