RobotApp/RobotApp.Client/Pages/Order/JsonOutputPanel.razor
Đăng Nguyễn 5c1851e92f update
2025-12-31 14:03:47 +07:00

132 lines
4.2 KiB
Plaintext

<MudPaper Class="pa-4 h-100 d-flex flex-column overflow-hidden" Elevation="2">
<MudStack Row AlignItems="AlignItems.Center" Justify="Justify.SpaceBetween"
Class="mb-4 flex-shrink-0">
<MudText Typo="Typo.h6">Output (/order)</MudText>
<div class="d-flex gap-2">
<!-- IMPORT -->
<MudButton Variant="Variant.Outlined"
Color="Color.Secondary"
Size="Size.Small"
StartIcon="@Icons.Material.Filled.UploadFile"
OnClick="OnImport">
Import JSON
</MudButton>
<!-- CANCEL -->
<MudButton Variant="Variant.Filled"
Color="@CancelButtonColor"
StartIcon="@CancelButtonIcon"
Disabled="@DisableCancel"
OnClick="OnCancel">
@CancelButtonText
</MudButton>
<!-- SEND -->
<MudButton Variant="Variant.Filled"
Color="@SendButtonColor"
StartIcon="@SendButtonIcon"
OnClick="OnSend"
Disabled="@(string.IsNullOrEmpty(OrderJson.Trim()))">
@SendButtonText
</MudButton>
<!-- COPY -->
<MudTooltip Text="@(Copied ? "Copied!" : "Copy to clipboard")">
<MudButton Variant="Variant.Filled"
Color="@(Copied ? Color.Success : Color.Primary)"
StartIcon="@(Copied ? Icons.Material.Filled.Check : Icons.Material.Filled.ContentCopy)"
OnClick="OnCopy">
@(Copied ? "Copied!" : "Copy")
</MudButton>
</MudTooltip>
</div>
</MudStack>
<div class="flex-grow-1">
<MudTextField Value="@OrderJson"
T="string"
ValueChanged="OrderJsonChange"
Variant="Variant.Filled"
Immediate=true
Lines="50"
Style="font-family: 'Roboto Mono', Consolas, monospace;
font-size: 0.85rem;
background:#1e1e1e;
color:#d4d4d4;" />
</div>
</MudPaper>
@code {
[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 bool? CancelSuccess { get; set; }
[Parameter] public EventCallback<string> OrderJsonChanged { 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
{
true => "Done",
false => "Error",
_ => "Send"
};
private Color SendButtonColor =>
SendSuccess switch
{
true => Color.Success,
false => Color.Error,
_ => Color.Success
};
private string SendButtonIcon =>
SendSuccess switch
{
true => Icons.Material.Filled.CheckCircle,
false => Icons.Material.Filled.Error,
_ => Icons.Material.Filled.Send
};
private string CancelButtonText =>
CancelSuccess switch
{
true => "Done",
false => "Error",
_ => "Cancel"
};
private Color CancelButtonColor =>
CancelSuccess switch
{
true => Color.Success,
false => Color.Error,
_ => Color.Error
};
private string CancelButtonIcon =>
CancelSuccess switch
{
true => Icons.Material.Filled.CheckCircle,
false => Icons.Material.Filled.Error,
_ => Icons.Material.Filled.Cancel
};
private void OrderJsonChange(string value)
{
OrderJson = value;
OrderJsonChanged.InvokeAsync(OrderJson);
StateHasChanged();
}
}