1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/modules/newrelic/widget.go
Chris Cummer f9a06540f1 Simplify the view loading for the keyboard widget
Signed-off-by: Chris Cummer <chriscummer@me.com>
2020-11-26 23:12:15 -08:00

64 lines
1.4 KiB
Go

package newrelic
import (
"sort"
"github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view"
)
type Widget struct {
view.MultiSourceWidget
view.TextWidget
Clients []*Client2
settings *Settings
}
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
widget := Widget{
MultiSourceWidget: view.NewMultiSourceWidget(settings.common, "applicationID", "applicationIDs"),
TextWidget: view.NewTextWidget(app, pages, settings.common),
settings: settings,
}
widget.initializeKeyboardControls()
for _, id := range utils.ToInts(widget.settings.applicationIDs) {
widget.Clients = append(widget.Clients, NewClient(widget.settings.apiKey, id))
}
sort.Slice(widget.Clients, func(i, j int) bool {
return widget.Clients[i].applicationId < widget.Clients[j].applicationId
})
widget.SetDisplayFunction(widget.Refresh)
return &widget
}
/* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() {
widget.Redraw(widget.content)
}
/* -------------------- Unexported Functions -------------------- */
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) currentData() *Client2 {
if len(widget.Clients) == 0 {
return nil
}
if widget.Idx < 0 || widget.Idx >= len(widget.Clients) {
return nil
}
return widget.Clients[widget.Idx]
}