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,121 @@
@inject IJSRuntime JSRuntime
@implements IDisposable
<path @ref="ErrorRef" style="stroke: red; opacity: 0.6; stroke-width: 0.6px;" />
<path @ref="Ref" @ondblclick="@(async () => await DoubleClick.InvokeAsync(Model))" class="@(IsSetting ? "setting" : "")" />
@code {
[Parameter, EditorRequired]
public EdgeModel Model { get; set; } = null!;
[Parameter]
public EventCallback<EdgeModel> DoubleClick { get; set; }
[CascadingParameter]
protected bool MapIsActive { get; set; }
[Parameter]
public EditorState EditorState { get; set; }
private ElementReference Ref;
private ElementReference ErrorRef;
private DotNetObjectReference<Edge> DotNetObj = null!;
private bool IsError = false;
private bool IsSetting => EditorState == EditorState.NavigationEdit || EditorState == EditorState.CreateStraighEdge || EditorState == EditorState.CreateCurveEdge ||
EditorState == EditorState.CreateDoubleCurveEdge;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (!firstRender) return;
DotNetObj = DotNetObjectReference.Create(this);
await JSRuntime.InvokeVoidAsync("AddEventListener", DotNetObj, Ref, "click", nameof(Click), false);
await UpdatePathData();
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", ErrorRef, "visibility", "hidden");
}
public override async Task SetParametersAsync(ParameterView parameters)
{
bool updateLine = false;
if (parameters.TryGetValue(nameof(Model), out EdgeModel? model))
{
if (((Model?.Id ?? Guid.Empty) != (model?.Id ?? Guid.Empty)))
{
if (Model != null)
{
Model.StartNodePositionChanged -= UpdatePathData;
Model.EndNodePositionChanged -= UpdatePathData;
Model.ControlPoint1PositionChanged -= UpdatePathData;
Model.ControlPoint2PositionChanged -= UpdatePathData;
Model.ActiveChanged -= ActivedChanged;
Model.ErrorChanged -= ErrorChanged;
}
if (model != null)
{
model.StartNodePositionChanged += UpdatePathData;
model.EndNodePositionChanged += UpdatePathData;
model.ControlPoint1PositionChanged += UpdatePathData;
model.ControlPoint2PositionChanged += UpdatePathData;
model.ActiveChanged += ActivedChanged;
model.ErrorChanged += ErrorChanged;
updateLine = true;
}
}
}
await base.SetParametersAsync(parameters);
if (updateLine) 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);
if (IsError) await JSRuntime.InvokeVoidAsync("ElementSetAttribute", ErrorRef, "d", data);
}
private async void ActivedChanged(bool state) => await JSRuntime.InvokeVoidAsync(state ? "AddSelected" : "RemoveSelected", Ref);
private async void ErrorChanged(bool state)
{
IsError = state;
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", ErrorRef, "visibility", state ? "visible" : "hidden");
await UpdatePathData();
}
[JSInvokable]
public void Click() => Model.Selected();
public void Dispose()
{
if (Model != null)
{
Model.StartNodePositionChanged -= UpdatePathData;
Model.EndNodePositionChanged -= UpdatePathData;
Model.ControlPoint1PositionChanged -= UpdatePathData;
Model.ControlPoint2PositionChanged -= UpdatePathData;
Model.ActiveChanged -= ActivedChanged;
Model.ErrorChanged -= ErrorChanged;
}
if (DotNetObj != null) DotNetObj.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,128 @@
@inject IJSRuntime JSRuntime
@implements IDisposable
<g visibility="@Visibility">
<path d="@EdgeData" />
<line x1="@X1" y1="@Y1" x2="@CX1" y2="@CY1"/>
<line x1="@CX1" y1="@CY1" x2="@X2" y2="@Y2" />
<circle @ref="CP1Ref" cx="@CX1" cy="@CY1" />
</g>
<g visibility="@ControlPoint2Visibility">
<line x1="@X1" y1="@Y1" x2="@CX2" y2="@CY2" />
<line x1="@CX2" y1="@CY2" x2="@X2" y2="@Y2" />
<circle @ref="CP2Ref" cx="@CX2" cy="@CY2" />
</g>
@code {
private ElementReference CP1Ref;
private ElementReference CP2Ref;
private DotNetObjectReference<EdgeControlPoint> DotNetObj = null!;
private double X1;
private double Y1;
private double CX1;
private double CY1;
private double CX2;
private double CY2;
private double X2;
private double Y2;
private string EdgeData = "";
private EdgeModel? Model;
private string Visibility = "hidden";
private string ControlPoint2Visibility = "hidden";
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (!firstRender) return;
DotNetObj = DotNetObjectReference.Create(this);
await JSRuntime.InvokeVoidAsync("AddMouseDownEventListener", DotNetObj, CP1Ref, nameof(OnMouseDown1), false);
await JSRuntime.InvokeVoidAsync("AddMouseDownEventListener", DotNetObj, CP2Ref, nameof(OnMouseDown2), false);
}
public void SetControl(EdgeModel? model)
{
if (Model != null)
{
Model.StartNodePositionChanged -= CaculatePath;
Model.EndNodePositionChanged -= CaculatePath;
Model.ControlPoint1PositionChanged -= CaculatePath;
Model.ControlPoint2PositionChanged -= CaculatePath;
}
Model = model;
if (Model != null)
{
Visibility = "visible";
if (Model.TrajectoryDegree == TrajectoryDegree.Three) ControlPoint2Visibility = "visible";
CaculatePath();
Model.StartNodePositionChanged += CaculatePath;
Model.EndNodePositionChanged += CaculatePath;
Model.ControlPoint1PositionChanged += CaculatePath;
Model.ControlPoint2PositionChanged += CaculatePath;
if (Model.TrajectoryDegree == TrajectoryDegree.Three) ControlPoint2Visibility = "visible";
else ControlPoint2Visibility = "hidden";
Visibility = "visible";
}
else
{
Visibility = "hidden";
ControlPoint2Visibility = "hidden";
}
StateHasChanged();
}
private Task CaculatePath()
{
if (Model == null) return Task.CompletedTask;
X1 = Model.X1;
Y1 = Model.Y1;
X2 = Model.X2;
Y2 = Model.Y2;
CX1 = Model.ControlPoint1X;
CY1 = Model.ControlPoint1Y;
CX2 = Model.ControlPoint2X;
CY2 = Model.ControlPoint2Y;
StateHasChanged();
return Task.CompletedTask;
}
[JSInvokable]
public void OnMouseDown1(int button, bool altKey, bool ctrlKey, bool shiftKey)
{
if (Model != null)
{
Model.ActivedControlPoint1 = true;
Model.ActivedControlPoint2 = false;
}
}
[JSInvokable]
public void OnMouseDown2(int button, bool altKey, bool ctrlKey, bool shiftKey)
{
if (Model != null)
{
Model.ActivedControlPoint2 = true;
Model.ActivedControlPoint1 = false;
}
}
public void Dispose()
{
if (Model != null)
{
Model.StartNodePositionChanged -= CaculatePath;
Model.EndNodePositionChanged -= CaculatePath;
Model.ControlPoint1PositionChanged -= CaculatePath;
Model.ControlPoint2PositionChanged -= CaculatePath;
Model = null;
}
GC.SuppressFinalize(this);
}
}

