save
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
@page "/"
|
||||
@using System.Text.Json
|
||||
@using System.Text.Json.Serialization
|
||||
@using RobotApp.Client.Services
|
||||
@using RobotApp.VDA5050.InstantAction
|
||||
@using RobotApp.VDA5050.Order
|
||||
@using RobotApp.VDA5050.Type
|
||||
@@ -41,7 +42,7 @@
|
||||
<MudExpansionPanels MultiExpansion="true">
|
||||
@foreach (var node in Order.Nodes)
|
||||
{
|
||||
<MudExpansionPanel @key="node">
|
||||
<MudExpansionPanel @key="node.NodeId">
|
||||
|
||||
<!-- ===== HEADER ===== -->
|
||||
<TitleContent>
|
||||
@@ -226,51 +227,107 @@
|
||||
<!-- Cuộn nội bộ chỉ cho phần danh sách Edges -->
|
||||
<div class="flex-grow-1" style="overflow:auto;">
|
||||
<MudExpansionPanels MultiExpansion="true">
|
||||
|
||||
@foreach (var edge in Order.Edges)
|
||||
{
|
||||
<MudExpansionPanel Text="@($"{edge.EdgeId} ({edge.StartNodeId} → {edge.EndNodeId})")" @key="edge">
|
||||
<MudGrid Spacing="3">
|
||||
<MudItem xs="12"><MudTextField @bind-Value="edge.EdgeId" Label="Edge ID" /></MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudSelect T="string"
|
||||
Label="Start Node"
|
||||
Dense="true"
|
||||
Required="true"
|
||||
@bind-Value="edge.StartNodeId">
|
||||
@foreach (var node in Order.Nodes)
|
||||
{
|
||||
<MudSelectItem Value="@node.NodeId">
|
||||
@node.NodeId
|
||||
</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
<MudExpansionPanel Text="@($"{edge.EdgeId} ({edge.StartNodeId} → {edge.EndNodeId})")"
|
||||
@key="edge.EdgeId">
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudSelect T="string"
|
||||
Label="End Node"
|
||||
Dense="true"
|
||||
Required="true"
|
||||
@bind-Value="edge.EndNodeId">
|
||||
@foreach (var node in Order.Nodes)
|
||||
{
|
||||
<MudSelectItem Value="@node.NodeId"
|
||||
Disabled="@(node.NodeId == edge.StartNodeId)">
|
||||
@node.NodeId
|
||||
</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
<ChildContent>
|
||||
<MudGrid Spacing="3">
|
||||
|
||||
<!-- Edge ID -->
|
||||
<MudItem xs="12">
|
||||
<MudTextField @bind-Value="edge.EdgeId"
|
||||
Label="Edge ID" />
|
||||
</MudItem>
|
||||
|
||||
<!-- Start Node -->
|
||||
<MudItem xs="12">
|
||||
<MudSelect T="string"
|
||||
Label="Start Node"
|
||||
Dense="true"
|
||||
Required="true"
|
||||
@bind-Value="edge.StartNodeId">
|
||||
@foreach (var node in Order.Nodes)
|
||||
{
|
||||
<MudSelectItem Value="@node.NodeId">
|
||||
@node.NodeId
|
||||
</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<!-- End Node -->
|
||||
<MudItem xs="12">
|
||||
<MudSelect T="string"
|
||||
Label="End Node"
|
||||
Dense="true"
|
||||
Required="true"
|
||||
@bind-Value="edge.EndNodeId">
|
||||
@foreach (var node in Order.Nodes)
|
||||
{
|
||||
<MudSelectItem Value="@node.NodeId"
|
||||
Disabled="@(node.NodeId == edge.StartNodeId)">
|
||||
@node.NodeId
|
||||
</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<!-- Radius: =0 → đường thẳng -->
|
||||
<MudItem xs="6">
|
||||
<MudNumericField T="double"
|
||||
@bind-Value="edge.Radius"
|
||||
Label="Bán kính (0 = đường thẳng)"
|
||||
Min="0"
|
||||
Step="0.1" />
|
||||
</MudItem>
|
||||
|
||||
<!-- Quadrant chỉ hiện khi Radius > 0 -->
|
||||
@if (edge.Radius > 0)
|
||||
{
|
||||
<MudItem xs="6">
|
||||
<MudSelect T="Quadrant"
|
||||
@bind-Value="edge.Quadrant"
|
||||
Label="Góc phần tư">
|
||||
<MudSelectItem Value="Quadrant.I">Góc I</MudSelectItem>
|
||||
<MudSelectItem Value="Quadrant.II">Góc II</MudSelectItem>
|
||||
<MudSelectItem Value="Quadrant.III">Góc III</MudSelectItem>
|
||||
<MudSelectItem Value="Quadrant.IV">Góc IV</MudSelectItem>
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
}
|
||||
@if (edge.Radius > 0 && !edge.Expanded)
|
||||
{
|
||||
<MudItem xs="12">
|
||||
<MudButton Color="Color.Primary"
|
||||
Variant="Variant.Outlined"
|
||||
StartIcon="@Icons.Material.Filled.Merge"
|
||||
OnClick="@(() => ApplyCurve(edge))">
|
||||
Apply Curve (tạo node)
|
||||
</MudButton>
|
||||
</MudItem>
|
||||
}
|
||||
|
||||
<MudItem xs="12" Class="mt-4">
|
||||
<MudButton Color="Color.Error"
|
||||
Variant="Variant.Text"
|
||||
StartIcon="@Icons.Material.Filled.Delete"
|
||||
OnClick="@(() => RemoveEdge(edge))">
|
||||
Remove Edge
|
||||
</MudButton>
|
||||
</MudItem>
|
||||
|
||||
</MudGrid>
|
||||
</ChildContent>
|
||||
|
||||
<MudItem xs="12" Class="mt-4">
|
||||
<MudButton Color="Color.Error" Variant="Variant.Text" StartIcon="@Icons.Material.Filled.Delete"
|
||||
OnClick="@(() => RemoveEdge(edge))">Remove Edge</MudButton>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
</MudExpansionPanel>
|
||||
}
|
||||
|
||||
</MudExpansionPanels>
|
||||
</div>
|
||||
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
@@ -369,6 +426,25 @@
|
||||
bool IsEditNodeOpen;
|
||||
Node? EditingNode;
|
||||
OrderMessage Order = new();
|
||||
void ApplyCurve(UiEdge edge)
|
||||
{
|
||||
if (edge.Radius <= 0 || edge.Expanded)
|
||||
return;
|
||||
|
||||
var startNode = Order.Nodes.First(n => n.NodeId == edge.StartNodeId);
|
||||
|
||||
// 1️⃣ Sinh node C (điểm kết thúc cung tròn)
|
||||
var endNode = OrderMessage.CreateCurveNode(startNode, edge);
|
||||
Order.Nodes.Add(endNode);
|
||||
|
||||
// 2️⃣ Edge trở thành A → C (đường cong)
|
||||
edge.EndNodeId = endNode.NodeId;
|
||||
edge.Expanded = true;
|
||||
|
||||
// 3️⃣ Resequence node (đúng chuẩn VDA5050)
|
||||
for (int i = 0; i < Order.Nodes.Count; i++)
|
||||
Order.Nodes[i].SequenceId = i;
|
||||
}
|
||||
|
||||
async Task SendOrderToServer()
|
||||
{
|
||||
@@ -413,7 +489,7 @@
|
||||
NodeId = $"NODE_{Order.Nodes.Count + 1}",
|
||||
SequenceId = Order.Nodes.Count,
|
||||
Released = true,
|
||||
NodePosition = new NodePosition()
|
||||
NodePosition = new NodePosition { MapId = "MAP_01" }
|
||||
});
|
||||
}
|
||||
|
||||
@@ -469,7 +545,7 @@
|
||||
{
|
||||
if (Order.Nodes.Count < 2) return;
|
||||
|
||||
Order.Edges.Add(new VDA5050.Order.Edge
|
||||
Order.Edges.Add(new RobotApp.Client.Services.UiEdge
|
||||
{
|
||||
EdgeId = $"EDGE_{Order.Edges.Count + 1}",
|
||||
StartNodeId = Order.Nodes[^2].NodeId,
|
||||
@@ -507,7 +583,7 @@
|
||||
}
|
||||
|
||||
|
||||
void RemoveEdge(VDA5050.Order.Edge edge)
|
||||
void RemoveEdge(RobotApp.Client.Services.UiEdge edge)
|
||||
{
|
||||
Order.Edges.Remove(edge);
|
||||
}
|
||||
@@ -522,113 +598,6 @@
|
||||
});
|
||||
|
||||
|
||||
public class UiActionParameter : ActionParameter
|
||||
{
|
||||
[JsonIgnore]
|
||||
public string ValueString
|
||||
{
|
||||
get => Value?.ToString() ?? "";
|
||||
set => Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public class OrderMessage
|
||||
{
|
||||
public int HeaderId { get; set; }
|
||||
public string Timestamp { get; set; } = "";
|
||||
public string Version { get; set; } = "v1";
|
||||
public string Manufacturer { get; set; } = "PNKX";
|
||||
public string SerialNumber { get; set; } = "AMR-01";
|
||||
public string OrderId { get; set; } = Guid.NewGuid().ToString();
|
||||
public int OrderUpdateId { get; set; }
|
||||
public string? ZoneSetId { get; set; }
|
||||
public List<Node> Nodes { get; set; } = new();
|
||||
public List<VDA5050.Order.Edge> Edges { get; set; } = new();
|
||||
|
||||
public object ToSchemaObject()
|
||||
{
|
||||
int seq = 0;
|
||||
|
||||
return new
|
||||
{
|
||||
headerId = HeaderId++,
|
||||
|
||||
timestamp = string.IsNullOrWhiteSpace(Timestamp)
|
||||
? DateTime.UtcNow.ToString("O")
|
||||
: Timestamp,
|
||||
|
||||
version = Version,
|
||||
manufacturer = Manufacturer,
|
||||
serialNumber = SerialNumber,
|
||||
orderId = OrderId,
|
||||
orderUpdateId = OrderUpdateId,
|
||||
|
||||
zoneSetId = string.IsNullOrWhiteSpace(ZoneSetId)
|
||||
? null
|
||||
: ZoneSetId,
|
||||
|
||||
// ================= NODES =================
|
||||
nodes = Nodes
|
||||
.Select(n => new
|
||||
{
|
||||
nodeId = n.NodeId,
|
||||
sequenceId = seq++,
|
||||
released = n.Released,
|
||||
|
||||
nodePosition = new
|
||||
{
|
||||
x = n.NodePosition.X,
|
||||
y = n.NodePosition.Y,
|
||||
theta = n.NodePosition.Theta,
|
||||
|
||||
allowedDeviationXY = n.NodePosition.AllowedDeviationXY,
|
||||
allowedDeviationTheta = n.NodePosition.AllowedDeviationTheta,
|
||||
|
||||
mapId = string.IsNullOrWhiteSpace(n.NodePosition.MapId)
|
||||
? "MAP_01"
|
||||
: n.NodePosition.MapId
|
||||
},
|
||||
|
||||
actions = n.Actions
|
||||
.Select(a => new
|
||||
{
|
||||
actionId = a.ActionId,
|
||||
actionType = a.ActionType,
|
||||
blockingType = a.BlockingType,
|
||||
|
||||
actionParameters = a.ActionParameters != null
|
||||
? a.ActionParameters
|
||||
.Select(p => new
|
||||
{
|
||||
key = p.Key,
|
||||
value = p.Value
|
||||
})
|
||||
.ToArray()
|
||||
: Array.Empty<object>()
|
||||
})
|
||||
.ToArray()
|
||||
})
|
||||
.ToArray(), // ✅ QUAN TRỌNG
|
||||
|
||||
// ================= EDGES =================
|
||||
edges = Edges
|
||||
.Select(e => new
|
||||
{
|
||||
edgeId = e.EdgeId,
|
||||
sequenceId = seq++,
|
||||
released = true,
|
||||
|
||||
startNodeId = e.StartNodeId,
|
||||
endNodeId = e.EndNodeId,
|
||||
|
||||
actions = Array.Empty<object>()
|
||||
})
|
||||
.ToArray() // ✅ QUAN TRỌNG
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private async Task OpenEditNodeDialog(Node node)
|
||||
{
|
||||
var parameters = new DialogParameters<EditNodeDialog>
|
||||
@@ -649,4 +618,4 @@
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
@page "/robot-state"
|
||||
@using RobotApp.Client.Services
|
||||
@using RobotApp.VDA5050.State
|
||||
@rendermode InteractiveWebAssemblyNoPrerender
|
||||
|
||||
@inject StateMsg RobotState
|
||||
@inject RobotStateClient RobotStateClient
|
||||
@implements IDisposable
|
||||
@rendermode InteractiveWebAssembly
|
||||
|
||||
<MudContainer MaxWidth="MaxWidth.False" Class="pa-4">
|
||||
<!-- ===================================================== -->
|
||||
@@ -11,34 +12,46 @@
|
||||
<MudPaper Class="pa-6 mb-4 d-flex align-center justify-space-between" Elevation="3">
|
||||
<div>
|
||||
<MudText Typo="Typo.h4">🤖 VDA 5050 Robot Dashboard</MudText>
|
||||
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">
|
||||
@RobotState.Version •
|
||||
@RobotState.Manufacturer
|
||||
@RobotState.SerialNumber
|
||||
</MudText>
|
||||
@if (CurrentState != null)
|
||||
{
|
||||
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">
|
||||
@CurrentState.Version •
|
||||
@CurrentState.Manufacturer •
|
||||
@CurrentState.SerialNumber
|
||||
</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">
|
||||
Connecting to robot...
|
||||
</MudText>
|
||||
}
|
||||
</div>
|
||||
@* @if (RobotState.Current != null)
|
||||
|
||||
@if (CurrentState != null)
|
||||
{
|
||||
<MudChip T="string" Size="Size.Large"
|
||||
Color="@(RobotState.Current ? Color.Success : Color.Error)">
|
||||
@(RobotState.Current.IsOnline ? "ONLINE" : "OFFLINE")
|
||||
Color="@(IsConnected ? Color.Success : Color.Error)"
|
||||
Variant="Variant.Filled">
|
||||
@(IsConnected ? "ONLINE" : "OFFLINE")
|
||||
</MudChip>
|
||||
} *@
|
||||
}
|
||||
</MudPaper>
|
||||
|
||||
@if (RobotState == null)
|
||||
@if (CurrentState == null)
|
||||
{
|
||||
<MudAlert Severity="Severity.Info" Variant="Variant.Outlined">
|
||||
Waiting for robot state (VDA5050)...
|
||||
<MudAlert Severity="Severity.Info" Variant="Variant.Outlined" Class="mb-4">
|
||||
<MudAlertTitle>Waiting for robot state data...</MudAlertTitle>
|
||||
Connecting to SignalR hub and subscribing to robot updates.
|
||||
<MudProgressLinear Indeterminate Class="mt-3" />
|
||||
</MudAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
var msg = RobotState;
|
||||
var msg = CurrentState;
|
||||
|
||||
<!-- ===================================================== -->
|
||||
<!-- 📨 MESSAGE META (DEBUG / TRACE) -->
|
||||
<!-- MESSAGE META -->
|
||||
<!-- ===================================================== -->
|
||||
<MudPaper Class="pa-3 mb-4" Elevation="1">
|
||||
<MudGrid Spacing="2">
|
||||
@@ -56,9 +69,7 @@
|
||||
</MudItem>
|
||||
<MudItem xs="12" md="2">
|
||||
<MudText Typo="Typo.caption">OrderUpdateId</MudText>
|
||||
<MudChip T="string" Color="Color.Primary">
|
||||
@msg.OrderUpdateId
|
||||
</MudChip>
|
||||
<MudChip T="string" Color="Color.Primary">@msg.OrderUpdateId</MudChip>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
</MudPaper>
|
||||
@@ -104,7 +115,7 @@
|
||||
</MudItem>
|
||||
<MudItem xs="6" Class="d-flex justify-end">
|
||||
<MudText Typo="Typo.caption">
|
||||
DeviationRange: <b>@msg.AgvPosition.DeviationRange</b>
|
||||
Deviation: <b>@msg.AgvPosition.DeviationRange</b>
|
||||
</MudText>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
@@ -141,7 +152,7 @@
|
||||
<MudText><b>@msg.BatteryState.BatteryVoltage.ToString("F1")</b> V</MudText>
|
||||
</MudItem>
|
||||
<MudItem xs="4">
|
||||
<MudText Typo="Typo.caption">Health</MudText>
|
||||
<MudText Typo="Typo.caption">Health (SOH)</MudText>
|
||||
<MudText><b>@msg.BatteryState.BatteryHealth</b> %</MudText>
|
||||
</MudItem>
|
||||
<MudItem xs="4">
|
||||
@@ -164,16 +175,14 @@
|
||||
Last Node: <b>@msg.LastNodeId</b>
|
||||
<MudText Typo="Typo.caption" Inline="true">Seq: @msg.LastNodeSequenceId</MudText>
|
||||
</MudText>
|
||||
<MudText>Distance: @msg.DistanceSinceLastNode:F1 m</MudText>
|
||||
<MudText>Distance since last node: @msg.DistanceSinceLastNode:F1 m</MudText>
|
||||
<MudDivider Class="my-3" />
|
||||
|
||||
@{
|
||||
var nodeReleased = msg.NodeStates?.Count(n => n.Released) ?? 0;
|
||||
var nodeTotal = msg.NodeStates?.Length ?? 0;
|
||||
var edgeReleased = msg.EdgeStates?.Count(e => e.Released) ?? 0;
|
||||
var edgeTotal = msg.EdgeStates?.Length ?? 0;
|
||||
}
|
||||
|
||||
<div class="d-flex align-center flex-wrap gap-2">
|
||||
<MudChip T="string" Color="Color.Info">Nodes: @nodeReleased / @nodeTotal</MudChip>
|
||||
<MudChip T="string" Color="Color.Info">Edges: @edgeReleased / @edgeTotal</MudChip>
|
||||
@@ -190,175 +199,89 @@
|
||||
<!-- ERRORS + INFORMATION -->
|
||||
<MudItem xs="12" md="12" lg="6">
|
||||
<MudPaper Class="pa-5 h-100" Elevation="2">
|
||||
|
||||
<MudText Typo="Typo.h6">🚨 Errors & Information</MudText>
|
||||
<MudDivider Class="my-3" />
|
||||
|
||||
@{
|
||||
var rows = new List<MessageRow>();
|
||||
|
||||
if (msg.Errors != null)
|
||||
{
|
||||
foreach (var err in msg.Errors)
|
||||
{
|
||||
rows.Add(new MessageRow(
|
||||
err.ErrorType ?? "-",
|
||||
err.ErrorLevel ?? "-",
|
||||
err.ErrorDescription ?? "",
|
||||
true
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
if (msg.Information != null)
|
||||
{
|
||||
foreach (var info in msg.Information)
|
||||
{
|
||||
rows.Add(new MessageRow(
|
||||
info.InfoType ?? "-",
|
||||
info.InfoLevel ?? "-",
|
||||
info.InfoDescription ?? "",
|
||||
false
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
var sortedMessages = rows
|
||||
.OrderBy(r => r.IsError ? 0 : 1) // Errors trước
|
||||
.ThenBy(r => r.Type)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
<MudTable Items="@sortedMessages"
|
||||
<MudTable Items="@MessageRows"
|
||||
Dense="true"
|
||||
Hover="true"
|
||||
Bordered="true"
|
||||
Elevation="0"
|
||||
Height="180px"
|
||||
Breakpoint="Breakpoint.Sm"
|
||||
HorizontalScrollbar="true">
|
||||
|
||||
Height="200px"
|
||||
FixedHeader="true">
|
||||
<ColGroup>
|
||||
<col style="width: 35%" />
|
||||
<col style="width: 20%" />
|
||||
<col />
|
||||
</ColGroup>
|
||||
|
||||
<HeaderContent>
|
||||
<MudTh>Type</MudTh>
|
||||
<MudTh>Level</MudTh>
|
||||
<MudTh>Description</MudTh>
|
||||
</HeaderContent>
|
||||
|
||||
<RowTemplate>
|
||||
<MudTd DataLabel="Type">
|
||||
<MudTd>
|
||||
<MudText Class="@(context.IsError ? "text-error" : "text-info")">
|
||||
<b>@context.Type</b>
|
||||
</MudText>
|
||||
</MudTd>
|
||||
|
||||
<MudTd DataLabel="Level">
|
||||
<MudChip T="string"
|
||||
Size="Size.Small"
|
||||
Color="@(context.Level == "ERROR"
|
||||
? Color.Error
|
||||
: context.Level == "WARNING"
|
||||
? Color.Warning
|
||||
: Color.Info)">
|
||||
@context.Level
|
||||
</MudChip>
|
||||
</MudTd>
|
||||
|
||||
<MudTd DataLabel="Description">
|
||||
<MudText Typo="Typo.caption"
|
||||
Class="text-truncate"
|
||||
Title="@context.Description">
|
||||
<MudTd>
|
||||
<MudChip T="string" Size="Size.Small"
|
||||
Color="@(context.Level.Contains("ERROR", StringComparison.OrdinalIgnoreCase) ? Color.Error :
|
||||
context.Level.Contains("WARN", StringComparison.OrdinalIgnoreCase) ? Color.Warning :
|
||||
Color.Info)">
|
||||
@context.Level
|
||||
</MudChip>
|
||||
</MudTd>
|
||||
<MudTd>
|
||||
<MudText Typo="Typo.caption" Class="text-truncate" Title="@context.Description">
|
||||
@context.Description
|
||||
</MudText>
|
||||
</MudTd>
|
||||
</RowTemplate>
|
||||
|
||||
<NoRecordsContent>
|
||||
<MudText Typo="Typo.caption"
|
||||
Color="Color.Secondary"
|
||||
Class="pa-4 text-center">
|
||||
<MudText Typo="Typo.caption" Color="Color.Secondary" Class="pa-4 text-center">
|
||||
No errors or information messages
|
||||
</MudText>
|
||||
</NoRecordsContent>
|
||||
|
||||
</MudTable>
|
||||
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
|
||||
|
||||
<!-- ACTIONS -->
|
||||
<MudItem xs="12" md="6" lg="3">
|
||||
<MudPaper Class="pa-5 h-100" Elevation="2">
|
||||
|
||||
<MudText Typo="Typo.h6">⚙️ Actions</MudText>
|
||||
<MudDivider Class="my-3" />
|
||||
|
||||
<MudTable Items="msg.ActionStates"
|
||||
Dense="true"
|
||||
Dense="true"
|
||||
Hover="true"
|
||||
Bordered="true"
|
||||
Elevation="0"
|
||||
Height="160px"
|
||||
Breakpoint="Breakpoint.Sm"
|
||||
HorizontalScrollbar="true"
|
||||
Height="180px"
|
||||
FixedHeader="true">
|
||||
|
||||
<ColGroup>
|
||||
<col style="width: 40%" />
|
||||
<col style="width: 35%" />
|
||||
<col style="width: 25%" />
|
||||
</ColGroup>
|
||||
|
||||
<HeaderContent>
|
||||
<MudTh>Action</MudTh>
|
||||
<MudTh>Action ID</MudTh>
|
||||
<MudTh class="text-right">Status</MudTh>
|
||||
</HeaderContent>
|
||||
|
||||
<RowTemplate>
|
||||
<MudTd DataLabel="Action">
|
||||
<MudText Typo="Typo.body2"
|
||||
Class="text-truncate"
|
||||
Title="@context.ActionType">
|
||||
@context.ActionType
|
||||
</MudText>
|
||||
<MudTd><MudText Typo="Typo.body2" Class="text-truncate" Title="@context.ActionType">@context.ActionType</MudText></MudTd>
|
||||
<MudTd><MudText Typo="Typo.caption">@context.ActionId</MudText></MudTd>
|
||||
<MudTd Class="text-right">
|
||||
<MudChip T="string" Size="Size.Small"
|
||||
Color="@(context.ActionStatus == "RUNNING" ? Color.Info :
|
||||
context.ActionStatus == "FINISHED" ? Color.Success :
|
||||
context.ActionStatus == "FAILED" ? Color.Error : Color.Default)">
|
||||
@context.ActionStatus
|
||||
</MudChip>
|
||||
</MudTd>
|
||||
|
||||
<MudTd DataLabel="Action ID">
|
||||
<MudText Typo="Typo.caption">
|
||||
@context.ActionId
|
||||
</MudText>
|
||||
</MudTd>
|
||||
|
||||
<MudTd DataLabel="Status" Class="text-right">
|
||||
<MudChip T="string"
|
||||
Size="Size.Small"
|
||||
Variant="Variant.Filled"
|
||||
Color="@(context.ActionStatus == "RUNNING"
|
||||
? Color.Info
|
||||
: context.ActionStatus == "FINISHED"
|
||||
? Color.Success
|
||||
: Color.Error)">
|
||||
@context.ActionStatus
|
||||
</MudChip>
|
||||
</MudTd>
|
||||
</RowTemplate>
|
||||
|
||||
</RowTemplate>
|
||||
<NoRecordsContent>
|
||||
<MudText Typo="Typo.caption"
|
||||
Color="Color.Secondary"
|
||||
Class="pa-4 text-center">
|
||||
<MudText Typo="Typo.caption" Color="Color.Secondary" Class="pa-4 text-center">
|
||||
No active actions
|
||||
</MudText>
|
||||
</NoRecordsContent>
|
||||
|
||||
</MudTable>
|
||||
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
|
||||
@@ -377,21 +300,75 @@
|
||||
</MudChip>
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
|
||||
</MudGrid>
|
||||
}
|
||||
</MudContainer>
|
||||
|
||||
@code {
|
||||
private StateMsg? CurrentState;
|
||||
private bool IsConnected => RobotStateClient.LatestStates.ContainsKey(RobotSerial);
|
||||
|
||||
private async Task OnStateChanged()
|
||||
=> await InvokeAsync(StateHasChanged);
|
||||
// Thay bằng serial number thật của robot bạn muốn theo dõi
|
||||
private readonly string RobotSerial = "T800-002";
|
||||
|
||||
private List<MessageRow> MessageRows = new();
|
||||
|
||||
private record MessageRow(
|
||||
string Type,
|
||||
string Level,
|
||||
string Description,
|
||||
bool IsError
|
||||
);
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
// Subscribe sự kiện nhận state
|
||||
RobotStateClient.OnStateReceived += OnRobotStateReceived;
|
||||
|
||||
// Bắt đầu kết nối SignalR (nếu chưa)
|
||||
if (RobotStateClient.LatestStates.Count == 0)
|
||||
{
|
||||
await RobotStateClient.StartAsync();
|
||||
}
|
||||
|
||||
// Đăng ký theo dõi robot cụ thể
|
||||
await RobotStateClient.SubscribeRobotAsync(RobotSerial);
|
||||
|
||||
// Lấy state hiện tại nếu đã có
|
||||
CurrentState = RobotStateClient.GetLatestState(RobotSerial);
|
||||
UpdateMessageRows();
|
||||
}
|
||||
|
||||
private void OnRobotStateReceived(string serialNumber, StateMsg state)
|
||||
{
|
||||
if (serialNumber != RobotSerial) return;
|
||||
|
||||
InvokeAsync(() =>
|
||||
{
|
||||
CurrentState = state;
|
||||
UpdateMessageRows();
|
||||
StateHasChanged();
|
||||
});
|
||||
}
|
||||
|
||||
private void UpdateMessageRows()
|
||||
{
|
||||
MessageRows.Clear();
|
||||
|
||||
if (CurrentState?.Errors != null)
|
||||
{
|
||||
foreach (var err in CurrentState.Errors)
|
||||
{
|
||||
MessageRows.Add(new MessageRow(err.ErrorType ?? "-", err.ErrorLevel ?? "ERROR", err.ErrorDescription ?? "", true));
|
||||
}
|
||||
}
|
||||
|
||||
if (CurrentState?.Information != null)
|
||||
{
|
||||
foreach (var info in CurrentState.Information)
|
||||
{
|
||||
MessageRows.Add(new MessageRow(info.InfoType ?? "-", info.InfoLevel ?? "INFO", info.InfoDescription ?? "", false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
RobotStateClient.OnStateReceived -= OnRobotStateReceived;
|
||||
}
|
||||
|
||||
private record MessageRow(string Type, string Level, string Description, bool IsError);
|
||||
}
|
||||
Reference in New Issue
Block a user