summaryrefslogtreecommitdiff
path: root/windowEvents.go
blob: 6a931886185cb4d32e1e5fd4c6e36067271a0948 (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
// 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
}