gus/windowEvents.go

95 lines
2.0 KiB
Go

// 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 makeEventsWin() {
me.eventswin = new(stdEventTableWin)
me.eventswin.win = gadgets.NewGenericWindow("Gus current event log", "who is squirreling around?")
me.eventswin.win.Custom = func() {
log.Info("test delete window here")
}
grid := me.eventswin.win.Group.RawGrid()
grid.NewButton("first 20", func() {
var count int
found := NewEvents()
all := me.events.All()
for all.Scan() {
e := all.Next()
count += 1
found.Append(e)
if count > 20 {
break
}
}
doEventsTable(found)
})
grid.NewButton("last 20", func() {
var count int
total := me.events.Len()
found := NewEvents()
all := me.events.All()
for all.Scan() {
e := all.Next()
count += 1
if count < total-20 {
continue
}
found.Append(e)
}
doEventsTable(found)
})
grid.NewButton("Save Current", func() {
log.Info("event log is len =", me.events.Len())
me.events.Save()
})
// make a box at the bottom of the window for the protobuf table
me.eventswin.box = me.eventswin.win.Bottom.Box().SetProgName("TBOX")
// doEventsTable(me.events)
}
func doEventsTable(currentEvents *Events) {
me.eventswin.Lock()
defer me.eventswin.Unlock()
if me.eventswin.TB != nil {
me.eventswin.TB.Delete()
me.eventswin.TB = nil
}
// display the protobuf
me.eventswin.TB = AddEventsPB(me.eventswin.box, currentEvents)
f := func(e *Event) {
log.Info("Triggered. do something here", e.Hostname)
// m.Enabled = true
}
me.eventswin.TB.Custom(f)
// log.Info("table has uuid", me.eventswin.TB.GetUuid())
}
func AddEventsPB(tbox *gui.Node, pb *Events) *EventsTable {
t := pb.NewTable("EventsPB")
t.NewUuid()
t.SetParent(tbox)
enabledf := func(p *Event) string {
return "todo"
}
t.AddStringFunc("enabled", enabledf)
t.AddHostname()
t.AddAddress()
t.AddWhere()
t.ShowTable()
return t
}