1
0
mirror of https://github.com/chylex/Minecraft-Phantom-Panel.git synced 2024-11-22 08:42:44 +01:00
Minecraft-Phantom-Panel/Server/Phantom.Server.Web/Pages/Instances.razor

95 lines
3.2 KiB
Plaintext

@page "/instances"
@attribute [Authorize(Permission.ViewInstancesPolicy)]
@using System.Collections.Immutable
@using Phantom.Server.Services.Agents
@using Phantom.Server.Services.Instances
@implements IDisposable
@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 = agentNames.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> agentNames = ImmutableDictionary<Guid, string>.Empty;
private ImmutableArray<Instance> instances = ImmutableArray<Instance>.Empty;
protected override void OnInitialized() {
AgentManager.AgentsChanged.Subscribe(this, agents => {
this.agentNames = agents.ToImmutableDictionary(static agent => agent.Guid, static agent => agent.Name);
InvokeAsync(StateHasChanged);
});
InstanceManager.InstancesChanged.Subscribe(this, instances => {
this.instances = instances.Values.OrderBy(instance => agentNames.TryGetValue(instance.Configuration.AgentGuid, out var agentName) ? agentName : string.Empty).ThenBy(static instance => instance.Configuration.InstanceName).ToImmutableArray();
InvokeAsync(StateHasChanged);
});
}
void IDisposable.Dispose() {
AgentManager.AgentsChanged.Unsubscribe(this);
InstanceManager.InstancesChanged.Unsubscribe(this);
}
}