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,156 @@
@implements IDisposable
@inject IHttpClientFactory HttpClientFactory
@inject ISnackbar Snackbar
@foreach (var zone in Models)
{
<Zone Model="@zone" IsSetting="@IsSetting" DoubleClick="ZoneDoubleClick" IsShow="IsShow" />
}
<MudDialog @bind-Visible="@UpdateZoneVisiable">
<TitleContent>
<MudText Typo="Typo.h6">
Update zone @UpdateModel.Id
</MudText>
</TitleContent>
<DialogContent>
<MudSelect Class="mt-2" @bind-Value="UpdateModel.Type" Label="Type" Variant="Variant.Outlined" AnchorOrigin="Origin.BottomLeft" Margin="Margin.Dense" Dense ReadOnly=@(MapIsActive)>
<MudSelectItem Value="@(ZoneType.Operating)" />
<MudSelectItem Value="@(ZoneType.OperatingHazard)" />
<MudSelectItem Value="@(ZoneType.Restricted)" />
<MudSelectItem Value="@(ZoneType.LoadTransfer)" />
<MudSelectItem Value="@(ZoneType.Confined)" />
<MudSelectItem Value="@(ZoneType.Forbidden)" />
</MudSelect>
<MudTextField Class="mt-2" @bind-Value="UpdateModel.Name" Label="Name" ShrinkLabel Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
<div class="d-flex flex-row mt-5">
<div class="d-flex flex-column me-2 w-50">
<div class="mb-4">
<MudNumericField Class="mb-3" @bind-Value="UpdateModel.X1" Label="X1" ShrinkLabel Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
<MudNumericField @bind-Value="UpdateModel.Y1" Label="Y1" ShrinkLabel Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
</div>
<div>
<MudNumericField Class="mb-3" @bind-Value="UpdateModel.X2" Label="X2" ShrinkLabel Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
<MudNumericField @bind-Value="UpdateModel.Y2" Label="Y2" ShrinkLabel Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
</div>
</div>
<div class="d-flex flex-column ms-2 w-50">
<div class="mb-4">
<MudNumericField Class="mb-3" @bind-Value="UpdateModel.X3" Label="X3" ShrinkLabel Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
<MudNumericField @bind-Value="UpdateModel.Y3" Label="Y3" ShrinkLabel Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
</div>
<div>
<MudNumericField Class="mb-3" @bind-Value="UpdateModel.X4" Label="X4" ShrinkLabel Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
<MudNumericField @bind-Value="UpdateModel.Y4" Label="Y4" ShrinkLabel Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
</div>
</div>
</div>
</DialogContent>
<DialogActions>
<MudButton OnClick="CancelUpdateZone" Class="px-10" Variant="Variant.Filled">Cancel</MudButton>
<MudButton OnClick="UpdateZone" Variant="Variant.Filled" Color="Color.Primary" Class="px-10" Disabled=@(MapIsActive)>Update</MudButton>
</DialogActions>
</MudDialog>
@code {
[Parameter, EditorRequired]
public MapZoneModel Models { get; set; } = null!;
[Parameter]
public bool IsShow { get; set; }
[Parameter]
public bool IsSetting { get; set; }
[CascadingParameter]
protected bool MapIsActive { get; set; }
[Parameter]
public EditorState EditorState { get; set; }
[Parameter]
public EventCallback<(ZoneModel, bool)> ActivedZoneChanged { get; set; }
private ZoneUpdateModel UpdateModel = new();
private bool UpdateZoneVisiable = false;
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.ActivedZoneChanged += OnActivedZoneChanged;
}
private void OnActivedZoneChanged(ZoneModel model, bool state)
{
_ = ActivedZoneChanged.InvokeAsync((model, state));
}
private void ZoneDoubleClick(ZoneModel model)
{
if (model == null || EditorState != EditorState.SettingZone) return;
UpdateModel.Id = model.Id;
UpdateModel.Type = model.Type;
UpdateModel.Name = model.Name;
UpdateModel.X1 = model.X1;
UpdateModel.Y1 = model.Y1;
UpdateModel.X2 = model.X2;
UpdateModel.Y2 = model.Y2;
UpdateModel.X3 = model.X3;
UpdateModel.Y3 = model.Y3;
UpdateModel.X4 = model.X4;
UpdateModel.Y4 = model.Y4;
UpdateZoneVisiable = true;
StateHasChanged();
}
private void CancelUpdateZone()
{
UpdateZoneVisiable = false;
StateHasChanged();
}
private async Task UpdateZone()
{
var selectedModel = Models.FirstOrDefault(e => e.Id == UpdateModel.Id);
if (selectedModel == null)
{
UpdateZoneVisiable = false;
StateHasChanged();
return;
}
var result = await (await Http.PutAsJsonAsync($"api/Zones", 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);
UpdateZoneVisiable = false;
Snackbar.Add("Cập nhật thành công", Severity.Success);
StateHasChanged();
}
public void Dispose()
{
Models.Changed -= StateHasChanged;
Models.ActivedZoneChanged -= OnActivedZoneChanged;
GC.SuppressFinalize(this);
}
}

