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

added addPNDView

parent f0e5e8c1
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
Pipeline #52910 passed
This commit is part of merge request !53. Comments created here will be created in the context of that merge request.
...@@ -5,8 +5,10 @@ import "github.com/rivo/tview" ...@@ -5,8 +5,10 @@ import "github.com/rivo/tview"
type view interface { type view interface {
GetContent() tview.Primitive GetContent() tview.Primitive
} }
type App struct { type App struct {
app *tview.Application app *tview.Application
pages *tview.Pages
} }
func NewApp() *App { func NewApp() *App {
...@@ -16,8 +18,19 @@ func NewApp() *App { ...@@ -16,8 +18,19 @@ func NewApp() *App {
return a return a
} }
func (a *App) SetView(v view) { func (a *App) SetRoot(v view) {
a.app.SetRoot(v.GetContent(), true) a.pages = v.GetContent().(*tview.Pages)
a.app.SetRoot(a.pages, true)
}
func (a *App) SwitchPage(s string) {
if a.pages.HasPage(s) {
a.pages.SwitchToPage(s)
}
}
func (a *App) AddPage(name string, p view) {
a.pages.AddPage(name, p.GetContent(), true, false)
} }
func (a *App) Run() error { func (a *App) Run() error {
......
...@@ -14,7 +14,11 @@ func main() { ...@@ -14,7 +14,11 @@ func main() {
} }
app := app.NewApp() app := app.NewApp()
app.SetView(views.NewMainView(app, conn)) mainView := views.NewMainView(app, conn)
addPNDView := views.NewAddPNDView(app)
app.SetRoot(mainView)
app.AddPage("PND", addPNDView)
app.Run() app.Run()
defer app.Stop() defer app.Stop()
......
package views
import (
"code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/app"
"github.com/rivo/tview"
)
type AddPNDView struct {
addPNDView *tview.Form
}
func NewAddPNDView(app *app.App) *AddPNDView {
pndv := &AddPNDView{
addPNDView: tview.NewForm(),
}
pndv.addPNDView.
AddInputField("Name", "", 20, nil, nil).
AddInputField("description", "", 20, nil, nil).
AddDropDown("SI", []string{"Southbound 1", "Southbound 2", "Southbound 3", "Southbound 4"}, 0, nil).
AddButton("Send", func() {
//TODO: call grpc function here
}).
AddButton("Abort", func() {
app.SwitchPage("main")
}).
SetCancelFunc(func() {
app.SwitchPage("main")
})
return pndv
}
func (pndv *AddPNDView) GetContent() tview.Primitive {
return pndv.addPNDView
}
...@@ -28,6 +28,11 @@ func (cv *CommandListView) GetContent() tview.Primitive { ...@@ -28,6 +28,11 @@ func (cv *CommandListView) GetContent() tview.Primitive {
func (cv *CommandListView) GetCommands(app *app.App, rv *ResultAndInputView, func (cv *CommandListView) GetCommands(app *app.App, rv *ResultAndInputView,
conn *grpc.ClientConn) { conn *grpc.ClientConn) {
//TODO: create own command in grpc -> commands
cv.commandsList.AddItem("AddPND", "closes the application", '!', func() {
app.SwitchPage("PND")
})
for i, command := range commands.CommandList { for i, command := range commands.CommandList {
f := command.Function f := command.Function
cv.commandsList. cv.commandsList.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment