Skip to content
Snippets Groups Projects
Commit f0e5e8c1 authored by Malte Bauch's avatar Malte Bauch
Browse files

added footerView

this view contains grpcStatus and databaseStatus
parent 64d027ae
No related branches found
No related tags found
3 merge requests!90Develop,!59Resolve "Simple ncurse-alike cli to manage gosdn",!53V.0.1.0 Codename Threadbare
package views
import (
"code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/app"
"github.com/rivo/tview"
"time"
)
type DatabaseStatusView struct {
databaseStatusView *tview.TextView
}
func NewDatabaseStatusView(app *app.App) *DatabaseStatusView {
dv := &DatabaseStatusView{
databaseStatusView: tview.NewTextView(),
}
dv.databaseStatusView.
SetDynamicColors(true).
SetTextAlign(tview.AlignCenter).
SetRegions(true).
SetBorder(true).
SetTitle("Database")
go databaseTicker(dv)
return dv
}
func (dv *DatabaseStatusView) GetContent() tview.Primitive {
return dv.databaseStatusView
}
func (dv *DatabaseStatusView) SetContent(s string) {
dv.databaseStatusView.Clear()
dv.databaseStatusView.SetText(s)
}
func databaseTicker(dv *DatabaseStatusView) {
ticker := time.NewTicker(5 * time.Second)
for t := range ticker.C {
dv.SetContent(t.String())
}
}
package views
import (
"code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/app"
"github.com/rivo/tview"
"google.golang.org/grpc"
)
type FooterView struct {
footerView *tview.Flex
databaseStatusView *DatabaseStatusView
gRPCStatusView *GRPCStatusView
}
func NewFooterView(app *app.App, conn *grpc.ClientConn) *FooterView {
fw := &FooterView{
footerView: tview.NewFlex(),
databaseStatusView: NewDatabaseStatusView(app),
gRPCStatusView: NewGRPCStatusView(app, conn),
}
fw.footerView.
SetBorder(true).
SetTitle("Status")
fw.footerView.
AddItem(fw.gRPCStatusView.GetContent(), 0, 1, false).
AddItem(fw.databaseStatusView.GetContent(), 0, 1, false)
return fw
}
func (fw *FooterView) GetContent() tview.Primitive {
return fw.footerView
}
...@@ -11,23 +11,25 @@ type GRPCStatusView struct { ...@@ -11,23 +11,25 @@ type GRPCStatusView struct {
gRPCStatusView *tview.TextView gRPCStatusView *tview.TextView
} }
//TODO: change to grpcStatusView
func NewGRPCStatusView(app *app.App, conn *grpc.ClientConn) *GRPCStatusView { func NewGRPCStatusView(app *app.App, conn *grpc.ClientConn) *GRPCStatusView {
//TODO: change to uses FlexBox if there is more to display in the header
sv := &GRPCStatusView{ sv := &GRPCStatusView{
gRPCStatusView: tview.NewTextView(), gRPCStatusView: tview.NewTextView(),
} }
sv.gRPCStatusView. sv.gRPCStatusView.
SetDynamicColors(true).
SetTextAlign(tview.AlignCenter).
SetRegions(true). SetRegions(true).
SetBorder(true). SetBorder(true).
SetTitle("gRPC") SetTitle("gRPC")
//TODO: maybe there is another way to do this.
// pretty ugly atm, since it re-draws every 5 seconds...
sv.gRPCStatusView.SetChangedFunc(func() { sv.gRPCStatusView.SetChangedFunc(func() {
app.Draw() app.Draw()
}) })
go goSDNTicker(sv, conn) go gRPCTicker(sv, conn)
return sv return sv
} }
...@@ -41,9 +43,14 @@ func (sv *GRPCStatusView) SetContent(s string) { ...@@ -41,9 +43,14 @@ func (sv *GRPCStatusView) SetContent(s string) {
sv.gRPCStatusView.SetText(s) sv.gRPCStatusView.SetText(s)
} }
func goSDNTicker(sv *GRPCStatusView, conn *grpc.ClientConn) { func gRPCTicker(sv *GRPCStatusView, conn *grpc.ClientConn) {
//TODO: refactor -> get rid of hardcoded values
ticker := time.NewTicker(5 * time.Second) ticker := time.NewTicker(5 * time.Second)
for range ticker.C { for range ticker.C {
sv.SetContent(conn.GetState().String()) if str := conn.GetState().String(); str == "READY" || str == "IDLE" {
sv.SetContent("[green]" + "connected")
} else {
sv.SetContent("[red]" + "disconnected")
}
} }
} }
...@@ -12,7 +12,7 @@ type MainView struct { ...@@ -12,7 +12,7 @@ type MainView struct {
commandsListView *CommandListView commandsListView *CommandListView
resultAndInputView *ResultAndInputView resultAndInputView *ResultAndInputView
headerView *HeaderView headerView *HeaderView
goSDNStatusView *GRPCStatusView footerView *FooterView
} }
func NewMainView(app *app.App, conn *grpc.ClientConn) *MainView { func NewMainView(app *app.App, conn *grpc.ClientConn) *MainView {
...@@ -22,15 +22,15 @@ func NewMainView(app *app.App, conn *grpc.ClientConn) *MainView { ...@@ -22,15 +22,15 @@ func NewMainView(app *app.App, conn *grpc.ClientConn) *MainView {
commandsListView: NewCommandListView(), commandsListView: NewCommandListView(),
resultAndInputView: NewResultAndInputView(), resultAndInputView: NewResultAndInputView(),
headerView: NewHeaderView(), headerView: NewHeaderView(),
goSDNStatusView: NewGRPCStatusView(app, conn), footerView: NewFooterView(app, conn),
} }
mv.commandsListView.GetCommands(app, mv.resultAndInputView, conn) mv.commandsListView.GetCommands(app, mv.resultAndInputView, conn)
mv.mainGrid. mv.mainGrid.
SetRows(8, 0, 3). SetRows(8, 0, 5).
SetColumns(40, 0). SetColumns(40, 0).
AddItem(mv.headerView.GetContent(), 0, 0, 1, 2, 0, 0, false). AddItem(mv.headerView.GetContent(), 0, 0, 1, 2, 0, 0, false).
AddItem(mv.goSDNStatusView.GetContent(), 2, 0, 1, 2, 0, 0, false) AddItem(mv.footerView.GetContent(), 2, 0, 1, 2, 0, 0, false)
mv.mainGrid.AddItem(mv.commandsListView.GetContent(), 1, 0, 1, 1, 0, 0, true). mv.mainGrid.AddItem(mv.commandsListView.GetContent(), 1, 0, 1, 1, 0, 0, true).
AddItem(mv.resultAndInputView.GetContent(), 1, 1, 1, 1, 0, 0, false) AddItem(mv.resultAndInputView.GetContent(), 1, 1, 1, 1, 0, 0, false)
...@@ -43,9 +43,3 @@ func NewMainView(app *app.App, conn *grpc.ClientConn) *MainView { ...@@ -43,9 +43,3 @@ func NewMainView(app *app.App, conn *grpc.ClientConn) *MainView {
func (mv *MainView) GetContent() tview.Primitive { func (mv *MainView) GetContent() tview.Primitive {
return mv.pages return mv.pages
} }
func newPrimitive(text string) tview.Primitive {
return tview.NewTextView().
SetTextAlign(tview.AlignCenter).
SetText(text)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment