first commit -push

This commit is contained in:
dungtt
2025-10-15 15:15:53 +07:00
parent 674ae395be
commit a9577c5756
885 changed files with 74595 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
@inject IJSRuntime JSRuntime
@implements IDisposable
<path @ref="Ref" />
@code {
[Parameter, EditorRequired]
public EdgeModel Model { get; set; } = null!;
[Parameter]
public EventCallback<EdgeModel> DoubleClick { get; set; }
[CascadingParameter]
protected bool MapIsActive { get; set; }
private ElementReference Ref;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (!firstRender) return;
await UpdatePathData();
}
private async Task UpdatePathData()
{
var data = $"M {Model.X1} {Model.Y1}";
if (Model.TrajectoryDegree == TrajectoryDegree.One)
{
data = $"{data} L {(Model.X1 + Model.X2) / 2} {(Model.Y1 + Model.Y2) / 2} L {Model.X2} {Model.Y2}";
}
else if (Model.TrajectoryDegree == TrajectoryDegree.Two)
{
data = $"{data} Q {Model.ControlPoint1X} {Model.ControlPoint1Y} {Model.X2} {Model.Y2}";
}
else if (Model.TrajectoryDegree == TrajectoryDegree.Three)
{
data = $"{data} C {Model.ControlPoint1X} {Model.ControlPoint1Y}, {Model.ControlPoint2X} {Model.ControlPoint2Y}, {Model.X2} {Model.Y2}";
}
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", Ref, "d", data);
}
public void Dispose()
{
GC.SuppressFinalize(this);
}
}

View File

@@ -0,0 +1,38 @@
using RobotNet.MapShares.Dtos;
using RobotNet.MapShares.Enums;
namespace RobotNet.WebApp.Robots.Components.Monitoring.Element;
public class EdgeModel(EdgeDto data, NodeModel startNode, NodeModel endNode) : IDisposable
{
public Guid Id => Data.Id;
public Guid MapId => Data.MapId;
public double X1 => StartNode.X;
public double Y1 => StartNode.Y;
public double X2 => EndNode.X;
public double Y2 => EndNode.Y;
public DirectionAllowed DirectionAllowed => Data.DirectionAllowed;
public TrajectoryDegree TrajectoryDegree => Data.TrajectoryDegree;
public double ControlPoint1X => Data.ControlPoint1X;
public double ControlPoint1Y => Data.ControlPoint1Y;
public double ControlPoint2X => Data.ControlPoint2X;
public double ControlPoint2Y => Data.ControlPoint2Y;
public double MaxSpeed => Data.MaxSpeed;
public double MaxHeight => Data.MaxHeight;
public double MinHeight => Data.MinHeight;
public bool RotationAllowed => Data.RotationAllowed;
public double MaxRotationSpeed => Data.MaxRotationSpeed;
public string Actions => Data.Actions;
public double AllowedDeviationXy => Data.AllowedDeviationXy;
public double AllowedDeviationTheta => Data.AllowedDeviationTheta;
public NodeModel StartNode { get; private set; } = startNode;
public NodeModel EndNode { get; private set; } = endNode;
private readonly EdgeDto Data = data;
public void Dispose()
{
GC.SuppressFinalize(this);
}
}

View File

@@ -0,0 +1,24 @@
path {
cursor: default;
stroke: #22B3FF;
stroke-width: var(--edge-stroke-width);
fill: none;
}
path.setting:hover {
stroke: #1E9DDF;
cursor: pointer;
}
path.setting:active {
stroke: #227CFF;
}
path.setting.active:hover {
stroke: #227CFF;
}
path.active {
stroke: #227CFF;
}

View File

@@ -0,0 +1,69 @@
@implements IDisposable
@inject IJSRuntime JSRuntime
<polyline @ref="Ref" />
@code {
[Parameter, EditorRequired]
public EdgeModel Model { get; set; } = null!;
private ElementReference Ref;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (!firstRender) return;
await UpdatePathData();
await UpdateMaker();
}
private async Task UpdatePathData()
{
string data = string.Empty;
double sx = 0, sy = 0, mx = 0, my = 0, ex = 0, ey = 0;
double sTime = 0.49, eTime = 0.5;
if (Model.TrajectoryDegree == TrajectoryDegree.One)
{
sx = Model.X1;
sy = Model.Y1;
ex = Model.X2;
ey = Model.Y2;
}
else if (Model.TrajectoryDegree == TrajectoryDegree.Two)
{
sx = (Model.X1 + Model.ControlPoint1X) / 2;
sy = (Model.Y1 + Model.ControlPoint1Y) / 2;
ex = (Model.X2 + Model.ControlPoint1X) / 2;
ey = (Model.Y2 + Model.ControlPoint1Y) / 2;
}
else if (Model.TrajectoryDegree == TrajectoryDegree.Three)
{
sx = Math.Pow(1 - sTime, 3) * Model.X1 + 3 * Math.Pow(1 - sTime, 2) * sTime * Model.ControlPoint1X + 3 * Math.Pow(sTime, 2) * (1 - sTime) * Model.ControlPoint2X + Math.Pow(sTime, 3) * Model.X2;
sy = Math.Pow(1 - sTime, 3) * Model.Y1 + 3 * Math.Pow(1 - sTime, 2) * sTime * Model.ControlPoint1Y + 3 * Math.Pow(sTime, 2) * (1 - sTime) * Model.ControlPoint2Y + Math.Pow(sTime, 3) * Model.Y2;
ex = Math.Pow(1 - eTime, 3) * Model.X1 + 3 * Math.Pow(1 - eTime, 2) * eTime * Model.ControlPoint1X + 3 * Math.Pow(eTime, 2) * (1 - eTime) * Model.ControlPoint2X + Math.Pow(eTime, 3) * Model.X2;
ey = Math.Pow(1 - eTime, 3) * Model.Y1 + 3 * Math.Pow(1 - eTime, 2) * eTime * Model.ControlPoint1Y + 3 * Math.Pow(eTime, 2) * (1 - eTime) * Model.ControlPoint2Y + Math.Pow(eTime, 3) * Model.Y2;
}
mx = (sx + ex) / 2;
my = (sy + ey) / 2;
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", Ref, "points", $"{sx},{sy} {mx},{my} {ex},{ey}");
}
private async Task UpdateMaker()
{
if (Model == null) return;
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", Ref, "marker-mid", MapSvgDefs.GetMakerMid(Model.DirectionAllowed));
}
public void Dispose()
{
GC.SuppressFinalize(this);
}
}

View File

@@ -0,0 +1,5 @@
polyline {
stroke-width: var(--edge-direction-stroke-width);
stroke: none;
fill: none;
}

View File

@@ -0,0 +1,95 @@
@implements IDisposable
@inject IHttpClientFactory HttpFactory
@inject IJSRuntime JSRuntime
<g class="element" visibility="@(Show ? "visible" : "hidden")" @ondblclick="@(async () => await DoubleClick.InvokeAsync(Model))">
<image @ref="@ImageRef" />
<text @ref="textRef" visibility="@(Show && ShowName ? "visible" : "hidden")">@Model?.Name</text>
</g>
@code {
[Parameter]
public bool Show { get; set; }
[Parameter]
public bool ShowName { get; set; }
[Parameter, EditorRequired]
public ElementModel Model { get; set; } = null!;
[Parameter]
public EventCallback<ElementModel> DoubleClick { get; set; }
private ElementReference ImageRef;
private ElementReference textRef;
private ElementModelDto ElementModel = new();
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (!firstRender) return;
using var Http = HttpFactory.CreateClient("MapManagerAPI");
var model = await Http.GetFromJsonAsync<MessageResult<ElementModelDto?>>($"api/ElementModels/{Model.ModelId}");
if (model is not null && model.Data is not null)
{
await JSRuntime.InvokeVoidAsync("SetImageAttribute", ImageRef, model.Data.Width, model.Data.Height, -model.Data.Width / 2, -model.Data.Height / 2, $"{Http.BaseAddress}api/images/elementModel/{model.Data.Id}?IsOpen={Model.IsOpen}");
ElementModel = model.Data;
}
if (Model is not null)
{
Model.UpdateChanged += Model_UpdateChanged;
await UpdatePosition(Model.X, Model.Y, Model.Theta);
}
}
private async Task Model_UpdateChanged()
{
await SetElementImage(Model.IsOpen);
await UpdatePosition(Model.OffsetX, Model.OffsetY);
}
public override async Task SetParametersAsync(ParameterView parameters)
{
bool updateRobot = false;
if (parameters.TryGetValue(nameof(Model), out ElementModel? model) && ((Model?.Id ?? Guid.Empty) != (model?.Id ?? Guid.Empty)))
{
if (Model != null) Model.UpdateChanged -= Model_UpdateChanged;
if (model != null)
{
updateRobot = true;
model.UpdateChanged -= Model_UpdateChanged;
}
}
await base.SetParametersAsync(parameters);
if (updateRobot && model != null)
{
await SetElementImage(model.IsOpen);
await UpdatePosition(model.X, model.Y, model.Theta);
}
}
private async Task SetElementImage(bool isOpen)
{
if (ElementModel.Id != Guid.Empty)
{
using var Http = HttpFactory.CreateClient("MapManagerAPI");
await JSRuntime.InvokeVoidAsync("SetImageAttribute", ImageRef, ElementModel.Width, ElementModel.Height, (-ElementModel.Width / 2), (-ElementModel.Height / 2), $"{Http.BaseAddress}api/images/elementModel/{ElementModel.Id}?IsOpen={isOpen}");
}
}
public async Task UpdatePosition(double x, double y, double theta)
=> await JSRuntime.InvokeVoidAsync("SetRobotPosition", ImageRef, textRef, x + Model.OffsetX, y + Model.OffsetY, theta, -ElementModel.Width / 2, -ElementModel.Height / 2);
public async Task UpdatePosition(double offsetX, double offsetY)
=> await JSRuntime.InvokeVoidAsync("SetRobotPosition", ImageRef, textRef, Model.X + offsetX, Model.Y + offsetY, Model.Theta, -ElementModel.Width / 2, -ElementModel.Height / 2);
public void Dispose()
{
if (Model != null) Model.UpdateChanged -= Model_UpdateChanged;
GC.SuppressFinalize(this);
}
}

View File

@@ -0,0 +1,38 @@
using RobotNet.MapShares.Dtos;
namespace RobotNet.WebApp.Robots.Components.Monitoring.Element;
public class ElementModel(ElementDto element, NodeModel node) : IDisposable
{
public Guid Id => Element.Id;
public Guid ModelId => Element.ModelId;
public Guid NodeId => Element.NodeId;
public Guid MapId => Element.MapId;
public string Name => Element.Name;
public double X => Node.X;
public double Y => Node.Y;
public double Theta => Node.Theta;
public double OffsetX => Element.OffsetX;
public double OffsetY => Element.OffsetY;
public bool IsOpen => Element.IsOpen;
public string Content => Element.Content;
public ElementDto Element { get; private set; } = element;
public NodeModel Node { get; private set; } = node;
public event Func<Task>? UpdateChanged;
public void Update(ElementDto element)
{
Element.IsOpen = element.IsOpen;
Element.OffsetX = element.OffsetX;
Element.OffsetY = element.OffsetY;
Element.Content = element.Content;
UpdateChanged?.Invoke();
}
public void Dispose()
{
GC.SuppressFinalize(this);
}
}

View File

@@ -0,0 +1,21 @@
text {
dominant-baseline: middle;
text-anchor: middle;
fill: red;
transform: scale(1, -1);
font-size: 0.01em;
user-select: none;
font-weight: normal;
}
.element {
transform-origin: center;
transform-box: fill-box;
}
.element:hover {
cursor: pointer;
transform: scale(1.2);
filter: drop-shadow(0 0 5px rgba(0, 0, 0, 0.5));
transition: all 0.2s ease;
}

View File

@@ -0,0 +1,47 @@
@using Microsoft.JSInterop
@implements IDisposable
@inject IJSRuntime JSRuntime
<circle @ref="circleErrorRef" style="fill: red; opacity: 0.6; r: 0.3px;"/>
<circle @ref="circleRef"/>
<text @ref="textRef" visibility="@(ShowName ? "visible" : "hidden")">@Model?.Name</text>
@code {
[Parameter, EditorRequired]
public NodeModel Model { get; set; } = null!;
[Parameter]
public EventCallback<NodeModel> DoubleClick { get; set; }
[Parameter]
public EventCallback<NodeModel?> OnClick { get; set; }
[CascadingParameter]
protected bool MapIsActive { get; set; }
[Parameter]
public bool ShowName { get; set; }
private ElementReference circleRef;
private ElementReference textRef;
private ElementReference circleErrorRef;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (!firstRender) return;
await UpdatePosition(Model.X, Model.Y);
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", circleErrorRef, "visibility", "hidden");
}
private async Task UpdatePosition(double x, double y)
{
await JSRuntime.InvokeVoidAsync("SetNodePosition", circleRef, textRef, x, y);
}
public void Dispose()
{
GC.SuppressFinalize(this);
}
}

View File

@@ -0,0 +1,21 @@
using RobotNet.MapShares.Dtos;
namespace RobotNet.WebApp.Robots.Components.Monitoring.Element;
public class NodeModel(NodeDto Data) : IDisposable
{
public Guid Id => Data.Id;
public Guid MapId => Data.MapId;
public string Name => Data.Name;
public double X => Data.X;
public double Y => Data.Y;
public double Theta => Data.Theta;
public string Actions => Data.Actions;
public double AllowedDeviationXy => Data.AllowedDeviationXy;
public double AllowedDeviationTheta => Data.AllowedDeviationTheta;
public void Dispose()
{
GC.SuppressFinalize(this);
}
}

View File

@@ -0,0 +1,41 @@
circle {
cursor: default;
fill: #FFBD33;
stroke: #FF5733;
stroke-width: 0;
r: var(--node-r);
}
circle.setting:hover {
stroke-width: 0.02px;
cursor: pointer;
}
circle.setting:active {
stroke-width: 0.02px;
stroke: green;
}
circle.active {
stroke-width: 0.02px;
stroke: green;
}
circle:hover + text.setting {
transition-delay: 0.1s;
font-weight: bold;
}
circle + text {
transition-delay: 0.3s;
font-size: 0.01em;
font-weight: normal;
}
text {
dominant-baseline: middle;
text-anchor: middle;
fill: red;
transform: scale(1, -1);
user-select: none;
}

View File

@@ -0,0 +1,111 @@
@implements IDisposable
@inject IJSRuntime JSRuntime
@inject IHttpClientFactory HttpFactory
<image @ref="@RobotRef" />
<image @ref="@ElementRef" visibility="@(isCarrying ? "visible" : "hidden")" />
<text @ref="textRef" visibility="@(ShowName ? "visible" : "hidden")">@Model?.RobotName</text>
@code {
[Parameter, EditorRequired]
public RobotVisualizationModel Model { get; set; } = null!;
[Parameter]
public bool ShowName { get; set; }
private ElementReference ElementRef;
private ElementReference RobotRef;
private ElementReference textRef;
private RobotModelDto RobotModel = new();
private bool isCarrying = false;
private ElementModelDto ElementModel = new();
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (!firstRender) return;
using var Http = HttpFactory.CreateClient("RobotManagerAPI");
var model = await Http.GetFromJsonAsync<MessageResult<RobotModelDto?>>($"api/Robots/Model/{Model.RobotId}");
if (model is not null && model.Data is not null)
{
await JSRuntime.InvokeVoidAsync("SetImageAttribute", RobotRef, model.Data.Length, model.Data.Width, model.Data.OriginX, model.Data.OriginY, $"{Http.BaseAddress}api/RobotModels/image/{model.Data.Id}");
RobotModel = model.Data;
}
if (Model is not null)
{
Model.PositionChanged += Model_PositionChanged;
Model.LoadsChanged += Model_LoadChanged;
await UpdatePosition(Model.X, Model.Y, Model.Theta);
if(Model.Loads.Length > 0 && Guid.TryParse(Model.Loads[0].LoadId, out Guid loadId))
{
await Model_LoadChanged(loadId);
await UpdateLoadPosition(Model.X, Model.Y, Model.Theta);
}
}
}
public override async Task SetParametersAsync(ParameterView parameters)
{
bool updateRobot = false;
if (parameters.TryGetValue(nameof(Model), out RobotVisualizationModel? model) && ((Model?.RobotId ?? string.Empty) != (model?.RobotId ?? string.Empty)))
{
if (Model != null)
{
Model.PositionChanged -= Model_PositionChanged;
Model.LoadsChanged -= Model_LoadChanged;
}
if (model != null)
{
updateRobot = true;
model.PositionChanged += Model_PositionChanged;
model.LoadsChanged += Model_LoadChanged;
}
}
await base.SetParametersAsync(parameters);
if (updateRobot && model != null)
{
await UpdatePosition(model.X, model.Y, model.Theta);
if (model.Loads.Length > 0) await UpdateLoadPosition(model.X, model.Y, model.Theta);
}
}
private async Task Model_PositionChanged()
{
await UpdatePosition(Model.X, Model.Y, Model.Theta);
await UpdateLoadPosition(Model.X, Model.Y, Model.Theta);
}
public async Task UpdatePosition(double x, double y, double theta)
=> await JSRuntime.InvokeVoidAsync("SetRobotPosition", RobotRef, textRef, x, y, theta, RobotModel.OriginX, RobotModel.OriginY);
private async Task UpdateLoadPosition(double x, double y, double theta)
=> await JSRuntime.InvokeVoidAsync("SetRobotPosition", ElementRef, null, x, y, theta, -ElementModel.Width / 2, -ElementModel.Height / 2);
private async Task Model_LoadChanged(Guid elementModelId)
{
if (elementModelId != Guid.Empty)
{
using var Http = HttpFactory.CreateClient("MapManagerAPI");
var model = await Http.GetFromJsonAsync<MessageResult<ElementModelDto?>>($"api/ElementModels/{elementModelId}");
if (model is not null && model.Data is not null)
{
isCarrying = true;;
await JSRuntime.InvokeVoidAsync("SetImageAttribute", ElementRef, model.Data.Width, model.Data.Height, -model.Data.Width / 2, -model.Data.Height / 2, $"{Http.BaseAddress}api/images/elementModel/{model.Data.Id}?IsOpen=true");
await UpdateLoadPosition(Model.X, Model.Y, Model.Theta);
ElementModel = model.Data;
}
}
else isCarrying = false;
StateHasChanged();
}
public void Dispose()
{
if (Model != null) Model.PositionChanged -= Model_PositionChanged;
GC.SuppressFinalize(this);
}
}

View File

@@ -0,0 +1,43 @@
using RobotNet.RobotShares.VDA5050.State;
namespace RobotNet.WebApp.Robots.Components.Monitoring.Element;
#nullable disable
public class RobotVisualizationModel : IDisposable
{
public string RobotId { get; set; }
public string RobotName { get; set; }
public double X { get; set; }
public double Y { get; set; }
public double Theta { get; set; }
public Load[] Loads { get; set; } = [];
public event Func<Task> PositionChanged;
public event Func<Guid, Task> LoadsChanged;
public void Update(double x, double y, double theta, Load[] loads)
{
if (X != x || Y != y || Theta != theta)
{
X = x;
Y = y;
Theta = theta;
PositionChanged?.Invoke();
}
if (loads.Length > 0 && (Loads.Length == 0 || Loads[0].LoadId != loads[0].LoadId))
{
if (Guid.TryParse(loads[0].LoadId, out Guid elementModelId)) LoadsChanged?.Invoke(elementModelId);
else LoadsChanged?.Invoke(Guid.Empty);
Loads = loads;
}
else if (Loads.Length != 0 && loads.Length == 0)
{
LoadsChanged?.Invoke(Guid.Empty);
Loads = loads;
}
}
public void Dispose()
{
GC.SuppressFinalize(this);
}
}

View File

@@ -0,0 +1,13 @@
text {
dominant-baseline: middle;
text-anchor: middle;
fill: red;
transform: scale(1, -1);
font-size: 0.01em;
user-select: none;
font-weight: normal;
}
/*
image {
transform: scale(1, -1);
}*/

View File

@@ -0,0 +1,40 @@
@inject IJSRuntime JSRuntime
@implements IDisposable
<polygon @ref="Ref" fill="@Model.Fill" style="visibility: @(IsShow ? "visible" : "hidden")" />
@code {
[Parameter, EditorRequired]
public ZoneModel Model { get; set; } = null!;
[Parameter]
public EventCallback<ZoneModel> DoubleClick { get; set; }
[Parameter]
public bool IsShow { get; set; }
[CascadingParameter]
protected bool MapIsActive { get; set; }
private ElementReference Ref;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (!firstRender) return;
await UpdateData();
}
private async Task UpdateData()
{
string data = $"{Model.X1},{Model.Y1} {Model.X2},{Model.Y2} {Model.X3},{Model.Y3} {Model.X4},{Model.Y4}";
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", Ref, "points", data);
}
public void Dispose()
{
GC.SuppressFinalize(this);
}
}

View File

@@ -0,0 +1,35 @@
using RobotNet.MapShares.Dtos;
using RobotNet.MapShares.Enums;
namespace RobotNet.WebApp.Robots.Components.Monitoring.Element;
public class ZoneModel(ZoneDto Data) : IDisposable
{
public Guid Id => Data.Id;
public Guid MapId => Data.MapId;
public ZoneType Type => Data.Type;
public double X1 => Data.X1;
public double Y1 => Data.Y1;
public double X2 => Data.X2;
public double Y2 => Data.Y2;
public double X3 => Data.X3;
public double Y3 => Data.Y3;
public double X4 => Data.X4;
public double Y4 => Data.Y4;
public string Fill => Data.Type switch
{
ZoneType.Confined => "#c29ffa", // Vùng hoạt động hạn chế
ZoneType.Forbidden => "#ea868f", // Vùng cấm di chuyển
ZoneType.Operating => "#79dfc1", // Vùng hoạt động bình thường
ZoneType.OperatingHazard => "#ffda6a", // Vùng hoạt động nguy hiểm
ZoneType.Restricted => "#fd9843", // Vùng hoạt động giới hạn
ZoneType.LoadTransfer => "#e685b5", // Vùng chuyển hàng
_ => "none",
};
public void Dispose()
{
GC.SuppressFinalize(this);
}
}

View File

@@ -0,0 +1,29 @@
polygon {
stroke: none;
fill-opacity: 0.5;
stroke-linejoin: round;
stroke-linecap: butt;
position: relative;
z-index: 1;
}
polygon.setting:hover {
stroke-width: 0.02px;
stroke: red;
cursor: pointer;
}
polygon.setting:active {
fill-opacity: 0.7;
stroke-width: 0.02px;
stroke: green;
cursor: pointer;
}
polygon.setting.active {
fill-opacity: 0.7;
stroke-width: 0.02px;
stroke: green;
cursor: pointer;
z-index: 2;
}

View File

@@ -0,0 +1,37 @@
<g visibility="@(Show ? "visible" : "hidden")">
@for (int x = startX; x <= endX; x += 1)
{
<line x1="@x" y1="@originY" x2="@x" y2="@(height + originY)" />
}
@for (int y = startY; y <= endY; y += 1)
{
<line x1="@originX" y1="@y" x2="@(width + originX)" y2="@y" />
}
</g>
@code {
[Parameter, EditorRequired]
public bool Show { get; set; }
private double originX;
private double originY;
private int startX;
private int startY;
private int endX;
private int endY;
private double width;
private double height;
public void Resize(double mapOriginX, double mapOriginY, double mapheight, double mapwidth)
{
width = mapwidth;
height = mapheight;
originX = mapOriginX;
originY = -height - mapOriginY;
startX = (int)Math.Ceiling(originX);
startY = (int)Math.Ceiling(originY);
endX = (int)Math.Floor(width + mapOriginX);
endY = (int)Math.Floor(-mapOriginY);
StateHasChanged();
}
}

View File

@@ -0,0 +1,6 @@
line {
stroke: gray;
stroke-width: 0.04px;
stroke-opacity: 1;
stroke-dasharray: 0.05 0.1;
}

View File

@@ -0,0 +1,20 @@
<div class="map-editor-info">
<div class="px-1 pt-1">
@X
</div>
<div class ="px-1 pb-1">
@Y
</div>
</div>
@code {
private double X;
private double Y;
public void Update(double x, double y)
{
X = Math.Round(x, 3);
Y = Math.Round(y, 3);
StateHasChanged();
}
}

View File

@@ -0,0 +1,14 @@
div {
width:fit-content;
height: fit-content;
}
.map-editor-info {
color: #00cc66;
font-size: 15px;
position: absolute;
top: 5px;
left: 5px;
font-weight: bold;
background-color:white;
border-radius:4px
}

View File

@@ -0,0 +1,30 @@
@implements IDisposable
@using RobotNet.WebApp.Robots.Components.Monitoring.Element
@foreach (var robot in Models)
{
<Robot Model="@robot" ShowName="@ShowName" />
}
@code {
[Parameter, EditorRequired]
public MapRobotModel Models { get; set; } = null!;
[Parameter]
public bool ShowName { get; set; }
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (!firstRender) return;
Models.Changed += StateHasChanged;
}
public void Dispose()
{
Models.Changed -= StateHasChanged;
GC.SuppressFinalize(this);
}
}

View File

@@ -0,0 +1,49 @@
using RobotNet.WebApp.Robots.Components.Monitoring.Element;
using System.Collections;
namespace RobotNet.WebApp.Robots.Components.Monitoring;
public class MapRobotModel : IEnumerable<RobotVisualizationModel>
{
private readonly Dictionary<string, RobotVisualizationModel> dicRobots = [];
public IEnumerator<RobotVisualizationModel> GetEnumerator() => dicRobots.Values.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
public event Action? Changed;
public void Add(RobotVisualizationModel robot)
{
if (dicRobots.ContainsKey(robot.RobotId)) return;
dicRobots.Add(robot.RobotId, robot);
Changed?.Invoke();
}
public bool ContainsKey(string key) => dicRobots.ContainsKey(key);
public void ReplaceAll(IEnumerable<RobotVisualizationModel> robots)
{
foreach (var robot in dicRobots.Values)
{
robot.Dispose();
}
dicRobots.Clear();
foreach (var robot in robots)
{
robot.Update(robot.X, robot.Y, robot.Theta, robot.Loads);
dicRobots.Add(robot.RobotId, robot);
}
Changed?.Invoke();
}
public void Remove(RobotVisualizationModel robot)
{
if (!dicRobots.ContainsKey(robot.RobotId)) return;
robot.Dispose();
dicRobots.Remove(robot.RobotId);
Changed?.Invoke();
}
public bool TryGetValue(string id, out RobotVisualizationModel? value) => dicRobots.TryGetValue(id, out value);
}

View File

@@ -0,0 +1,32 @@
<defs>
<marker id="edge-two-way" markerWidth="2" markerHeight="1" refX="1" refY="0.5" orient="auto">
<polyline points="0.8,0.3 0.6,0.5 0.8,0.7"/>
<polyline points="1.2,0.3 1.4,0.5 1.2,0.7"/>
<polyline points="0.6,0.5 1.4,0.5" />
</marker>
<marker id="edge-forward" markerWidth="2" markerHeight="1" refX="1" refY="0.5" orient="auto">
<polyline points="1.2,0.3 1.4,0.5 1.2,0.7"/>
<polyline points="0.6,0.5 1.4,0.5"/>
</marker>
<marker id="edge-backward" markerWidth="2" markerHeight="1" refX="1" refY="0.5" orient="auto">
<polyline points="0.8,0.3 0.6,0.5 0.8,0.7"/>
<polyline points="0.6,0.5 1.4,0.5"/>
</marker>
<marker id="edge-none" markerWidth="2" markerHeight="1" refX="1" refY="0.5" orient="auto">
<polyline points="0.6,0.5 1.4,0.5"/>
</marker>
</defs>
@code {
public static string GetMakerMid(DirectionAllowed direction)
{
return direction switch
{
DirectionAllowed.Both => $"url(#edge-two-way)",
DirectionAllowed.Forward => $"url(#edge-forward)",
DirectionAllowed.Backward => $"url(#edge-backward)",
DirectionAllowed.None => $"url(#edge-none)",
_ => "",
};
}
}

View File

@@ -0,0 +1,5 @@
polyline {
stroke: #DD22FF;
stroke-width: 0.05px;
fill: none;
}

View File

@@ -0,0 +1,125 @@
@using RobotNet.RobotShares.VDA5050.State
<div class="d-flex h-100 d-flex flex-column overflow-x-hidden overflow-y-auto p-2" style="width: 250px" hidden="@(!IsExpand)">
<MudExpansionPanels Elevation="0" Style="border: 1px solid silver">
<MudExpansionPanel Expanded="true">
<TitleContent>
<MudText>Visualization</MudText>
</TitleContent>
<ChildContent>
<MudTextField Class="mb-2" Label="X" Value="RobotStateSelected.AgvPosition.X" Variant="Variant.Outlined" Margin="Margin.Dense" />
<MudTextField Class="my-2" Label="Y" Value="RobotStateSelected.AgvPosition.Y" Variant="Variant.Outlined" Margin="Margin.Dense" />
<MudTextField Class="my-2" Label="Theta" Value="RobotStateSelected.AgvPosition.Theta" Variant="Variant.Outlined" Margin="Margin.Dense" />
<MudTextField Class="my-2" Label="Velocity X" Value="RobotStateSelected.AgvVelocity.Vx" Variant="Variant.Outlined" Margin="Margin.Dense" />
<MudTextField Class="mt-2" Label="Velocity Y" Value="RobotStateSelected.AgvVelocity.Vy" Variant="Variant.Outlined" Margin="Margin.Dense" />
<MudTextField Class="mt-2" Label="Angular Velocity" Value="RobotStateSelected.AgvVelocity.Omega" Variant="Variant.Outlined" Margin="Margin.Dense" />
</ChildContent>
</MudExpansionPanel>
</MudExpansionPanels>
<MudExpansionPanels Elevation="0" Class="mt-2" Style="border: 1px solid silver">
<MudExpansionPanel Expanded="true">
<TitleContent>
<MudText>Localization</MudText>
</TitleContent>
<ChildContent>
<MudText Class="ms-2">Initialized: @RobotStateSelected.AgvPosition.PositionInitialized</MudText>
<MudText Class="ms-2">Quality: @RobotStateSelected.AgvPosition.LocalizationScore</MudText>
<MudText Class="ms-2">DeviationRange: @RobotStateSelected.AgvPosition.DeviationRange</MudText>
</ChildContent>
</MudExpansionPanel>
</MudExpansionPanels>
<MudExpansionPanels Elevation="0" Class="mt-2" Style="border: 1px solid silver">
<MudExpansionPanel Expanded="true">
<TitleContent>
<MudText>Battery</MudText>
</TitleContent>
<ChildContent>
<MudProgressLinear Class="m-2" Color="@(RobotStateSelected.Battery.BatteryHealth < 10 ? Color.Error : RobotStateSelected.Battery.BatteryHealth > 20 ? Color.Success : Color.Warning)" Rounded Striped Size="Size.Large" Value="@RobotStateSelected.Battery.BatteryHealth" />
<MudText Class="ms-2">@($"Health: {Math.Round(RobotStateSelected.Battery.BatteryHealth, 1)}%")</MudText>
<MudText Class="ms-2">@($"Voltage: {Math.Round(RobotStateSelected.Battery.BatteryVoltage, 1)}V")</MudText>
<MudText Class="ms-2">@($"State: {Math.Round(RobotStateSelected.Battery.BatteryCharge, 1)}")</MudText>
<MudText Class="ms-2">@($"Charging: {RobotStateSelected.Battery.Charging}")</MudText>
</ChildContent>
</MudExpansionPanel>
</MudExpansionPanels>
<MudExpansionPanels Elevation="0" Class="mt-2" Style="border: 1px solid silver">
<MudExpansionPanel>
<TitleContent>
<div class="d-flex">
<MudText>Errors</MudText>
<MudBadge Content="RobotStateSelected.Errors.Length" Color="Color.Info" Overlap="true" Class="d-flex ml-auto">
<MudIcon Icon="@Icons.Material.Filled.Info" Color="Color.Secondary" />
</MudBadge>
</div>
</TitleContent>
<ChildContent>
@foreach (var error in RobotStateSelected.Errors)
{
<MudTooltip Text="@error.ErrorDescription" Placement="Placement.Top" Color="Color.Info">
<MudButton Class="m-2" Color="@(error.ErrorLevel == ErrorLevel.FATAL.ToString() ? Color.Error : Color.Warning)" Variant="Variant.Filled" Size="Size.Small" Style="text-transform:none">@error.ErrorType</MudButton>
</MudTooltip>
}
</ChildContent>
</MudExpansionPanel>
</MudExpansionPanels>
<MudExpansionPanels Elevation="0" Class="mt-2" Style="border: 1px solid silver">
<MudExpansionPanel>
<TitleContent>
<div class="d-flex">
<MudText>Notification</MudText>
<MudBadge Content="RobotStateSelected.Infomations.Length" Color="Color.Info" Overlap="true" Class="d-flex ml-auto">
<MudIcon Icon="@Icons.Material.Filled.Notifications" Color="Color.Warning" />
</MudBadge>
</div>
</TitleContent>
<ChildContent>
<div class="d-flex flex-column">
@foreach (var info in RobotStateSelected.Infomations)
{
<MudTooltip Text="@info.InfoDescription" Placement="Placement.Top" Color="Color.Info">
<MudButton Class="m-2" Color="@(info.InfoLevel == InfoLevel.INFO.ToString() ? Color.Info : Color.Default)" Variant="Variant.Filled" Size="Size.Small" Style="text-transform:none">@info.InfoType</MudButton>
</MudTooltip>
}
</div>
</ChildContent>
</MudExpansionPanel>
</MudExpansionPanels>
</div>
@code {
private RobotInfomationDto RobotStateSelected = new();
private bool IsExpand = true;
public void ExpandedClick(bool value)
{
IsExpand = value;
StateHasChanged();
}
public void UpdateState(RobotInfomationDto data)
{
RobotStateSelected.Battery.BatteryVoltage = data.Battery.BatteryVoltage;
RobotStateSelected.Battery.BatteryHealth = data.Battery.BatteryHealth;
RobotStateSelected.Battery.BatteryCharge = data.Battery.BatteryCharge;
RobotStateSelected.Battery.Charging = data.Battery.Charging;
RobotStateSelected.AgvPosition.LocalizationScore = data.AgvPosition.LocalizationScore;
RobotStateSelected.AgvPosition.PositionInitialized = data.AgvPosition.PositionInitialized;
RobotStateSelected.AgvPosition.DeviationRange = data.AgvPosition.DeviationRange;
RobotStateSelected.AgvPosition.X = data.AgvPosition.X;
RobotStateSelected.AgvPosition.Y = data.AgvPosition.Y;
RobotStateSelected.AgvPosition.Theta = data.AgvPosition.Theta;
RobotStateSelected.AgvVelocity.Vx = data.AgvVelocity.Vx;
RobotStateSelected.AgvVelocity.Vy = data.AgvVelocity.Vy;
RobotStateSelected.AgvVelocity.Omega = data.AgvVelocity.Omega;
RobotStateSelected.Errors = [.. data.Errors];
RobotStateSelected.Infomations = [.. data.Infomations];
StateHasChanged();
}
}

View File

@@ -0,0 +1,501 @@
@using RobotNet.WebApp.Robots.Components.Monitoring.Element
@using System.Text.Json
@inject IJSRuntime JSRuntime
@inject ISnackbar Snackbar
@inject IDialogService DialogService
@inject IHttpClientFactory HttpFactory
<div class="monitor-map" @ref="ViewContainerRef">
<div @ref="ViewMovementRef">
<svg @ref="MapContainerRef" class="monitor-map-view" letter-spacing="normal">
<MapSvgDefs />
<image @ref="MapImageRef" class="monitor-map-image" />
<OriginVector />
<MapGrid @ref="@MapGridRef" Show="@ShowGrid" />
@foreach (var zone in zones)
{
<Zone Model="zone" IsShow="true" />
}
@foreach (var edge in edges)
{
<Edge Model="edge" />
}
@foreach (var edge in edges)
{
<EdgeDirection Model="edge" />
}
@foreach (var node in nodes)
{
<Node Model="node" ShowName="@ShowName" />
}
@foreach (var element in elements)
{
<Element Model="element" ShowName="@ShowName" Show="@ShowElement" DoubleClick="ElementDoubleClick" />
}
<RobotCurrentPath @ref="@RobotCurrentPathRef" Show="@ShowPath" />
<RobotPath @ref="@RobotPathRef" Show="@ShowPath" />
<MapRobot Models="robots" ShowName="@ShowName" />
<RobotLaserScaner @ref="RobotLaserScanerRef" ShowLaser="ShowLaser" />
</svg>
</div>
<MapMousePosition @ref="MapInfoRef" />
</div>
<MudDialog @bind-Visible="updateElementVisble">
<TitleContent>
<MudText Typo="Typo.h6">
Update Element @ElementUpdateModel.Name
</MudText>
</TitleContent>
<DialogContent>
<div class="d-flex flex-row" style="max-height: 700px; overflow-y: auto; width: 600px">
<div class="d-flex flex-column h-100 me-2" style="width: 47%">
<MudTextField T="string" Label="Name" @bind-value="ElementUpdateModel.Name" Variant="Variant.Outlined"
Required="true" RequiredError="Name is required!" ReadOnly
Validation="@(new Func<string, IEnumerable<string>>(MapEditorHelper.NameValidation))" />
<MudNumericField T="double" Label="Offset X" @bind-value="ElementUpdateModel.OffsetX" Variant="Variant.Outlined" Step="0.1" ReadOnly />
<MudNumericField T="double" Label="Offset Y" @bind-value="ElementUpdateModel.OffsetY" Variant="Variant.Outlined" Step="0.1" ReadOnly />
<MudCheckBox Size="Size.Small" T="bool" LabelPlacement="Placement.Start" Label="IsOpen" @bind-value="ElementUpdateModel.IsOpen" Color="Color.Success"
UncheckedColor="Color.Default" />
</div>
<div class="paper-property-container">
<div class="paper-property ms-2">
@foreach (var property in ElementProperties)
{
@if (property.Type == typeof(int).ToString())
{
if (int.TryParse(property.DefaultValue, out int value))
{
<MudNumericField T="int" Margin="Margin.Dense" Label="@property.Name" Value="value" Variant="Variant.Outlined" ReadOnly="@(property.ReadOnly)"
ValueChanged="((data) => DefaultIntValueChanged(property.Id, data))" />
}
}
else if (property.Type == typeof(double).ToString())
{
if (double.TryParse(property.DefaultValue, out double value))
{
<MudNumericField T="double" Margin="Margin.Dense" Label="@property.Name" Value="value" Variant="Variant.Outlined" Step="0.1" ReadOnly="@(property.ReadOnly)"
ValueChanged="((data) => DefaultDoubleValueChanged(property.Id, data))" />
}
}
else if (property.Type == typeof(bool).ToString())
{
if (bool.TryParse(property.DefaultValue, out bool value))
{
<MudCheckBox Class="m-0" Size="Size.Small" T="bool" LabelPlacement="Placement.Start" Label="@property.Name" Value="value" Color="Color.Success"
UncheckedColor="Color.Default" ReadOnly="@(property.ReadOnly)" ValueChanged="((data) => DefaultBooleanValueChanged(property.Id, data))" />
}
}
else if (property.Type == typeof(string).ToString())
{
<MudTextField T="string" Label="@property.Name" Value="@property.DefaultValue" Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly="@(property.ReadOnly)"
ValueChanged="((data) => property.DefaultValue = data)" />
}
}
</div>
<span class="paper-title">Properties</span>
</div>
</div>
</DialogContent>
<DialogActions>
<MudButton OnClick="(() => updateElementVisble = false)" Class="px-10" Variant="Variant.Filled">Cancel</MudButton>
<MudButton OnClick="UpdateElement" Variant="Variant.Filled" Color="Color.Primary" Class="px-10 me-4">Update</MudButton>
</DialogActions>
</MudDialog>
@code {
[Parameter]
public bool ShowGrid { get; set; }
[Parameter]
public bool ShowName { get; set; }
[Parameter]
public bool ShowPath { get; set; }
[Parameter]
public bool ShowLaser { get; set; }
[Parameter]
public bool ShowElement { get; set; }
private MapMousePosition MapInfoRef = null!;
private RobotPath RobotPathRef = null!;
private RobotCurrentPath RobotCurrentPathRef = null!;
private MapGrid MapGridRef = null!;
private RobotLaserScaner RobotLaserScanerRef = null!;
private DotNetObjectReference<MonitorMap> DotNetObj = null!;
private ElementReference ViewContainerRef;
private ElementReference ViewMovementRef;
private ElementReference MapContainerRef;
private ElementReference MapImageRef;
private double ViewContainerRectX;
private double ViewContainerRectY;
private double ViewContainerRectWidth;
private double ViewContainerRectHeight;
private double ViewContainerRectTop;
private double ViewContainerRectRight;
private double ViewContainerRectBottom;
private double ViewContainerRectLeft;
private double CursorX;
private double CursorY;
private double ClientOriginX;
private double ClientOriginY;
private double Resolution = 1;
private double OriginX;
private double OriginY;
private double ImageOriginY;
private double ImageWidth;
private double ImageHeight;
private double Scale = 1;
private double Left;
private double Top;
private double FitScale = 1;
private double OldOriginY;
private List<EdgeModel> edges = new();
private List<NodeModel> nodes = new();
private List<ZoneModel> zones = new();
private List<ElementModel> elements = new();
private MapRobotModel robots = new();
private bool IsFocusRobot = false;
private string RobotSelectedId = "";
private bool updateElementVisble;
private ElementUpdateModel ElementUpdateModel = new();
private List<MapShares.Property.ElementProperty> ElementProperties = [];
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (!firstRender) return;
DotNetObj = DotNetObjectReference.Create(this);
await JSRuntime.InvokeVoidAsync("DOMCssLoaded");
await JSRuntime.InvokeVoidAsync("UpdateViewContainerRect", DotNetObj, ViewContainerRef, nameof(ViewContainerResize));
await JSRuntime.InvokeVoidAsync("ResizeObserverRegister", DotNetObj, ViewContainerRef, nameof(ViewContainerResize));
await JSRuntime.InvokeVoidAsync("AddEventListener", DotNetObj, ViewContainerRef, "click", nameof(ViewContainerClick));
await JSRuntime.InvokeVoidAsync("AddMouseMoveEventListener", DotNetObj, ViewContainerRef, nameof(MouseMoveOnMapContainer));
await JSRuntime.InvokeVoidAsync("AddMouseWheelEventListener", DotNetObj, MapContainerRef, nameof(MouseWheelOnMapContainer));
await JSRuntime.InvokeVoidAsync("AddTouchMoveEventListener", DotNetObj, ViewContainerRef, nameof(TouchMoveOnMapContainer));
}
public async Task LoadMap(MapDataDto? mapData)
{
if (mapData == null)
{
nodes.Clear();
edges.Clear();
zones.Clear();
elements.Clear();
robots.ReplaceAll([]);
RobotCurrentPathRef.UpdatePath([]);
RobotPathRef.UpdatePath([]);
Resolution = 1.0;
OriginY = 0;
OriginX = 0;
OldOriginY = 0;
ImageOriginY = 0;
ImageHeight = 0;
ImageWidth = 0;
MapGridRef.Resize(OriginX, OriginY, ImageHeight, ImageWidth);
await JSRuntime.InvokeVoidAsync("SetMapSvgConfig", MapContainerRef, ImageWidth, ImageHeight, OriginX, 1.0);
await JSRuntime.InvokeVoidAsync("SetImageAttribute", MapImageRef, ImageWidth, ImageHeight, OriginX, OriginY, "");
}
else
{
nodes = [.. mapData.Nodes.Select(node => new NodeModel(node))];
edges = [.. mapData.Edges.Select(edge => new EdgeModel(edge, nodes.First(n => n.Id == edge.StartNodeId), nodes.First(n => n.Id == edge.EndNodeId)))];
zones = [.. mapData.Zones.Select(zone => new ZoneModel(zone))];
elements = [.. mapData.Elements.Select(element => new ElementModel(element, nodes.First(n => n.Id == element.NodeId)))];
Resolution = mapData.Resolution;
OldOriginY = mapData.OriginY;
OriginY = -mapData.ImageHeight * Resolution - mapData.OriginY;
OriginX = mapData.OriginX;
ImageOriginY = mapData.OriginY;
ImageHeight = mapData.ImageHeight * Resolution;
ImageWidth = mapData.ImageWidth * Resolution;
MapGridRef.Resize(OriginX, OriginY, ImageHeight, ImageWidth);
using var Http = HttpFactory.CreateClient("MapManagerAPI");
await JSRuntime.InvokeVoidAsync("SetMapSvgConfig", MapContainerRef, ImageWidth, ImageHeight, OriginX, mapData.OriginY);
await JSRuntime.InvokeVoidAsync("SetImageAttribute", MapImageRef, ImageWidth, ImageHeight, OriginX, OriginY, $"{Http.BaseAddress}api/images/map/{mapData.Id}");
await JSRuntime.InvokeVoidAsync("UpdateViewContainerRect", DotNetObj, ViewContainerRef, nameof(ViewContainerResize));
await ScaleFitContentAsync();
}
StateHasChanged();
}
public async Task ScaleFitContentAsync()
{
Scale = FitScale;
await SetViewMovement((ViewContainerRectWidth - ImageWidth * Scale) / 2, (ViewContainerRectHeight - ImageHeight * Scale) / 2);
await JSRuntime.InvokeVoidAsync("SetMapSvgRect", MapContainerRef, ImageWidth * Scale, ImageHeight * Scale);
}
private async Task SetViewMovement(double left, double top)
{
Top = top;
Left = left;
ClientOriginX = ViewContainerRectLeft + Left - OriginX * Scale;
ClientOriginY = ViewContainerRectTop + Top - OriginY * Scale;
await JSRuntime.InvokeVoidAsync("SetMapMovement", ViewMovementRef, Top, Left);
}
public async Task ScaleZoom(double deltaY)
{
if (deltaY > 0)
{
if (Scale >= FitScale * 20) return;
}
else
{
if (Scale <= FitScale / 2) return;
}
double oldScale = Scale;
Scale += deltaY;
double centerXBefore = ((ViewContainerRectLeft + ViewContainerRectWidth / 2) - ClientOriginX) / oldScale - OriginX;
double centerYBefore = (ClientOriginY - (ViewContainerRectHeight / 2 + ViewContainerRectTop)) / oldScale - OldOriginY;
await SetViewMovement(Left - centerXBefore * deltaY, Top - (ImageHeight - centerYBefore) * deltaY);
await JSRuntime.InvokeVoidAsync("SetMapSvgRect", MapContainerRef, ImageWidth * Scale, ImageHeight * Scale);
}
[JSInvokable]
public void ViewContainerResize(double x, double y, double width, double height, double top, double right, double bottom, double left)
{
ViewContainerRectX = x;
ViewContainerRectY = y;
ViewContainerRectWidth = width;
ViewContainerRectHeight = height;
ViewContainerRectTop = top;
ViewContainerRectRight = right;
ViewContainerRectBottom = bottom;
ViewContainerRectLeft = left;
ClientOriginX = ViewContainerRectLeft + Left - OriginX * Scale;
ClientOriginY = ViewContainerRectTop + Top - OriginY * Scale;
FitScale = Math.Min(ViewContainerRectWidth / ImageWidth, ViewContainerRectHeight / ImageHeight);
}
[JSInvokable]
public async Task TouchMoveOnMapContainer(double clientX, double clientY, int touchCount, double movementX, double movementY)
{
CursorX = (clientX - ClientOriginX) / Scale;
CursorY = (ClientOriginY - clientY) / Scale;
MapInfoRef.Update(CursorX, CursorY);
if (touchCount == 1) await SetViewMovement(Left + movementX, Top + movementY);
}
[JSInvokable]
public async Task MouseWheelOnMapContainer(double deltaY, double offsetX, double offsetY)
{
double scaleChange;
if (deltaY > 0)
{
if (Scale <= FitScale / 2) return;
scaleChange = Scale > FitScale ? -(Scale / FitScale) : -0.1;
}
else
{
if (Scale >= FitScale * 100) return;
scaleChange = Scale < FitScale ? 0.5 : (Scale / FitScale);
}
double oldScale = Scale;
Scale += scaleChange;
await JSRuntime.InvokeVoidAsync("SetMapSvgRect", MapContainerRef, ImageWidth * Scale, ImageHeight * Scale);
double mouseX = CursorX - OriginX;
double mouseY = CursorY - OldOriginY;
await SetViewMovement(Left - mouseX * scaleChange, Top - (ImageHeight - mouseY) * scaleChange);
}
[JSInvokable]
public async Task ViewContainerClick() => await ViewContainerRef.FocusAsync();
[JSInvokable]
public async Task MouseMoveOnMapContainer(double clientX, double clientY, long buttons, bool ctrlKey, double movementX, double movementY)
{
CursorX = (clientX - ClientOriginX) / Scale;
CursorY = (ClientOriginY - clientY) / Scale;
MapInfoRef.Update(CursorX, CursorY);
if (IsFocusRobot) return;
switch (buttons)
{
case 4:
await SetViewMovement(Left + movementX, Top + movementY);
break;
}
}
public void LoadRobots(IEnumerable<RobotInfomationDto> robotDtos)
{
if (robotDtos.Any())
{
var robotModel = robotDtos.Select(robot => new RobotVisualizationModel()
{
RobotId = robot.RobotId,
RobotName = robot.Name,
X = robot.AgvPosition.X,
Y = robot.AgvPosition.Y,
Theta = robot.AgvPosition.Theta,
}).ToArray();
robots.ReplaceAll(robotModel);
}
else robots.ReplaceAll([]);
StateHasChanged();
}
public void RobotSelectedChange(string robotId)
{
if (robotId != RobotSelectedId) RobotSelectedId = robotId;
}
public void FocusRobot(bool value) => IsFocusRobot = value;
public async Task FocusRobotAsync()
{
var robot = robots.FirstOrDefault(r => r.RobotId == RobotSelectedId);
if (robot is null) return;
double mapX = (ViewContainerRectWidth - ImageWidth * Scale) / 2 + ((ImageWidth / 2 + OriginX) * Scale) - robot.X * Scale;
double mapY = (ViewContainerRectHeight - ImageHeight * Scale) / 2 + ((ImageHeight / 2 + OriginY) * Scale) + robot.Y * Scale;
await SetViewMovement(mapX, mapY);
}
public async Task SetRobotPosition(List<RobotInfomationDto> robotStates)
{
foreach (var robot in robotStates)
{
var robotModel = robots.FirstOrDefault(rm => rm.RobotId == robot.RobotId);
if (robotModel is not null)
{
robotModel.Update(robot.AgvPosition.X, robot.AgvPosition.Y, robot.AgvPosition.Theta, robot.Loads);
if (IsFocusRobot && robot.RobotId == RobotSelectedId) await FocusRobotAsync();
}
else
{
robots.Add(new()
{
RobotId = robot.RobotId,
RobotName = robot.Name,
X = robot.AgvPosition.X,
Y = robot.AgvPosition.Y,
Theta = robot.AgvPosition.Theta,
Loads = robot.Loads
});
StateHasChanged();
}
if (robot.RobotId == RobotSelectedId)
{
RobotPathRef.UpdatePath([.. robot.Navigation.RobotPath]);
RobotCurrentPathRef.UpdatePath([.. robot.Navigation.RobotBasePath]);
RobotLaserScanerRef.SetData(robot.Navigation.LaserScaner);
}
}
}
public void ElementStateUpdated(IEnumerable<ElementDto> elementsState)
{
foreach (var elmenet in elementsState)
{
var elemetModel = elements.FirstOrDefault(e => e.Id == elmenet.Id);
if (elemetModel is not null)
{
elemetModel.Update(elmenet);
}
else
{
var node = nodes.FirstOrDefault(n => n.Id == elmenet.NodeId);
if (node is not null) elements.Add(new ElementModel(elmenet, node));
}
}
StateHasChanged();
}
private void DefaultIntValueChanged(Guid id, int value)
{
var property = ElementProperties.FirstOrDefault(p => p.Id == id);
if (property is null) return;
property.DefaultValue = value.ToString();
}
private void DefaultDoubleValueChanged(Guid id, double value)
{
var property = ElementProperties.FirstOrDefault(p => p.Id == id);
if (property is null) return;
property.DefaultValue = value.ToString();
}
private void DefaultBooleanValueChanged(Guid id, bool value)
{
var property = ElementProperties.FirstOrDefault(p => p.Id == id);
if (property is null) return;
property.DefaultValue = value.ToString();
}
private void ElementDoubleClick(ElementModel model)
{
ElementUpdateModel.Id = model.Id;
ElementUpdateModel.Name = model.Name;
ElementUpdateModel.IsOpen = model.IsOpen;
ElementUpdateModel.OffsetX = model.OffsetX;
ElementUpdateModel.OffsetY = model.OffsetY;
ElementUpdateModel.Content = model.Content;
if (model is not null && !string.IsNullOrEmpty(model.Content))
{
var properties = JsonSerializer.Deserialize<List<MapShares.Property.ElementProperty>>(model.Content, JsonOptionExtends.Read);
if (properties is not null) ElementProperties = [.. properties];
}
updateElementVisble = true;
StateHasChanged();
}
private async Task UpdateElement()
{
var selectedElement = elements.FirstOrDefault(e => e.Id == ElementUpdateModel.Id);
if (selectedElement is null) return;
using var Http = HttpFactory.CreateClient("MapManagerAPI");
var result = await (await Http.PutAsJsonAsync($"api/Elements", new ElementUpdateModel()
{
Id = ElementUpdateModel.Id,
Name = ElementUpdateModel.Name,
IsOpen = ElementUpdateModel.IsOpen,
OffsetX = ElementUpdateModel.OffsetX,
OffsetY = ElementUpdateModel.OffsetY,
Content = JsonSerializer.Serialize(ElementProperties, JsonOptionExtends.Write),
})).Content.ReadFromJsonAsync<MessageResult<ElementDto>>();
if (result == null) Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error);
else if (!result.IsSuccess) Snackbar.Add(result.Message, Severity.Error);
else if (result.Data is null) Snackbar.Add("Lỗi dữ liệu", Severity.Error);
else
{
selectedElement.Update(result.Data);
Snackbar.Add("Cập nhật thành công", Severity.Success);
}
updateElementVisble = false;
StateHasChanged();
}
}

