summaryrefslogtreecommitdiff
path: root/windowPortmap.go
blob: 3fb1ecf4b6b4e9b3e0b4e92223838ff09b6465a4 (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
// 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/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("ConfigSave() ", func() {
		saveMachineState()
	})
	grid.NewButton("Add() ", func() {
	})
	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)

	editf := func(m *Portmap) string {
		log.Info("machine =", m.Connect)
		return "edit"
	}
	t.AddButtonFunc("edit", editf)

	enablef := func(p *Portmap) string {
		if p.Enabled {
			p.Enabled = false
		} else {
			p.Enabled = true
		}
		return "enable"
	}
	t.AddButtonFunc("enable", enablef)

	enabledf := func(p *Portmap) string {
		if p.Enabled {
			return "true"
		}
		return "false"
	}
	t.AddStringFunc("enabled", enabledf)

	t.AddListen()
	t.AddConnect()
	t.ShowTable()
	return t
}

func saveMachineState() {
	me.portmaps.ConfigSave()
}