2018-03-24 14:23:24 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "github.com/rivo/tview"
|
|
|
|
|
|
|
|
type ServicesView struct {
|
|
|
|
*tview.List
|
|
|
|
|
|
|
|
Model []ServiceItem
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewServicesView() *ServicesView {
|
|
|
|
v := &ServicesView{
|
|
|
|
List: tview.NewList(),
|
|
|
|
}
|
|
|
|
|
|
|
|
v.
|
|
|
|
SetBorder(true).
|
|
|
|
SetTitle("Services")
|
|
|
|
v.
|
|
|
|
SetDoneFunc(func() {
|
|
|
|
// app.SetFocus(logView)
|
|
|
|
})
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2018-03-24 14:58:07 +08:00
|
|
|
func (list *ServicesView) loadModel(specialServices, activeOnly bool) error {
|
2018-03-24 14:23:24 +08:00
|
|
|
var err error
|
|
|
|
list.Clear()
|
|
|
|
|
|
|
|
if activeOnly {
|
|
|
|
list.SetTitle("Active Services")
|
|
|
|
} else {
|
|
|
|
list.SetTitle("All Services")
|
|
|
|
}
|
|
|
|
|
2018-03-24 14:58:07 +08:00
|
|
|
list.Model, err = serviceModel(specialServices, activeOnly)
|
2018-03-24 14:23:24 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, srv := range list.Model {
|
|
|
|
list.AddItem(srv.Name, srv.Description, 0, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|