fixed some little UI bugs
- We could open the CDashDisplay specific layout before it existed - Crash! - We could open the stream UI before there was a provider- Crash!
This commit is contained in:
@@ -71,6 +71,14 @@ func (ds *DeviceService) GetDevice(name string) (devices.Device, error) {
|
||||
return val, nil
|
||||
}
|
||||
|
||||
func (ds *DeviceService) DeviceExists(name string) bool {
|
||||
if _, ok := ds.Devices[name]; !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (ds *DeviceService) StartStream() {
|
||||
// NOTE: i'm using this pattern a whole lot. Maybe I can create a struct to handle this
|
||||
var ctx context.Context
|
||||
|
||||
@@ -230,3 +230,11 @@ func (t *TelemetryService) StopStream() {
|
||||
|
||||
t.activeProvider.StopStream()
|
||||
}
|
||||
|
||||
func (t *TelemetryService) HasActiveProvider() bool {
|
||||
if t.activeProvider == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ package controllers
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"esdi/devices/cdashdisplay"
|
||||
serv "esdi/services"
|
||||
"esdi/tui/internal/views"
|
||||
|
||||
@@ -65,6 +66,12 @@ func (mc *DeviceController) setDeviceAPIViewEvents() {
|
||||
func (mc *DeviceController) AddDeviceAPIListItems() {
|
||||
mc.DeviceAPIView.DevAPIList.
|
||||
AddItem("layout", "build a layout for CDashDisplay", func() {
|
||||
// This CDashDisplay specific, only load if we have a CDashDisplay
|
||||
if !mc.DevService.DeviceExists(cdashdisplay.Name) {
|
||||
mc.DevService.Messages <- "CDashDisplay it not loaded yet\n"
|
||||
return
|
||||
}
|
||||
|
||||
// Get the api pages
|
||||
views.AddAndShowPage(
|
||||
mc.DeviceAPIView.DevAPIToolView.Pages,
|
||||
@@ -75,6 +82,12 @@ func (mc *DeviceController) AddDeviceAPIListItems() {
|
||||
})
|
||||
mc.DeviceAPIView.DevAPIList.
|
||||
AddItem("stream", "stream data to the display", func() {
|
||||
// If we don't have a CDashDisplay or data source, this should be blocked
|
||||
if !mc.StreamCtrl.TelemServ.HasActiveProvider() {
|
||||
mc.StreamCtrl.Messages <- "no active provider present\n"
|
||||
return
|
||||
}
|
||||
|
||||
views.AddAndShowPage(
|
||||
mc.DeviceAPIView.DevAPIToolView.Pages,
|
||||
"streaming-tool",
|
||||
|
||||
Reference in New Issue
Block a user