View File

@@ -0,0 +1,57 @@
.monitor-map {
background-color: #808080;
width: 100%;
height: 100%;
cursor: not-allowed;
border-top: solid 2px #808080;
overflow: hidden;
position: relative;
}
.monitor-map > div {
width: fit-content;
height: fit-content;
position: absolute;
cursor: default;
display: flex;
}
.monitor-map-image {
user-select: none;
image-rendering: pixelated;
transform: scale(1, -1);
}
.monitor-map-view {
transform: scale(1, -1);
}
.paper-property-container {
position: relative;
display: inline-block;
width: 50%;
height: 240px;
}
.paper-title {
font-size: 12px;
padding: 0 5px;
position: absolute;
background-color: var(--mud-palette-surface);
top: 0px;
left: 15px;
}
.paper-property {
padding: 10px;
border-radius: var(--mud-default-borderradius);
border: 1px solid var(--mud-palette-lines-inputs);
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
position: relative;
overflow-x: hidden;
overflow-y: auto;
margin: 8px;
}

View File

@@ -0,0 +1,96 @@
<div class="d-flex flex-row justify-content-between w-100 overflow-x-auto px-1">
<div class="d-flex flex-row">
<MudIconButton Class="mx-1 my-2" Icon="@Icons.Material.Filled.ZoomIn" Variant="Variant.Outlined" OnClick="(async () => await ButtonEventClick.InvokeAsync(MonitorToolbarButtonType.ZoomIn))" />
<MudIconButton Class="mx-1 my-2" Icon="@Icons.Material.Filled.ZoomOut" Variant="Variant.Outlined" OnClick="(async () => await ButtonEventClick.InvokeAsync(MonitorToolbarButtonType.ZoomOut))" />
<MudIconButton Class="mx-1 my-2" Icon="@Icons.Material.Filled.FitScreen" Variant="Variant.Outlined" OnClick="(async () => await ButtonEventClick.InvokeAsync(MonitorToolbarButtonType.Fit))" />
<MudIconButton Class="mx-1 my-2" Icon="@Icons.Material.Filled.MyLocation" Variant="Variant.Outlined" OnClick="(async () => await ButtonEventClick.InvokeAsync(MonitorToolbarButtonType.Focus))" />
<div class="mt-1 d-flex flex-row">
<MudCheckBox @bind-Value="Model.FocusRobot" Label="Focus" T="bool" UncheckedColor="Color.Default" Color="Color.Success" @bind-Value:after="(() => CheckedClick(MonitorToolbarCheckedType.FocusRobot, Model.FocusRobot))"></MudCheckBox>
<MudCheckBox @bind-Value="Model.ShowPath" Label="Path" T="bool" UncheckedColor="Color.Default" Color="Color.Success" @bind-Value:after="(() => CheckedClick(MonitorToolbarCheckedType.ShowPath, Model.ShowPath))"></MudCheckBox>
<MudCheckBox @bind-Value="Model.ShowName" Label="Name" T="bool" UncheckedColor="Color.Default" Color="Color.Success" @bind-Value:after="(() => CheckedClick(MonitorToolbarCheckedType.ShowName, Model.ShowName))"></MudCheckBox>
<MudCheckBox @bind-Value="Model.ShowElement" Label="Element" T="bool" UncheckedColor="Color.Default" Color="Color.Success" @bind-Value:after="(() => CheckedClick(MonitorToolbarCheckedType.ShowElement, Model.ShowElement))"></MudCheckBox>
<MudCheckBox @bind-Value="Model.ShowGrid" Label="Grid" T="bool" UncheckedColor="Color.Default" Color="Color.Success" @bind-Value:after="(() => CheckedClick(MonitorToolbarCheckedType.ShowGrid, Model.ShowGrid))"></MudCheckBox>
<MudCheckBox @bind-Value="Model.ShowLaser" Label="Laser" T="bool" UncheckedColor="Color.Default" Color="Color.Success" @bind-Value:after="(() => CheckedClick(MonitorToolbarCheckedType.ShowLaser, Model.ShowLaser))"></MudCheckBox>
</div>
</div>
<div class="d-flex flex-row">
<MudSelect Class="ms-2" Label="Map Name" Variant="Variant.Outlined" T="MapInfoDto" Margin="Margin.Dense" Dense @bind-Value="MapSelected" Style="width: 200px" @bind-Value:after="(async () => await MapChanged.InvokeAsync(MapSelected))">
@foreach(var map in Maps)
{
<MudSelectItem Value="@map">@map.Name</MudSelectItem>
}
</MudSelect>
<MudSelect Class="ms-2" @bind-Value="@RobotSelected" T="RobotInfomationDto" @bind-Value:after="(async () => await RobotChanged.InvokeAsync(RobotSelected))" Margin="Margin.Dense" Dense Variant="Variant.Outlined" Label="Robot Name" Style="width: 200px">
@foreach (var robot in Robots)
{
<MudSelectItem Value="@robot">@robot.Name</MudSelectItem>
}
</MudSelect>
<MudIconButton Icon="@ExpandIcon" Color="Color.Success" OnClick="ExpandedClick" />
</div>
</div>
@code {
[Parameter]
public MonitorToolBarModel Model { get; set; } = null!;
[Parameter]
public EventCallback<MonitorToolbarButtonType> ButtonEventClick { get; set; }
[Parameter]
public EventCallback<bool> ExpandChanged { get; set; }
[Parameter]
public EventCallback<MapInfoDto> MapChanged { get; set; }
[Parameter]
public EventCallback<RobotInfomationDto> RobotChanged { get; set; }
[Parameter]
public Func<MonitorToolbarCheckedType, bool, Task>? CheckedEventClick { get; set; }
public List<MapInfoDto> Maps = [];
private MapInfoDto? MapSelected = default!;
private bool isExpand = true;
private string ExpandIcon = @Icons.Material.Filled.ArrowForwardIos;
public List<RobotInfomationDto> Robots = [];
private RobotInfomationDto? RobotSelected = null;
public void LoadMaps(List<MapInfoDto> maps, MapInfoDto mapSelected)
{
Maps = maps;
MapSelected = mapSelected;
StateHasChanged();
}
public void LoadRobots(List<RobotInfomationDto> robots)
{
Robots = robots;
if(Robots.Count > 0 && (RobotSelected is null || !Robots.Any(r => r.RobotId == RobotSelected.RobotId)))
{
RobotSelected = Robots.First();
_ = RobotChanged.InvokeAsync(RobotSelected);
}
StateHasChanged();
}
private async Task ExpandedClick()
{
if (isExpand)
{
ExpandIcon = @Icons.Material.Filled.ArrowBackIos;
isExpand = false;
}
else
{
ExpandIcon = @Icons.Material.Filled.ArrowForwardIos;
isExpand = true;
}
await ExpandChanged.InvokeAsync(isExpand);
StateHasChanged();
}
private void CheckedClick(MonitorToolbarCheckedType type, bool value) => CheckedEventClick?.Invoke(type, value);
}

View File

@@ -0,0 +1,11 @@
namespace RobotNet.WebApp.Robots.Components.Monitoring;
public class MonitorToolBarModel
{
public bool ShowGrid { get; set; }
public bool ShowName { get; set; }
public bool ShowPath { get; set; }
public bool FocusRobot { get; set; }
public bool ShowLaser { get; set; }
public bool ShowElement { get; set; }
}

View File

@@ -0,0 +1,10 @@
<defs>
<marker id="originvector" markerWidth="2.4" markerHeight="2.4" refX="0.4" refY="0.4">
<line x1="0" y1="0.4" x2="2" y2="0.4" stroke="red" stroke-width="0.15" />
<path d="M 2 0.6 L 2.4 0.4 L 2 0.2 Z" fill="red" stroke-width="0" />
<line x1="0.4" y1="0" x2="0.4" y2="2" stroke="blue" stroke-width="0.15" />
<path d="M 0.6 2 L 0.4 2.4 L 0.2 2 Z" fill="blue" stroke-width="0" />
</marker>
</defs>
<line class="origin" marker-end="url(#originvector)" />

