From 5f14cd6976c1d875d7c4b97875e9cb1b06bb5663 Mon Sep 17 00:00:00 2001
From: Malte Bauch <malte.bauch@stud.h-da.de>
Date: Thu, 22 Oct 2020 16:53:21 +0200
Subject: [PATCH] a few simple fixes for goSDN-tview

- changed status check of grpc and database
- reordered commandlist
---
 cmd/gosdn-tview/grpc/commands.go           | 13 ++++++-------
 cmd/gosdn-tview/views/commandsListView.go  |  4 ++--
 cmd/gosdn-tview/views/datbaseStatusView.go | 15 ++++-----------
 cmd/gosdn-tview/views/gRPCStatusView.go    | 15 ++++++++++-----
 4 files changed, 22 insertions(+), 25 deletions(-)

diff --git a/cmd/gosdn-tview/grpc/commands.go b/cmd/gosdn-tview/grpc/commands.go
index 1ea3806a4..1ce55dd37 100644
--- a/cmd/gosdn-tview/grpc/commands.go
+++ b/cmd/gosdn-tview/grpc/commands.go
@@ -22,17 +22,16 @@ type command struct {
 
 //CommandList contains the specific goSDN gRPC calls
 var CommandList = []command{
-	{"hello", "test connection to goSDN controller", goSDNSayHello},
-	{"shutdown", "request goSDN controller to shutdown", goSDNShutdown},
+	{"hello", "test connection to controller", goSDNSayHello},
 	{"testdb", "test all database connections", goSDNTestDB},
-	{"tapigetedge", "get list of edges", TAPIGetEdge},
-	{"tapigetedgenode", "get list of edgenodes", TAPIGetEdgeNode},
-	{"tapigetlink", "get list of links", TAPIGetLink},
+	{"tapiGetDevices", "creates devices", TAPIGetEdge},
+	{"tapiGetInterfaces", "creates interfaces", TAPIGetEdgeNode},
+	{"tapiGetLinks", "creates links between devices", TAPIGetLink},
+	{"shutdown", "request controller to shutdown", goSDNShutdown},
 }
 
 //Connect creates a new connection to the gRPC server
 func Connect(address string) (*grpc.ClientConn, error) {
-	//address := "141.100.70.170:55066"
 	return grpc.Dial(address, grpc.WithInsecure(), grpc.WithTimeout(5*time.Second), grpc.WithBlock())
 }
 
@@ -51,7 +50,7 @@ func GoSDNLogStream(conn *grpc.ClientConn, clv *tview.TextView) error {
 				streamError = err
 				break
 			}
-			response := []byte(msg.Log + "\n")
+			response := []byte(msg.Log)
 			clv.Write(response)
 		}
 	}(stream)
diff --git a/cmd/gosdn-tview/views/commandsListView.go b/cmd/gosdn-tview/views/commandsListView.go
index 761a171fa..b9e42b904 100644
--- a/cmd/gosdn-tview/views/commandsListView.go
+++ b/cmd/gosdn-tview/views/commandsListView.go
@@ -35,7 +35,7 @@ func (cv *CommandListView) GetContent() tview.Primitive {
 func (cv *CommandListView) GetCommands(app *app.App, rv *ResultAndInputView,
 	conn *grpc.ClientConn) {
 	//TODO: create own command in grpc -> commands
-	cv.commandsList.AddItem("AddPND", "closes the application", 'a', func() {
+	cv.commandsList.AddItem("addPND", "closes the application", 'a', func() {
 		rv.ChangeContentView("addPND")
 		app.SetFocus(rv.GetContent())
 	})
@@ -50,7 +50,7 @@ func (cv *CommandListView) GetCommands(app *app.App, rv *ResultAndInputView,
 			})
 	}
 
-	cv.commandsList.AddItem("Show Log", "shows the log of goSDN", 'l', func() {
+	cv.commandsList.AddItem("log", "shows the log of goSDN", 'l', func() {
 		rv.ChangeContentView("log")
 	})
 
diff --git a/cmd/gosdn-tview/views/datbaseStatusView.go b/cmd/gosdn-tview/views/datbaseStatusView.go
index 6c217b416..3c8e3c366 100644
--- a/cmd/gosdn-tview/views/datbaseStatusView.go
+++ b/cmd/gosdn-tview/views/datbaseStatusView.go
@@ -3,7 +3,7 @@ package views
 import (
 	"code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/app"
 	"github.com/rivo/tview"
-	"time"
+	//"time"
 )
 
 //DatabaseStatusView is an application view to display the current status of
@@ -24,8 +24,9 @@ func NewDatabaseStatusView(app *app.App) *DatabaseStatusView {
 		SetBorder(true).
 		SetTitle("Database")
 
-	// run the periodical refresh in a new go routine
-	go databaseTicker(dv)
+	//TODO: dummy text at the moment. database status check has to be initilized
+	//here
+	dv.databaseStatusView.SetText("[green]" + "connected")
 
 	return dv
 }
@@ -40,11 +41,3 @@ func (dv *DatabaseStatusView) SetContent(s string) {
 	dv.databaseStatusView.Clear()
 	dv.databaseStatusView.SetText(s)
 }
-
-func databaseTicker(dv *DatabaseStatusView) {
-	//TODO see gRPCStatusView!
-	ticker := time.NewTicker(5 * time.Second)
-	for t := range ticker.C {
-		dv.SetContent(t.String())
-	}
-}
diff --git a/cmd/gosdn-tview/views/gRPCStatusView.go b/cmd/gosdn-tview/views/gRPCStatusView.go
index ef024aecc..f4f11555f 100644
--- a/cmd/gosdn-tview/views/gRPCStatusView.go
+++ b/cmd/gosdn-tview/views/gRPCStatusView.go
@@ -49,13 +49,18 @@ func (sv *GRPCStatusView) SetContent(s string) {
 }
 
 func gRPCTicker(sv *GRPCStatusView, conn *grpc.ClientConn) {
+	sv.SetContent(checkStatus(conn))
 	//TODO: refactor -> get rid of hardcoded values
 	ticker := time.NewTicker(5 * time.Second)
 	for range ticker.C {
-		if str := conn.GetState().String(); str == "READY" || str == "IDLE" {
-			sv.SetContent("[green]" + "connected")
-		} else {
-			sv.SetContent("[red]" + "disconnected")
-		}
+		sv.SetContent(checkStatus(conn))
+	}
+}
+
+func checkStatus(conn *grpc.ClientConn) string {
+	if str := conn.GetState().String(); str == "READY" || str == "IDLE" {
+		return "[green]" + "connected"
+	} else {
+		return "[red]" + "disconnected"
 	}
 }
-- 
GitLab