summaryrefslogtreecommitdiff
path: root/windowPortmap.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-03-09 07:07:41 -0500
committerJeff Carr <[email protected]>2025-03-09 07:07:41 -0500
commit66000419bf15cb255e436db44a2a74bf104484e3 (patch)
tree819327cff4db2f2e0e78e6f0caa575ea8e54968d /windowPortmap.go
parenteaedaded622316d3b59c2f3765cd2362e96ce54c (diff)
preliminary gui
Diffstat (limited to 'windowPortmap.go')
-rw-r--r--windowPortmap.go115
1 files changed, 115 insertions, 0 deletions
diff --git a/windowPortmap.go b/windowPortmap.go
new file mode 100644
index 0000000..83ce7aa
--- /dev/null
+++ b/windowPortmap.go
@@ -0,0 +1,115 @@
+// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
+// Use of this source code is governed by the GPL 3.0
+
+package main
+
+import (
+ "go.wit.com/gui"
+ "go.wit.com/lib/gadgets"
+ "go.wit.com/lib/protobuf/zoopb"
+ "go.wit.com/log"
+)
+
+func makePortmapWin() {
+ me.portwin = new(stdTableWin)
+ me.portwin.win = gadgets.NewGenericWindow("zood daemon versions", "todo: add global controls here")
+ me.portwin.win.Custom = func() {
+ log.Info("test delete window here")
+ }
+ grid := me.portwin.win.Group.RawGrid()
+ grid.NewButton("save machines.pb", func() {
+ saveMachineState()
+ })
+ grid.NewCheckbox("hide active")
+ grid.NewButton("update", func() {
+ doMachinesUpgradeTable()
+ })
+
+ // make a box at the bottom of the window for the protobuf table
+ me.portwin.box = me.portwin.win.Bottom.Box().SetProgName("TBOX")
+ doMachinesUpgradeTable()
+}
+
+func doMachinesUpgradeTable() {
+ me.portwin.Lock()
+ defer me.portwin.Unlock()
+ if me.portwin.TB != nil {
+ me.portwin.TB.Delete()
+ me.portwin.TB = nil
+ }
+
+ // display the protobuf
+ me.portwin.TB = AddMachinesPB(me.portwin.box, me.portmaps)
+ f := func(m *Portmap) {
+ log.Info("Triggering machine", m.Connect, "to upgrade portwin")
+ m.Enabled = true
+ }
+ me.portwin.TB.Custom(f)
+ log.Info("table has uuid", me.portwin.TB.GetUuid())
+}
+
+func AddMachinesPB(tbox *gui.Node, pb *Portmaps) *PortmapsTable {
+ t := pb.NewTable("PortmapsPB")
+ t.NewUuid()
+ t.SetParent(tbox)
+
+ f := func(m *Portmap) string {
+ log.Info("machine =", m.Connect)
+ return "now"
+ }
+ t.AddButtonFunc("upgrade", f)
+
+ t.AddConnect()
+ // t.AddMemory()
+ // t.AddCpus()
+ /*
+ t.AddStringFunc("sMB", func(m *oopb.Machine) string {
+ return fmt.Sprintf("%d mb", m.Memory/(1024*1024))
+ })
+
+ t.AddStringFunc("portwin", func(m *zoopb.Machine) string {
+ return findVersion(m, "portwin")
+ })
+ */
+
+ /*
+ // show if the machine needs to be upgraded
+ t.AddStringFunc("triggered?", func(m *zoopb.Machine) string {
+ if m.Upgrade {
+ return "yes"
+ }
+ return ""
+ })
+ */
+
+ /*
+ t.AddTimeFunc("age", func(m *zoopb.Machine) time.Time {
+ return m.Laststamp.AsTime()
+ })
+ */
+
+ t.ShowTable()
+ return t
+}
+
+func findVersion(m *zoopb.Machine, pkgname string) string {
+ portwin := m.Packages.FindByName(pkgname)
+ if portwin == nil {
+ return "n/a"
+ }
+ return portwin.Version
+}
+
+func saveMachineState() {
+ /*
+ cur := zoopb.NewMachines()
+
+ all := me.machines.SortByHostname()
+ for all.Scan() {
+ m := all.Next()
+ log.Info("have machine:", m.Hostname)
+ cur.Append(m)
+ }
+ cur.ConfigSave()
+ */
+}