summaryrefslogtreecommitdiff
path: root/windowFound.go
blob: 9b085f18df1d76ac33d5f3c32e13f2ba684db645 (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
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

// shows a window of the 'found' repos

import (
	"go.wit.com/lib/gadgets"
	"go.wit.com/lib/protobuf/gitpb"
	"go.wit.com/log"

	"go.wit.com/gui"
)

type foundWindow struct {
	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
	totalOL    *gadgets.OneLiner
	dirtyOL    *gadgets.OneLiner
	readonlyOL *gadgets.OneLiner
	rw         *gadgets.OneLiner
	// checkB     *gui.Node
}

func (r *foundWindow) Hidden() bool {
	return r.win.Hidden()
}

func (r *foundWindow) Toggle() {
	if r.Hidden() {
		r.Show()
	} else {
		r.Hide()
	}
}

func (r *foundWindow) Show() {
	r.win.Show()
}

func (r *foundWindow) Hide() {
	r.win.Hide()
}

// you can only have one of these
func (r *foundWindow) initWindow() {
	r.win = gadgets.RawBasicWindow("Found Repos")
	r.win.Make()

	r.stack = r.win.Box().NewBox("bw vbox", false)
	// me.reposwin.Draw()
	r.win.Custom = func() {
		log.Warn("Found Window close. setting hidden=true")
		// sets the hidden flag to false so Toggle() works
		r.win.Hide()
	}
	group1 := r.stack.NewGroup("Repo Summary")
	group1.NewButton("dirty", func() {
		log.Info("find dirty here")
		found := findDirty()
		me.forge.PrintHumanTable(found)
	})
	group1.NewButton("all", func() {
		log.Info("find all here")
		me.found = new(gitpb.Repos)
		findAll()
		me.forge.PrintHumanTable(me.found)
	})

	r.grid = r.stack.RawGrid()

	group1.NewButton("show", func() {
		r.listRepos()
	})
}

func (r *foundWindow) listRepos() {
	all := me.found.All()
	for all.Scan() {
		repo := all.Next()
		r.addRepo(repo)
	}
}

func (r *foundWindow) addRepo(repo *gitpb.Repo) {
	r.grid.NewButton("View", func() {
	})
	r.grid.NewLabel(repo.GetGoPath())
	r.grid.NewLabel(repo.GetMasterVersion())
	r.grid.NewLabel(repo.GetDevelVersion())
	r.grid.NewLabel(repo.GetUserVersion())
	r.grid.NewLabel(repo.GetCurrentBranchName())
	r.grid.NextRow()
}

// will update this from the current state of the protobuf
func (r *foundWindow) Update() {
}