update
This commit is contained in:
commit
1289a6c331
|
|
@ -14,6 +14,15 @@
|
||||||
Import JSON
|
Import JSON
|
||||||
</MudButton>
|
</MudButton>
|
||||||
|
|
||||||
|
<!-- CANCEL -->
|
||||||
|
<MudButton Variant="Variant.Filled"
|
||||||
|
Color="Color.Error"
|
||||||
|
StartIcon="@Icons.Material.Filled.Cancel"
|
||||||
|
Disabled="@DisableCancel"
|
||||||
|
OnClick="OnCancel">
|
||||||
|
Cancel
|
||||||
|
</MudButton>
|
||||||
|
|
||||||
<!-- SEND -->
|
<!-- SEND -->
|
||||||
<MudButton Variant="Variant.Filled"
|
<MudButton Variant="Variant.Filled"
|
||||||
Color="@SendButtonColor"
|
Color="@SendButtonColor"
|
||||||
|
|
@ -51,10 +60,12 @@
|
||||||
[Parameter] public string OrderJson { get; set; } = "";
|
[Parameter] public string OrderJson { get; set; } = "";
|
||||||
[Parameter] public bool Copied { get; set; }
|
[Parameter] public bool Copied { get; set; }
|
||||||
[Parameter] public bool? SendSuccess { get; set; }
|
[Parameter] public bool? SendSuccess { get; set; }
|
||||||
|
[Parameter] public bool DisableCancel { get; set; }
|
||||||
|
|
||||||
[Parameter] public EventCallback OnCopy { get; set; }
|
[Parameter] public EventCallback OnCopy { get; set; }
|
||||||
[Parameter] public EventCallback OnSend { get; set; }
|
[Parameter] public EventCallback OnSend { get; set; }
|
||||||
[Parameter] public EventCallback OnImport { get; set; }
|
[Parameter] public EventCallback OnImport { get; set; }
|
||||||
|
[Parameter] public EventCallback OnCancel { get; set; }
|
||||||
|
|
||||||
private string SendButtonText =>
|
private string SendButtonText =>
|
||||||
SendSuccess switch
|
SendSuccess switch
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
@inject IJSRuntime JS
|
@inject IJSRuntime JS
|
||||||
@inject IDialogService DialogService
|
@inject IDialogService DialogService
|
||||||
|
@inject ISnackbar Snackbar
|
||||||
@inject HttpClient Http
|
@inject HttpClient Http
|
||||||
|
|
||||||
<MudMainContent Class="pa-0 ma-0">
|
<MudMainContent Class="pa-0 ma-0">
|
||||||
|
|
@ -50,8 +51,8 @@
|
||||||
SendSuccess="@sendSuccess"
|
SendSuccess="@sendSuccess"
|
||||||
OnCopy="CopyJsonToClipboard"
|
OnCopy="CopyJsonToClipboard"
|
||||||
OnSend="SendOrderToServer"
|
OnSend="SendOrderToServer"
|
||||||
OnImport="OpenImportDialog" />
|
OnImport="OpenImportDialog"
|
||||||
|
OnCancel="CancelOrder" />
|
||||||
</MudItem>
|
</MudItem>
|
||||||
|
|
||||||
</MudGrid>
|
</MudGrid>
|
||||||
|
|
@ -65,7 +66,6 @@
|
||||||
private string OrderJson = ""; // 🔥 CACHE JSON (QUAN TRỌNG)
|
private string OrderJson = ""; // 🔥 CACHE JSON (QUAN TRỌNG)
|
||||||
private bool copied;
|
private bool copied;
|
||||||
private bool? sendSuccess;
|
private bool? sendSuccess;
|
||||||
private bool sending;
|
|
||||||
private CancellationTokenSource? _copyCts;
|
private CancellationTokenSource? _copyCts;
|
||||||
|
|
||||||
// ================= INIT =================
|
// ================= 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()
|
async Task CopyJsonToClipboard()
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using RobotApp.Services.Robot;
|
using RobotApp.Interfaces;
|
||||||
using RobotApp.VDA5050.Order;
|
using RobotApp.VDA5050.Order;
|
||||||
using System.Text.Json;
|
|
||||||
|
|
||||||
namespace RobotApp.Controllers;
|
namespace RobotApp.Controllers;
|
||||||
|
|
||||||
|
|
@ -10,24 +9,11 @@ namespace RobotApp.Controllers;
|
||||||
[Route("api/order")]
|
[Route("api/order")]
|
||||||
//[Authorize]
|
//[Authorize]
|
||||||
[AllowAnonymous]
|
[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]
|
[HttpPost]
|
||||||
public IActionResult SendOrder([FromBody] OrderMsg order)
|
public IActionResult SendOrder([FromBody] OrderMsg order)
|
||||||
{
|
{
|
||||||
Console.WriteLine("===== ORDER RECEIVED =====");
|
|
||||||
Console.WriteLine(JsonSerializer.Serialize(order, new JsonSerializerOptions
|
|
||||||
{
|
|
||||||
WriteIndented = true
|
|
||||||
}));
|
|
||||||
|
|
||||||
robotOrderController.UpdateOrder(order);
|
robotOrderController.UpdateOrder(order);
|
||||||
|
|
||||||
return Ok(new
|
return Ok(new
|
||||||
|
|
@ -36,4 +22,17 @@ public class OrderController : ControllerBase
|
||||||
message = "Order received"
|
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