mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2025-05-07 00:34:03 +02:00
89 lines
3.1 KiB
Plaintext
89 lines
3.1 KiB
Plaintext
@page "/events"
|
|
@attribute [Authorize(Permission.ViewEventsPolicy)]
|
|
@using System.Collections.Immutable
|
|
@using Phantom.Common.Data.Web.EventLog
|
|
@using Phantom.Common.Data.Web.Users
|
|
@using Phantom.Web.Services.Agents
|
|
@using Phantom.Web.Services.Events
|
|
@using Phantom.Web.Services.Instances
|
|
@inherits Phantom.Web.Components.PhantomComponent
|
|
@inject AgentManager AgentManager
|
|
@inject EventLogManager EventLogManager
|
|
@inject InstanceManager InstanceManager
|
|
|
|
<h1>Event Log</h1>
|
|
|
|
<Table TItem="EventLogItem" Items="logItems">
|
|
<HeaderRow>
|
|
<Column Class="text-end" MinWidth="200px">Time</Column>
|
|
<Column>Agent</Column>
|
|
<Column>Event Type</Column>
|
|
<Column>Subject</Column>
|
|
<Column Width="100%">Data</Column>
|
|
</HeaderRow>
|
|
<ItemRow Context="logItem">
|
|
<Cell class="text-end">
|
|
<TimeWithOffset Time="logItem.UtcTime.ToLocalTime()" />
|
|
</Cell>
|
|
<Cell>
|
|
@if (logItem.AgentGuid is {} agentGuid) {
|
|
<p class="fw-semibold">@(GetAgentName(agentGuid))</p>
|
|
<small class="font-monospace text-uppercase">@agentGuid.ToString()</small>
|
|
}
|
|
else {
|
|
<text>-</text>
|
|
}
|
|
</Cell>
|
|
<Cell>@logItem.EventType.ToNiceString()</Cell>
|
|
<Cell>
|
|
<p class="fw-semibold">@(GetSubjectName(logItem.SubjectType, logItem.SubjectId) ?? "-")</p>
|
|
<small class="font-monospace text-uppercase">@(logItem.SubjectId)</small>
|
|
</Cell>
|
|
<Cell>
|
|
<code>@logItem.JsonData</code>
|
|
</Cell>
|
|
</ItemRow>
|
|
<NoItemsRow>
|
|
No event log entries found.
|
|
</NoItemsRow>
|
|
</Table>
|
|
|
|
@code {
|
|
|
|
private CancellationTokenSource? initializationCancellationTokenSource;
|
|
private ImmutableArray<EventLogItem>? logItems;
|
|
private ImmutableDictionary<Guid, string> agentNamesByGuid = ImmutableDictionary<Guid, string>.Empty;
|
|
private ImmutableDictionary<Guid, string> instanceNamesByGuid = ImmutableDictionary<Guid, string>.Empty;
|
|
|
|
protected override async Task OnInitializedAsync() {
|
|
initializationCancellationTokenSource = new CancellationTokenSource();
|
|
var cancellationToken = initializationCancellationTokenSource.Token;
|
|
|
|
try {
|
|
logItems = await EventLogManager.GetMostRecentItems(50, cancellationToken);
|
|
agentNamesByGuid = AgentManager.GetAll().ToImmutableDictionary(static kvp => kvp.AgentGuid, static kvp => kvp.Configuration.AgentName);
|
|
instanceNamesByGuid = InstanceManager.GetAll().Values.ToImmutableDictionary(static instance => instance.InstanceGuid, static instance => instance.Configuration.InstanceName);
|
|
} finally {
|
|
initializationCancellationTokenSource.Dispose();
|
|
}
|
|
}
|
|
|
|
private string GetAgentName(Guid agentGuid) {
|
|
return agentNamesByGuid.TryGetValue(agentGuid, out var name) ? name : "?";
|
|
}
|
|
|
|
private string? GetSubjectName(EventLogSubjectType type, string id) {
|
|
return type switch {
|
|
EventLogSubjectType.Instance => instanceNamesByGuid.TryGetValue(Guid.Parse(id), out var name) ? name : null,
|
|
_ => null
|
|
};
|
|
}
|
|
|
|
protected override void OnDisposed() {
|
|
try {
|
|
initializationCancellationTokenSource?.Cancel();
|
|
} catch (ObjectDisposedException) {}
|
|
}
|
|
|
|
}
|