View File

@@ -0,0 +1,23 @@
circle {
cursor: default;
fill: #FFBD33;
stroke: #FF5733;
stroke-width: 0;
r: var(--node-r);
}
circle:hover {
stroke-width: 0.02px;
}
circle:active {
stroke-width: 0.02px;
cursor: pointer;
stroke: green;
}
line {
stroke-width: 0.03px;
stroke: #d63384;
stroke-dasharray: 0.1 0.1;
}

View File

@@ -0,0 +1,163 @@
@inject IJSRuntime JSRuntime
<g @ref="Ref" visibility="hidden">
<defs>
<marker id="arrowhead" markerWidth="5" markerHeight="4" refX="5" refY="2" orient="auto">
<line x1="0" y1="0" x2="5" y2="2" style="stroke: #ff0000; stroke-width: 1px;" />
<line x1="5" y1="2" x2="0" y2="4" style="stroke: #ff0000; stroke-width: 1px;" />
</marker>
</defs>
<path @ref="PathRef" />
<line @ref="SubPath1Ref" x1="@StartNode.X" x2="@SubStartNode.X" y1="@StartNode.Y" y2="@SubStartNode.Y" stroke="#ff0000" stroke-width="0.05" marker-end="url(#arrowhead)" />
<line @ref="SubPath2Ref" x1="@EndNode.X" x2="@SubEndNode.X" y1="@EndNode.Y" y2="@SubEndNode.Y" stroke="#ff0000" stroke-width="0.05" marker-end="url(#arrowhead)" />
<circle cx="@StartNode.X" cy="@StartNode.Y" />
<circle cx="@EndNode.X" cy="@EndNode.Y" />
</g>
@code {
private ElementReference Ref;
private ElementReference PathRef;
private ElementReference SubPath1Ref;
private ElementReference SubPath2Ref;
private (double X, double Y) StartNode;
private (double X, double Y) SubStartNode;
private (double X, double Y) EndNode;
private (double X, double Y) SubEndNode;
private TrajectoryDegree Degree;
private (double X, double Y) ControlPoint1;
private (double X, double Y) ControlPoint2;
public CreateCurveEdgeStep CreateStep { get; set; } = CreateCurveEdgeStep.Hidden;
public async Task Update(double x, double y)
{
if (CreateStep == CreateCurveEdgeStep.CreateSubStartEdge)
{
SubStartNode.X = x;
SubStartNode.Y = y;
}
else if (CreateStep == CreateCurveEdgeStep.FinishCreateSubStartEdge)
{
EndNode.X = x;
EndNode.Y = y;
await CreateTangentPath();
}
else if (CreateStep == CreateCurveEdgeStep.CreateSubEndEdge)
{
SubEndNode.X = x;
SubEndNode.Y = y;
await CreateTangentPath();
}
StateHasChanged();
}
public async Task CreateSubEdgeAsync(double x, double y, TrajectoryDegree degree = TrajectoryDegree.Two)
{
Degree = degree;
if (CreateStep == CreateCurveEdgeStep.Hidden)
{
await Visible();
StartNode.X = x;
StartNode.Y = y;
SubStartNode.X = x;
SubStartNode.Y = y;
CreateStep = CreateCurveEdgeStep.CreateSubStartEdge;
}
else if (CreateStep == CreateCurveEdgeStep.FinishCreateSubStartEdge)
{
EndNode.X = x;
EndNode.Y = y;
SubEndNode.X = x;
SubEndNode.Y = y;
CreateStep = CreateCurveEdgeStep.CreateSubEndEdge;
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", SubPath2Ref, "visibility", "visible");
}
StateHasChanged();
}
public async Task FinishSubEdgeAsync(double x, double y)
{
if (CreateStep == CreateCurveEdgeStep.CreateSubStartEdge)
{
SubStartNode.X = x;
SubStartNode.Y = y;
EndNode.X = x;
EndNode.Y = y;
CreateStep = CreateCurveEdgeStep.FinishCreateSubStartEdge;
await CreateTangentPath();
}
else if (CreateStep == CreateCurveEdgeStep.CreateSubEndEdge) CreateStep = CreateCurveEdgeStep.Finish;
}
public EdgeCreateModel GetEdgeCreateModel()
{
return new()
{
X1 = StartNode.X,
Y1 = StartNode.Y,
X2 = EndNode.X,
Y2 = EndNode.Y,
ControlPoint1X = ControlPoint1.X,
ControlPoint1Y = ControlPoint1.Y,
ControlPoint2X = ControlPoint2.X,
ControlPoint2Y = ControlPoint2.Y,
TrajectoryDegree = Degree,
};
}
private async Task CreateTangentPath()
{
var data = $"M {StartNode.X} {StartNode.Y}";
if(Degree == TrajectoryDegree.Two)
{
var cp = MapEditorHelper.CaculateIntersectionPoint(SubStartNode.X, SubStartNode.Y, StartNode.X, StartNode.Y, EndNode.X, EndNode.Y, SubEndNode.X, SubEndNode.Y);
if (cp is null || CreateStep == CreateCurveEdgeStep.FinishCreateSubStartEdge) cp = MapEditorHelper.CaculateControlPoint(StartNode.X, StartNode.Y, EndNode.X, EndNode.Y, 45, 1 / Math.Sqrt(2));
data = $"{data} Q {cp.Value.X} {cp.Value.Y} {EndNode.X} {EndNode.Y}";
ControlPoint1 = (cp.Value.X, cp.Value.Y);
}
else if(Degree == TrajectoryDegree.Three)
{
if (CreateStep == CreateCurveEdgeStep.FinishCreateSubStartEdge)
{
ControlPoint1 = MapEditorHelper.CaculateControlPoint(StartNode.X, StartNode.Y, EndNode.X, EndNode.Y, 45, 1 / Math.Sqrt(2));
ControlPoint2 = MapEditorHelper.CaculateControlPoint(StartNode.X, StartNode.Y, EndNode.X, EndNode.Y, -45, 1 / Math.Sqrt(2));
}
else (ControlPoint1.X, ControlPoint1.Y, ControlPoint2.X, ControlPoint2.Y) = MapEditorHelper.CaculateDoubleControlPoint(SubStartNode.X, SubStartNode.Y, StartNode.X, StartNode.Y, EndNode.X, EndNode.Y, SubEndNode.X, SubEndNode.Y);
data = $"{data} C {ControlPoint1.X} {ControlPoint1.Y}, {ControlPoint2.X} {ControlPoint2.Y}, {EndNode.X} {EndNode.Y}";
}
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", PathRef, "d", data);
StateHasChanged();
}
public async Task Visible()
{
EndNode = (0, 0);
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", PathRef, "d", "");
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", SubPath1Ref, "visibility", "visible");
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", SubPath2Ref, "visibility", "hidden");
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", Ref, "visibility", "visible");
}
public async Task Hidden()
{
CreateStep = CreateCurveEdgeStep.Hidden;
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", SubPath1Ref, "visibility", "hidden");
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", SubPath2Ref, "visibility", "hidden");
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", Ref, "visibility", "hidden");
}
public enum CreateCurveEdgeStep
{
Hidden,
CreateSubStartEdge,
FinishCreateSubStartEdge,
CreateSubEndEdge,
Finish,
}
}

