CONTROL ACCESS
@{
var ls = State.LockState;
var wfActive = ls?.Workflow is not null;
var grpActive = ls?.Groups is { } grpDict && grpDict.Values.Any(v => v is not null);
}
@if (_expanded)
{
@* ── Mode banner ── *@
@if (wfActive)
{
WF — @(ls!.Workflow!.Name)
@Lang.T("Manual tắt", "Manual disabled")
}
else if (grpActive)
{
MANUAL
@Lang.T("Workflow tắt", "Workflow disabled")
}
else
{
@Lang.T("Không có ai nắm quyền", "No one holds control")
}
@* ── OPERATIONS CONTROL row ── *@
OPS
@if (!CanWorkflow && UseReal)
{
Manual only
}
@if (ls?.Workflow is { } wfHolder)
{
bool isMine = wfHolder.UserId == MyUserId;
@(isMine ? Lang.T("Bạn giữ", "You hold") : wfHolder.Name)
@if (isMine)
{
RELEASE
}
else if (IsManager)
{
Preempt
}
else
{
var qPos = ls.WorkflowQueue?.ToList().FindIndex(w => w.UserId == MyUserId) ?? -1;
@if (qPos >= 0)
{
@Lang.T("Chờ", "Queue") #@(qPos + 1)
}
else if (CanWorkflow)
{
JOIN
}
}
}
else if (!grpActive || IsManager)
{
Free
@if (CanWorkflow)
{
ACQUIRE
}
else
{
@Lang.T("Cần quyền WF", "Need WF perm")
}
}
else
{
@Lang.T("Manual đang bật", "Manual is active")
}
@if (ls?.WorkflowQueue is { Count: > 0 } wfQueue)
{
@foreach (var (w, i) in wfQueue.Select((w, i) => (w, i)))
{
@(i + 1). @w.Name
}
}
@* ── Group row ── *@
@foreach (var group in new[] { "ImrDobot", "AmrC1", "C2Asrs" })
{
var groupLabel = group switch { "ImrDobot" => "IMR·Dobot", "AmrC1" => "AMR·C1", _ => "C2·ASRS" };
LockHolderDto? groupHolder = null;
IReadOnlyList
? groupQueue = null;
ls?.Groups?.TryGetValue(group, out groupHolder);
ls?.GroupQueues?.TryGetValue(group, out groupQueue);
@groupLabel
@if (wfActive)
{
WF
}
else if (groupHolder is not null)
{
bool isMine = groupHolder.UserId == MyUserId;
@(isMine ? Lang.T("Bạn", "You") : groupHolder.Name)
@if (isMine)
{
var grp = group;
UNLOCK
}
else if (IsManager)
{
var grp = group;
Unassign
}
else
{
var grp = group;
var qPos2 = groupQueue?.ToList().FindIndex(w => w.UserId == MyUserId) ?? -1;
@if (qPos2 >= 0)
{
#@(qPos2 + 1)
}
else if (CanManual)
{
JOIN
}
}
}
else
{
Free
var grp = group;
var assignedIds = State.LockState?.Groups?
.Where(kv => kv.Key != grp && kv.Value is not null)
.Select(kv => kv.Value!.UserId)
.ToHashSet() ?? new HashSet();
var availableUsers = _users.Where(u => !assignedIds.Contains(u.Id)).ToList();
if (IsManager)
{
@if (availableUsers.Count == 0)
{
@Lang.T("Hết user", "All assigned")
}
else
{
@foreach (var u in availableUsers)
{
var uid = u.Id;
var uname = u.Username;
@u.Username
@u.Role
}
}
}
else if (CanManual)
{
LOCK
}
else
{
@Lang.T("Cần Manual", "Need Manual")
}
}
@if (groupQueue is { Count: > 0 })
{
@foreach (var (w, i) in groupQueue.Select((w, i) => (w, i)))
{
@(i + 1). @w.Name
}
}
}
}
@code {
[Parameter] public bool UseReal { get; set; }
[Parameter] public string MyUserId { get; set; } = "";
[Parameter] public string MyRole { get; set; } = "";
[Parameter] public bool CanWorkflow { get; set; }
[Parameter] public bool CanManual { get; set; }
private bool IsManager => MyRole is "Manager" or "Admin";
private bool _expanded = true;
private bool _usersLoaded = false;
private List