RobotApp/RobotApp.Client/Pages/Components/Config/RobotPLCConfig.razor
Đăng Nguyễn 8736bad3e7 update
2025-11-06 14:14:10 +07:00

74 lines
2.6 KiB
Plaintext

@implements IDisposable
<div class="d-flex w-100 h-100 flex-column">
<EditForm EditContext="EditContext">
<DataAnnotationsValidator />
<div class="row g-2 mb-2">
<div class="col-md-8">
<label class="form-label">PLC Address</label>
<InputText class="form-control" @bind-Value="Model.PLCAddress" />
<ValidationMessage For="@(() => Model.PLCAddress)" />
</div>
<div class="col-md-4">
<label class="form-label">Port</label>
<InputNumber class="form-control" @bind-Value="Model.PLCPort" />
<ValidationMessage For="@(() => Model.PLCPort)" />
</div>
</div>
<div class="row g-2 mb-2">
<div class="col-md-4">
<label class="form-label">Unit Id</label>
<InputNumber class="form-control" @bind-Value="Model.PLCUnitId" />
<ValidationMessage For="@(() => Model.PLCUnitId)" />
</div>
</div>
<div class="mb-2">
<label class="form-label">Description</label>
<InputTextArea class="form-control" @bind-Value="Model.Description" />
<ValidationMessage For="@(() => Model.Description)" />
</div>
</EditForm>
<div class="flex-grow-1" />
<div>
@if (Model.CreatedAt != default || Model.UpdatedAt != default)
{
<div class="d-flex justify-content-end mt-2">
<small class="text-muted">Created: @Model.CreatedAt.ToString("dd/MM/yyyy HH:mm:ss")</small>
<small class="text-muted ms-3">Updated: @Model.UpdatedAt.ToString("dd/MM/yyyy HH:mm:ss")</small>
</div>
}
</div>
</div>
@code {
[Parameter]
public RobotPlcConfigDto Model { get; set; } = new();
[Parameter]
public EventCallback<RobotPlcConfigDto> ModelChanged { get; set; }
private EditContext? EditContext;
protected override void OnParametersSet()
{
if (EditContext is null || !EditContext.Model!.Equals(Model))
{
if (EditContext is not null) EditContext.OnFieldChanged -= EditContext_OnFieldChanged;
EditContext = new EditContext(Model);
EditContext.OnFieldChanged += EditContext_OnFieldChanged;
}
}
private void EditContext_OnFieldChanged(object? sender, FieldChangedEventArgs e)
{
_ = ModelChanged.InvokeAsync(Model);
}
public void Dispose()
{
if (EditContext is not null) EditContext.OnFieldChanged -= EditContext_OnFieldChanged;
}
}