View File

@@ -0,0 +1,4 @@
line.origin {
stroke-width: var(--origin-vector-stroke-width);
fill: none;
}

View File

@@ -0,0 +1,35 @@
<path d="@data" fill="none" stroke="Green" stroke-width="0.35" stroke-opacity="1" visibility="@(Show ? PathIsNot : "hidden")" />
@code {
[Parameter]
public bool Show { get; set; }
private string data = "";
private string PathIsNot = "hidden";
public void Clear()
{
data = "";
PathIsNot = "hidden";
StateHasChanged();
}
public void UpdatePath(List<NavigationPathEdge> path)
{
if (path.Count > 0)
{
var inPath = $"M {path[0].StartX} {path[0].StartY}";
for (int i = 0; i < path.Count; i++)
{
if (path[i].Degree == 1) inPath = $"{inPath} L {path[i].EndX} {path[i].EndY}";
else if (path[i].Degree == 2) inPath = $"{inPath} Q {path[i].ControlPoint1X} {path[i].ControlPoint1Y} {path[i].EndX} {path[i].EndY}";
else inPath = $"{inPath} C {path[i].ControlPoint1X} {path[i].ControlPoint1Y}, {path[i].ControlPoint2X} {path[i].ControlPoint2Y}, {path[i].EndX} {path[i].EndY}";
}
data = inPath;
PathIsNot = "visible";
}
else Clear();
StateHasChanged();
}
}

View File

@@ -0,0 +1,17 @@
@foreach (var point in LidarPoints)
{
<circle cx="@point.X" cy="@point.Y" r="0.05" fill="blue" visibility="@(ShowLaser ? "visible" : "hidden")" />
}
@code {
[Parameter]
public bool ShowLaser { get; set; }
private List<NavigationPathNode> LidarPoints { get; set; } = new();
public void SetData(List<NavigationPathNode> laser)
{
LidarPoints.Clear();
LidarPoints.AddRange(laser);
}
}

View File

@@ -0,0 +1,45 @@
<path d="@data" fill="none" stroke="Green" stroke-width="0.15" stroke-opacity="0.7" visibility="@(Show ? PathIsNot : "hidden")" marker-end="url(#target)" />
<defs>
<marker id="target" markerWidth="8" markerHeight="8" refX="4" refY="4">
<circle r="0.8" cx="4" cy="4" fill="red" />
<circle r="3" cx="4" cy="4" stroke="red" stroke-width="0.2" fill="transparent" stroke-dasharray="0.2 0.2" />
<line x1="0" y1="4" x2="2" y2="4" stroke="red" stroke-width="0.2" />
<line x1="6" y1="4" x2="8" y2="4" stroke="red" stroke-width="0.2" />
<line x1="4" y1="0" x2="4" y2="2" stroke="red" stroke-width="0.2" />
<line x1="4" y1="6" x2="4" y2="8" stroke="red" stroke-width="0.2" />
</marker>
</defs>
@code {
[Parameter]
public bool Show { get; set; }
private string data = "";
private string PathIsNot = "hidden";
public void Clear()
{
data = "";
PathIsNot = "hidden";
StateHasChanged();
}
public void UpdatePath(List<NavigationPathEdge> path)
{
if (path.Count > 0)
{
var inPath = $"M {path[0].StartX} {path[0].StartY}";
for (int i = 0; i < path.Count; i++)
{
if(path[i].Degree == 1) inPath = $"{inPath} L {path[i].EndX} {path[i].EndY}";
else if (path[i].Degree == 2) inPath = $"{inPath} Q {path[i].ControlPoint1X} {path[i].ControlPoint1Y} {path[i].EndX} {path[i].EndY}";
else inPath = $"{inPath} C {path[i].ControlPoint1X} {path[i].ControlPoint1Y}, {path[i].ControlPoint2X} {path[i].ControlPoint2Y}, {path[i].EndX} {path[i].EndY}";
}
data = inPath;
PathIsNot = "visible";
}
else Clear();
StateHasChanged();
}
}

View File

@@ -0,0 +1,128 @@
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@using RobotNet.MapShares.Models
@inject IConfiguration Configuration
@inject IJSRuntime JSRuntime
@inject IHttpClientFactory HttpClientFactory
<div class="data-preview">
<div class="d-flex" style="height: fit-content;">
<MudTextField Class="mt-1 ms-2 d-flex justify-content-center" T="string" Value="FilterLog" Adornment="Adornment.End" ValueChanged="OnSearch" AdornmentIcon="@Icons.Material.Filled.Search"
IconSize="Size.Medium" Variant="Variant.Text" Margin="Margin.Dense" AdornmentColor="Color.Secondary" Label="Search" />
<MudSpacer />
<div class="m-1 d-flex flex-row">
<MudDatePicker Class="mx-4" Label="Date" Date="DateLog" DateChanged="OnDateChanged" MaxDate="DateTime.Today" Variant="Variant.Text" Color="Color.Primary"
ShowToolbar="false" Margin="Margin.Dense" AdornmentColor="Color.Primary" />
<MudTooltip Text="Refresh">
<MudFab Class="mx-4 mt-2" StartIcon="@Icons.Material.Filled.Refresh" Color="Color.Primary" Size="Size.Small" OnClick="@(async() => await LoadLogs(false))" />
</MudTooltip>
</div>
</div>
<div class="content">
<div class="log-container" @ref="LogContainerRef">
@foreach (var log in SearchLogs)
{
<div class="log">
<span class="log-head">
@log.Time <span class="log-level">@log.Level</span>
</span>
<span class="@log.ColorClass">@log.Message</span>
@if (log.HasException)
{
<br />
<pre class="log-exception">
@log.Exception
</pre>
}
</div>
}
</div>
</div>
<MudOverlay @bind-Visible="IsLoading" DarkBackground="true" Absolute="true">
<MudText Typo="Typo.h1" Color="@Color.Error" Style="font-weight: bold;">Loadding...</MudText>
</MudOverlay>
</div>
@code {
private DateTime DateLog = DateTime.Today;
private bool IsLoading;
private readonly List<string> ShowLogs = new();
private readonly List<LoggerModel> SearchLogs = new();
private string? FilterLog { get; set; }
private ElementReference LogContainerRef { get; set; }
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (!firstRender) return;
await LoadLogs(true);
}
private async Task LoadLogs(bool firstRender)
{
try
{
if(!firstRender)
{
IsLoading = true;
ShowLogs.Clear();
StateHasChanged();
}
var Http = HttpClientFactory.CreateClient("RobotManagerAPI");
var logs = await Http.GetFromJsonAsync<IEnumerable<string>>($"api/RobotManagerLogger/open-acs?date={DateLog}");
ShowLogs.AddRange(logs ?? []);
IsLoading = false;
StateHasChanged();
await ReloadLogs();
}
catch (AccessTokenNotAvailableException ex)
{
ex.Redirect();
return;
}
}
private async Task ReloadLogs()
{
IsLoading = true;
SearchLogs.Clear();
StateHasChanged();
foreach (var line in ShowLogs.Where(log => string.IsNullOrEmpty(FilterLog) || log.Contains(FilterLog)).TakeLast(2000))
{
try
{
var log = System.Text.Json.JsonSerializer.Deserialize<LoggerModel>(line);
if (log is not null) SearchLogs.Add(log);
}
catch (System.Text.Json.JsonException)
{
continue;
}
}
IsLoading = false;
StateHasChanged();
await JSRuntime.InvokeVoidAsync("ScrollToBottom", LogContainerRef);
}
private async Task OnSearch(string text)
{
FilterLog = text;
await ReloadLogs();
}
private async Task OnDateChanged(DateTime? date)
{
if (date is not null && date.HasValue)
{
DateLog = date.Value;
await LoadLogs(false);
}
}
}

View File

@@ -0,0 +1,57 @@
.data-preview {
display: flex;
height: 100%;
width: 100%;
flex-direction: column;
border: 1px solid silver;
border-radius: 5px;
position: relative;
}
.data-preview .content {
display: flex;
font-size: 13px;
overflow-x: hidden;
overflow-y: auto;
flex-grow: 1;
padding: 5px;
position: relative;
}
.data-preview .content.log-container {
display: flex;
height: 100%;
width: 100%;
position: absolute;
top: 0px;
left: 0px;
padding: 10px;
flex-direction: column;
}
.log {
word-wrap: break-word;
line-height: 18px;
margin-bottom: 5px;
}
.log-logger {
color: rgba(0, 0, 0, 0.3);
font-size: 12px;
}
.log-level {
display: inline-block;
width: 46px;
}
.log-head {
border-radius: 3px;
padding: 2px 5px;
}
.log-exception {
line-height: 16px;
margin-left: 30px;
color: crimson;
}

View File

@@ -0,0 +1,111 @@
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@inject ISnackbar Snackbar
@inject IHttpClientFactory HttpClientFactory
<MudCard Class="w-100 me-2 position-relative mt-2" Elevation="0" Outlined Style="height: 350px">
<MudCardHeader>
<MudText Typo="Typo.h5">Dashboard Mission Names</MudText>
</MudCardHeader>
<MudCardContent>
<div class="d-flex flex-column">
<div class="d-flex flex-row">
<MudTextField Label="Mission Name" Variant="Variant.Outlined" @bind-Value="MissionName" ShrinkLabel />
<MudButton Class="mt-2 mb-1 ms-2" Variant="Variant.Filled" Color="Color.Info" OnClick="Add">Add</MudButton>
</div>
<div class="d-flex flex-wrap overflow-x-hidden overflow-y-auto mt-2" style="border: 1px solid silver; height: 115px; border-radius: 5px">
@foreach(var missionName in MissionNames)
{
<div class="m-1" style="height: fit-content">
<MudButton Variant="Variant.Filled" Color="Color.Tertiary" Style="text-transform:none" OnClick="@(() => MissionNames.Remove(missionName))">
@missionName
</MudButton>
</div>
}
</div>
<div class="d-flex flex-row-reverse mt-4">
<div>
<MudButton Class="d-flex flex-grow-1 mt-2 mb-1 ms-2" Variant="Variant.Filled" Color="Color.Info" OnClick="Update">Update</MudButton>
</div>
</div>
</div>
</MudCardContent>
<MudOverlay Visible="OverlayIsVisible" DarkBackground="true" Absolute="true">
<MudProgressCircular Color="Color.Secondary" Indeterminate="true" />
</MudOverlay>
</MudCard>
@code {
private List<string> MissionNames = [];
private bool OverlayIsVisible;
private string MissionName = "";
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (!firstRender) return;
await LoadMisison();
}
private async Task LoadMisison()
{
try
{
OverlayIsVisible = true;
StateHasChanged();
using var client = HttpClientFactory.CreateClient("ScriptManagerAPI");
var mission = await client.GetFromJsonAsync<MessageResult<string[]>>("api/DashboardConfig");
if (mission is null || mission.Data is null || !mission.IsSuccess) MissionNames = [];
else MissionNames = [.. mission.Data];
OverlayIsVisible = false;
StateHasChanged();
}
catch (AccessTokenNotAvailableException ex)
{
ex.Redirect();
}
}
private async Task Update()
{
try
{
OverlayIsVisible = true;
StateHasChanged();
using var Http = HttpClientFactory.CreateClient("ScriptManagerAPI");
var result = await (await Http.PostAsJsonAsync($"api/DashboardConfig", MissionNames)).Content.ReadFromJsonAsync<MessageResult>();
if (result is null) { Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Warning); return; }
else if (!result.IsSuccess) { Snackbar.Add(result.Message ?? "Cập nhật không thành công", Severity.Warning); return; }
OverlayIsVisible = false;
Snackbar.Add("Cập nhật thành công", Severity.Success);
StateHasChanged();
}
catch (AccessTokenNotAvailableException ex)
{
ex.Redirect();
}
}
private void Add()
{
if (string.IsNullOrEmpty(MissionName))
{
Snackbar.Add("Vui lòng nhập mission name", Severity.Warning);
return;
}
if (MissionNames.Contains(MissionName))
{
Snackbar.Add("Mission name đã tồn tại", Severity.Warning);
return;
}
MissionNames.Add(MissionName);
StateHasChanged();
}
}

View File

@@ -0,0 +1,128 @@
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@using RobotNet.RobotShares.OpenACS
@inject IHttpClientFactory HttpClientFactory
@inject ISnackbar Snackbar
<MudCard Class="w-100 me-2 position-relative" Elevation="0" Outlined Style="height: 350px">
<MudCardHeader>
<MudText Typo="Typo.h5">Publish Setting</MudText>
</MudCardHeader>
<MudCardContent>
<div class="d-flex flex-column">
<MudSwitch @bind-Value="NewSettingDto.IsPublishEnabled" Color="Color.Primary" Label="Enable" @bind-Value:after="EnableChanged" />
<MudAutocomplete T="string" Variant="Variant.Outlined" Label="Url" ShrinkLabel Disabled="@NewSettingDto.IsPublishEnabled" Modal SearchFunc="UrlSearch"
CoerceText="false" CoerceValue="true" MaxItems="NewSettingDto.PublishUrlsUsed.Length" ShowProgressIndicator="true" @bind-Value="NewSettingDto.PublishUrl">
</MudAutocomplete>
<MudNumericField T="int" Label="Interval(ms)" @bind-Value="NewSettingDto.PublishInterval" Disabled="@NewSettingDto.IsPublishEnabled" Variant="Variant.Outlined" Min="500" />
<div class="d-flex flex-row-reverse mt-4">
<div>
<MudButton Class="d-flex flex-grow-1 mt-2 mb-1 ms-2" Variant="Variant.Filled" Color="Color.Info" Disabled="@NewSettingDto.IsPublishEnabled" OnClick="Update">Update</MudButton>
</div>
</div>
</div>
</MudCardContent>
<MudOverlay Visible="OverlayIsVisible" DarkBackground="true" Absolute="true">
<MudProgressCircular Color="Color.Secondary" Indeterminate="true" />
</MudOverlay>
</MudCard>
@code {
[Parameter, EditorRequired]
public OpenACSPublishSettingDto SettingDto { get; set; } = new(false, "", [], 2000);
private OpenACSPublishSettingDto NewSettingDto { get; set; } = new(false, "", [], 2000);
private bool OverlayIsVisible;
public void UpdateSettings(OpenACSPublishSettingDto settings)
{
SettingDto = settings;
NewSettingDto = new()
{
IsPublishEnabled = SettingDto.IsPublishEnabled,
PublishInterval = SettingDto.PublishInterval,
PublishUrl = SettingDto.PublishUrl,
PublishUrlsUsed = SettingDto.PublishUrlsUsed,
};
StateHasChanged();
}
private async Task<IEnumerable<string>> UrlSearch(string value, CancellationToken token)
{
await Task.Delay(5, token);
if (string.IsNullOrEmpty(value))
{
return SettingDto.PublishUrlsUsed;
}
return SettingDto.PublishUrlsUsed.Where(x => x.Contains(value, StringComparison.InvariantCultureIgnoreCase));
}
private async Task Update()
{
try
{
if (NewSettingDto.PublishUrl == SettingDto.PublishUrl && NewSettingDto.PublishInterval == SettingDto.PublishInterval)
{
Snackbar.Add("Không có thay đổi nào để cập nhật", Severity.Warning);
return;
}
OverlayIsVisible = true;
StateHasChanged();
using var Http = HttpClientFactory.CreateClient("RobotManagerAPI");
var result = await (await Http.PostAsJsonAsync($"api/OpenACSSettings/publish", new OpenACSPublishSettingModel(NewSettingDto.PublishUrl, NewSettingDto.PublishInterval))).Content.ReadFromJsonAsync<MessageResult<OpenACSPublishSettingDto>>();
if (result is null) { Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Warning); return; }
else if (!result.IsSuccess) { Snackbar.Add(result.Message ?? "Cập nhật không thành công", Severity.Warning); return; }
else if (result.Data == null)
{
Snackbar.Add("Lỗi dữ liệu trả về", Severity.Warning);
return;
}
SettingDto = result.Data;
NewSettingDto = new()
{
IsPublishEnabled = SettingDto.IsPublishEnabled,
PublishInterval = SettingDto.PublishInterval,
PublishUrl = SettingDto.PublishUrl,
PublishUrlsUsed = SettingDto.PublishUrlsUsed,
};
OverlayIsVisible = false;
Snackbar.Add("Cập nhật thành công", Severity.Success);
StateHasChanged();
}
catch (AccessTokenNotAvailableException ex)
{
ex.Redirect();
}
}
private async Task EnableChanged()
{
try
{
OverlayIsVisible = true;
StateHasChanged();
using var Http = HttpClientFactory.CreateClient("RobotManagerAPI");
var result = await Http.GetFromJsonAsync<MessageResult>($"api/OpenACSSettings/publish?enable={NewSettingDto.IsPublishEnabled}");
if (result is null) { Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error); return; }
else if (!result.IsSuccess) { Snackbar.Add(result.Message ?? "Cập nhật không thành công", Severity.Warning); return; }
SettingDto.IsPublishEnabled = NewSettingDto.IsPublishEnabled;
OverlayIsVisible = false;
StateHasChanged();
}
catch (AccessTokenNotAvailableException ex)
{
ex.Redirect();
}
}
}