View File

@@ -0,0 +1,95 @@
@inject IJSRuntime JSRuntime
@implements IDisposable
<polygon @ref="Ref" class="@(IsSetting ? "setting" : "")" fill="@Model.Fill" @ondblclick="OnDoubleClick" style="visibility: @(IsShow ? "visible" : "hidden")" />
@code {
[Parameter, EditorRequired]
public ZoneModel Model { get; set; } = null!;
[Parameter]
public EventCallback<ZoneModel> DoubleClick { get; set; }
[Parameter]
public bool IsSetting { get; set; }
[Parameter]
public bool IsShow { get; set; }
[CascadingParameter]
protected bool MapIsActive { get; set; }
private ElementReference Ref;
private DotNetObjectReference<Zone> DotNetObj = null!;
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 UpdateData();
}
public override async Task SetParametersAsync(ParameterView parameters)
{
bool UpdateZone = false;
if (parameters.TryGetValue(nameof(Model), out ZoneModel? model))
{
if (((Model?.Id ?? Guid.Empty) != (model?.Id ?? Guid.Empty)))
{
if (Model != null)
{
Model.ControlNodePosittionChanged -= UpdateData;
Model.TypeChanged -= StateHasChanged;
Model.ActiveChanged -= ActiveChanged;
}
if (model != null)
{
model.ControlNodePosittionChanged += UpdateData;
model.TypeChanged += StateHasChanged;
model.ActiveChanged += ActiveChanged;
UpdateZone = true;
}
}
}
await base.SetParametersAsync(parameters);
if (UpdateZone) await UpdateData();
}
private async Task OnDoubleClick()
{
await DoubleClick.InvokeAsync(Model);
}
[JSInvokable]
public void Click()
{
Model.Active();
}
private async void ActiveChanged(ZoneModel zone, bool state) => await JSRuntime.InvokeVoidAsync(state ? "AddSelected" : "RemoveSelected", Ref);
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()
{
if (Model != null)
{
Model.ControlNodePosittionChanged -= UpdateData;
Model.ActiveChanged -= ActiveChanged;
Model.TypeChanged -= StateHasChanged;
}
if (DotNetObj != null) DotNetObj.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,137 @@
@inject IJSRuntime JSRuntime
@implements IDisposable
<g visibility="@Visibility">
<circle @ref="Node1Ref" cx="@X1" cy="@Y1" />
<text x="@X1" y="@(-Y1 - 0.15)">1</text>
<circle @ref="Node2Ref" cx="@X2" cy="@Y2" />
<text x="@X2" y="@(-Y2 - 0.15)">2</text>
<circle @ref="Node3Ref" cx="@X3" cy="@Y3" />
<text x="@X3" y="@(-Y3 - 0.15)">3</text>
<circle @ref="Node4Ref" cx="@X4" cy="@Y4" />
<text x="@X4" y="@(-Y4 - 0.15)">4</text>
</g>
@code {
private ElementReference Node1Ref;
private ElementReference Node2Ref;
private ElementReference Node3Ref;
private ElementReference Node4Ref;
private DotNetObjectReference<ZoneControlPoint> DotNetObj = null!;
private double X1;
private double Y1;
private double X2;
private double Y2;
private double X3;
private double Y3;
private double X4;
private double Y4;
private ZoneModel? Model;
private string Visibility = "hidden";
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (!firstRender) return;
DotNetObj = DotNetObjectReference.Create(this);
await JSRuntime.InvokeVoidAsync("AddMouseDownEventListener", DotNetObj, Node1Ref, nameof(OnMouseDownNode1), false);
await JSRuntime.InvokeVoidAsync("AddMouseDownEventListener", DotNetObj, Node2Ref, nameof(OnMouseDownNode2), false);
await JSRuntime.InvokeVoidAsync("AddMouseDownEventListener", DotNetObj, Node3Ref, nameof(OnMouseDownNode3), false);
await JSRuntime.InvokeVoidAsync("AddMouseDownEventListener", DotNetObj, Node4Ref, nameof(OnMouseDownNode4), false);
}
public void SetControl(ZoneModel? model)
{
if (Model != null)
{
Model.ControlNodePosittionChanged -= CaculateZoneAsync;
}
Model = model;
if (Model != null)
{
Visibility = "visible";
CaculateZone();
Model.ControlNodePosittionChanged += CaculateZoneAsync;
Visibility = "visible";
}
else
{
Visibility = "hidden";
}
StateHasChanged();
}
private Task CaculateZoneAsync()
{
CaculateZone();
return Task.CompletedTask;
}
private void CaculateZone()
{
if (Model == null) return;
X1 = Model.X1;
Y1 = Model.Y1;
X2 = Model.X2;
Y2 = Model.Y2;
X3 = Model.X3;
Y3 = Model.Y3;
X4 = Model.X4;
Y4 = Model.Y4;
StateHasChanged();
}
[JSInvokable]
public void OnMouseDownNode1(int button, bool altKey, bool ctrlKey, bool shiftKey)
{
if (Model != null)
{
Model.ActiveNode = 1;
}
}
[JSInvokable]
public void OnMouseDownNode2(int button, bool altKey, bool ctrlKey, bool shiftKey)
{
if (Model != null)
{
Model.ActiveNode = 2;
}
}
[JSInvokable]
public void OnMouseDownNode3(int button, bool altKey, bool ctrlKey, bool shiftKey)
{
if (Model != null)
{
Model.ActiveNode = 3;
}
}
[JSInvokable]
public void OnMouseDownNode4(int button, bool altKey, bool ctrlKey, bool shiftKey)
{
if (Model != null)
{
Model.ActiveNode = 4;
}
}
public void Dispose()
{
if (Model != null)
{
Model.ControlNodePosittionChanged -= CaculateZoneAsync;
Model = null;
}
if (DotNetObj is not null) DotNetObj.Dispose();
GC.SuppressFinalize(this);
}
}

