save
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
@page "/"
|
||||
@attribute [Authorize]
|
||||
@using RobotApp.Client.Services
|
||||
@using RobotApp.VDA5050.State
|
||||
@using MudBlazor
|
||||
|
||||
@@ -117,14 +117,14 @@
|
||||
}
|
||||
|
||||
<!-- Apply Curve -->
|
||||
@if (edge.Radius > 0 && !edge.Expanded)
|
||||
@if (!edge.HasTrajectory && edge.Radius > 0 && !edge.Expanded)
|
||||
{
|
||||
<MudItem xs="12">
|
||||
<MudButton Color="Color.Primary"
|
||||
Variant="Variant.Outlined"
|
||||
StartIcon="@Icons.Material.Filled.Merge"
|
||||
OnClick="@(() => ApplyCurveAsync(edge))">
|
||||
Apply Curve
|
||||
Apply Curve (generate node)
|
||||
</MudButton>
|
||||
</MudItem>
|
||||
}
|
||||
|
||||
104
RobotApp.Client/Pages/Order/ImportOrderDialog.razor
Normal file
104
RobotApp.Client/Pages/Order/ImportOrderDialog.razor
Normal file
@@ -0,0 +1,104 @@
|
||||
@using System.Text.Json
|
||||
@using MudBlazor
|
||||
|
||||
<MudDialog>
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">Import Order JSON</MudText>
|
||||
</TitleContent>
|
||||
|
||||
<DialogContent>
|
||||
|
||||
@if (ShowWarning)
|
||||
{
|
||||
<MudAlert Severity="Severity.Warning"
|
||||
Variant="Variant.Outlined"
|
||||
Class="mb-4">
|
||||
Only valid <b>VDA 5050 Order JSON</b> is accepted.<br />
|
||||
Invalid structure will be rejected.
|
||||
</MudAlert>
|
||||
}
|
||||
|
||||
<MudTextField @bind-Value="JsonText"
|
||||
Label="Paste Order JSON"
|
||||
Lines="20"
|
||||
Variant="Variant.Filled"
|
||||
Immediate
|
||||
Style="font-family: monospace" />
|
||||
|
||||
@if (!string.IsNullOrEmpty(ErrorMessage))
|
||||
{
|
||||
<MudAlert Severity="Severity.Error" Class="mt-3">
|
||||
@ErrorMessage
|
||||
</MudAlert>
|
||||
}
|
||||
|
||||
</DialogContent>
|
||||
|
||||
<DialogActions>
|
||||
<MudButton OnClick="Cancel">Cancel</MudButton>
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="Color.Primary"
|
||||
OnClick="ValidateAndImport">
|
||||
Import
|
||||
</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
@code {
|
||||
[CascadingParameter] public IMudDialogInstance MudDialog { get; set; } = default!;
|
||||
|
||||
public string JsonText { get; set; } = "";
|
||||
public string? ErrorMessage;
|
||||
public bool ShowWarning { get; set; } = false;
|
||||
|
||||
private void Cancel() => MudDialog.Cancel();
|
||||
|
||||
private void ValidateAndImport()
|
||||
{
|
||||
ErrorMessage = null;
|
||||
ShowWarning = false;
|
||||
|
||||
try
|
||||
{
|
||||
using var doc = JsonDocument.Parse(JsonText);
|
||||
var root = doc.RootElement;
|
||||
|
||||
// ===== BASIC STRUCTURE CHECK =====
|
||||
if (!root.TryGetProperty("nodes", out _) ||
|
||||
!root.TryGetProperty("edges", out _))
|
||||
throw new Exception("Missing 'nodes' or 'edges' field.");
|
||||
|
||||
var order = OrderMessage.FromSchemaObject(root);
|
||||
|
||||
ValidateOrder(order);
|
||||
|
||||
MudDialog.Close(DialogResult.Ok(order));
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
ShowWarning = true;
|
||||
ErrorMessage = "Invalid JSON format.";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ShowWarning = true;
|
||||
ErrorMessage = ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
private void ValidateOrder(OrderMessage order)
|
||||
{
|
||||
if (order.Nodes.Count == 0)
|
||||
throw new Exception("Order must contain at least one node.");
|
||||
|
||||
var nodeIds = order.Nodes.Select(n => n.NodeId).ToHashSet();
|
||||
|
||||
foreach (var e in order.Edges)
|
||||
{
|
||||
if (!nodeIds.Contains(e.StartNodeId) ||
|
||||
!nodeIds.Contains(e.EndNodeId))
|
||||
throw new Exception(
|
||||
$"Edge '{e.EdgeId}' references unknown node."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,16 @@
|
||||
|
||||
<div class="d-flex gap-2">
|
||||
|
||||
<!-- ================= SEND BUTTON ================= -->
|
||||
<!-- IMPORT -->
|
||||
<MudButton Variant="Variant.Outlined"
|
||||
Color="Color.Secondary"
|
||||
Size="Size.Small"
|
||||
StartIcon="@Icons.Material.Filled.UploadFile"
|
||||
OnClick="OnImport">
|
||||
Import JSON
|
||||
</MudButton>
|
||||
|
||||
<!-- SEND -->
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="@SendButtonColor"
|
||||
StartIcon="@SendButtonIcon"
|
||||
@@ -14,7 +23,7 @@
|
||||
@SendButtonText
|
||||
</MudButton>
|
||||
|
||||
<!-- ================= COPY ================= -->
|
||||
<!-- COPY -->
|
||||
<MudTooltip Text="@(Copied ? "Copied!" : "Copy to clipboard")">
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="@(Copied ? Color.Success : Color.Primary)"
|
||||
@@ -27,15 +36,14 @@
|
||||
</div>
|
||||
</MudStack>
|
||||
|
||||
<!-- ================= JSON ================= -->
|
||||
<div class="flex-grow-1" style="overflow:auto;">
|
||||
<MudTextField Value="@OrderJson"
|
||||
ReadOnly="true"
|
||||
ReadOnly
|
||||
Variant="Variant.Filled"
|
||||
Lines="70"
|
||||
Class="h-100"
|
||||
Style="font-family: 'Roboto Mono', Consolas, 'Courier New', monospace;
|
||||
font-size: 0.875rem;
|
||||
Style="font-family: 'Roboto Mono', Consolas, monospace;
|
||||
font-size: 0.85rem;
|
||||
background:#1e1e1e;
|
||||
color:#d4d4d4;" />
|
||||
</div>
|
||||
@@ -45,10 +53,11 @@
|
||||
[Parameter] public string OrderJson { get; set; } = "";
|
||||
[Parameter] public bool Copied { get; set; }
|
||||
[Parameter] public bool? SendSuccess { get; set; }
|
||||
|
||||
[Parameter] public EventCallback OnCopy { get; set; }
|
||||
[Parameter] public EventCallback OnSend { get; set; }
|
||||
[Parameter] public EventCallback OnImport { get; set; }
|
||||
|
||||
// ================= SEND BUTTON STATE =================
|
||||
private string SendButtonText =>
|
||||
SendSuccess switch
|
||||
{
|
||||
|
||||
@@ -50,7 +50,8 @@
|
||||
Copied="@copied"
|
||||
SendSuccess="@sendSuccess"
|
||||
OnCopy="CopyJsonToClipboard"
|
||||
OnSend="SendOrderToServer" />
|
||||
OnSend="SendOrderToServer"
|
||||
OnImport="OpenImportDialog" />
|
||||
|
||||
</MudItem>
|
||||
|
||||
@@ -85,6 +86,25 @@
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
|
||||
});
|
||||
}
|
||||
private async Task OpenImportDialog()
|
||||
{
|
||||
var dialog = await DialogService.ShowAsync<ImportOrderDialog>(
|
||||
"Import Order JSON",
|
||||
new DialogOptions
|
||||
{
|
||||
FullWidth = true,
|
||||
MaxWidth = MaxWidth.Large
|
||||
});
|
||||
|
||||
var result = await dialog.Result;
|
||||
|
||||
if (!result.Canceled && result.Data is OrderMessage imported)
|
||||
{
|
||||
Order = imported;
|
||||
RebuildOrderJson();
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnOrderChanged()
|
||||
{
|
||||
@@ -151,7 +171,7 @@
|
||||
|
||||
Order.Nodes.Add(newNode);
|
||||
edge.EndNodeId = newNode.NodeId;
|
||||
edge.Expanded = true;
|
||||
edge.MarkExpanded(); // ✅
|
||||
|
||||
ResequenceNodes();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user