@using RobotNet10.RobotApp.Client.Shared.Devices @using Microsoft.AspNetCore.Components @using MudBlazor @* Compact Header *@
@Device.DeviceName @Device.DeviceId
@Device.Status.ToString()
@* Compact Info Grid - 2 columns *@ @* Device Type *@ Type: @Device.DeviceType @* Connection Status *@ Status: @(Device.IsConnected ? "Yes" : "No") @* Last Update - Compact format *@ Updated: @Device.LastUpdateTime.ToString("MM-dd HH:mm:ss") @* Reconnect Attempts - Only show if > 0 *@ @if (Device.ReconnectAttemptCount > 0) { Retries: @Device.ReconnectAttemptCount } @* Error Message - Compact *@ @if (!string.IsNullOrWhiteSpace(Device.LastError)) { @Device.LastError } @* Properties - Collapsed by default, only show count *@ @if (Device.Properties.Any()) { Property Value @foreach (var prop in GetDisplayedProperties().Take(5)) { @prop.DisplayName @if (Device.Properties.TryGetValue(prop.Key, out var value)) { @FormatPropertyValue(value, prop) } } @if (Device.Properties.Count > 5) { ... and @(Device.Properties.Count - 5) more } }
@code { [Parameter, EditorRequired] public DeviceDto Device { get; set; } = null!; [Inject] private NavigationManager NavigationManager { get; set; } = null!; private void NavigateToDeviceManagement() { var deviceType = GetDeviceTypeRoute(Device.DeviceType); var deviceId = Uri.EscapeDataString(Device.DeviceId); NavigationManager.NavigateTo($"/devices/{deviceType}/{deviceId}"); } private string GetDeviceTypeRoute(DeviceType deviceType) { return deviceType switch { DeviceType.Lidar => "lidar", DeviceType.Imu => "imu", DeviceType.Battery => "battery", DeviceType.ModbusTcp => "modbustcp", DeviceType.RfHandle => "rfhandle", DeviceType.CameraQr => "cameraqr", DeviceType.CiA402Servo => "cia402servo", _ => deviceType.ToString().ToLowerInvariant() }; } private string GetDeviceIcon() { return Device.DeviceType switch { DeviceType.Lidar => Icons.Material.Filled.Radar, DeviceType.Imu => Icons.Material.Filled.Explore, DeviceType.Battery => Icons.Material.Filled.BatteryFull, DeviceType.ModbusTcp => Icons.Material.Filled.Lan, DeviceType.RfHandle => Icons.Material.Filled.RadioButtonChecked, DeviceType.CameraQr => Icons.Material.Filled.QrCodeScanner, DeviceType.CiA402Servo => Icons.Material.Filled.Settings, _ => Icons.Material.Filled.Devices }; } private Color GetStatusColor() { return Device.Status switch { DeviceStatus.Connected => Color.Success, DeviceStatus.Connecting => Color.Info, DeviceStatus.Disconnecting => Color.Warning, DeviceStatus.Disconnected => Color.Default, DeviceStatus.Reconnecting => Color.Warning, DeviceStatus.Error => Color.Error, DeviceStatus.Initializing => Color.Info, _ => Color.Default }; } private IEnumerable GetDisplayedProperties() { return Device.PropertyDescriptions .OrderBy(p => p.DisplayOrder) .ThenBy(p => p.Category ?? "") .ThenBy(p => p.DisplayName); } private string FormatPropertyValue(string value, PropertyDescription prop) { if (string.IsNullOrWhiteSpace(value)) return "-"; if (prop.DataType == "number" && double.TryParse(value, out var numValue)) { if (!string.IsNullOrWhiteSpace(prop.Format)) { try { return string.Format(prop.Format, numValue) + (prop.Unit != null ? $" {prop.Unit}" : ""); } catch { return value + (prop.Unit != null ? $" {prop.Unit}" : ""); } } return value + (prop.Unit != null ? $" {prop.Unit}" : ""); } return value + (prop.Unit != null ? $" {prop.Unit}" : ""); } }