View File

@@ -0,0 +1,31 @@
circle {
cursor: default;
fill: #FFBD33;
stroke-width: 0;
r: var(--node-r);
}
circle:hover {
stroke-width: 0.03px;
cursor: pointer;
stroke: green;
}
circle:active {
stroke-width: 0.03px;
stroke: #FF5733;
}
circle + text {
transition-delay: 0.1s;
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,92 @@
@inject IJSRuntime JSRuntime
<polygon @ref="Ref" visibility="hidden" />
<g @ref="PointRef" visibility="hidden">
<circle cx="@X1" cy="@Y1" />
<circle cx="@X2" cy="@Y2" />
<circle cx="@X3" cy="@Y3" />
<circle cx="@X4" cy="@Y4" />
<circle cx="@X5" cy="@Y5" />
</g>
@code {
private ElementReference Ref;
private ElementReference PointRef;
public double X1 { get; private set; }
public double Y1 { get; private set; }
public double X2 { get; private set; }
public double Y2 { get; private set; }
public double X3 { get; private set; }
public double Y3 { get; private set; }
public double X4 { get; private set; }
public double Y4 { get; private set; }
public double X5 { get; private set; }
public double Y5 { get; private set; }
public int Step { get; private set; }
public async Task CreateAsync(double x, double y)
{
if (Step == 0)
{
await Visible();
Step = 1;
X1 = x;
Y1 = y;
}
else if (Step == 1) Step = 2;
else if (Step == 2) Step = 3;
else if (Step == 3)
{
X4 = x;
Y4 = y;
Step = 4;
await CalculatorZone();
}
}
public async Task Update(double x, double y)
{
if (Step == 1)
{
X2 = x;
Y2 = y;
}
else if (Step == 2)
{
X3 = x;
Y3 = y;
}
else if (Step == 3)
{
X4 = x;
Y4 = y;
}
await CalculatorZone();
StateHasChanged();
}
private async Task CalculatorZone()
{
var points = $"{X1},{Y1} {X2},{Y2}";
if (Step == 2) points += $" {X3},{Y3}";
if (Step == 3) points += $" {X3},{Y3} {X4},{Y4}";
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", Ref, "points", points);
}
public async Task Visible()
{
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", Ref, "visibility", "visible");
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", PointRef, "visibility", "visible");
}
public async Task Hidden()
{
Step = 0;
X1 = X2 = X3 = X4 = Y1 = Y2 = Y3 = Y4 = 0;
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", Ref, "visibility", "hidden");
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", PointRef, "visibility", "hidden");
}
}

View File

@@ -0,0 +1,12 @@
polygon {
fill: #c2c2a3;
stroke: none;
fill-opacity: 0.5;
}
circle {
fill: #FFBD33;
stroke: #FF5733;
stroke-width: 0;
r: var(--node-r);
}