View File

@@ -0,0 +1,59 @@
@using RobotNet.RobotShares.OpenACS
@inject IHttpClientFactory HttpFactory
@inject ISnackbar Snackbar
<div class="view-paper">
<div class="d-flex" style="height: fit-content;">
<MudSelect Class="mt-1 ms-2 d-flex justify-content-center" T="RobotACSLockedDto" Adornment="Adornment.End" @bind-Value="RobotSeleced"
IconSize="Size.Medium" Variant="Variant.Text" Margin="Margin.Dense" AdornmentColor="Color.Secondary" Label="Robot">
@foreach(var robot in RobotACSLockedDto)
{
<MudSelectItem Value="robot">@robot.RobotId</MudSelectItem>
}
</MudSelect>
<MudSpacer />
<div class="m-1 d-flex flex-row">
<MudTooltip Text="Refresh">
<MudFab Class="mx-4 mt-2" StartIcon="@Icons.Material.Filled.Refresh" Color="Color.Primary" Size="Size.Small" OnClick="@(async () => await LoadRobots())" />
</MudTooltip>
</div>
</div>
<div class="content">
@if(RobotSeleced is not null)
{
foreach(var zone in RobotSeleced.ZoneIds)
{
<div class="zone">
<span>@zone</span>
</div>
}
}
</div>
</div>
@code {
private RobotACSLockedDto[] RobotACSLockedDto = [];
private RobotACSLockedDto? RobotSeleced = null;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (!firstRender) return;
await LoadRobots();
}
private async Task LoadRobots()
{
RobotACSLockedDto = [];
using var Http = HttpFactory.CreateClient("RobotManagerAPI");
var robots = await Http.GetFromJsonAsync<RobotACSLockedDto[]>("api/TrafficACSRequest");
if (robots is null) Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error);
else if (robots.Length > 0)
{
RobotACSLockedDto = [..robots.OrderByDescending(robot => robot.RobotId)];
RobotSeleced = RobotACSLockedDto.First();
}
StateHasChanged();
}
}

View File

@@ -0,0 +1,29 @@
.view-paper {
display: flex;
width: 100%;
height: 100%;
border: 1px solid silver;
border-radius: 5px;
position: relative;
flex-direction: column;
}
.view-paper .content {
display: flex;
overflow-x: hidden;
overflow-y: auto;
flex-grow: 1;
padding: 5px;
position: relative;
}
.view-paper .content .zone {
margin: 5px;
border: 1px solid silver;
padding: 5px;
height: fit-content;
width: fit-content;
font-size: 13px;
border-radius: 5px;
flex-wrap: wrap;
}

View File

@@ -0,0 +1,104 @@
@using RobotNet.RobotShares.OpenACS
@inject ISnackbar Snackbar
@inject IHttpClientFactory HttpClientFactory
<MudCard Class="w-100 me-2 position-relative mt-2" Elevation="0" Outlined Style="height: 370px">
<MudCardHeader>
<MudText Typo="Typo.h5">Traffic Request</MudText>
</MudCardHeader>
<MudCardContent>
<div class="d-flex flex-column">
<MudAutocomplete T="string" Variant="Variant.Outlined" Label="Robot Id" ShrinkLabel Modal SearchFunc="UrlSearch"
CoerceText="false" CoerceValue="true" MaxItems="Robots.Length" ShowProgressIndicator="true" @bind-Value="RobotId">
</MudAutocomplete>
<MudTextField Label="Zone Id" Variant="Variant.Outlined" @bind-Value="ZoneId" ShrinkLabel />
<MudSelect T="TrafficRequestType" Label="Type" @bind-Value="@Type" Variant="Variant.Outlined">
@foreach (TrafficRequestType item in Enum.GetValues(typeof(TrafficRequestType)))
{
<MudSelectItem Value="@item" />
}
</MudSelect>
<div class="d-flex flex-row-reverse mt-4">
<div>
<MudButton Class="d-flex flex-grow-1 mt-2 mb-1 ms-2" Variant="Variant.Filled" Color="Color.Info" OnClick="Request">Request</MudButton>
</div>
</div>
</div>
</MudCardContent>
<MudOverlay Visible="OverlayIsVisible" DarkBackground="true" Absolute="true">
<MudProgressCircular Color="Color.Secondary" Indeterminate="true" />
</MudOverlay>
</MudCard>
@code {
private bool OverlayIsVisible;
private RobotDto[] Robots = [];
private string RobotId = string.Empty;
private string ZoneId = string.Empty;
private TrafficRequestType Type = TrafficRequestType.OUT;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (!firstRender) return;
await LoadRobots();
}
private async Task LoadRobots()
{
OverlayIsVisible = true;
StateHasChanged();
using var Http = HttpClientFactory.CreateClient("RobotManagerAPI");
var robots = await Http.GetFromJsonAsync<MessageResult<IEnumerable<RobotDto>>>("api/Robots");
if (robots is null) Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error);
else if (!robots.IsSuccess) Snackbar.Add($"Có lỗi xảy ra: {robots.Message}", Severity.Error);
else if (robots.Data is not null && robots.Data.Any())
{
Robots = [..robots.Data];
}
OverlayIsVisible = false;
StateHasChanged();
}
private async Task<IEnumerable<string>> UrlSearch(string value, CancellationToken token)
{
await Task.Delay(5, token);
if (string.IsNullOrEmpty(value))
{
return Robots.Select(n => n.Name);
}
return Robots.Where(x => x.Name.Contains(value, StringComparison.InvariantCultureIgnoreCase)).Select(n => n.Name);
}
private async Task Request()
{
if(string.IsNullOrEmpty(RobotId))
{
Snackbar.Add($"Trường thông tin Robot Id không được để trống", Severity.Warning);
return;
}
if (string.IsNullOrEmpty(ZoneId))
{
Snackbar.Add($"Trường thông tin Zone Id không được để trống", Severity.Warning);
return;
}
OverlayIsVisible = true;
StateHasChanged();
using var Http = HttpClientFactory.CreateClient("RobotManagerAPI");
var request = await (await Http.PostAsJsonAsync("api/TrafficACSRequest", new TrafficACSRequestModel() { RobotId = RobotId, ZoneId = ZoneId, Type = Type})).Content.ReadFromJsonAsync<MessageResult<bool>>();
if (request is null) Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Warning);
else if (!request.IsSuccess) Snackbar.Add($"Có lỗi xảy ra: {request.Message}", Severity.Warning);
else if (!request.Data) Snackbar.Add("ACS trả về không thành công thành công", Severity.Warning);
else if (request.Data) Snackbar.Add($"{(string.IsNullOrEmpty(request.Message) ? "Yêu cầu thành công" : request.Message)}", Severity.Success);
OverlayIsVisible = false;
StateHasChanged();
}
}

View File

@@ -0,0 +1,124 @@
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@using RobotNet.RobotShares.OpenACS
@inject IHttpClientFactory HttpClientFactory
@inject ISnackbar Snackbar
<MudCard Class="w-100 me-2 position-relative mt-2" Elevation="0" Outlined Style="height: 280px">
<MudCardHeader>
<MudText Typo="Typo.h5">Traffic Setting</MudText>
</MudCardHeader>
<MudCardContent>
<div class="d-flex flex-column">
<MudSwitch @bind-Value="NewSettingDto.IsTrafficEnabled" Color="Color.Primary" Label="Enable" @bind-Value:after="EnableChanged" />
<MudAutocomplete T="string" Variant="Variant.Outlined" Label="Url" ShrinkLabel Disabled="@NewSettingDto.IsTrafficEnabled" Modal SearchFunc="UrlSearch"
CoerceText="false" CoerceValue="true" MaxItems="NewSettingDto.PublishUrlsUsed.Length" ShowProgressIndicator="true" @bind-Value="NewSettingDto.TrafficUrl">
</MudAutocomplete>
<div class="d-flex flex-row-reverse mt-4">
<div>
<MudButton Class="d-flex flex-grow-1 mt-2 mb-1 ms-2" Variant="Variant.Filled" Color="Color.Info" Disabled="@NewSettingDto.IsTrafficEnabled" OnClick="Update">Update</MudButton>
</div>
</div>
</div>
</MudCardContent>
<MudOverlay Visible="OverlayIsVisible" DarkBackground="true" Absolute="true">
<MudProgressCircular Color="Color.Secondary" Indeterminate="true" />
</MudOverlay>
</MudCard>
@code {
[Parameter, EditorRequired]
public OpenACSTrafficSettingDto SettingDto { get; set; } = new(false, "", []);
private OpenACSTrafficSettingDto NewSettingDto { get; set; } = new(false, "", []);
private bool OverlayIsVisible;
public void UpdateSettings(OpenACSTrafficSettingDto settings)
{
SettingDto = settings;
NewSettingDto = new()
{
IsTrafficEnabled = SettingDto.IsTrafficEnabled,
TrafficUrl = SettingDto.TrafficUrl,
PublishUrlsUsed = SettingDto.PublishUrlsUsed,
};
StateHasChanged();
}
private async Task<IEnumerable<string>> UrlSearch(string value, CancellationToken token)
{
await Task.Delay(5, token);
if (string.IsNullOrEmpty(value))
{
return SettingDto.PublishUrlsUsed;
}
return SettingDto.PublishUrlsUsed.Where(x => x.Contains(value, StringComparison.InvariantCultureIgnoreCase));
}
private async Task Update()
{
try
{
if (NewSettingDto.TrafficUrl == SettingDto.TrafficUrl)
{
Snackbar.Add("Không có thay đổi nào để cập nhật", Severity.Warning);
return;
}
OverlayIsVisible = true;
StateHasChanged();
using var Http = HttpClientFactory.CreateClient("RobotManagerAPI");
var result = await (await Http.PostAsJsonAsync($"api/OpenACSSettings/traffic", new OpenACSTrafficSettingModel(NewSettingDto.TrafficUrl))).Content.ReadFromJsonAsync<MessageResult<OpenACSTrafficSettingDto>>();
if (result is null) { Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Warning); return; }
else if (!result.IsSuccess) { Snackbar.Add(result.Message ?? "Cập nhật không thành công", Severity.Warning); return; }
else if (result.Data == null)
{
Snackbar.Add("Lỗi dữ liệu trả về", Severity.Warning);
return;
}
SettingDto = result.Data;
NewSettingDto = new()
{
IsTrafficEnabled = SettingDto.IsTrafficEnabled,
TrafficUrl = SettingDto.TrafficUrl,
PublishUrlsUsed = SettingDto.PublishUrlsUsed,
};
OverlayIsVisible = false;
Snackbar.Add("Cập nhật thành công", Severity.Success);
StateHasChanged();
}
catch (AccessTokenNotAvailableException ex)
{
ex.Redirect();
}
}
private async Task EnableChanged()
{
try
{
OverlayIsVisible = true;
StateHasChanged();
using var Http = HttpClientFactory.CreateClient("RobotManagerAPI");
var result = await Http.GetFromJsonAsync<MessageResult>($"api/OpenACSSettings/traffic?enable={NewSettingDto.IsTrafficEnabled}");
if (result is null) { Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Warning); return; }
else if (!result.IsSuccess) { Snackbar.Add(result.Message ?? "Cập nhật không thành công", Severity.Warning); return; }
SettingDto.IsTrafficEnabled = NewSettingDto.IsTrafficEnabled;
OverlayIsVisible = false;
StateHasChanged();
}
catch (AccessTokenNotAvailableException ex)
{
ex.Redirect();
}
}
}

View File

