update
This commit is contained in:
@@ -1,32 +1,47 @@
|
||||
@using RobotApp.Common.Shares.Dtos
|
||||
@implements IDisposable
|
||||
<div class="d-flex w-100 h-100 flex-column">
|
||||
<EditForm EditContext="EditContext">
|
||||
<DataAnnotationsValidator />
|
||||
|
||||
<EditForm Model="@Local" OnValidSubmit="OnSubmit">
|
||||
<DataAnnotationsValidator />
|
||||
<ValidationSummary />
|
||||
<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="Local.PLCAddress" />
|
||||
<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="col-md-4">
|
||||
<label class="form-label">Port</label>
|
||||
<InputNumber class="form-control" @bind-Value="Local.PLCPort" />
|
||||
|
||||
<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>
|
||||
|
||||
<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="Local.PLCUnitId" />
|
||||
<div class="mb-2">
|
||||
<label class="form-label">Description</label>
|
||||
<InputTextArea class="form-control" @bind-Value="Model.Description" />
|
||||
<ValidationMessage For="@(() => Model.Description)" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-2">
|
||||
<label class="form-label">Description</label>
|
||||
<InputTextArea class="form-control" @bind-Value="Local.Description" />
|
||||
</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>
|
||||
|
||||
</EditForm>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
@@ -35,16 +50,25 @@
|
||||
[Parameter]
|
||||
public EventCallback<RobotPlcConfigDto> ModelChanged { get; set; }
|
||||
|
||||
private RobotPlcConfigDto Local = new();
|
||||
private EditContext? EditContext;
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
Local = Model is not null ? Model with { } : new RobotPlcConfigDto();
|
||||
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 async Task OnSubmit()
|
||||
private void EditContext_OnFieldChanged(object? sender, FieldChangedEventArgs e)
|
||||
{
|
||||
Model = Local;
|
||||
await ModelChanged.InvokeAsync(Model);
|
||||
_ = ModelChanged.InvokeAsync(Model);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (EditContext is not null) EditContext.OnFieldChanged -= EditContext_OnFieldChanged;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user