Files
Lab505/Lab505.Client/Pages/StatusPanel.razor
2026-10-22 14:31:58 +07:00

107 lines
4.8 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
@implements IAsyncDisposable
@inject IJSRuntime JS
<MudPaper Elevation="0" Class="pa-2" Style="background:transparent;">
<MudStack Row="true" AlignItems="AlignItems.Center" Style="cursor:pointer" @onclick="ToggleExpand">
<MudText Typo="Typo.subtitle1">STATUS</MudText>
<MudText Typo="Typo.caption" Style="@($"font-weight:800;letter-spacing:0.5px;margin-left:20px;white-space:nowrap;{WfColor}")">@WfPhaseText</MudText>
@if (State.Workflow.CompletedCycles > 0)
{
<MudText Typo="Typo.caption" Style="color:#5a8a6a;font-weight:700;white-space:nowrap;">@State.Workflow.CompletedCycles ×</MudText>
}
<MudSpacer />
<MudIcon Icon="@(_expanded ? Icons.Material.Filled.ExpandMore : Icons.Material.Filled.ExpandLess)" Size="Size.Small" />
</MudStack>
@if (!string.IsNullOrEmpty(State.Workflow.LastError))
{
<MudAlert Severity="Severity.Error" Dense="true" Class="mt-1" Style="font-size:0.7rem;">@State.Workflow.LastError</MudAlert>
}
@if (_expanded)
{
@* ── IMR + AMR ── *@
<ImrAmrStatusPanel />
<MudDivider Class="mt-2 mb-1" />
@* ── ASRS grid — Slot.{cột}.{tầng}.Occupied từ gateway OPC UA, tầng cao nhất ở trên ── *@
<div style="display:grid;grid-template-columns:repeat(3,1fr);gap:4px;">
@foreach (var row in AsrsRows)
{
@foreach (var cell in row.Cells)
{
bool on = cell.Val == true && State.AsrsOpc.Online;
<MudChip T="string" Size="Size.Small"
Color="@(on ? Color.Info : Color.Default)"
Variant="@(on ? Variant.Filled : Variant.Outlined)"
Style="width:100%;margin:0;justify-content:center;height:25px;font-size:13px;font-weight:700;">@cell.Label</MudChip>
}
}
</div>
@* ── Nav ── *@
<MudStack Row="true" Spacing="1" Class="mt-2">
<MudButton Variant="Variant.Outlined" Size="Size.Small" Style="flex:1;min-width:0;padding:0 4px;" OnClick='()=>ScrollTo("p-ctrl")'>CTRL</MudButton>
<MudButton Variant="Variant.Outlined" Size="Size.Small" Style="flex:1;min-width:0;padding:0 4px;" OnClick='()=>ScrollTo("p-ops")'>OPS</MudButton>
<MudButton Variant="Variant.Outlined" Size="Size.Small" Style="flex:1;min-width:0;padding:0 4px;" OnClick='()=>ScrollTo("p-conveyor")'>CV</MudButton>
<MudButton Variant="Variant.Outlined" Size="Size.Small" Style="flex:1;min-width:0;padding:0 4px;" OnClick='()=>ScrollTo("p-imr")'>IMR</MudButton>
<MudButton Variant="Variant.Outlined" Size="Size.Small" Style="flex:1;min-width:0;padding:0 4px;" OnClick='()=>ScrollTo("p-amr")'>AMR</MudButton>
<MudButton Variant="Variant.Outlined" Size="Size.Small" Style="flex:1;min-width:0;padding:0 4px;" OnClick='()=>ScrollTo("p-dobot")'>Dobot</MudButton>
<MudButton Variant="Variant.Outlined" Size="Size.Small" Style="flex:1;min-width:0;padding:0 4px;" OnClick='()=>ScrollTo("p-asrs")'>ASRS</MudButton>
</MudStack>
}
</MudPaper>
@code {
[Inject] StateService State { get; set; } = default!;
private bool _expanded = true;
void ToggleExpand() => _expanded = !_expanded;
protected override async Task OnInitializedAsync()
{
await State.StartAsync();
State.AsrsOpcChanged += Refresh;
State.WorkflowChanged += Refresh;
}
public ValueTask DisposeAsync()
{
State.AsrsOpcChanged -= Refresh;
State.WorkflowChanged -= Refresh;
return ValueTask.CompletedTask;
}
private void Refresh() => InvokeAsync(StateHasChanged);
private Task ScrollTo(string id) =>
JS.InvokeVoidAsync("eval", $"document.getElementById('{id}')?.scrollIntoView({{behavior:'smooth'}})").AsTask();
private string WfPhaseText
{
get
{
var wf = State.Workflow;
if (!string.IsNullOrEmpty(wf.LastError)) return "ERROR";
if (wf.IsRunning) return "RUNNING";
return "IDLE";
}
}
private string WfColor =>
!string.IsNullOrEmpty(State.Workflow.LastError) ? "color:#e74c3c;" :
State.Workflow.IsRunning ? "color:#4a9eff;" : "color:#9CA3AF;";
private (string RowLabel, (string Label, bool? Val)[] Cells)[] AsrsRows =>
Enumerable.Range(1, AsrsOpcLayout.Shelves).Reverse()
.Select(shelf => ($"T{shelf}",
Enumerable.Range(1, AsrsOpcLayout.Columns)
.Select(col => ($"{col}.{shelf}",
State.AsrsOpc.Occupied.ElementAtOrDefault(AsrsOpcLayout.SlotIndex(col, shelf))))
.ToArray()))
.ToArray();
}