update
This commit is contained in:
commit
1289a6c331
|
|
@ -14,6 +14,15 @@
|
|||
Import JSON
|
||||
</MudButton>
|
||||
|
||||
<!-- CANCEL -->
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="Color.Error"
|
||||
StartIcon="@Icons.Material.Filled.Cancel"
|
||||
Disabled="@DisableCancel"
|
||||
OnClick="OnCancel">
|
||||
Cancel
|
||||
</MudButton>
|
||||
|
||||
<!-- SEND -->
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="@SendButtonColor"
|
||||
|
|
@ -51,10 +60,12 @@
|
|||
[Parameter] public string OrderJson { get; set; } = "";
|
||||
[Parameter] public bool Copied { get; set; }
|
||||
[Parameter] public bool? SendSuccess { get; set; }
|
||||
[Parameter] public bool DisableCancel { get; set; }
|
||||
|
||||
[Parameter] public EventCallback OnCopy { get; set; }
|
||||
[Parameter] public EventCallback OnSend { get; set; }
|
||||
[Parameter] public EventCallback OnImport { get; set; }
|
||||
[Parameter] public EventCallback OnCancel { get; set; }
|
||||
|
||||
private string SendButtonText =>
|
||||
SendSuccess switch
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
@inject IJSRuntime JS
|
||||
@inject IDialogService DialogService
|
||||
@inject ISnackbar Snackbar
|
||||
@inject HttpClient Http
|
||||
|
||||
<MudMainContent Class="pa-0 ma-0">
|
||||
|
|
@ -50,8 +51,8 @@
|
|||
SendSuccess="@sendSuccess"
|
||||
OnCopy="CopyJsonToClipboard"
|
||||
OnSend="SendOrderToServer"
|
||||
OnImport="OpenImportDialog" />
|
||||
|
||||
OnImport="OpenImportDialog"
|
||||
OnCancel="CancelOrder" />
|
||||
</MudItem>
|
||||
|
||||
</MudGrid>
|
||||
|
|
@ -65,7 +66,6 @@
|
|||
private string OrderJson = ""; // 🔥 CACHE JSON (QUAN TRỌNG)
|
||||
private bool copied;
|
||||
private bool? sendSuccess;
|
||||
private bool sending;
|
||||
private CancellationTokenSource? _copyCts;
|
||||
|
||||
// ================= INIT =================
|
||||
|
|
@ -245,6 +245,35 @@
|
|||
});
|
||||
}
|
||||
|
||||
async Task CancelOrder()
|
||||
{
|
||||
try
|
||||
{
|
||||
var res = await Http.PostAsync("/api/order/cancel", null);
|
||||
|
||||
sendSuccess = null; // reset trạng thái SEND
|
||||
copied = false;
|
||||
|
||||
if (res.IsSuccessStatusCode)
|
||||
{
|
||||
Snackbar.Add(
|
||||
"⛔ Order đã huỷ",
|
||||
Severity.Info);
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add(
|
||||
"❌ Huỷ order thất bại",
|
||||
Severity.Error);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add(
|
||||
$"❌ Lỗi: {ex.Message}",
|
||||
Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async Task CopyJsonToClipboard()
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using RobotApp.Services.Robot;
|
||||
using RobotApp.Interfaces;
|
||||
using RobotApp.VDA5050.Order;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace RobotApp.Controllers;
|
||||
|
||||
|
|
@ -10,24 +9,11 @@ namespace RobotApp.Controllers;
|
|||
[Route("api/order")]
|
||||
//[Authorize]
|
||||
[AllowAnonymous]
|
||||
public class OrderController : ControllerBase
|
||||
public class OrderController(IOrder robotOrderController, IInstantActions instantActions) : ControllerBase
|
||||
{
|
||||
private readonly RobotOrderController robotOrderController;
|
||||
|
||||
public OrderController(RobotOrderController robotOrderController)
|
||||
{
|
||||
this.robotOrderController = robotOrderController;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult SendOrder([FromBody] OrderMsg order)
|
||||
{
|
||||
Console.WriteLine("===== ORDER RECEIVED =====");
|
||||
Console.WriteLine(JsonSerializer.Serialize(order, new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true
|
||||
}));
|
||||
|
||||
robotOrderController.UpdateOrder(order);
|
||||
|
||||
return Ok(new
|
||||
|
|
@ -36,4 +22,17 @@ public class OrderController : ControllerBase
|
|||
message = "Order received"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("cancel")]
|
||||
public IActionResult CancelOrder()
|
||||
{
|
||||
robotOrderController.StopOrder();
|
||||
instantActions.StopOrderAction();
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
success = true,
|
||||
message = "Order and actions have been cancelled"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user