View File

@@ -0,0 +1,12 @@
path {
stroke: red;
stroke-width: var(--edge-stroke-width);
fill: none;
}
circle {
fill: #FFBD33;
stroke: #FF5733;
stroke-width: 0;
r: var(--node-r);
}

View File

@@ -0,0 +1,113 @@
@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();
}
public override async Task SetParametersAsync(ParameterView parameters)
{
bool updateLine = false;
if (parameters.TryGetValue(nameof(Model), out EdgeModel? model))
{
if (((Model?.Id ?? Guid.Empty) != (model?.Id ?? Guid.Empty)))
{
if (Model != null)
{
Model.StartNodePositionChanged -= UpdatePathData;
Model.EndNodePositionChanged -= UpdatePathData;
Model.ControlPoint1PositionChanged -= UpdatePathData;
Model.ControlPoint2PositionChanged -= UpdatePathData;
Model.DirectionChanged -= UpdateMaker;
}
if (model != null)
{
model.StartNodePositionChanged += UpdatePathData;
model.EndNodePositionChanged += UpdatePathData;
model.ControlPoint1PositionChanged += UpdatePathData;
model.ControlPoint2PositionChanged += UpdatePathData;
model.DirectionChanged += UpdateMaker;
updateLine = true;
}
}
}
await base.SetParametersAsync(parameters);
if (updateLine)
{
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()
{
if (Model != null)
{
Model.StartNodePositionChanged -= UpdatePathData;
Model.EndNodePositionChanged -= UpdatePathData;
Model.ControlPoint1PositionChanged -= UpdatePathData;
Model.ControlPoint2PositionChanged -= UpdatePathData;
Model.DirectionChanged -= UpdateMaker;
}
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,46 @@
@inject IJSRuntime JSRuntime
<g @ref="Ref" visibility="hidden">
<path @ref="PathRef" />
<circle cx="@X1" cy="@Y1" />
<circle cx="@X2" cy="@Y2" />
</g>
@code {
private ElementReference Ref;
private ElementReference PathRef;
public double X1;
public double Y1;
public double X2;
public double Y2;
public async Task Update(double x, double y)
{
X2 = x;
Y2 = y;
await CaculatePath();
}
public async Task StartCreateAsync(double x, double y)
{
X1 = x;
Y1 = y;
X2 = x;
Y2 = y;
await CaculatePath();
await Visible();
}
private async Task CaculatePath()
{
var data = $"M {X1} {Y1} L {(X1 + X2) / 2} {(Y1 + Y2) / 2} L {X2} {Y2}";
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", PathRef, "d", data);
StateHasChanged();
}
public async Task Visible() => await JSRuntime.InvokeVoidAsync("ElementSetAttribute", Ref, "visibility", "visible");
public async Task Hidden() => await JSRuntime.InvokeVoidAsync("ElementSetAttribute", Ref, "visibility", "hidden");
}

View File

@@ -0,0 +1,12 @@
path {
stroke: red;
stroke-width: var(--edge-stroke-width);
fill: none;
}
circle {
fill: #FFBD33;
stroke: #FF5733;
stroke-width: 0;
r: var(--node-r);
}

View File

@@ -0,0 +1,255 @@
@implements IDisposable
@inject IJSRuntime JSRuntime
@inject IHttpClientFactory HttpClientFactory
@inject ISnackbar Snackbar
<g>
@foreach (var edge in Models)
{
<Edge Model="edge" DoubleClick="OnEdgeDoubleClick" EditorState="@EditorState" />
}
@foreach (var edge in Models)
{
<EdgeDirection Model="edge" />
}
</g>
<MudDialog @bind-Visible="updateEdgeVisible">
<TitleContent>
<MudText Typo="Typo.h6">
Update edge @UpdateModel.Id
</MudText>
</TitleContent>
<DialogContent>
<div class="d-flex flex-row align-items-center">
<MudText>
Length: @SelectModelLength m
</MudText>
</div>
<div class="d-flex flex-row mt-2">
<div class="d-flex flex-column">
<div class="mb-2">
<MudNumericField @bind-Value="UpdateModel.ControlPoint1X" Label="Control Point 1 X" Variant="Variant.Outlined" Margin="Margin.Dense" Step="0.1" ReadOnly=@(MapIsActive) />
</div>
<div class="mb-2">
<MudNumericField @bind-Value="UpdateModel.ControlPoint2X" Label="Control Point 2 X" Variant="Variant.Outlined" Margin="Margin.Dense" Step="0.1" ReadOnly=@(MapIsActive) />
</div>
<div class="mb-2">
<MudSelect @bind-Value="UpdateModel.DirectionAllowed" Label="Direction Allowed" Variant="Variant.Outlined" AnchorOrigin="Origin.BottomLeft" Margin="Margin.Dense" Dense ReadOnly=@(MapIsActive)>
<MudSelectItem Value="@(DirectionAllowed.None)" />
<MudSelectItem Value="@(DirectionAllowed.Backward)" />
<MudSelectItem Value="@(DirectionAllowed.Forward)" />
<MudSelectItem Value="@(DirectionAllowed.Both)" />
</MudSelect>
</div>
<div class="mb-2">
<MudNumericField @bind-Value="UpdateModel.AllowedDeviationXy" Label="AllowedDeviationXy" Step="0.01" Min="0" Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
</div>
<div class="mb-2">
<MudNumericField @bind-Value="UpdateModel.AllowedDeviationTheta" Label="AllowedDeviationTheta" Step="1" Min="0" Max="180" Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
</div>
<div class="d-flex">
<MudCheckBox @bind-Value="UpdateModel.RotationAllowed" Label="Rotation Allowed" LabelPlacement="Placement.Start" ReadOnly=@(MapIsActive) UncheckedColor="Color.Default" Color="Color.Success" />
</div>
</div>
<div class="d-flex flex-column ms-2">
<div class="mb-2">
<MudNumericField @bind-Value="UpdateModel.ControlPoint1Y" Label="Control Point 1 Y" Variant="Variant.Outlined" Margin="Margin.Dense" Step="0.1" ReadOnly=@(MapIsActive) />
</div>
<div class="mb-2">
<MudNumericField @bind-Value="UpdateModel.ControlPoint2Y" Label="Control Point 2 Y" Variant="Variant.Outlined" Margin="Margin.Dense" Step="0.1" ReadOnly=@(MapIsActive) />
</div>
<div class="mb-2">
<MudNumericField @bind-Value="UpdateModel.MaxSpeed" Label="Max Speed" Variant="Variant.Outlined" Margin="Margin.Dense" Step="0.1" Min="0" ReadOnly=@(MapIsActive) />
</div>
<div class="mb-2">
<MudNumericField @bind-Value="UpdateModel.MaxRotationSpeed" Label="Max Rotation Speed" Variant="Variant.Outlined" Margin="Margin.Dense" Step="0.1" Min="0" ReadOnly=@(MapIsActive) />
</div>
<div class="mb-2">
<MudNumericField @bind-Value="UpdateModel.MaxHeight" Label="Max Height" Variant="Variant.Outlined" Margin="Margin.Dense" Step="0.1" Min="0" ReadOnly=@(MapIsActive) />
</div>
<div class="mb-2">
<MudNumericField @bind-Value="UpdateModel.MinHeight" Label="Min Height" Variant="Variant.Outlined" Margin="Margin.Dense" Step="0.1" Min="0" ReadOnly=@(MapIsActive) />
</div>
</div>
<div class="d-flex flex-column ms-2 flex-grow-1">
<div class="d-flex flex-row mb-2">
<MudSelect @bind-Value=ActionSelected Margin="Margin.Dense" T="ActionDto" Label="Action" Variant="Variant.Outlined" Class="w-100" AnchorOrigin="Origin.BottomLeft">
@foreach (var action in Actions)
{
<MudSelectItem Value="@action">@action.Name</MudSelectItem>
}
</MudSelect>
<MudFab Class="ms-2" Color="Color.Secondary" StartIcon="@Icons.Material.Filled.Add" Size="Size.Medium" OnClick="AddAction" />
</div>
<div class="paper-action">
@foreach (var actionId in UpdateModel.Actions)
{
<div class="m-1" style="height: fit-content">
<MudButton Variant="Variant.Filled" Color="Color.Info" Style="text-transform:none" OnClick="(() => DeleteAction(actionId))">
@(Actions.FirstOrDefault(ac => ac.Id == actionId)?.Name)
</MudButton>
</div>
}
</div>
</div>
</div>
</DialogContent>
<DialogActions>
<MudButton OnClick="CancelUpdateEdge" Class="px-10" Variant="Variant.Filled">Cancel</MudButton>
<MudButton OnClick="UpdateEdge" Variant="Variant.Filled" Color="Color.Primary" Class="px-10" Disabled=@(MapIsActive || EditorState == EditorState.View)>Update</MudButton>
</DialogActions>
</MudDialog>
@code {
[Parameter, EditorRequired]
public MapEdgeModel Models { get; set; } = null!;
[CascadingParameter]
protected bool MapIsActive { get; set; }
[Parameter]
public EventCallback<EdgeModel?> EdgeSelectedChanged { get; set; }
[Parameter]
public EditorState EditorState { get; set; }
private EdgeUpdateModel UpdateModel = new();
private bool updateEdgeVisible;
private string ActionsText { get; set; } = "";
private double SelectModelLength;
private List<ActionDto> Actions = [];
private ActionDto? ActionSelected = null;
private HttpClient Http = default!;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (!firstRender) return;
Http = HttpClientFactory.CreateClient("MapManagerAPI");
Models.Changed += StateHasChanged;
Models.EdgeSelectedChanged += async (model) => await EdgeSelectedChanged.InvokeAsync(model);
}
private async Task LoadActionAsync(Guid mapVersionId)
{
var result = await Http.GetFromJsonAsync<IEnumerable<ActionDto>>($"api/Actions/{mapVersionId}");
if (result is not null && result.Any())
{
Actions.Clear();
Actions.AddRange(result);
}
if (Actions.Any()) ActionSelected = Actions.First();
StateHasChanged();
}
private void AddAction()
{
if (ActionSelected is null) return;
if (UpdateModel.Actions.Any(action => action == ActionSelected.Id))
{
Snackbar.Add("Action đã tồn tại", Severity.Warning);
return;
}
UpdateModel.Actions = [.. UpdateModel.Actions, ActionSelected.Id];
StateHasChanged();
}
private void DeleteAction(Guid actionId)
{
UpdateModel.Actions = UpdateModel.Actions.Where(a => actionId != a).ToArray();
StateHasChanged();
}
private async Task OnEdgeDoubleClick(EdgeModel model)
{
if (model == null || EditorState != EditorState.NavigationEdit) return;
await LoadActionAsync(model.MapId);
UpdateModel.Id = model.Id;
UpdateModel.ControlPoint1X = model.ControlPoint1X;
UpdateModel.ControlPoint1Y = model.ControlPoint1Y;
UpdateModel.ControlPoint2X = model.ControlPoint2X;
UpdateModel.ControlPoint2Y = model.ControlPoint2Y;
UpdateModel.DirectionAllowed = model.DirectionAllowed;
UpdateModel.MaxSpeed = model.MaxSpeed;
UpdateModel.MaxHeight = model.MaxHeight;
UpdateModel.MinHeight = model.MinHeight;
UpdateModel.RotationAllowed = model.RotationAllowed;
UpdateModel.MaxRotationSpeed = model.MaxRotationSpeed;
UpdateModel.AllowedDeviationXy = model.AllowedDeviationXy;
UpdateModel.AllowedDeviationTheta = model.AllowedDeviationTheta;
UpdateModel.Actions = [];
var actions = JsonSerializer.Deserialize<Guid[]>(model.Actions);
if (actions is not null && actions.Length > 0)
{
UpdateModel.Actions = [.. actions];
}
SelectModelLength = MapEditorHelper.GetEdgeLength(new()
{
TrajectoryDegree = model.TrajectoryDegree,
X1 = model.X1,
Y1 = model.Y1,
X2 = model.X2,
Y2 = model.Y2,
ControlPoint1X = model.ControlPoint1X,
ControlPoint1Y = model.ControlPoint1Y,
ControlPoint2X = model.ControlPoint2X,
ControlPoint2Y = model.ControlPoint2Y,
});
updateEdgeVisible = true;
StateHasChanged();
}
private void CancelUpdateEdge()
{
updateEdgeVisible = false;
StateHasChanged();
}
private async Task UpdateEdge()
{
var selectedModel = Models.FirstOrDefault(e => e.Id == UpdateModel.Id);
if (selectedModel == null)
{
updateEdgeVisible = false;
StateHasChanged();
return;
}
var result = await (await Http.PutAsJsonAsync($"api/Edges", UpdateModel)).Content.ReadFromJsonAsync<MessageResult>();
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, Severity.Error);
return;
}
selectedModel.UpdateData(UpdateModel);
updateEdgeVisible = false;
Snackbar.Add("Cập nhật thành công", Severity.Success);
StateHasChanged();
}
public void Dispose()
{
Models.Changed -= StateHasChanged;
GC.SuppressFinalize(this);
}
}

View File

@@ -0,0 +1,13 @@
.paper-action {
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: 280px;
max-height: 288px;
height: 100%;
}