1
0
mirror of https://github.com/chylex/Minecraft-Phantom-Panel.git synced 2025-05-10 08:34:11 +02:00
Minecraft-Phantom-Panel/Web/Phantom.Web/Pages/Instances.razor
2023-12-18 06:04:12 +01:00

101 lines
3.4 KiB
Plaintext

@page "/instances"
@attribute [Authorize(Permission.ViewInstancesPolicy)]
@using System.Collections.Immutable
@using Phantom.Common.Data.Web.Instance
@using Phantom.Common.Data.Web.Users
@using Phantom.Web.Services.Agents
@using Phantom.Web.Services.Authorization
@using Phantom.Web.Services.Instances
@inherits Phantom.Web.Components.PhantomComponent
@inject AgentManager AgentManager
@inject InstanceManager InstanceManager
<h1>Instances</h1>
<PermissionView Permission="Permission.CreateInstances">
<a href="instances/create" class="btn btn-primary" role="button">New Instance</a>
</PermissionView>
<table class="table align-middle">
<thead>
<tr>
<Column Width="200px; 28%">Agent</Column>
<Column Width="200px; 28%">Name</Column>
<Column Width="130px; 11%">Version</Column>
<Column Width="110px; 8%" Class="text-center">Server Port</Column>
<Column Width="110px; 8%" Class="text-center">Rcon Port</Column>
<Column Width=" 90px; 8%" Class="text-end">Memory</Column>
<Column Width="320px">Identifier</Column>
<Column Width="200px; 9%">Status</Column>
<Column Width=" 75px">Actions</Column>
</tr>
</thead>
@if (!instances.IsEmpty) {
<tbody>
@foreach (var (configuration, status, _) in instances) {
var agentName = agentNamesByGuid.TryGetValue(configuration.AgentGuid, out var name) ? name : string.Empty;
var instanceGuid = configuration.InstanceGuid.ToString();
<tr>
<td>@agentName</td>
<td>@configuration.InstanceName</td>
<td>@configuration.MinecraftServerKind @configuration.MinecraftVersion</td>
<td class="text-center">
<code>@configuration.ServerPort</code>
</td>
<td class="text-center">
<code>@configuration.RconPort</code>
</td>
<td class="text-end">
<code>@configuration.MemoryAllocation.InMegabytes MB</code>
</td>
<td>
<code class="text-uppercase">@instanceGuid</code>
</td>
<td>
<InstanceStatusText Status="status" />
</td>
<td>
<a href="instances/@instanceGuid" class="btn btn-info btn-sm">Detail</a>
</td>
</tr>
}
</tbody>
}
@if (instances.IsEmpty) {
<tfoot>
<tr>
<td colspan="9">
No instances.
</td>
</tr>
</tfoot>
}
</table>
@code {
private ImmutableDictionary<Guid, string> agentNamesByGuid = ImmutableDictionary<Guid, string>.Empty;
private ImmutableArray<Instance> instances = ImmutableArray<Instance>.Empty;
protected override void OnInitialized() {
AgentManager.AgentsChanged.Subscribe(this, agents => {
this.agentNamesByGuid = agents.ToImmutableDictionary(static agent => agent.Guid, static agent => agent.Name);
InvokeAsync(StateHasChanged);
});
InstanceManager.InstancesChanged.Subscribe(this, instances => {
this.instances = instances.Values
.OrderBy(instance => agentNamesByGuid.TryGetValue(instance.Configuration.AgentGuid, out var agentName) ? agentName : string.Empty)
.ThenBy(static instance => instance.Configuration.InstanceName)
.ToImmutableArray();
InvokeAsync(StateHasChanged);
});
}
protected override void OnDisposed() {
AgentManager.AgentsChanged.Unsubscribe(this);
InstanceManager.InstancesChanged.Unsubscribe(this);
}
}