diff options
Diffstat (limited to 'windowZood.go')
| -rw-r--r-- | windowZood.go | 83 |
1 files changed, 53 insertions, 30 deletions
diff --git a/windowZood.go b/windowZood.go index 347aa4e..bd18044 100644 --- a/windowZood.go +++ b/windowZood.go @@ -5,6 +5,7 @@ package main import ( "fmt" + "sync" "time" "go.wit.com/gui" @@ -13,42 +14,71 @@ import ( "go.wit.com/log" ) -func makeZoodWin() { - me.zood = new(stdTableWin) - me.zood.win = gadgets.NewGenericWindow("zood daemon versions", "todo: add global controls here") - me.zood.win.Custom = func() { +type stdTableWin struct { + sync.Mutex + win *gadgets.GenericWindow // the machines gui window + box *gui.Node // the machines gui parent box widget + TB *zoopb.MachinesTable // the machines gui table buffer + update bool // if the window should be updated +} + +func (w *stdTableWin) Toggle() { + if w == nil { + return + } + if w.win == nil { + return + } + w.win.Toggle() +} + +func makeZoodWin() *stdTableWin { + zood := new(stdTableWin) + zood.win = gadgets.NewGenericWindow("zood daemon versions", "todo: add global controls here") + zood.win.Custom = func() { log.Info("test delete window here") } - grid := me.zood.win.Group.RawGrid() + grid := zood.win.Group.RawGrid() grid.NewButton("save machines.pb", func() { saveMachineState() }) grid.NewCheckbox("hide active") grid.NewButton("update", func() { - doMachinesUpgradeTable() + zood.doMachinesUpgradeTable(me.machines) }) // make a box at the bottom of the window for the protobuf table - me.zood.box = me.zood.win.Bottom.Box().SetProgName("TBOX") - doMachinesUpgradeTable() + zood.box = zood.win.Bottom.Box().SetProgName("TBOX") + zood.doMachinesUpgradeTable(me.machines) + + return zood } -func doMachinesUpgradeTable() { - me.zood.Lock() - defer me.zood.Unlock() - if me.zood.TB != nil { - me.zood.TB.Delete() - me.zood.TB = nil +func (zood *stdTableWin) doMachinesUpgradeTable(pb *zoopb.Machines) { + zood.Lock() + defer zood.Unlock() + if zood.TB != nil { + zood.TB.Delete() + zood.TB = nil } + /* + found := zoopb.NewMachines() + all := pb.SortByHostname() + for all.Scan() { + m := all.Next() + found.Append(m) + } + */ + // display the protobuf - me.zood.TB = AddMachinesPB(me.zood.box, me.machines) + zood.TB = AddMachinesPB(zood.box, pb) f := func(m *zoopb.Machine) { log.Info("Triggering machine", m.Hostname, "to upgrade zood") m.Upgrade = true } - me.zood.TB.Custom(f) - log.Info("table has uuid", me.zood.TB.GetUuid()) + zood.TB.Custom(f) + log.Info("table has uuid", zood.TB.GetUuid()) } func AddMachinesPB(tbox *gui.Node, pb *zoopb.Machines) *zoopb.MachinesTable { @@ -57,7 +87,7 @@ func AddMachinesPB(tbox *gui.Node, pb *zoopb.Machines) *zoopb.MachinesTable { t.SetParent(tbox) f := func(m *zoopb.Machine) string { - log.Info("machine =", m.Hostname) + // log.Info("machine =", m.Hostname) return "now" } t.AddButtonFunc("upgrade", f) @@ -72,6 +102,11 @@ func AddMachinesPB(tbox *gui.Node, pb *zoopb.Machines) *zoopb.MachinesTable { t.AddStringFunc("zood", func(m *zoopb.Machine) string { return findVersion(m, "zood") }) + delf := func(m *zoopb.Machine) string { + pb.DeleteByHostname(m.Hostname) + return "delete" + } + t.AddButtonFunc("delete", delf) /* // show if the machine needs to be upgraded @@ -98,15 +133,3 @@ func findVersion(m *zoopb.Machine, pkgname string) string { } return zood.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() -} |
