138 lines
4.3 KiB
Text
138 lines
4.3 KiB
Text
@page "/Servers"
|
|
@attribute [Authorize]
|
|
@inject ServerService ServerService
|
|
@inject ServerProcessService ServerProcessService
|
|
@inject NavigationManager NavigationManager
|
|
|
|
<PageHeader Title="Servers">
|
|
<PageHeaderExtra>
|
|
<Button OnClick="() => Add()" Type="@ButtonType.Primary">Add Server</Button>
|
|
</PageHeaderExtra>
|
|
</PageHeader>
|
|
|
|
<Table TItem="Server" DataSource="@Servers" Loading="@Loading">
|
|
<PropertyColumn Property="s => s.Name" Sortable />
|
|
<PropertyColumn Property="s => s.CreatedOn" Format="MM/dd/yyyy hh:mm tt" Sortable />
|
|
<PropertyColumn Property="s => s.CreatedBy" Sortable>
|
|
@context.CreatedBy?.UserName
|
|
</PropertyColumn>
|
|
<PropertyColumn Property="g => g.UpdatedOn" Format="MM/dd/yyyy hh:mm tt" Sortable />
|
|
<PropertyColumn Property="g => g.UpdatedBy" Sortable>
|
|
@context.UpdatedBy?.UserName
|
|
</PropertyColumn>
|
|
<Column TData="string" Title="Status">
|
|
|
|
@switch (Status.GetValueOrDefault(context.Id))
|
|
{
|
|
case ServerProcessStatus.Running:
|
|
<Badge Status="success" Text="Running" />
|
|
break;
|
|
|
|
case ServerProcessStatus.Starting:
|
|
<Badge Status="processing" Text="Starting" />
|
|
break;
|
|
|
|
case ServerProcessStatus.Error:
|
|
<Badge Status="error" Text="Error" />
|
|
break;
|
|
|
|
case ServerProcessStatus.Stopped:
|
|
default:
|
|
<Badge Status="default" Text="Stopped" />
|
|
break;
|
|
}
|
|
</Column>
|
|
<ActionColumn Title="">
|
|
<Space Direction="DirectionVHType.Horizontal">
|
|
<SpaceItem>
|
|
<Button OnClick="() => Edit(context)">Edit</Button>
|
|
<Button OnClick="() => Logs(context)">Logs</Button>
|
|
|
|
@if (Status.GetValueOrDefault(context.Id) != ServerProcessStatus.Running)
|
|
{
|
|
<Button Type="@ButtonType.Primary" OnClick="() => Start(context)">Start</Button>
|
|
}
|
|
|
|
@if (Status.GetValueOrDefault(context.Id) == ServerProcessStatus.Running)
|
|
{
|
|
<Popconfirm OnConfirm="() => Stop(context)" Title="Are you sure you want to kill this server process?">
|
|
<Button Danger Type="@ButtonType.Primary">Stop</Button>
|
|
</Popconfirm>
|
|
}
|
|
</SpaceItem>
|
|
<SpaceItem>
|
|
<Popconfirm OnConfirm="() => Delete(context)" Title="Are you sure you want to delete this server?">
|
|
<Button Icon="@IconType.Outline.Close" Type="@ButtonType.Text" Danger />
|
|
</Popconfirm>
|
|
</SpaceItem>
|
|
</Space>
|
|
</ActionColumn>
|
|
</Table>
|
|
|
|
@code {
|
|
IEnumerable<Server> Servers { get; set; } = new List<Server>();
|
|
|
|
bool Loading = true;
|
|
Dictionary<Guid, ServerProcessStatus> Status = new Dictionary<Guid, ServerProcessStatus>();
|
|
Timer Timer;
|
|
|
|
protected override void OnAfterRender(bool firstRender)
|
|
{
|
|
if (firstRender)
|
|
{
|
|
Servers = ServerService.Get().OrderBy(s => s.Name).ToList();
|
|
|
|
Loading = false;
|
|
|
|
Timer = new Timer(async (object? stateInfo) =>
|
|
{
|
|
foreach (var server in Servers)
|
|
{
|
|
Status[server.Id] = ServerProcessService.GetStatus(server);
|
|
}
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
}, new AutoResetEvent(false), 1000, 1000);
|
|
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
|
|
private void Add()
|
|
{
|
|
NavigationManager.NavigateTo("/Servers/Add");
|
|
}
|
|
|
|
private void Edit(Server server)
|
|
{
|
|
NavigationManager.NavigateTo($"/Servers/{server.Id}/Edit/General");
|
|
}
|
|
|
|
private void Logs(Server server)
|
|
{
|
|
NavigationManager.NavigateTo($"/Servers/{server.Id}/Edit/Logs");
|
|
}
|
|
|
|
private void Start(Server server)
|
|
{
|
|
ServerProcessService.StartServer(server);
|
|
}
|
|
|
|
private void Stop(Server server)
|
|
{
|
|
ServerProcessService.StopServer(server);
|
|
}
|
|
|
|
private async Task Delete(Server server)
|
|
{
|
|
Servers = new List<Server>();
|
|
|
|
Loading = true;
|
|
|
|
await ServerService.Delete(server);
|
|
|
|
Servers = ServerService.Get().OrderBy(s => s.Name).ToList();
|
|
|
|
Loading = false;
|
|
}
|
|
}
|