@@ -0,0 +1,310 @@
@implements IAsyncDisposable
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@using RobotNet.WebApp.Clients
@inject RobotHubClient RobotHub
@inject ISnackbar Snackbar
@inject IHttpClientFactory HttpFactory
<MudCard Class="w-100 me-2 position-relative" Elevation="0" Outlined Style="height: 450px">
<MudCardHeader>
<MudText Typo="Typo.h5">Setting</MudText>
<MudSpacer />
<MudText Typo="Typo.subtitle1">@Robot.Name</MudText>
</MudCardHeader>
<MudCardContent>
<div class="d-flex flex-column">
<div class="d-flex flex-row my-2">
<div class="d-flex flex-row" style="width: 350px">
<MudAutocomplete T="MapInfoDto" Variant="Variant.Outlined" Label="Map" ShrinkLabel Disabled="!Robot.Online" Modal SearchFunc="MapSearch"
ToStringFunc="@(e=> e == null ? null : $"{e.Name}")" MaxItems="Maps.Count" ValueChanged="MapChanged" ShowProgressIndicator="true">
<NoItemsTemplate>
<MudText Align="Align.Center" Class="px-4 py-1">
No items found
</MudText>
</NoItemsTemplate>
</MudAutocomplete>
</div>
<MudButton Class="d-flex flex-grow-1 mt-2 mb-1 ms-2" Variant="Variant.Filled" Color="Color.Info" Disabled="!Robot.Online" OnClick="SetMap">SetMap</MudButton>
</div>
<div class="d-flex flex-row my-2">
<div class="d-flex flex-row" style="width: 350px">
<MudAutocomplete T="string" Variant="Variant.Outlined" Label="Node" ShrinkLabel Disabled="!Robot.Online" Modal SearchFunc="NodeSearch" ShowProgressIndicator="true"
MaxItems="@Nodes.Count" ValueChanged="NodeChanged">
<NoItemsTemplate>
<MudText Align="Align.Center" Class="px-4 py-1">
No items found
</MudText>
</NoItemsTemplate>
</MudAutocomplete>
<MudButton Class="ms-2 mt-2 mb-1" Variant="Variant.Filled" Color="Color.Info" Disabled="@(!Robot.Online || IsWorking)" OnClick="MoveToNode">Move</MudButton>
</div>
<MudButton Class="d-flex flex-grow-1 mt-2 mb-1 ms-2" Variant="Variant.Filled" Color="Color.Secondary" Disabled="@(!Robot.Online)" OnClick="CancelOrder">CancelOrder</MudButton>
</div>
<div class="d-flex flex-row my-2">
<div class="d-flex flex-row" style="width: 350px">
<MudAutocomplete T="ActionDto" Variant="Variant.Outlined" Label="Action" ShrinkLabel Disabled="!Robot.Online" Modal SearchFunc="ActionSearch" ShowProgressIndicator="true"
MaxItems="@Actions.Count" ValueChanged="ActionChanged" ToStringFunc="@(e=> e == null ? null : $"{e.Name}")">
<NoItemsTemplate>
<MudText Align="Align.Center" Class="px-4 py-1">
No items found
</MudText>
</NoItemsTemplate>
</MudAutocomplete>
<MudButton Class="ms-2 mt-2 mb-1" Variant="Variant.Filled" Color="Color.Info" Disabled="@(!Robot.Online || IsWorking)" OnClick="SendAction">Send</MudButton>
</div>
<MudButton Class="d-flex flex-grow-1 mt-2 mb-1 ms-2" Variant="Variant.Filled" Color="Color.Secondary" Disabled="@(!Robot.Online)" OnClick="CancelAction">CancelAction</MudButton>
</div>
<div class="d-flex flex-row my-2">
<div class="d-flex flex-row" style="width: 350px">
<MudNumericField T="double" Label="X(m)" Class="me-2" @bind-Value="InitPosition.X" Disabled="!Robot.Online" Variant="Variant.Outlined"></MudNumericField>
<MudNumericField T="double" Label="Y(m)" Class="me-2" @bind-Value="InitPosition.Y" Disabled="!Robot.Online" Variant="Variant.Outlined"></MudNumericField>
<MudNumericField T="double" Label="Theta(degree)" @bind-Value="InitPosition.Theta" Disabled="!Robot.Online" Variant="Variant.Outlined"></MudNumericField>
</div>
<MudButton Class="d-flex flex-grow-1 ms-2" Variant="Variant.Filled" Color="Color.Info" Disabled="!Robot.Online" OnClick="InitPose">InitPose</MudButton>
</div>
</div>
</MudCardContent>
<MudOverlay Visible="OverlayIsVisible" DarkBackground="true" Absolute="true">
<MudProgressCircular Color="Color.Secondary" Indeterminate="true" />
</MudOverlay>
</MudCard>
@code {
[Parameter, EditorRequired]
public RobotDto Robot { get; set; } = new();
private MapInfoDto MapSelected = default!;
private string SelectedNode = "";
private List<NodeDto> Nodes = [];
private List<MapInfoDto> Maps = [];
private (double X, double Y, double Theta) InitPosition = new();
private bool IsWorking = false;
private bool OverlayIsVisible;
private List<ActionDto> Actions = [];
private ActionDto? ActionSelected = null;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (!firstRender) return;
await RobotHub.StartAsync();
await LoadMaps();
}
public void UpdateState(bool isOnline, bool isWorking)
{
Robot.Online = isOnline;
IsWorking = isWorking;
StateHasChanged();
}
private async Task MoveToNode()
{
if (string.IsNullOrEmpty(SelectedNode))
{
Snackbar.Add("Vui lòng chọn node", Severity.Warning);
}
else
{
OverlayIsVisible = true;
StateHasChanged();
var result = await RobotHub.MoveToNode(Robot.RobotId, SelectedNode);
if (result.IsSuccess) Snackbar.Add("Ra lệnh thành công", Severity.Success);
else Snackbar.Add($"Ra lệnh không thành công: {result.Message}", Severity.Warning);
OverlayIsVisible = false;
}
StateHasChanged();
}
private async Task CancelOrder()
{
OverlayIsVisible = true;
StateHasChanged();
var result = await RobotHub.CancelNavigation(Robot.RobotId);
if (result.IsSuccess) Snackbar.Add("Ra lệnh thành công", Severity.Success);
else Snackbar.Add($"Ra lệnh không thành công: {result.Message}", Severity.Warning);
OverlayIsVisible = false;
StateHasChanged();
}
private async Task SetMap()
{
OverlayIsVisible = true;
StateHasChanged();
var result = await RobotHub.SetMap(Robot.RobotId, MapSelected.Id);
if (result.IsSuccess)
{
Robot.MapId = MapSelected.Id;
await LoadNodes();
await LoadActionAsync();
Snackbar.Add("Ra lệnh thành công", Severity.Success);
}
else Snackbar.Add($"Ra lệnh không thành công: {result.Message}", Severity.Warning);
OverlayIsVisible = false;
StateHasChanged();
}
private async Task InitPose()
{
OverlayIsVisible = true;
StateHasChanged();
var result = await RobotHub.SetInitialPose(Robot.RobotId, InitPosition.X, InitPosition.Y, InitPosition.Theta * Math.PI / 180);
if (result.IsSuccess) Snackbar.Add("Ra lệnh thành công", Severity.Success);
else Snackbar.Add($"Ra lệnh không thành công: {result.Message}", Severity.Warning);
OverlayIsVisible = false;
StateHasChanged();
}
private async Task SendAction()
{
if (ActionSelected is null)
{
Snackbar.Add("Vui lòng chọn action", Severity.Warning);
}
else
{
OverlayIsVisible = true;
StateHasChanged();
var result = await RobotHub.SendAction(Robot.RobotId, ActionSelected);
if (result.IsSuccess) Snackbar.Add("Ra lệnh thành công", Severity.Success);
else Snackbar.Add($"Ra lệnh không thành công: {result.Message}", Severity.Warning);
OverlayIsVisible = false;
}
StateHasChanged();
}
private async Task CancelAction()
{
OverlayIsVisible = true;
StateHasChanged();
var result = await RobotHub.CancelAction(Robot.RobotId);
if (result.IsSuccess) Snackbar.Add("Ra lệnh thành công", Severity.Success);
else Snackbar.Add($"Ra lệnh không thành công: {result.Message}", Severity.Warning);
OverlayIsVisible = false;
StateHasChanged();
}
public async Task LoadActionAsync()
{
Actions.Clear();
using var Http = HttpFactory.CreateClient("MapManagerAPI");
var result = await Http.GetFromJsonAsync<IEnumerable<ActionDto>>($"api/Actions/{Robot.MapId}");
if (result is not null && result.Any())
{
Actions.AddRange(result);
}
if (Actions.Any()) ActionSelected = Actions.First();
StateHasChanged();
}
public async Task LoadNodes()
{
try
{
using var Http = HttpFactory.CreateClient("MapManagerAPI");
var result = await Http.GetFromJsonAsync<NodeDto[]>($"api/Nodes/{Robot.MapId}");
if (result is not null) Nodes = result.Where(n => !string.IsNullOrEmpty(n.Name)).ToList();
}
catch (AccessTokenNotAvailableException ex)
{
ex.Redirect();
}
}
private async Task LoadMaps()
{
try
{
Maps.Clear();
using var Http = HttpFactory.CreateClient("MapManagerAPI");
var maps = await Http.GetFromJsonAsync<IEnumerable<MapInfoDto>>($"api/MapsManager?txtSearch=");
Maps.AddRange(maps ?? []);
StateHasChanged();
}
catch (AccessTokenNotAvailableException ex)
{
ex.Redirect();
return;
}
}
private async Task<IEnumerable<MapInfoDto>> MapSearch(string value, CancellationToken token)
{
await Task.Delay(5, token);
if (string.IsNullOrEmpty(value))
{
return Maps;
}
return Maps.Where(x => x.Name.Contains(value, StringComparison.InvariantCultureIgnoreCase));
}
private async Task<IEnumerable<string>> NodeSearch(string value, CancellationToken token)
{
await Task.Delay(5, token);
if (string.IsNullOrEmpty(value))
{
return Nodes.Select(n => n.Name);
}
return Nodes.Where(x => x.Name.Contains(value, StringComparison.InvariantCultureIgnoreCase)).Select(n => n.Name);
}
private async Task<IEnumerable<ActionDto>> ActionSearch(string value, CancellationToken token)
{
await Task.Delay(5, token);
if (string.IsNullOrEmpty(value))
{
return Actions;
}
return Actions.Where(x => x.Name.Contains(value, StringComparison.InvariantCultureIgnoreCase));
}
private void NodeChanged(string value)
{
if (string.IsNullOrEmpty(SelectedNode) || value != SelectedNode) SelectedNode = value;
}
private void ActionChanged(ActionDto value)
{
if (ActionSelected is null || value.Id != ActionSelected.Id) ActionSelected = value;
}
private void MapChanged(MapInfoDto value)
{
if (MapSelected is null || value.Id != MapSelected.Id) MapSelected = value;
}
public async ValueTask DisposeAsync()
{
await RobotHub.StopAsync();
}
}

View File

@@ -0,0 +1,129 @@
@using System.Text.Json
<div class="data-preview">
<div class="d-flex" style="height: fit-content;">
<MudToggleGroup Class="w-100" T="DataPreviewType" SelectionMode="SelectionMode.SingleSelection" @bind-Value="DataType" Color="Color.Default"
Outlined="false" SelectedClass="custom-background" @bind-Value:after="DataTypeChanged" Disabled="!RobotState.Online">
<MudToggleItem Value="@(DataPreviewType.Visualization)" Style="text-transform:none" />
<MudToggleItem Value="@(DataPreviewType.Node)" Style="text-transform:none" />
<MudToggleItem Value="@(DataPreviewType.Edge)" Style="text-transform:none" />
<MudToggleItem Value="@(DataPreviewType.Order)" Style="text-transform:none" />
<MudToggleItem Value="@(DataPreviewType.Action)" Style="text-transform:none" />
<MudToggleItem Value="@(DataPreviewType.Infomation)" Style="text-transform:none" />
<MudToggleItem Value="@(DataPreviewType.Battery)" Style="text-transform:none" />
<MudToggleItem Value="@(DataPreviewType.Error)" Style="text-transform:none" />
</MudToggleGroup>
</div>
<div class="content">
@DataPreview
</div>
</div>
<style>
.custom-background {
background-color: #283593;
color: white !important;
}
.custom-background:hover {
background-color: #283593;
color: white !important;
}
</style>
@code {
private DataPreviewType DataType;
private string DataPreview = "";
private RobotVDA5050StateDto RobotState = new();
public void UpdateState(RobotVDA5050StateDto robotstate)
{
RobotState = robotstate;
DataTypeChanged();
StateHasChanged();
}
private void DataTypeChanged()
{
switch (DataType)
{
case DataPreviewType.Visualization:
DataPreview = JsonSerializer.Serialize(RobotState.Visualization, JsonOptionExtends.Read);
break;
case DataPreviewType.Node:
DataPreview = JsonSerializer.Serialize(RobotState.State.NodeStates, JsonOptionExtends.Read);
break;
case DataPreviewType.Edge:
DataPreview = JsonSerializer.Serialize(RobotState.State.EdgeStates, JsonOptionExtends.Read);
break;
case DataPreviewType.Order:
DataPreview = JsonSerializer.Serialize(GetOrderState(RobotState), JsonOptionExtends.Read);
break;
case DataPreviewType.Action:
DataPreview = JsonSerializer.Serialize(RobotState.State.ActionStates, JsonOptionExtends.Read);
break;
case DataPreviewType.Infomation:
DataPreview = JsonSerializer.Serialize(RobotState.State.Information, JsonOptionExtends.Read);
break;
case DataPreviewType.Battery:
DataPreview = JsonSerializer.Serialize(RobotState.State.BatteryState, JsonOptionExtends.Read);
break;
case DataPreviewType.Error:
DataPreview = JsonSerializer.Serialize(RobotState.State.Errors, JsonOptionExtends.Read);
break;
};
StateHasChanged();
}
private OrderState GetOrderState(RobotVDA5050StateDto state)
{
return new()
{
OrderId = state.State.OrderId,
OrderUpdateId = state.State.OrderUpdateId,
ZoneSetId = state.State.ZoneSetId,
LastNodeId = state.State.LastNodeId,
LastNodeSequenceId = state.State.LastNodeSequenceId,
Driving = state.State.Driving,
Paused = state.State.Paused,
NewBaseRequest = state.State.NewBaseRequest,
DistanceSinceLastNode = state.State.DistanceSinceLastNode,
OperatingMode = state.State.OperatingMode,
IsCanceled = state.OrderState.IsCanceled,
IsCompleted = state.OrderState.IsCompleted,
IsError = state.OrderState.IsError,
IsProcessing = state.OrderState.IsProcessing,
};
}
public enum DataPreviewType
{
Visualization,
Node,
Edge,
Order,
Action,
Infomation,
Battery,
Error
}
public class OrderState
{
public string OrderId { get; set; } = "";
public int OrderUpdateId { get; set; }
public string ZoneSetId { get; set; } = "";
public string LastNodeId { get; set; } = "";
public int LastNodeSequenceId { get; set; }
public bool Driving { get; set; }
public bool Paused { get; set; }
public bool NewBaseRequest { get; set; }
public double DistanceSinceLastNode { get; set; }
public string OperatingMode { get; set; } = "";
public bool IsError { get; set; }
public bool IsCompleted { get; set; }
public bool IsProcessing { get; set; }
public bool IsCanceled { get; set; }
}
}

View File

@@ -0,0 +1,19 @@
.data-preview {
display: flex;
height: 100%;
width: 100%;
flex-direction: column;
border: 1px solid silver;
border-radius: 5px;
}
.data-preview .content {
display: flex;
white-space: pre;
overflow-y: auto;
overflow-x: hidden;
font-size: 15px;
flex-grow: 1;
border-top: 1px solid silver;
padding: 5px;
}

View File

