update
This commit is contained in:
@@ -1,40 +1,60 @@
|
||||
@using RobotApp.Common.Shares.Dtos
|
||||
|
||||
<EditForm Model="@Local" OnValidSubmit="OnSubmit">
|
||||
<DataAnnotationsValidator />
|
||||
<ValidationSummary />
|
||||
<div class="form-check mb-2">
|
||||
<InputCheckbox class="form-check-input" @bind-Value="Local.EnableSimulation" />
|
||||
<label class="form-check-label">Enable Simulation</label>
|
||||
</div>
|
||||
@implements IDisposable
|
||||
|
||||
<div class="row g-2 mb-2">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Max Velocity (m/s)</label>
|
||||
<InputNumber class="form-control" @bind-Value="Local.SimulationMaxVelocity" />
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Max Angular Velocity (rad/s)</label>
|
||||
<InputNumber class="form-control" @bind-Value="Local.SimulationMaxAngularVelocity" />
|
||||
</div>
|
||||
</div>
|
||||
<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-6">
|
||||
<label class="form-label">Acceleration (m/s²)</label>
|
||||
<InputNumber class="form-control" @bind-Value="Local.SimulationAcceleration" />
|
||||
<div class="form-check mb-2">
|
||||
<InputCheckbox class="form-check-input" @bind-Value="Model.EnableSimulation" />
|
||||
<label class="form-check-label">Enable Simulation</label>
|
||||
<ValidationMessage For="@(() => Model.EnableSimulation)" />
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Deceleration (m/s²)</label>
|
||||
<InputNumber class="form-control" @bind-Value="Local.SimulationDeceleration" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-2">
|
||||
<label class="form-label">Description</label>
|
||||
<InputTextArea class="form-control" @bind-Value="Local.Description" />
|
||||
<div class="row g-2 mb-2">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Max Velocity (m/s)</label>
|
||||
<InputNumber class="form-control" @bind-Value="Model.SimulationMaxVelocity" />
|
||||
<ValidationMessage For="@(() => Model.SimulationMaxVelocity)" />
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Max Angular Velocity (rad/s)</label>
|
||||
<InputNumber class="form-control" @bind-Value="Model.SimulationMaxAngularVelocity" />
|
||||
<ValidationMessage For="@(() => Model.SimulationMaxAngularVelocity)" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row g-2 mb-2">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Acceleration (m/s²)</label>
|
||||
<InputNumber class="form-control" @bind-Value="Model.SimulationAcceleration" />
|
||||
<ValidationMessage For="@(() => Model.SimulationAcceleration)" />
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Deceleration (m/s²)</label>
|
||||
<InputNumber class="form-control" @bind-Value="Model.SimulationDeceleration" />
|
||||
<ValidationMessage For="@(() => Model.SimulationDeceleration)" />
|
||||
</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>
|
||||
</EditForm>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
@@ -43,17 +63,25 @@
|
||||
[Parameter]
|
||||
public EventCallback<RobotSimulationConfigDto> ModelChanged { get; set; }
|
||||
|
||||
private RobotSimulationConfigDto Local = new();
|
||||
private EditContext? EditContext;
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
// Use record 'with' to create a shallow copy so parent isn't mutated until submit
|
||||
Local = Model is not null ? Model with { } : new RobotSimulationConfigDto();
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,10 @@
|
||||
<i class="mdi mdi-content-save" aria-hidden="true"></i>
|
||||
</button>
|
||||
|
||||
<button type="button" class="btn rcm-icon-btn" data-tooltip="Load config" aria-label="Update" @onclick="LoadConfig">
|
||||
<i class="mdi mdi-file-download" aria-hidden="true"></i>
|
||||
</button>
|
||||
|
||||
<button type="button" class="btn rcm-icon-btn rcm-danger" data-tooltip="Delete config" aria-label="Delete" @onclick="DeleteConfig">
|
||||
<i class="mdi mdi-delete" aria-hidden="true"></i>
|
||||
</button>
|
||||
|
||||
@@ -306,7 +306,7 @@ public partial class RobotConfigManager
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<bool> SaveCertificates(Guid id)
|
||||
private async Task<bool> SaveCertificates()
|
||||
{
|
||||
using var content = new MultipartFormDataContent();
|
||||
|
||||
@@ -325,12 +325,16 @@ public partial class RobotConfigManager
|
||||
var fileContent = new StreamContent(RobotVDA5050ConfigRef.KeyFile.OpenReadStream(maxAllowedSize: RobotVDA5050ConfigRef.MaxFileSize));
|
||||
content.Add(fileContent, "KeyFile", RobotVDA5050ConfigRef.KeyFile.Name);
|
||||
}
|
||||
|
||||
var response = await (await Http.PostAsync($"api/File/certificates/{id}", content)).Content.ReadFromJsonAsync<MessageResult>();
|
||||
if (response is null) Snackbar.Add("Failed to update certificates", Severity.Warning);
|
||||
else if (!response.IsSuccess) Snackbar.Add(response.Message ?? "Failed to update certificates config", Severity.Warning);
|
||||
else return true;
|
||||
return false;
|
||||
if (content.Any())
|
||||
{
|
||||
var response = await (await Http.PostAsync($"api/File/certificates", content)).Content.ReadFromJsonAsync<MessageResult>();
|
||||
if (response is null) Snackbar.Add("Failed to update certificates", Severity.Warning);
|
||||
else if (!response.IsSuccess) Snackbar.Add(response.Message ?? "Failed to update certificates", Severity.Warning);
|
||||
else return true;
|
||||
StateHasChanged();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task SaveConfig()
|
||||
@@ -377,7 +381,7 @@ public partial class RobotConfigManager
|
||||
SelectedVda.VDA5050Key,
|
||||
SelectedVda.Description
|
||||
};
|
||||
var saveCer = await SaveCertificates(SelectedVda.Id);
|
||||
var saveCer = await SaveCertificates();
|
||||
if (saveCer) result = await (await Http.PutAsJsonAsync($"api/RobotConfigs/vda5050/{id}", updateDto)).Content.ReadFromJsonAsync<MessageResult>();
|
||||
else return;
|
||||
break;
|
||||
@@ -551,4 +555,13 @@ public partial class RobotConfigManager
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadConfig()
|
||||
{
|
||||
var response = await (await Http.PostAsync($"api/RobotConfigs/load", null)).Content.ReadFromJsonAsync<MessageResult>();
|
||||
if (response is null) Snackbar.Add("Failed to load config", Severity.Warning);
|
||||
else if (!response.IsSuccess) Snackbar.Add(response.Message ?? "Failed to load config", Severity.Warning);
|
||||
else Snackbar.Add("Config loaded", Severity.Success);
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user