1
0
mirror of https://github.com/chylex/Minecraft-Phantom-Panel.git synced 2025-05-05 03:34:05 +02:00

Redesign Web tables

This commit is contained in:
chylex 2023-12-19 06:50:17 +01:00
parent 578ec2d11c
commit e679b17e3b
Signed by: chylex
GPG Key ID: 4DE42C8F19A80548
16 changed files with 361 additions and 292 deletions

View File

@ -4,7 +4,7 @@ using System.Diagnostics.CodeAnalysis;
namespace Phantom.Utils.Collections; namespace Phantom.Utils.Collections;
public sealed class Table<TRow, TKey> : IReadOnlyList<TRow>, IReadOnlyDictionary<TKey, TRow> where TRow : notnull where TKey : notnull { public sealed class TableData<TRow, TKey> : IReadOnlyList<TRow>, IReadOnlyDictionary<TKey, TRow> where TRow : notnull where TKey : notnull {
private readonly List<TRow> rowList = new(); private readonly List<TRow> rowList = new();
private readonly Dictionary<TKey, TRow> rowDictionary = new (); private readonly Dictionary<TKey, TRow> rowDictionary = new ();

View File

@ -39,8 +39,10 @@ $dropdown-link-active-bg: mix($gray-200, $gray-300, 75%);
@import "./components"; @import "./components";
.spinner-border-sm { .spinner-border {
--bs-spinner-border-width: 0.15em; --bs-spinner-width: 1em;
--bs-spinner-height: 1em;
--bs-spinner-border-width: 0.15rem;
} }
.progress { .progress {

View File

@ -1,9 +1,9 @@
.progress { .progress {
height: 4px; height: 4px;
margin: 0.15rem 0;
} }
.progress-label { .progress-label {
width: 100%; width: 100%;
margin-bottom: 0.15rem;
font-size: 0.9rem; font-size: 0.9rem;
} }

View File

@ -0,0 +1,14 @@
@using System.Globalization
<p>
<time datetime="@Time.ToString("o", CultureInfo.InvariantCulture)" data-time-type="relative">
@Time.ToString("dd MMM yyyy, HH:mm:ss", CultureInfo.InvariantCulture)
</time>
</p>
<small>@Time.ToString("zzz", CultureInfo.InvariantCulture)</small>
@code {
[Parameter, EditorRequired]
public DateTimeOffset Time { get; set; }
}

View File

@ -1,4 +1,4 @@
<th style="min-width: @minWidth; width: @preferredWidth;" class="@Class"> <th style="@style" class="@Class">
@ChildContent @ChildContent
</th> </th>
@ -7,32 +7,29 @@
[Parameter] [Parameter]
public string Class { get; set; } = string.Empty; public string Class { get; set; } = string.Empty;
[Parameter]
public string? MinWidth { get; set; }
[Parameter] [Parameter]
public string? Width { get; set; } public string? Width { get; set; }
[Parameter] [Parameter]
public RenderFragment? ChildContent { get; set; } public RenderFragment? ChildContent { get; set; }
private string minWidth = string.Empty; private string style = string.Empty;
private string preferredWidth = string.Empty;
protected override void OnParametersSet() { protected override void OnParametersSet() {
if (string.IsNullOrEmpty(Width)) { List<string> styles = new (2);
minWidth = string.Empty;
preferredWidth = string.Empty; if (MinWidth != null) {
return; styles.Add("min-width: " + MinWidth);
}
if (Width != null) {
styles.Add("width: " + Width);
} }
int separator = Width.IndexOf(';'); style = string.Join(';', styles);
if (separator == -1) {
minWidth = Width;
preferredWidth = Width;
return;
}
var span = Width.AsSpan();
minWidth = span[..separator].Trim().ToString();
preferredWidth = span[(separator + 1)..].Trim().ToString();
} }
} }

View File

@ -0,0 +1,58 @@
@typeparam TItem
<div class="horizontal-scroll">
<table class="table align-middle@(Class.Length == 0 ? "" : " " + Class)">
<thead>
<tr>
@HeaderRow
</tr>
</thead>
@if (Items is null) {
<tbody>
<tr>
<td colspan="1000" class="fw-semibold">
Loading...
</td>
</tr>
</tbody>
}
else if (Items.Count > 0) {
<tbody>
@foreach (var item in Items) {
<tr>
@ItemRow(item)
</tr>
}
</tbody>
}
else if (NoItemsRow != null) {
<tfoot>
<tr>
<td colspan="1000">@NoItemsRow</td>
</tr>
</tfoot>
}
</table>
</div>
@code {
[Parameter]
public string Class { get; set; } = string.Empty;
[Parameter, EditorRequired]
public RenderFragment HeaderRow { get; set; } = null!;
[Parameter, EditorRequired]
public RenderFragment<TItem> ItemRow { get; set; } = null!;
[Parameter]
public RenderFragment? NoItemsRow { get; set; } = null!;
[Parameter, EditorRequired]
public IReadOnlyList<TItem>? Items { get; set; }
}

View File

@ -7,75 +7,63 @@
<h1>Agents</h1> <h1>Agents</h1>
<table class="table align-middle"> <Table Items="agentTable">
<thead> <HeaderRow>
<tr> <Column Width="50%">Name</Column>
<Column Width="200px; 44%">Name</Column> <Column Class="text-end" Width="24%" MinWidth="90px">Instances</Column>
<Column Width=" 90px; 19%" Class="text-end">Instances</Column> <Column Class="text-end" Width="26%" MinWidth="145px">Memory</Column>
<Column Width="145px; 21%" Class="text-end">Memory</Column> <Column>Version</Column>
<Column Width="180px; 8%">Version</Column> <Column Class="text-center">Status</Column>
<Column Width="320px">Identifier</Column> <Column Class="text-end" MinWidth="200px">Last Ping</Column>
<Column Width="100px; 8%" Class="text-center">Status</Column> </HeaderRow>
<Column Width="215px" Class="text-end">Last Ping</Column> <ItemRow Context="agent">
</tr> @{
</thead> var usedInstances = agent.Stats?.RunningInstanceCount;
@if (!agentTable.IsEmpty) { var usedMemory = agent.Stats?.RunningInstanceMemory.InMegabytes;
<tbody> }
@foreach (var agent in agentTable) { <td>
var usedInstances = agent.Stats?.RunningInstanceCount; <p class="fw-semibold">@agent.Name</p>
var usedMemory = agent.Stats?.RunningInstanceMemory.InMegabytes; <small class="font-monospace text-uppercase">@agent.Guid.ToString()</small>
</td>
<tr> <td class="text-end">
<td>@agent.Name</td> <ProgressBar Value="@(usedInstances ?? 0)" Maximum="@agent.MaxInstances">
<td class="text-end"> @(usedInstances?.ToString() ?? "?") / @agent.MaxInstances.ToString()
<ProgressBar Value="@(usedInstances ?? 0)" Maximum="@agent.MaxInstances"> </ProgressBar>
@(usedInstances?.ToString() ?? "?") / @agent.MaxInstances </td>
</ProgressBar> <td class="text-end">
</td> <ProgressBar Value="@(usedMemory ?? 0)" Maximum="@agent.MaxMemory.InMegabytes">
<td class="text-end"> @(usedMemory?.ToString() ?? "?") / @agent.MaxMemory.InMegabytes.ToString() MB
<ProgressBar Value="@(usedMemory ?? 0)" Maximum="@agent.MaxMemory.InMegabytes"> </ProgressBar>
@(usedMemory?.ToString() ?? "?") / @agent.MaxMemory.InMegabytes MB </td>
</ProgressBar> <td class="text-condensed">
</td> Build: <span class="font-monospace">@agent.BuildVersion</span>
<td class="text-condensed"> <br>
Build: <code>@agent.BuildVersion</code> Protocol: <span class="font-monospace">v@(agent.ProtocolVersion.ToString())</span>
<br> </td>
Protocol: <code>v@(agent.ProtocolVersion)</code> @if (agent.IsOnline) {
</td> <td class="fw-semibold text-center text-success">Online</td>
<td> <td class="text-end">-</td>
<code class="text-uppercase">@agent.Guid.ToString()</code> }
</td> else {
@if (agent.IsOnline) { <td class="fw-semibold text-center">Offline</td>
<td class="text-center text-success">Online</td> <td class="text-end">
<td class="text-end"></td> @if (agent.LastPing is {} lastPing) {
} <TimeWithOffset Time="lastPing" />
else {
<td class="text-center text-danger">Offline</td>
@if (agent.LastPing is {} lastPing) {
<td class="text-end">
<time datetime="@lastPing.ToString("o")" data-time-type="relative">@lastPing.ToString()</time>
</td>
}
else {
<td class="text-end">-</td>
}
}
</tr>
} }
</tbody> else {
} <text>N/A</text>
else { }
<tfoot> </td>
<tr> }
<td colspan="7">No agents registered.</td> </ItemRow>
</tr> <NoItemsRow>
</tfoot> No agents registered.
} </NoItemsRow>
</table> </Table>
@code { @code {
private readonly Table<AgentWithStats, Guid> agentTable = new(); private readonly TableData<AgentWithStats, Guid> agentTable = new();
protected override void OnInitialized() { protected override void OnInitialized() {
AgentManager.AgentsChanged.Subscribe(this, agents => { AgentManager.AgentsChanged.Subscribe(this, agents => {

View File

@ -12,48 +12,42 @@
<h1>Audit Log</h1> <h1>Audit Log</h1>
<table class="table"> <Table TItem="AuditLogItem" Items="logItems">
<thead> <HeaderRow>
<tr> <Column Class="text-end" MinWidth="200px">Time</Column>
<Column Width="165px" Class="text-end">Time</Column> <Column>User</Column>
<Column Width="320px; 20%">User</Column> <Column>Event Type</Column>
<Column Width="160px">Event Type</Column> <Column>Subject</Column>
<Column Width="320px; 20%">Subject</Column> <Column Width="100%">Data</Column>
<Column Width="100px; 60%">Data</Column> </HeaderRow>
</tr> <ItemRow Context="logItem">
</thead> <td class="text-end">
<tbody> <TimeWithOffset Time="logItem.UtcTime.ToLocalTime()" />
@foreach (var logItem in logItems) { </td>
DateTimeOffset time = logItem.UtcTime.ToLocalTime(); <td>
<tr> <p class="fw-semibold">@(logItem.UserName ?? "-")</p>
<td class="text-end"> <small class="font-monospace text-uppercase">@logItem.UserGuid.ToString()</small>
<time datetime="@time.ToString("o")">@time.ToString()</time> </td>
</td> <td>
<td> <p>@logItem.EventType.ToNiceString()</p>
@(logItem.UserName ?? "-") </td>
<br> <td>
<code class="text-uppercase">@logItem.UserGuid</code> <p class="fw-semibold">@(logItem.SubjectId is {} subjectId && GetSubjectName(logItem.SubjectType, subjectId) is {} subjectName ? subjectName : "-")</p>
</td> <small class="font-monospace text-uppercase">@(logItem.SubjectId ?? "-")</small>
<td>@logItem.EventType.ToNiceString()</td> </td>
<td> <td>
@if (logItem.SubjectId is {} subjectId && GetSubjectName(logItem.SubjectType, subjectId) is {} subjectName) { <code>@logItem.JsonData</code>
@subjectName </td>
<br> </ItemRow>
} <NoItemsRow>
<code class="text-uppercase">@(logItem.SubjectId ?? "-")</code> No audit log entries found.
</td> </NoItemsRow>
<td> </Table>
<code>@logItem.JsonData</code>
</td>
</tr>
}
</tbody>
</table>
@code { @code {
private CancellationTokenSource? initializationCancellationTokenSource; private CancellationTokenSource? initializationCancellationTokenSource;
private ImmutableArray<AuditLogItem> logItems = ImmutableArray<AuditLogItem>.Empty; private ImmutableArray<AuditLogItem>? logItems;
private ImmutableDictionary<Guid, string>? userNamesByGuid; private ImmutableDictionary<Guid, string>? userNamesByGuid;
private ImmutableDictionary<Guid, string> instanceNamesByGuid = ImmutableDictionary<Guid, string>.Empty; private ImmutableDictionary<Guid, string> instanceNamesByGuid = ImmutableDictionary<Guid, string>.Empty;
@ -72,9 +66,9 @@
private string? GetSubjectName(AuditLogSubjectType type, string id) { private string? GetSubjectName(AuditLogSubjectType type, string id) {
return type switch { return type switch {
AuditLogSubjectType.Instance => instanceNamesByGuid.TryGetValue(Guid.Parse(id), out var name) ? name : null, AuditLogSubjectType.Instance => instanceNamesByGuid.TryGetValue(Guid.Parse(id), out var name) ? name : null,
AuditLogSubjectType.User => userNamesByGuid != null && userNamesByGuid.TryGetValue(Guid.Parse(id), out var name) ? name : null, AuditLogSubjectType.User => userNamesByGuid != null && userNamesByGuid.TryGetValue(Guid.Parse(id), out var name) ? name : null,
_ => null _ => null
}; };
} }

View File

@ -13,53 +13,45 @@
<h1>Event Log</h1> <h1>Event Log</h1>
<table class="table"> <Table TItem="EventLogItem" Items="logItems">
<thead> <HeaderRow>
<tr> <Column Class="text-end" MinWidth="200px">Time</Column>
<Column Width="165px" Class="text-end">Time</Column> <Column>Agent</Column>
<Column Width="320px; 20%">Agent</Column> <Column>Event Type</Column>
<Column Width="160px">Event Type</Column> <Column>Subject</Column>
<Column Width="320px; 20%">Subject</Column> <Column Width="100%">Data</Column>
<Column Width="100px; 60%">Data</Column> </HeaderRow>
</tr> <ItemRow Context="logItem">
</thead> <td class="text-end">
<tbody> <TimeWithOffset Time="logItem.UtcTime.ToLocalTime()" />
@foreach (var logItem in logItems) { </td>
DateTimeOffset time = logItem.UtcTime.ToLocalTime(); <td>
<tr> @if (logItem.AgentGuid is {} agentGuid) {
<td class="text-end"> <p class="fw-semibold">@(GetAgentName(agentGuid))</p>
<time datetime="@time.ToString("o")">@time.ToString()</time> <small class="font-monospace text-uppercase">@agentGuid.ToString()</small>
</td> }
<td> else {
@if (logItem.AgentGuid is {} agentGuid) { <text>-</text>
@(GetAgentName(agentGuid)) }
<br> </td>
<code class="text-uppercase">@agentGuid</code> <td>@logItem.EventType.ToNiceString()</td>
} <td>
else { <p class="fw-semibold">@(GetSubjectName(logItem.SubjectType, logItem.SubjectId) ?? "-")</p>
<text>-</text> <small class="font-monospace text-uppercase">@(logItem.SubjectId)</small>
} </td>
</td> <td>
<td>@logItem.EventType.ToNiceString()</td> <code>@logItem.JsonData</code>
<td> </td>
@if (GetSubjectName(logItem.SubjectType, logItem.SubjectId) is {} subjectName) { </ItemRow>
@subjectName <NoItemsRow>
<br> No event log entries found.
} </NoItemsRow>
<code class="text-uppercase">@logItem.SubjectId</code> </Table>
</td>
<td>
<code>@logItem.JsonData</code>
</td>
</tr>
}
</tbody>
</table>
@code { @code {
private CancellationTokenSource? initializationCancellationTokenSource; private CancellationTokenSource? initializationCancellationTokenSource;
private ImmutableArray<EventLogItem> logItems = ImmutableArray<EventLogItem>.Empty; private ImmutableArray<EventLogItem>? logItems;
private ImmutableDictionary<Guid, string> agentNamesByGuid = ImmutableDictionary<Guid, string>.Empty; private ImmutableDictionary<Guid, string> agentNamesByGuid = ImmutableDictionary<Guid, string>.Empty;
private ImmutableDictionary<Guid, string> instanceNamesByGuid = ImmutableDictionary<Guid, string>.Empty; private ImmutableDictionary<Guid, string> instanceNamesByGuid = ImmutableDictionary<Guid, string>.Empty;
@ -82,8 +74,8 @@
private string? GetSubjectName(EventLogSubjectType type, string id) { private string? GetSubjectName(EventLogSubjectType type, string id) {
return type switch { return type switch {
EventLogSubjectType.Instance => instanceNamesByGuid.TryGetValue(Guid.Parse(id), out var name) ? name : null, EventLogSubjectType.Instance => instanceNamesByGuid.TryGetValue(Guid.Parse(id), out var name) ? name : null,
_ => null _ => null
}; };
} }

View File

@ -14,14 +14,19 @@
<p>Return to <a href="instances">all instances</a>.</p> <p>Return to <a href="instances">all instances</a>.</p>
} }
else { else {
<h1>Instance: @Instance.Configuration.InstanceName</h1> <div class="d-flex flex-row align-items-center gap-3 mb-3">
<h1 class="mb-0">Instance: @Instance.Configuration.InstanceName</h1>
<span class="fs-4 text-muted">//</span>
<div class="mt-2">
<InstanceStatusText Status="Instance.Status" />
</div>
</div>
<div class="d-flex flex-row align-items-center gap-2"> <div class="d-flex flex-row align-items-center gap-2">
<PermissionView Permission="Permission.ControlInstances"> <PermissionView Permission="Permission.ControlInstances">
<button type="button" class="btn btn-success" @onclick="LaunchInstance" disabled="@(isLaunchingInstance || !Instance.Status.CanLaunch())">Launch</button> <button type="button" class="btn btn-success" @onclick="LaunchInstance" disabled="@(isLaunchingInstance || !Instance.Status.CanLaunch())">Launch</button>
<button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#stop-instance" disabled="@(!Instance.Status.CanStop())">Stop...</button> <button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#stop-instance" disabled="@(!Instance.Status.CanStop())">Stop...</button>
<span><!-- extra spacing --></span> <span><!-- extra spacing --></span>
</PermissionView> </PermissionView>
<InstanceStatusText Status="Instance.Status" />
<PermissionView Permission="Permission.CreateInstances"> <PermissionView Permission="Permission.CreateInstances">
<a href="instances/@InstanceGuid/edit" class="btn btn-warning ms-auto">Edit Configuration</a> <a href="instances/@InstanceGuid/edit" class="btn btn-warning ms-auto">Edit Configuration</a>
</PermissionView> </PermissionView>

View File

@ -6,7 +6,7 @@
@using Phantom.Web.Services.Agents @using Phantom.Web.Services.Agents
@using Phantom.Web.Services.Authorization @using Phantom.Web.Services.Authorization
@using Phantom.Web.Services.Instances @using Phantom.Web.Services.Instances
@inherits Phantom.Web.Components.PhantomComponent @inherits PhantomComponent
@inject AgentManager AgentManager @inject AgentManager AgentManager
@inject InstanceManager InstanceManager @inject InstanceManager InstanceManager
@ -16,66 +16,56 @@
<a href="instances/create" class="btn btn-primary" role="button">New Instance</a> <a href="instances/create" class="btn btn-primary" role="button">New Instance</a>
</PermissionView> </PermissionView>
<table class="table align-middle"> <Table TItem="Instance" Items="instances">
<thead> <HeaderRow>
<tr> <Column Width="40%">Agent</Column>
<Column Width="200px; 28%">Agent</Column> <Column Width="40%">Name</Column>
<Column Width="200px; 28%">Name</Column> <Column MinWidth="215px">Status</Column>
<Column Width="130px; 11%">Version</Column> <Column Width="20%">Version</Column>
<Column Width="110px; 8%" Class="text-center">Server Port</Column> <Column Class="text-center" MinWidth="110px">Server Port</Column>
<Column Width="110px; 8%" Class="text-center">Rcon Port</Column> <Column Class="text-center" MinWidth="110px">Rcon Port</Column>
<Column Width=" 90px; 8%" Class="text-end">Memory</Column> <Column Class="text-end" MinWidth="90px">Memory</Column>
<Column Width="320px">Identifier</Column> <Column MinWidth="75px">Actions</Column>
<Column Width="200px; 9%">Status</Column> </HeaderRow>
<Column Width=" 75px">Actions</Column> <ItemRow Context="instance">
</tr> @{
</thead> var configuration = instance.Configuration;
@if (!instances.IsEmpty) { var agentName = agentNamesByGuid.TryGetValue(configuration.AgentGuid, out var name) ? name : string.Empty;
<tbody> }
@foreach (var (configuration, status, _) in instances) { <td>
var agentName = agentNamesByGuid.TryGetValue(configuration.AgentGuid, out var name) ? name : string.Empty; <p class="fw-semibold">@agentName</p>
var instanceGuid = configuration.InstanceGuid.ToString(); <small class="font-monospace text-uppercase">@configuration.AgentGuid.ToString()</small>
<tr> </td>
<td>@agentName</td> <td>
<td>@configuration.InstanceName</td> <p class="fw-semibold">@configuration.InstanceName</p>
<td>@configuration.MinecraftServerKind @configuration.MinecraftVersion</td> <small class="font-monospace text-uppercase">@configuration.InstanceGuid.ToString()</small>
<td class="text-center"> </td>
<code>@configuration.ServerPort</code> <td>
</td> <InstanceStatusText Status="instance.Status" />
<td class="text-center"> </td>
<code>@configuration.RconPort</code> <td>@configuration.MinecraftServerKind @configuration.MinecraftVersion</td>
</td> <td class="text-center">
<td class="text-end"> <p class="font-monospace">@configuration.ServerPort.ToString()</p>
<code>@configuration.MemoryAllocation.InMegabytes MB</code> </td>
</td> <td class="text-center">
<td> <p class="font-monospace">@configuration.RconPort.ToString()</p>
<code class="text-uppercase">@instanceGuid</code> </td>
</td> <td class="text-end">
<td> <p class="font-monospace">@configuration.MemoryAllocation.InMegabytes.ToString() MB</p>
<InstanceStatusText Status="status" /> </td>
</td> <td>
<td> <a href="instances/@configuration.InstanceGuid.ToString()" class="btn btn-info btn-sm">Detail</a>
<a href="instances/@instanceGuid" class="btn btn-info btn-sm">Detail</a> </td>
</td> </ItemRow>
</tr> <NoItemsRow>
} No instances found.
</tbody> </NoItemsRow>
} </Table>
@if (instances.IsEmpty) {
<tfoot>
<tr>
<td colspan="9">
No instances.
</td>
</tr>
</tfoot>
}
</table>
@code { @code {
private ImmutableDictionary<Guid, string> agentNamesByGuid = ImmutableDictionary<Guid, string>.Empty; private ImmutableDictionary<Guid, string> agentNamesByGuid = ImmutableDictionary<Guid, string>.Empty;
private ImmutableArray<Instance> instances = ImmutableArray<Instance>.Empty; private ImmutableArray<Instance>? instances;
protected override void OnInitialized() { protected override void OnInitialized() {
AgentManager.AgentsChanged.Subscribe(this, agents => { AgentManager.AgentsChanged.Subscribe(this, agents => {

View File

@ -18,43 +18,36 @@
<AuthorizeView> <AuthorizeView>
<Authorized> <Authorized>
@{ var canEdit = PermissionManager.CheckPermission(context.User, Permission.EditUsers); } @{ var canEdit = PermissionManager.CheckPermission(context.User, Permission.EditUsers); }
<table class="table align-middle"> <Table TItem="UserInfo" Items="allUsers">
<thead> <HeaderRow>
<tr> <Column>Username</Column>
<Column Width="320px">Identifier</Column> <Column Width="100%">Roles</Column>
<Column Width="125px; 40%">Username</Column> @if (canEdit) {
<Column Width="125px; 60%">Roles</Column> <Column MinWidth="175px">Actions</Column>
@if (canEdit) {
<Column Width="175px">Actions</Column>
}
</tr>
</thead>
<tbody>
@foreach (var user in allUsers) {
var isMe = me == user.Guid;
<tr>
<td>
<code class="text-uppercase">@user.Guid</code>
</td>
@if (isMe) {
<td class="fw-semibold">@user.Name</td>
}
else {
<td>@user.Name</td>
}
<td>@(userGuidToRoleDescription.TryGetValue(user.Guid, out var roles) ? roles : "?")</td>
@if (canEdit) {
<td>
@if (!isMe) {
<button class="btn btn-primary btn-sm" @onclick="() => userRolesDialog.Show(user)">Edit Roles</button>
<button class="btn btn-danger btn-sm" @onclick="() => userDeleteDialog.Show(user)">Delete...</button>
}
</td>
}
</tr>
} }
</tbody> </HeaderRow>
</table> <ItemRow Context="user">
@{ var isMe = me == user.Guid; }
<td>
<p class="fw-semibold">@user.Name</p>
<small class="font-monospace text-uppercase">@user.Guid.ToString()</small>
</td>
<td>
@(userGuidToRoleDescription.TryGetValue(user.Guid, out var roles) ? roles : "?")
</td>
@if (canEdit) {
<td>
@if (!isMe) {
<button class="btn btn-primary btn-sm" @onclick="() => userRolesDialog.Show(user)">Edit Roles</button>
<button class="btn btn-danger btn-sm" @onclick="() => userDeleteDialog.Show(user)">Delete...</button>
}
</td>
}
</ItemRow>
<NoItemsRow>
No users found.
</NoItemsRow>
</Table>
</Authorized> </Authorized>
</AuthorizeView> </AuthorizeView>
@ -67,10 +60,12 @@
@code { @code {
private Guid? me = Guid.Empty; private Guid? me = Guid.Empty;
private ImmutableArray<UserInfo> allUsers = ImmutableArray<UserInfo>.Empty; private ImmutableArray<UserInfo>? allUsers;
private ImmutableDictionary<Guid, RoleInfo> allRolesByGuid = ImmutableDictionary<Guid, RoleInfo>.Empty; private ImmutableDictionary<Guid, RoleInfo> allRolesByGuid = ImmutableDictionary<Guid, RoleInfo>.Empty;
private readonly Dictionary<Guid, string> userGuidToRoleDescription = new(); private readonly Dictionary<Guid, string> userGuidToRoleDescription = new ();
private ImmutableArray<UserInfo> AllUsers => allUsers.GetValueOrDefault(ImmutableArray<UserInfo>.Empty);
private UserRolesDialog userRolesDialog = null!; private UserRolesDialog userRolesDialog = null!;
private UserDeleteDialog userDeleteDialog = null!; private UserDeleteDialog userDeleteDialog = null!;
@ -81,9 +76,10 @@
allRolesByGuid = (await RoleManager.GetAll(CancellationToken)).ToImmutableDictionary(static role => role.Guid, static role => role); allRolesByGuid = (await RoleManager.GetAll(CancellationToken)).ToImmutableDictionary(static role => role.Guid, static role => role);
var allUserGuids = allUsers var allUserGuids = allUsers
.Select(static user => user.Guid) .Value
.ToImmutableHashSet(); .Select(static user => user.Guid)
.ToImmutableHashSet();
foreach (var (userGuid, roleGuids) in await UserRoleManager.GetUserRoles(allUserGuids, CancellationToken)) { foreach (var (userGuid, roleGuids) in await UserRoleManager.GetUserRoles(allUserGuids, CancellationToken)) {
userGuidToRoleDescription[userGuid] = StringifyRoles(roleGuids); userGuidToRoleDescription[userGuid] = StringifyRoles(roleGuids);
} }
@ -102,7 +98,7 @@
} }
private Task OnUserAdded(UserInfo user) { private Task OnUserAdded(UserInfo user) {
allUsers = allUsers.Add(user); allUsers = AllUsers.Add(user);
return RefreshUserRoles(user); return RefreshUserRoles(user);
} }
@ -111,7 +107,7 @@
} }
private void OnUserDeleted(UserInfo user) { private void OnUserDeleted(UserInfo user) {
allUsers = allUsers.Remove(user); allUsers = AllUsers.Remove(user);
userGuidToRoleDescription.Remove(user.Guid); userGuidToRoleDescription.Remove(user.Guid);
} }

View File

@ -1,46 +1,48 @@
@using Phantom.Common.Data.Instance @using Phantom.Common.Data.Instance
<nobr>
@switch (Status) { @switch (Status) {
case InstanceIsOffline: case InstanceIsOffline:
<text>Offline</text> <span class="fw-semibold">Offline</span>
break; break;
case InstanceIsInvalid invalid: case InstanceIsInvalid invalid:
<text>Invalid <sup title="@invalid.Reason">[?]</sup></text> <span class="fw-semibold text-danger">Invalid <sup title="@invalid.Reason">[?]</sup></span>
break; break;
case InstanceIsNotRunning: case InstanceIsNotRunning:
<text>Not Running</text> <span class="fw-semibold">Not Running</span>
break; break;
case InstanceIsDownloading downloading: case InstanceIsDownloading downloading:
<ProgressBar Value="@downloading.Progress" Maximum="100"> <ProgressBar Value="@downloading.Progress" Maximum="100">
Downloading Server (@downloading.Progress%) <span class="fw-semibold">Downloading Server</span> (@downloading.Progress%)
</ProgressBar> </ProgressBar>
break; break;
case InstanceIsLaunching: case InstanceIsLaunching:
<div class="spinner-border spinner-border-sm" role="status"></div> <div class="spinner-border" role="status"></div>
<text>&nbsp;Launching</text> <span class="fw-semibold">&nbsp;Launching</span>
break; break;
case InstanceIsRunning: case InstanceIsRunning:
<text>Running</text> <span class="fw-semibold text-success">Running</span>
break; break;
case InstanceIsRestarting: case InstanceIsRestarting:
<div class="spinner-border spinner-border-sm" role="status"></div> <div class="spinner-border" role="status"></div>
<text>&nbsp;Restarting</text> <span class="fw-semibold">&nbsp;Restarting</span>
break; break;
case InstanceIsStopping: case InstanceIsStopping:
<div class="spinner-border spinner-border-sm" role="status"></div> <div class="spinner-border" role="status"></div>
<text>&nbsp;Stopping</text> <span class="fw-semibold">&nbsp;Stopping</span>
break; break;
case InstanceIsFailed failed: case InstanceIsFailed failed:
<text>Failed <sup title="@failed.Reason.ToSentence()">[?]</sup></text> <span class="fw-semibold text-danger">Failed <sup title="@failed.Reason.ToSentence()">[?]</sup></span>
break; break;
} }
</nobr>
@code { @code {

View File

@ -26,16 +26,21 @@
flex-direction: column; flex-direction: column;
position: sticky; position: sticky;
top: 0; top: 0;
width: 250px; width: 230px;
min-height: 100vh; min-height: 100vh;
} }
} }
main { main {
flex: 1; flex: 1;
min-width: 0;
padding: 1.1rem 1.5rem 0; padding: 1.1rem 1.5rem 0;
} }
h1 {
font-weight: 600;
}
h1:focus { h1:focus {
outline: none; outline: none;
} }
@ -51,14 +56,30 @@ code {
.table { .table {
margin-top: 0.5rem; margin-top: 0.5rem;
white-space: nowrap;
} }
.table > :not(:first-child) { .table > :not(:first-child) {
border-top: 2px solid #a6a6a6; border-top: 2px solid #a6a6a6;
} }
.table > :not(caption) > * > * { .table th, .table td {
padding: 0.5rem 0.75rem; padding: 0.5rem 1.25rem;
}
.table p {
margin: 0;
}
.table small {
display: block;
font-weight: normal;
font-size: 0.825rem;
color: #666;
}
.table small.font-monospace {
font-size: 0.875rem;
} }
.form-range { .form-range {
@ -91,9 +112,19 @@ code {
.text-condensed { .text-condensed {
font-size: 0.9rem; font-size: 0.9rem;
line-height: 1.05rem; line-height: 1.15rem;
} }
.text-condensed code { .text-condensed code {
font-size: 0.9rem; font-size: 0.9rem;
} }
.horizontal-scroll {
overflow-x: auto;
scrollbar-width: thin;
margin-bottom: 1rem;
}
.horizontal-scroll > .table {
margin-bottom: 0;
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long