@@ -0,0 +1,160 @@
@using System.Net.Http.Headers
@inject IHttpClientFactory HttpFactory
@inject IJSRuntime JSRuntime
@inject ISnackbar Snackbar
<div class="d-flex flex-column">
<span Class="title">@RobotModelName</span>
<div class="d-flex flex-grow-1 w-100 flex-column">
<div class="robot-item">
<img src="@imageSrc" alt="robot model image" onerror="this.onerror=null; this.src='/images/Image-not-found.png';" />
</div>
<div class="d-flex flex-row m-3 align-items-center justify-content-between">
<MudText Typo="Typo.h5">Image</MudText>
<div class="d-flex flex-row">
<MudIconButton Class="me-3" Size="Size.Small" Variant="Variant.Filled" Icon="@Icons.Material.Filled.Download" Color="Color.Primary" Disabled="@Disable" OnClick="@(async () => await DownloadImage())" />
<MudIconButton Class="me-3" Size="Size.Small" Variant="Variant.Filled" Icon="@Icons.Material.Filled.Upload" Color="Color.Primary" Disabled="@Disable" OnClick="OpenUpdateRobotImage" />
</div>
</div>
</div>
</div>
<MudDialog @bind-Visible="@IsUpdateRobotImageVisable">
<TitleContent>
<MudText Typo="Typo.h6">
Update RobotModel's Image
</MudText>
</TitleContent>
<DialogContent>
<div class="d-flex flex-column w-100 h-100 px-3">
<div class="d-flex flex-row mb-2">
<InputFile id="fileRobotImageCreate" OnChange="RobotImageChanged" accept=".png" hidden />
<MudButton HtmlTag="label"
Variant="Variant.Filled"
Color="Color.Primary"
StartIcon="@Icons.Material.Filled.CloudUpload"
for="fileRobotImageCreate">
Robot Model Image
</MudButton>
</div>
<div class="d-flex mb-2">
<div class="robot-update-item">
<img alt="Robot Model Image" src="@ImagePreview" style="image-rendering: pixelated;" />
</div>
</div>
</div>
</DialogContent>
<DialogActions>
<MudButton OnClick="@(() => IsUpdateRobotImageVisable = false)" Variant="Variant.Filled">Cancel</MudButton>
<MudButton Color="Color.Primary" OnClick="UpdateRobotModelImage" Variant="Variant.Filled">Update</MudButton>
</DialogActions>
</MudDialog>
@code {
private bool Disable = true;
private string imageSrc = "/images/Image-not-found.png";
private string RobotModelName = "Robot Model preview";
private Guid RobotModelId = Guid.Empty;
private string ImagePreview = "";
private IBrowserFile? RobotImageChange;
private bool IsUpdateRobotImageVisable;
public void SetRobotPreview(RobotModelDto? robotmodel)
{
if (robotmodel is null)
{
Disable = true;
RobotModelName = "Robot Model preview";
imageSrc = "/images/Image-not-found.png";
RobotModelId = Guid.Empty;
}
else
{
using var Http = HttpFactory.CreateClient("RobotManagerAPI");
imageSrc = $"{Http.BaseAddress}api/RobotModels/image/{robotmodel.Id}?t={DateTime.Now}";
RobotModelName = robotmodel.ModelName;
RobotModelId = robotmodel.Id;
Disable = false;
}
StateHasChanged();
}
private async Task DownloadImage()
{
try
{
using var Http = HttpFactory.CreateClient("RobotManagerAPI");
var response = await Http.GetAsync(imageSrc);
if (response.IsSuccessStatusCode)
{
var fileBytes = await response.Content.ReadAsByteArrayAsync();
var base64Data = Convert.ToBase64String(fileBytes);
var mimeType = "image/png";
var url = $"data:{mimeType};base64,{base64Data}";
await JSRuntime.InvokeVoidAsync("DownloadImage", url, $"{RobotModelName}.png");
}
else Snackbar.Add("Không thể tải ảnh robot", Severity.Warning);
}
catch (Exception ex)
{
Snackbar.Add($"Không thể tải ảnh robot: {ex.Message}", Severity.Warning);
}
}
private void OpenUpdateRobotImage()
{
ImagePreview = imageSrc;
RobotImageChange = null;
IsUpdateRobotImageVisable = true;
StateHasChanged();
}
public async Task<string> UploadMedia(IBrowserFile file)
{
var path = Path.Combine(Path.GetTempPath(), RobotModelName);
await using var fs = new FileStream(path, FileMode.Create);
await file.OpenReadStream(file.Size).CopyToAsync(fs);
var bytes = new byte[file.Size];
fs.Position = 0;
await fs.ReadAsync(bytes);
fs.Close();
File.Delete(path);
return $"data:{file.ContentType};base64,{Convert.ToBase64String(bytes)}";
}
private async Task RobotImageChanged(InputFileChangeEventArgs e)
{
RobotImageChange = e.File;
if (RobotImageChange is not null)
{
ImagePreview = await UploadMedia(RobotImageChange);
StateHasChanged();
}
}
private async Task UpdateRobotModelImage()
{
if (RobotImageChange is null) return;
using var content = new MultipartFormDataContent();
var fileContent = new StreamContent(RobotImageChange.OpenReadStream(maxAllowedSize: 20480000));
fileContent.Headers.ContentType = new MediaTypeHeaderValue(RobotImageChange.ContentType);
content.Add(fileContent, "image", RobotImageChange.Name);
using var Http = HttpFactory.CreateClient("RobotManagerAPI");
var result = await (await Http.PutAsync($"api/RobotModels/image/{RobotModelId}", content)).Content.ReadFromJsonAsync<MessageResult>();
if (result is null) Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error);
else if (!result.IsSuccess) Snackbar.Add(result.Message ?? "Lỗi chưa xác định.", Severity.Error);
else
{
imageSrc = ImagePreview;
IsUpdateRobotImageVisable = false;
Snackbar.Add("Thay đổi thành công", Severity.Success);
}
StateHasChanged();
}
}

View File

@@ -0,0 +1,43 @@
.robot-item {
display: flex;
justify-content: center;
width: 100%;
height: fit-content;
}
.robot-item img {
justify-content: center;
max-width: 300px;
width: 95%;
height: 400px;
object-fit: contain;
border-radius: 10px;
image-rendering: pixelated;
}
.title {
display: flex;
height: 77px;
width: 100%;
justify-content: center;
align-content: center;
/*border-bottom: 0.5px solid gray;*/
font-size: 30px;
flex-wrap: wrap;
padding-bottom: .5rem;
}
.robot-update-item {
display: flex;
justify-content: center;
width: 100%;
height: fit-content;
}
.robot-update-item img {
width: 400px;
height: 300px;
object-fit: contain;
border-radius: 10px;
image-rendering: pixelated;
}

View File

@@ -0,0 +1,147 @@
@implements IAsyncDisposable
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@using RobotNet.WebApp.Clients
@inject RobotHubClient RobotHub
@inject ISnackbar Snackbar
@inject IHttpClientFactory HttpFactory
<MudCard Class="w-100 me-2" Elevation="0" Outlined Style="height: 450px">
<MudCardHeader>
<MudText Typo="Typo.h5">Test</MudText>
</MudCardHeader>
<MudCardContent>
<div class="d-flex flex-column">
<div class="d-flex flex-row my-2">
<div class="d-flex flex-row" style="width: 415px">
@* <MudAutocomplete T="NodeDto" Variant="Variant.Outlined" Label="Node" Disabled="!Robot.Online" SearchFunc="NodeSearch"
MaxItems="@Nodes.Count" ToStringFunc="@(e=> e == null ? null : $"{e.Name}")" ValueChanged="NodeChanged" ShowProgressIndicator="true">
<NoItemsTemplate>
<MudText Align="Align.Center" Class="px-4 py-1">
No items found
</MudText>
</NoItemsTemplate>
</MudAutocomplete> *@
<MudSelect T="NodeDto" Label="Node" Variant="Variant.Outlined" MultiSelection="true" SelectAll="true" SelectAllText="Select all nodes" Disabled="!Robot.Online"
@bind-SelectedValues="PreSelectedNodes" HelperText="@($"{PreSelectedNodes.Count()} node{(PreSelectedNodes.Count() > 1 ? "s have" : " has")} been selected")">
@foreach (var node in Nodes)
{
<MudSelectItem T="NodeDto" Value="@node">@node.Name</MudSelectItem>
}
</MudSelect>
</div>
<div class="d-flex flex-grow-1 mt-2 mb-7 ms-2">
<MudButton Class="w-100" Variant="Variant.Filled" Color="Color.Info" Disabled="@(!Robot.Online)" OnClick="AddNode">Add</MudButton>
</div>
</div>
<div class="paper-nodes">
@foreach (var node in SelectedNodes)
{
<div class="m-1" style="height: fit-content">
<MudButton Variant="Variant.Filled" Color="Color.Info" Style="text-transform:none" OnClick="@(() => SelectedNodes.Remove(node))">
@(node.Name)
</MudButton>
</div>
}
</div>
<div class="d-flex w-100 flex-row my-2">
<MudButton Class="d-flex mt-2 mb-1" Variant="Variant.Filled" Color="Color.Info" Disabled="@(!Robot.Online || IsWorking)" OnClick="Run">Run</MudButton>
<MudButton Class="d-flex mt-2 mb-1 ms-2" Variant="Variant.Filled" Color="Color.Secondary" Disabled="@(!Robot.Online)" OnClick="Cancel">Cancel</MudButton>
</div>
</div>
</MudCardContent>
</MudCard>
@code {
[Parameter, EditorRequired]
public RobotDto Robot { get; set; } = new();
// private NodeDto? SelectedNode;
private List<NodeDto> Nodes = [];
private bool IsWorking = false;
private List<NodeDto> SelectedNodes = [];
private IEnumerable<NodeDto> PreSelectedNodes = new HashSet<NodeDto>();
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (!firstRender) return;
await RobotHub.StartAsync();
}
public void UpdateState(bool isOnline, bool isWorking)
{
Robot.Online = isOnline;
IsWorking = isWorking;
StateHasChanged();
}
public async Task LoadNodes()
{
try
{
using var Http = HttpFactory.CreateClient("MapManagerAPI");
var result = await Http.GetFromJsonAsync<NodeDto[]>($"api/Nodes/{Robot.MapId}");
if (result is not null) Nodes = result.Where(n => !string.IsNullOrEmpty(n.Name)).ToList();
}
catch (AccessTokenNotAvailableException ex)
{
ex.Redirect();
}
}
private async Task<IEnumerable<NodeDto>> NodeSearch(string value, CancellationToken token)
{
await Task.Delay(5, token);
if (string.IsNullOrEmpty(value))
{
return Nodes.Select(n => n);
}
return Nodes.Where(x => x.Name.Contains(value, StringComparison.InvariantCultureIgnoreCase)).Select(n => n);
}
// private void NodeChanged(List<NodeDto> value)
// {
// if (SelectedNode is null || value.Id != SelectedNode.Id) SelectedNode = value;
// }
private void AddNode()
{
// if (SelectedNode is not null && !SelectedNodes.Contains(SelectedNode))
// {
// SelectedNodes.Add(SelectedNode);
// StateHasChanged();
// }
if (PreSelectedNodes.Any())
{
SelectedNodes.Clear();
SelectedNodes.AddRange(PreSelectedNodes);
StateHasChanged();
}
}
private async Task Cancel()
{
var result = await RobotHub.CancelNavigation(Robot.RobotId);
if (result.IsSuccess) Snackbar.Add("Ra lệnh thành công", Severity.Success);
else Snackbar.Add($"Ra lệnh không thành công: {result.Message}", Severity.Warning);
StateHasChanged();
}
private async Task Run()
{
var result = await RobotHub.MoveRandom(Robot.RobotId, [.. SelectedNodes.Select(n => n.Name)]);
if (result.IsSuccess) Snackbar.Add("Ra lệnh thành công", Severity.Success);
else Snackbar.Add($"Ra lệnh không thành công: {result.Message}", Severity.Warning);
StateHasChanged();
}
public async ValueTask DisposeAsync()
{
await RobotHub.StopAsync();
}
}

View File

@@ -0,0 +1,13 @@
.paper-nodes {
padding: 5px;
border: 1px solid silver;
border-radius: 10px;
display: flex;
flex-wrap: wrap;
align-content: flex-start;
overflow-x: hidden;
overflow-y: auto;
width: 100%;
max-width: 530px;
height: 200px;
}

View File

@@ -0,0 +1,123 @@
<div class="d-flex h-100 d-flex flex-column overflow-x-hidden overflow-y-auto p-2" style="width: 100%; max-width: 550px">
<MudExpansionPanels Elevation="0" Class="mt-2" Style="border: 1px solid silver">
<MudExpansionPanel Expanded="true">
<TitleContent>
<div class="d-flex">
<MudText>LockedNodes</MudText>
<MudBadge Content="Agent.LockedNodes.Count" Color="Color.Warning" Overlap="true" Class="d-flex ml-auto">
<MudIcon Icon="@Icons.Material.Filled.Info" Color="Color.Info" />
</MudBadge>
</div>
</TitleContent>
<ChildContent>
<div class="d-flex overflow-y-auto flex-wrap" style="max-height: 500px">
@foreach (var node in Agent.LockedNodes)
{
<div class="p-2">
<TrafficNodePreview Node="node" />
</div>
}
</div>
</ChildContent>
</MudExpansionPanel>
</MudExpansionPanels>
<MudExpansionPanels Elevation="0" Class="mt-2" Style="border: 1px solid silver">
<MudExpansionPanel Expanded="true">
<TitleContent>
<div class="d-flex">
<MudText>Path</MudText>
<MudBadge Content="Agent.Nodes.Count" Color="Color.Warning" Overlap="true" Class="d-flex ml-auto">
<MudIcon Icon="@Icons.Material.Filled.Info" Color="Color.Info" />
</MudBadge>
</div>
</TitleContent>
<ChildContent>
<div class="d-flex overflow-y-auto flex-wrap" style="max-height: 500px">
@foreach (var node in Agent.Nodes)
{
<div class="p-2">
<TrafficNodePreview Node="node" />
</div>
}
</div>
</ChildContent>
</MudExpansionPanel>
</MudExpansionPanels>
<MudExpansionPanels Elevation="0" Class="mt-2" Style="border: 1px solid silver">
<MudExpansionPanel Expanded="true">
<TitleContent>
<div class="d-flex">
<MudText>SubNodes</MudText>
<MudBadge Content="Agent.SubNodes.Count" Color="Color.Warning" Overlap="true" Class="d-flex ml-auto">
<MudIcon Icon="@Icons.Material.Filled.Info" Color="Color.Info" />
</MudBadge>
</div>
</TitleContent>
<ChildContent>
<div class="d-flex overflow-y-auto flex-wrap" style="max-height: 500px">
@foreach (var node in Agent.SubNodes)
{
<div class="p-2">
<TrafficNodePreview Node="node" />
</div>
}
</div>
</ChildContent>
</MudExpansionPanel>
</MudExpansionPanels>
<MudExpansionPanels Elevation="0" Class="mt-2" Style="border: 1px solid silver">
<MudExpansionPanel Expanded="true">
<TitleContent>
<div class="d-flex">
<MudText>GiveWayNodes</MudText>
<MudBadge Content="Agent.GiveWayNodes.Count" Color="Color.Warning" Overlap="true" Class="d-flex ml-auto">
<MudIcon Icon="@Icons.Material.Filled.Info" Color="Color.Info" />
</MudBadge>
</div>
</TitleContent>
<ChildContent>
<div class="d-flex overflow-y-auto flex-wrap" style="max-height: 500px">
@foreach (var node in Agent.GiveWayNodes)
{
<div class="p-2">
<TrafficNodePreview Node="node" />
</div>
}
</div>
</ChildContent>
</MudExpansionPanel>
</MudExpansionPanels>
<MudExpansionPanels Elevation="0" Class="mt-2" Style="border: 1px solid silver">
<MudExpansionPanel Expanded="true">
<TitleContent>
<div class="d-flex">
<MudText>Conflict Agent</MudText>
</div>
</TitleContent>
<ChildContent>
<MudText Typo="Typo.body1">Conflict Agent: @Agent.ConflictAgentId</MudText>
<MudText Typo="Typo.body1">Conflict Node: @(Agent.ConflictNode is null ? "" : string.IsNullOrEmpty(Agent.ConflictNode.Name) ? Agent.ConflictNode.Id.ToString("N").Substring(0, 4) : Agent.ConflictNode.Name)</MudText>
</ChildContent>
</MudExpansionPanel>
</MudExpansionPanels>
</div>
@code {
private TrafficAgentDto Agent { get; set; } = new();
public void UpdateState(TrafficAgentDto agent)
{
Agent.Nodes = [.. agent.Nodes];
Agent.ReleaseNode = agent.ReleaseNode;
Agent.LockedNodes = [.. agent.LockedNodes];
Agent.InNode = agent.InNode;
Agent.SubNodes = [.. agent.SubNodes];
Agent.GiveWayNodes = [.. agent.GiveWayNodes];
Agent.ConflictNode = agent.ConflictNode;
Agent.ConflictAgentId = agent.ConflictAgentId;
StateHasChanged();
}
}

View File

@@ -0,0 +1,15 @@
<MudTooltip Arrow="true">
<ChildContent>
<MudButton Variant="Variant.Filled" Color="Color.Warning">@(string.IsNullOrEmpty(Node.Name) ? Node.Id.ToString("N").Substring(0,4) : Node.Name)</MudButton>
</ChildContent>
<TooltipContent>
<MudText Typo="Typo.body2">ID: @Node.Id</MudText>
<MudText Typo="Typo.body2">X: @Node.X</MudText>
<MudText Typo="Typo.body2">Y: @Node.Y</MudText>
</TooltipContent>
</MudTooltip>
@code {
[Parameter, EditorRequired]
public TrafficNodeDto Node { get; set; } = new();
}

View File

@@ -0,0 +1,7 @@
@using RobotNet.MapShares
@using RobotNet.MapShares.Dtos
@using RobotNet.MapShares.Enums
@using RobotNet.RobotShares.Dtos
@using RobotNet.RobotShares.Enums
@using RobotNet.RobotShares.Models
@using RobotNet.Shares