Recreated plugin with new project template. Started implementing server system daemon
This commit is contained in:
@@ -1,79 +0,0 @@
|
||||
@page "/admin/servers/all/create"
|
||||
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonCore.Blazor.FlyonUi.Toasts
|
||||
@using MoonCore.Helpers
|
||||
@using Moonlight.Shared.Http.Responses.Admin.Users
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Servers
|
||||
@using MoonlightServers.Frontend.UI.Components.Servers.CreatePartials
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.NodeAllocations
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Stars
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ToastService ToastService
|
||||
|
||||
@attribute [Authorize(Policy = "permissions:admin.servers.create")]
|
||||
|
||||
<PageHeader Title="Create Server">
|
||||
<a href="/admin/servers/all" class="btn btn-secondary">
|
||||
<i class="icon-chevron-left"></i>
|
||||
Back
|
||||
</a>
|
||||
<WButton OnClick="Form.SubmitAsync" CssClasses="btn btn-primary">
|
||||
<i class="icon-check"></i>
|
||||
Create
|
||||
</WButton>
|
||||
</PageHeader>
|
||||
|
||||
<div class="mt-5">
|
||||
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
|
||||
<Tabs>
|
||||
<Tab Name="General">
|
||||
<General Request="Request" Parent="this" />
|
||||
</Tab>
|
||||
<Tab Name="Allocations">
|
||||
<Allocations Request="Request" Parent="this" />
|
||||
</Tab>
|
||||
<Tab Name="Variables">
|
||||
<Variables Request="Request" Parent="this" />
|
||||
</Tab>
|
||||
<Tab Name="Advanced">
|
||||
<Advanced Request="Request" />
|
||||
</Tab>
|
||||
</Tabs>
|
||||
</HandleForm>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
private HandleForm Form;
|
||||
private CreateServerRequest Request;
|
||||
|
||||
public List<NodeAllocationResponse> Allocations = new();
|
||||
public UserResponse? Owner;
|
||||
public StarResponse? Star;
|
||||
public NodeResponse? Node;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
Request = new();
|
||||
}
|
||||
|
||||
private async Task OnSubmit()
|
||||
{
|
||||
Request.AllocationIds = Allocations
|
||||
.Select(x => x.Id)
|
||||
.ToArray();
|
||||
|
||||
Request.StarId = Star?.Id ?? -1;
|
||||
Request.NodeId = Node?.Id ?? -1;
|
||||
Request.OwnerId = Owner?.Id ?? -1;
|
||||
|
||||
await ApiClient.Post("api/admin/servers", Request);
|
||||
|
||||
await ToastService.SuccessAsync("Successfully created Server");
|
||||
Navigation.NavigateTo("/admin/servers/all");
|
||||
}
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
@page "/admin/servers/all"
|
||||
|
||||
@using MoonCore.Blazor.FlyonUi.Alerts
|
||||
@using MoonCore.Blazor.FlyonUi.Common
|
||||
@using MoonCore.Blazor.FlyonUi.Toasts
|
||||
@using MoonCore.Helpers
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Servers
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Stars
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonCore.Blazor.FlyonUi.Grid
|
||||
@using MoonCore.Blazor.FlyonUi.Grid.Columns
|
||||
@using MoonCore.Common
|
||||
@using Moonlight.Shared.Http.Responses.Admin.Users
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject AlertService AlertService
|
||||
@inject ToastService ToastService
|
||||
|
||||
@attribute [Authorize(Policy = "permissions:admin.servers.get")]
|
||||
|
||||
<div class="mb-3">
|
||||
<NavTabs Index="1" Names="@UiConstants.AdminNavNames" Links="@UiConstants.AdminNavLinks"/>
|
||||
</div>
|
||||
|
||||
<div class="mb-5">
|
||||
<PageHeader Title="Servers">
|
||||
<a href="/admin/servers/all/create" class="btn btn-primary">
|
||||
Create
|
||||
</a>
|
||||
</PageHeader>
|
||||
</div>
|
||||
|
||||
<DataGrid @ref="Grid"
|
||||
TGridItem="ServerResponse"
|
||||
ItemSource="ItemSource">
|
||||
<PropertyColumn Field="x => x.Id"/>
|
||||
<TemplateColumn Title="Name">
|
||||
<td>
|
||||
<a class="text-primary" href="/admin/servers/all/update/@context.Id">
|
||||
@context.Name
|
||||
</a>
|
||||
</td>
|
||||
</TemplateColumn>
|
||||
<TemplateColumn Title="Owner">
|
||||
<td>
|
||||
@{
|
||||
var owner = Users.GetValueOrDefault(context.OwnerId);
|
||||
}
|
||||
|
||||
<span>
|
||||
@(owner?.Username ?? "N/A")
|
||||
</span>
|
||||
</td>
|
||||
</TemplateColumn>
|
||||
<TemplateColumn Title="Node">
|
||||
<td>
|
||||
@{
|
||||
var node = Nodes.GetValueOrDefault(context.NodeId);
|
||||
}
|
||||
|
||||
<span>
|
||||
@(node?.Name ?? "N/A")
|
||||
</span>
|
||||
</td>
|
||||
</TemplateColumn>
|
||||
<TemplateColumn Title="Star">
|
||||
<td>
|
||||
@{
|
||||
var star = Stars.GetValueOrDefault(context.StarId);
|
||||
}
|
||||
|
||||
<span>
|
||||
@(star?.Name ?? "N/A")
|
||||
</span>
|
||||
</td>
|
||||
</TemplateColumn>
|
||||
<TemplateColumn Title="Actions">
|
||||
<td>
|
||||
<div class="flex justify-end">
|
||||
<a href="/admin/servers/all/update/@(context.Id)" class="text-primary mr-2 sm:mr-3">
|
||||
<i class="icon-pencil text-base"></i>
|
||||
</a>
|
||||
|
||||
<a href="#" @onclick="() => DeleteAsync(context)" @onclick:preventDefault
|
||||
class="text-error">
|
||||
<i class="icon-trash text-base"></i>
|
||||
</a>
|
||||
</div>
|
||||
</td>
|
||||
</TemplateColumn>
|
||||
</DataGrid>
|
||||
|
||||
@code
|
||||
{
|
||||
private DataGrid<ServerResponse> Grid;
|
||||
|
||||
private Dictionary<int, StarResponse> Stars = new();
|
||||
private Dictionary<int, NodeResponse> Nodes = new();
|
||||
private Dictionary<int, UserResponse> Users = new();
|
||||
|
||||
private ItemSource<ServerResponse> ItemSource => ItemSourceFactory.From(LoadAsync);
|
||||
|
||||
private async Task<IEnumerable<ServerResponse>> LoadAsync(int startIndex, int count)
|
||||
{
|
||||
var query = $"?startIndex={startIndex}&count={count}";
|
||||
|
||||
var countedData = await ApiClient.GetJson<CountedData<ServerResponse>>($"api/admin/servers{query}");
|
||||
|
||||
// Fetch relations
|
||||
|
||||
var nodesToFetch = countedData.Items
|
||||
.Where(x => !Nodes.ContainsKey(x.Id))
|
||||
.Select(x => x.Id)
|
||||
.Distinct();
|
||||
|
||||
foreach (var id in nodesToFetch)
|
||||
{
|
||||
var node = await ApiClient.GetJson<NodeResponse>($"api/admin/servers/nodes/{id}");
|
||||
Nodes[node.Id] = node;
|
||||
}
|
||||
|
||||
var starsToFetch = countedData.Items
|
||||
.Where(x => !Stars.ContainsKey(x.Id))
|
||||
.Select(x => x.Id)
|
||||
.Distinct();
|
||||
|
||||
foreach (var id in starsToFetch)
|
||||
{
|
||||
var star = await ApiClient.GetJson<StarResponse>($"api/admin/servers/stars/{id}");
|
||||
Stars[star.Id] = star;
|
||||
}
|
||||
|
||||
var usersToFetch = countedData.Items
|
||||
.Where(x => !Users.ContainsKey(x.Id))
|
||||
.Select(x => x.Id)
|
||||
.Distinct();
|
||||
|
||||
foreach (var id in usersToFetch)
|
||||
{
|
||||
var user = await ApiClient.GetJson<UserResponse>($"api/admin/users/{id}");
|
||||
Users[user.Id] = user;
|
||||
}
|
||||
|
||||
return countedData;
|
||||
}
|
||||
|
||||
private async Task DeleteAsync(ServerResponse response)
|
||||
{
|
||||
await AlertService.ConfirmDangerAsync(
|
||||
"Server deletion",
|
||||
$"Do you really want to delete the server '{response.Name}'",
|
||||
async () =>
|
||||
{
|
||||
await ApiClient.Delete($"api/admin/servers/{response.Id}");
|
||||
await ToastService.SuccessAsync("Successfully deleted server");
|
||||
|
||||
await Grid.RefreshAsync();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
@page "/admin/servers/all/update/{Id:int}"
|
||||
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonCore.Blazor.FlyonUi.Toasts
|
||||
@using MoonCore.Helpers
|
||||
@using Moonlight.Shared.Http.Responses.Admin.Users
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Servers
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Servers
|
||||
@using MoonlightServers.Frontend.UI.Components.Servers.UpdatePartials
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.NodeAllocations
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ToastService ToastService
|
||||
|
||||
@attribute [Authorize(Policy = "permissions:admin.servers.update")]
|
||||
|
||||
<LazyLoader Load="LoadAsync">
|
||||
<PageHeader Title="Update Server">
|
||||
<a href="/admin/servers/all" class="btn btn-secondary">
|
||||
<i class="icon-chevron-left"></i>
|
||||
Back
|
||||
</a>
|
||||
<WButton OnClick="Form.SubmitAsync" CssClasses="btn btn-primary">
|
||||
<i class="icon-check"></i>
|
||||
Update
|
||||
</WButton>
|
||||
</PageHeader>
|
||||
|
||||
<div class="mt-5">
|
||||
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
|
||||
<Tabs>
|
||||
<Tab Name="General">
|
||||
<General Request="Request" Parent="this"/>
|
||||
</Tab>
|
||||
<Tab Name="Allocations">
|
||||
<Allocations Request="Request" Server="Server" Parent="this"/>
|
||||
</Tab>
|
||||
<Tab Name="Variables">
|
||||
<Variables Request="Request" Server="Server"/>
|
||||
</Tab>
|
||||
<Tab Name="Advanced">
|
||||
<Advanced Request="Request"/>
|
||||
</Tab>
|
||||
</Tabs>
|
||||
</HandleForm>
|
||||
</div>
|
||||
</LazyLoader>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public int Id { get; set; }
|
||||
|
||||
private HandleForm Form;
|
||||
private UpdateServerRequest Request;
|
||||
private ServerResponse Server;
|
||||
|
||||
public List<NodeAllocationResponse> Allocations = new();
|
||||
public UserResponse Owner;
|
||||
|
||||
private async Task LoadAsync(LazyLoader _)
|
||||
{
|
||||
Server = await ApiClient.GetJson<ServerResponse>($"api/admin/servers/{Id}");
|
||||
|
||||
Request = new()
|
||||
{
|
||||
Name = Server.Name,
|
||||
AllocationIds = Server.AllocationIds,
|
||||
OwnerId = Server.OwnerId,
|
||||
Cpu = Server.Cpu,
|
||||
Disk = Server.Disk,
|
||||
DockerImageIndex = Server.DockerImageIndex,
|
||||
Memory = Server.Memory,
|
||||
StartupOverride = Server.StartupOverride
|
||||
};
|
||||
|
||||
foreach (var allocationId in Server.AllocationIds)
|
||||
{
|
||||
var allocation = await ApiClient.GetJson<NodeAllocationResponse>(
|
||||
$"api/admin/servers/nodes/{Server.NodeId}/allocations/{allocationId}"
|
||||
);
|
||||
|
||||
Allocations.Add(allocation);
|
||||
}
|
||||
|
||||
Owner = await ApiClient.GetJson<UserResponse>(
|
||||
$"api/admin/users/{Server.OwnerId}"
|
||||
);
|
||||
}
|
||||
|
||||
private async Task OnSubmit()
|
||||
{
|
||||
Request.AllocationIds = Allocations.Select(x => x.Id).ToArray();
|
||||
Request.OwnerId = Owner.Id;
|
||||
|
||||
await ApiClient.Patch($"api/admin/servers/{Id}", Request);
|
||||
|
||||
await ToastService.SuccessAsync("Successfully updated server");
|
||||
Navigation.NavigateTo("/admin/servers/all");
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
@page "/admin/servers"
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
|
||||
|
||||
@attribute [Authorize(Policy = "permissions:admin.servers.overview")]
|
||||
|
||||
<NavTabs Index="0" Names="@UiConstants.AdminNavNames" Links="@UiConstants.AdminNavLinks"/>
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
@page "/admin/servers/nodes/create"
|
||||
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonCore.Blazor.FlyonUi.Toasts
|
||||
@using MoonCore.Helpers
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Nodes
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ToastService ToastService
|
||||
|
||||
@attribute [Authorize(Policy = "permissions:admin.servers.nodes.create")]
|
||||
|
||||
<PageHeader Title="Create Node">
|
||||
<a href="/admin/servers/nodes" class="btn btn-secondary">
|
||||
<i class="icon-chevron-left"></i>
|
||||
Back
|
||||
</a>
|
||||
<WButton OnClick="Form.SubmitAsync" CssClasses="btn btn-primary">
|
||||
<i class="icon-check"></i>
|
||||
Create
|
||||
</WButton>
|
||||
</PageHeader>
|
||||
|
||||
<div class="mt-5">
|
||||
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
|
||||
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-base-content">Name</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.Name" type="text" autocomplete="off" class="input w-full">
|
||||
</div>
|
||||
</div>
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-base-content">Fqdn</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.Fqdn" type="text" autocomplete="off" class="input w-full">
|
||||
</div>
|
||||
</div>
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-base-content">HttpPort</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.HttpPort" type="number" autocomplete="off" class="input w-full">
|
||||
</div>
|
||||
</div>
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-base-content">FtpPort</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.FtpPort" type="number" autocomplete="off" class="input w-full">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</HandleForm>
|
||||
</div>
|
||||
|
||||
@*
|
||||
TODO: EnableTransparentMode, EnableDynamicFirewall
|
||||
*@
|
||||
|
||||
@code
|
||||
{
|
||||
private HandleForm Form;
|
||||
private CreateNodeRequest Request;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
Request = new();
|
||||
}
|
||||
|
||||
private async Task OnSubmit()
|
||||
{
|
||||
await ApiClient.Post("api/admin/servers/nodes", Request);
|
||||
|
||||
await ToastService.SuccessAsync("Successfully created node");
|
||||
Navigation.NavigateTo("/admin/servers/nodes");
|
||||
}
|
||||
}
|
||||
@@ -1,245 +0,0 @@
|
||||
@page "/admin/servers/nodes"
|
||||
|
||||
@using Microsoft.Extensions.Logging
|
||||
@using MoonCore.Blazor.FlyonUi.Alerts
|
||||
@using MoonCore.Blazor.FlyonUi.Common
|
||||
@using MoonCore.Blazor.FlyonUi.Toasts
|
||||
@using MoonCore.Helpers
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes
|
||||
@using MoonlightServers.Frontend.Services
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes.Statistics
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes.Sys
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonCore.Blazor.FlyonUi.Grid
|
||||
@using MoonCore.Blazor.FlyonUi.Grid.Columns
|
||||
@using MoonCore.Common
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject NodeService NodeService
|
||||
@inject AlertService AlertService
|
||||
@inject ToastService ToastService
|
||||
@inject ILogger<Index> Logger
|
||||
|
||||
@attribute [Authorize(Policy = "permissions:admin.servers.nodes.get")]
|
||||
|
||||
<div class="mb-3">
|
||||
<NavTabs Index="2" Names="@UiConstants.AdminNavNames" Links="@UiConstants.AdminNavLinks"/>
|
||||
</div>
|
||||
|
||||
<div class="mb-5">
|
||||
<PageHeader Title="Nodes">
|
||||
<a href="/admin/servers/nodes/create" class="btn btn-primary">
|
||||
Create
|
||||
</a>
|
||||
</PageHeader>
|
||||
</div>
|
||||
|
||||
<DataGrid @ref="Grid"
|
||||
TGridItem="NodeResponse"
|
||||
ItemSource="ItemSource">
|
||||
<PropertyColumn Field="x => x.Id"/>
|
||||
<TemplateColumn Title="Name">
|
||||
<td>
|
||||
<a class="text-primary" href="/admin/servers/nodes/update/@(context.Id)">
|
||||
@context.Name
|
||||
</a>
|
||||
</td>
|
||||
</TemplateColumn>
|
||||
<PropertyColumn Field="x => x.Fqdn"/>
|
||||
<TemplateColumn Title="Status">
|
||||
<td>
|
||||
@{
|
||||
var isFetched = StatusResponses.TryGetValue(context.Id, out var data);
|
||||
}
|
||||
|
||||
@if (isFetched)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
<div class="text-error flex items-center">
|
||||
<i class="icon-server-off text-base me-1"></i>
|
||||
<span>
|
||||
API Error
|
||||
</span>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
if (data.RoundtripSuccess)
|
||||
{
|
||||
<div class="text-success flex items-center">
|
||||
<i class="icon-check text-base me-1"></i>
|
||||
<span>Online (@(data.Version))</span>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="text-error flex items-center">
|
||||
<i class="icon-server-off text-base me-1"></i>
|
||||
<span class="me-2">
|
||||
Error
|
||||
</span>
|
||||
<a @onclick="() => ShowErrorDetailsAsync(context.Id)" @onclick:preventDefault
|
||||
href="#" class="ms-1 text-base-content/40">Details</a>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="text-gray-500">
|
||||
<i class="icon-loader text-base me-1 align-middle"></i>
|
||||
<span class="align-middle">Loading</span>
|
||||
</div>
|
||||
}
|
||||
</td>
|
||||
</TemplateColumn>
|
||||
<TemplateColumn Title="Utilization">
|
||||
<td>
|
||||
@{
|
||||
var isFetched = Statistics.TryGetValue(context.Id, out var data);
|
||||
}
|
||||
|
||||
@if (isFetched)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
<div class="flex items-center text-error">
|
||||
<i class="icon-server-off text-base me-1"></i>
|
||||
<span>
|
||||
API Error
|
||||
</span>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="flex flex-row">
|
||||
<div class="flex items-center">
|
||||
<i class="text-primary text-base me-2 icon-cpu"></i>
|
||||
<span>@(Math.Round(data.Cpu.Usage))%</span>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center ms-5">
|
||||
<i class="text-primary text-base me-2 icon-memory-stick"></i>
|
||||
<span>
|
||||
@(Math.Round((data.Memory.Total - data.Memory.Free - data.Memory.Cached) / (double)data.Memory.Total * 100))%
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="flex items-center text-gray-500">
|
||||
<i class="icon-loader text-base me-1"></i>
|
||||
<span>Loading</span>
|
||||
</div>
|
||||
}
|
||||
</td>
|
||||
</TemplateColumn>
|
||||
<TemplateColumn Title="Actions">
|
||||
<td>
|
||||
<div class="flex justify-end">
|
||||
<a href="/admin/servers/nodes/update/@(context.Id)" class="text-primary mr-2 sm:mr-3">
|
||||
<i class="icon-pencil text-base"></i>
|
||||
</a>
|
||||
|
||||
<a href="#" @onclick="() => DeleteAsync(context)" @onclick:preventDefault
|
||||
class="text-error">
|
||||
<i class="icon-trash text-base"></i>
|
||||
</a>
|
||||
</div>
|
||||
</td>
|
||||
</TemplateColumn>
|
||||
</DataGrid>
|
||||
|
||||
@code
|
||||
{
|
||||
private DataGrid<NodeResponse> Grid;
|
||||
|
||||
private Dictionary<int, NodeSystemStatusResponse?> StatusResponses = new();
|
||||
private Dictionary<int, StatisticsResponse?> Statistics = new();
|
||||
|
||||
private ItemSource<NodeResponse> ItemSource => ItemSourceFactory.From(LoadAsync);
|
||||
|
||||
private async Task<IEnumerable<NodeResponse>> LoadAsync(int startIndex, int count)
|
||||
{
|
||||
var query = $"?startIndex={startIndex}&count={count}";
|
||||
|
||||
var countedData = await ApiClient.GetJson<CountedData<NodeResponse>>($"api/admin/servers/nodes{query}");
|
||||
|
||||
Statistics.Clear();
|
||||
StatusResponses.Clear();
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
foreach (var item in countedData.Items)
|
||||
{
|
||||
try
|
||||
{
|
||||
Statistics[item.Id] = await NodeService.GetStatisticsAsync(item.Id);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogWarning(
|
||||
"An error occured while fetching statistics for node {nodeId}: {e}",
|
||||
item.Id,
|
||||
e
|
||||
);
|
||||
|
||||
Statistics[item.Id] = null;
|
||||
}
|
||||
|
||||
await InvokeAsync(StateHasChanged);
|
||||
|
||||
try
|
||||
{
|
||||
StatusResponses[item.Id] = await NodeService.GetSystemStatusAsync(item.Id);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogWarning(
|
||||
"An error occured while fetching status for node {nodeId}: {e}",
|
||||
item.Id,
|
||||
e
|
||||
);
|
||||
|
||||
StatusResponses[item.Id] = null;
|
||||
}
|
||||
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
});
|
||||
|
||||
return countedData;
|
||||
}
|
||||
|
||||
private async Task DeleteAsync(NodeResponse response)
|
||||
{
|
||||
await AlertService.ConfirmDangerAsync(
|
||||
"Node deletion",
|
||||
$"Do you really want to delete the node '{response.Name}'",
|
||||
async () =>
|
||||
{
|
||||
await ApiClient.Delete($"api/admin/servers/nodes/{response.Id}");
|
||||
await ToastService.SuccessAsync("Successfully deleted node");
|
||||
|
||||
await Grid.RefreshAsync();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private async Task ShowErrorDetailsAsync(int id)
|
||||
{
|
||||
var data = StatusResponses.GetValueOrDefault(id);
|
||||
|
||||
if (data == null)
|
||||
return;
|
||||
|
||||
var message = $"Failed after {Math.Round(data.RoundtripTime.TotalSeconds, 2)} seconds: " +
|
||||
(data.RoundtripRemoteFailure ? "(Failed at node)" : "(Failed at api server)") +
|
||||
$" {data.RoundtripError}";
|
||||
|
||||
await AlertService.ErrorAsync("Node error details", message);
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
@page "/admin/servers/nodes/update/{Id:int}"
|
||||
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonCore.Blazor.FlyonUi.Toasts
|
||||
@using MoonCore.Helpers
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Nodes
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes
|
||||
@using MoonlightServers.Frontend.UI.Components.Nodes.UpdatePartials
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ToastService ToastService
|
||||
|
||||
@attribute [Authorize(Policy = "permissions:admin.servers.nodes.update")]
|
||||
|
||||
<LazyLoader Load="LoadAsync">
|
||||
<PageHeader Title="@Node.Name">
|
||||
<a href="/admin/servers/nodes" class="btn btn-secondary">
|
||||
<i class="icon-chevron-left"></i>
|
||||
Back
|
||||
</a>
|
||||
<WButton OnClick="Form.SubmitAsync" CssClasses="btn btn-primary">
|
||||
<i class="icon-check"></i>
|
||||
Update
|
||||
</WButton>
|
||||
</PageHeader>
|
||||
|
||||
<div class="mt-5">
|
||||
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
|
||||
|
||||
<Tabs>
|
||||
<Tab Name="Overview">
|
||||
<Overview Node="Node" />
|
||||
</Tab>
|
||||
|
||||
<Tab Name="Settings">
|
||||
<General Request="Request"/>
|
||||
</Tab>
|
||||
|
||||
<Tab Name="Allocations">
|
||||
<Allocations Node="Node"/>
|
||||
</Tab>
|
||||
|
||||
<Tab Name="Advanced Settings">
|
||||
<Advanced Request="Request"/>
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
</HandleForm>
|
||||
</div>
|
||||
</LazyLoader>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public int Id { get; set; }
|
||||
|
||||
private HandleForm Form;
|
||||
private UpdateNodeRequest Request;
|
||||
private NodeResponse Node;
|
||||
|
||||
private async Task LoadAsync(LazyLoader _)
|
||||
{
|
||||
Node = await ApiClient.GetJson<NodeResponse>($"api/admin/servers/nodes/{Id}");
|
||||
|
||||
Request = new UpdateNodeRequest()
|
||||
{
|
||||
Name = Node.Name,
|
||||
Fqdn = Node.Fqdn,
|
||||
FtpPort = Node.FtpPort,
|
||||
HttpPort = Node.HttpPort
|
||||
};
|
||||
}
|
||||
|
||||
private async Task OnSubmit()
|
||||
{
|
||||
await ApiClient.Patch($"api/admin/servers/nodes/{Id}", Request);
|
||||
|
||||
await ToastService.SuccessAsync("Successfully updated Node");
|
||||
Navigation.NavigateTo("/admin/servers/nodes");
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
@page "/admin/servers/stars/create"
|
||||
|
||||
@using Microsoft.AspNetCore.Components.Authorization
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonCore.Blazor.FlyonUi.Toasts
|
||||
@using MoonCore.Helpers
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Stars
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ToastService ToastService
|
||||
|
||||
@attribute [Authorize(Policy = "permissions:admin.servers.stars.create")]
|
||||
|
||||
<PageHeader Title="Create Star">
|
||||
<a href="/admin/servers/stars" class="btn btn-secondary">
|
||||
<i class="icon-chevron-left"></i>
|
||||
Back
|
||||
</a>
|
||||
<WButton OnClick="Form.SubmitAsync" CssClasses="btn btn-primary">
|
||||
<i class="icon-check"></i>
|
||||
Create
|
||||
</WButton>
|
||||
</PageHeader>
|
||||
|
||||
<div class="mt-5">
|
||||
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
|
||||
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-base-content">Name</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.Name" type="text" autocomplete="off" class="input w-full">
|
||||
</div>
|
||||
</div>
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-base-content">Author</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.Author" type="text" autocomplete="off" class="input w-full">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</HandleForm>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[CascadingParameter] public Task<AuthenticationState> AuthState { get; set; }
|
||||
|
||||
private HandleForm Form;
|
||||
private CreateStarRequest Request;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
Request = new();
|
||||
|
||||
var authState = await AuthState;
|
||||
Request.Author = authState.User.Claims.First(x => x.Type == "email").Value;
|
||||
}
|
||||
|
||||
private async Task OnSubmit()
|
||||
{
|
||||
await ApiClient.Post("api/admin/servers/stars", Request);
|
||||
|
||||
await ToastService.SuccessAsync("Successfully created star");
|
||||
Navigation.NavigateTo("/admin/servers/stars");
|
||||
}
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
@page "/admin/servers/stars"
|
||||
|
||||
@using MoonCore.Blazor.FlyonUi.Alerts
|
||||
@using MoonCore.Blazor.FlyonUi.Common
|
||||
@using MoonCore.Blazor.FlyonUi.Helpers
|
||||
@using MoonCore.Blazor.FlyonUi.Toasts
|
||||
@using MoonCore.Helpers
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Stars
|
||||
@using MoonCore.Exceptions
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonCore.Blazor.FlyonUi.Grid
|
||||
@using MoonCore.Blazor.FlyonUi.Grid.Columns
|
||||
@using MoonCore.Common
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject DownloadService DownloadService
|
||||
@inject ToastService ToastService
|
||||
@inject AlertService AlertService
|
||||
|
||||
@attribute [Authorize(Policy = "permissions:admin.servers.stars.get")]
|
||||
|
||||
<div class="mb-3">
|
||||
<NavTabs Index="3" Names="@UiConstants.AdminNavNames" Links="@UiConstants.AdminNavLinks"/>
|
||||
</div>
|
||||
|
||||
<div class="mb-5">
|
||||
<PageHeader Title="Stars">
|
||||
<InputFile id="import-file" hidden="" multiple OnChange="OnImportFiles"/>
|
||||
<label for="import-file" class="btn btn-accent cursor-pointer">
|
||||
<i class="icon-file-up"></i>
|
||||
Import
|
||||
</label>
|
||||
|
||||
<a href="/admin/servers/nodes/create" class="btn btn-primary">
|
||||
Create
|
||||
</a>
|
||||
</PageHeader>
|
||||
</div>
|
||||
|
||||
<DataGrid @ref="Grid"
|
||||
TGridItem="StarResponse"
|
||||
ItemSource="ItemSource">
|
||||
<PropertyColumn Field="x => x.Id" />
|
||||
<TemplateColumn Title="Name">
|
||||
<td>
|
||||
<a class="text-primary" href="/admin/servers/stars/update/@(context.Id)">
|
||||
@context.Name
|
||||
</a>
|
||||
</td>
|
||||
</TemplateColumn>
|
||||
<PropertyColumn Field="x => x.Version" />
|
||||
<PropertyColumn Field="x => x.Author" />
|
||||
<TemplateColumn>
|
||||
<td>
|
||||
<div class="flex justify-end">
|
||||
@if (!string.IsNullOrEmpty(context.DonateUrl))
|
||||
{
|
||||
<a href="@context.DonateUrl" target="_blank" class="text-accent mr-3">
|
||||
<i class="icon-heart align-middle"></i>
|
||||
<span class="align-middle">Donate</span>
|
||||
</a>
|
||||
}
|
||||
|
||||
@if (!string.IsNullOrEmpty(context.UpdateUrl))
|
||||
{
|
||||
<a href="#" @onclick:preventDefault class="text-accent mr-3">
|
||||
<i class="icon-refresh-cw align-middle"></i>
|
||||
<span class="align-middle">Update</span>
|
||||
</a>
|
||||
}
|
||||
|
||||
<a href="#" @onclick="() => ExportAsync(context)" @onclick:preventDefault class="text-success mr-3">
|
||||
<i class="icon-download align-middle"></i>
|
||||
<span class="align-middle">Export</span>
|
||||
</a>
|
||||
|
||||
<a href="/admin/servers/stars/update/@(context.Id)" class="text-primary mr-2 sm:mr-3">
|
||||
<i class="icon-pencil text-base"></i>
|
||||
</a>
|
||||
|
||||
<a href="#" @onclick="() => DeleteAsync(context)" @onclick:preventDefault
|
||||
class="text-error">
|
||||
<i class="icon-trash text-base"></i>
|
||||
</a>
|
||||
</div>
|
||||
</td>
|
||||
</TemplateColumn>
|
||||
</DataGrid>
|
||||
|
||||
@code
|
||||
{
|
||||
private DataGrid<StarResponse> Grid;
|
||||
|
||||
private ItemSource<StarResponse> ItemSource => ItemSourceFactory.From(LoadAsync);
|
||||
|
||||
private async Task<IEnumerable<StarResponse>> LoadAsync(int startIndex, int count)
|
||||
{
|
||||
var query = $"?startIndex={startIndex}&count={count}";
|
||||
|
||||
return await ApiClient.GetJson<CountedData<StarResponse>>($"api/admin/servers/stars{query}");
|
||||
}
|
||||
|
||||
private async Task DeleteAsync(StarResponse response)
|
||||
{
|
||||
await AlertService.ConfirmDangerAsync(
|
||||
"Star deletion",
|
||||
$"Do you really want to delete the star '{response.Name}'",
|
||||
async () =>
|
||||
{
|
||||
await ApiClient.Delete($"api/admin/servers/stars/{response.Id}");
|
||||
await ToastService.SuccessAsync("Successfully deleted star");
|
||||
|
||||
await Grid.RefreshAsync();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private async Task ExportAsync(StarResponse star)
|
||||
{
|
||||
var json = await ApiClient.GetString($"api/admin/servers/stars/{star.Id}/export");
|
||||
|
||||
var formattedFileName = star.Name.Replace(" ", "_") + ".json";
|
||||
|
||||
await DownloadService.DownloadAsync(formattedFileName, json);
|
||||
await ToastService.SuccessAsync($"Successfully exported '{star.Name}'");
|
||||
}
|
||||
|
||||
private async Task OnImportFiles(InputFileChangeEventArgs eventArgs)
|
||||
{
|
||||
IBrowserFile[] files;
|
||||
|
||||
if(eventArgs.FileCount == 0)
|
||||
return;
|
||||
|
||||
if (eventArgs.FileCount > 1)
|
||||
files = eventArgs.GetMultipleFiles().ToArray();
|
||||
else
|
||||
files = [eventArgs.File];
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!file.Name.EndsWith(".json"))
|
||||
{
|
||||
await ToastService.ErrorAsync($"Failed to import '{file.Name}': Only json files are supported");
|
||||
continue;
|
||||
}
|
||||
|
||||
await using var stream = file.OpenReadStream();
|
||||
var content = new MultipartFormDataContent();
|
||||
content.Add(new StreamContent(stream), "file", file.Name);
|
||||
|
||||
var star = await ApiClient.PostJson<StarResponse>("api/admin/servers/stars/import", content);
|
||||
|
||||
await ToastService.SuccessAsync($"Successfully imported '{star.Name}'");
|
||||
}
|
||||
catch (HttpApiException e)
|
||||
{
|
||||
await ToastService.ErrorAsync($"Failed to import '{file.Name}': {e.Title}");
|
||||
}
|
||||
}
|
||||
|
||||
await Grid.RefreshAsync();
|
||||
}
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
@page "/admin/servers/stars/update/{Id:int}"
|
||||
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonCore.Blazor.FlyonUi.Toasts
|
||||
@using MoonCore.Helpers
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Stars
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Stars
|
||||
@using MoonlightServers.Frontend.UI.Components.Stars.UpdatePartials
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ToastService ToastService
|
||||
|
||||
@attribute [Authorize(Policy = "permissions:admin.servers.stars.update")]
|
||||
|
||||
<LazyLoader Load="LoadAsync">
|
||||
<PageHeader Title="Update Star">
|
||||
<a href="/admin/servers/stars" class="btn btn-secondary">
|
||||
<i class="icon-chevron-left"></i>
|
||||
Back
|
||||
</a>
|
||||
<WButton OnClick="Form.SubmitAsync" CssClasses="btn btn-primary">
|
||||
<i class="icon-check"></i>
|
||||
Update
|
||||
</WButton>
|
||||
</PageHeader>
|
||||
|
||||
<div class="mt-5">
|
||||
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
|
||||
|
||||
<Tabs>
|
||||
<Tab Name="General">
|
||||
<General Request="Request" />
|
||||
</Tab>
|
||||
|
||||
<Tab Name="Start, Stop & Status">
|
||||
<StartStopStatus Request="Request" />
|
||||
</Tab>
|
||||
|
||||
<Tab Name="Parse Configuration">
|
||||
<ParseConfig Request="Request" />
|
||||
</Tab>
|
||||
|
||||
<Tab Name="Installation">
|
||||
<Installation Request="Request" />
|
||||
</Tab>
|
||||
|
||||
<Tab Name="Variables">
|
||||
<Variables Star="Detail" />
|
||||
</Tab>
|
||||
|
||||
<Tab Name="Docker Images">
|
||||
<DockerImage Star="Detail" />
|
||||
</Tab>
|
||||
|
||||
<Tab Name="Miscellaneous">
|
||||
<Misc Star="Detail" Request="Request" />
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
</HandleForm>
|
||||
</div>
|
||||
</LazyLoader>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public int Id { get; set; }
|
||||
|
||||
private HandleForm Form;
|
||||
private UpdateStarRequest Request;
|
||||
private StarResponse Detail;
|
||||
|
||||
private async Task LoadAsync(LazyLoader _)
|
||||
{
|
||||
Detail = await ApiClient.GetJson<StarResponse>($"api/admin/servers/stars/{Id}");
|
||||
Request = new()
|
||||
{
|
||||
Name = Detail.Name,
|
||||
AllowDockerImageChange = Detail.AllowDockerImageChange,
|
||||
Author = Detail.Author,
|
||||
DefaultDockerImage = Detail.DefaultDockerImage,
|
||||
DonateUrl = Detail.DonateUrl,
|
||||
InstallDockerImage = Detail.InstallDockerImage,
|
||||
InstallScript = Detail.InstallScript,
|
||||
InstallShell = Detail.InstallShell,
|
||||
OnlineDetection = Detail.OnlineDetection,
|
||||
ParseConfiguration = Detail.ParseConfiguration,
|
||||
RequiredAllocations = Detail.RequiredAllocations,
|
||||
StartupCommand = Detail.StartupCommand,
|
||||
StopCommand = Detail.StopCommand,
|
||||
UpdateUrl = Detail.UpdateUrl,
|
||||
Version = Detail.Version
|
||||
};
|
||||
}
|
||||
|
||||
private async Task OnSubmit()
|
||||
{
|
||||
await ApiClient.Patch($"api/admin/servers/stars/{Id}", Request);
|
||||
|
||||
await ToastService.SuccessAsync("Successfully updated Star");
|
||||
Navigation.NavigateTo("/admin/servers/stars");
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
@page "/servers"
|
||||
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonCore.Common
|
||||
@using MoonlightServers.Frontend.UI.Components.Servers
|
||||
@using MoonlightServers.Frontend.Services
|
||||
@using MoonlightServers.Shared.Http.Responses.Client.Servers
|
||||
|
||||
@inject ServerService ServerService
|
||||
|
||||
<Tabs>
|
||||
<Tab Name="Your servers">
|
||||
<LazyLoader Load="LoadOwnServersAsync">
|
||||
@if (OwnServers.Length == 0)
|
||||
{
|
||||
<IconAlert Title="No servers found" Color="text-primary" Icon="icon-search">
|
||||
There are no servers linked to your account
|
||||
</IconAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="flex flex-col gap-y-5">
|
||||
@* Folder design idea
|
||||
<div class="w-full bg-gray-800 px-5 py-3.5 rounded-xl">
|
||||
<div class="flex items-center">
|
||||
<div class="bg-gray-900 bg-opacity-45 py-1 px-2 rounded-lg flex items-center">
|
||||
<i class="icon-folder-open me-3 align-middle"></i>
|
||||
<div class="text-lg align-middle">
|
||||
My Cool Folder
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-5 flex flex-col gap-y-3">
|
||||
@foreach (var server in Servers)
|
||||
{
|
||||
<ServerCard Server="server" />
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
*@
|
||||
@foreach (var server in OwnServers)
|
||||
{
|
||||
<ServerCard Server="server"/>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</LazyLoader>
|
||||
</Tab>
|
||||
<Tab Name="Shared servers">
|
||||
<LazyLoader Load="LoadSharedServersAsync">
|
||||
@if (SharedServers.Length == 0)
|
||||
{
|
||||
<IconAlert Title="No shared servers found" Color="text-primary" Icon="icon-share-2">
|
||||
There are no shared servers linked to your account
|
||||
</IconAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="flex flex-col gap-y-5">
|
||||
@foreach (var server in SharedServers)
|
||||
{
|
||||
<ServerCard Server="server"/>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</LazyLoader>
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
@code
|
||||
{
|
||||
private ServerDetailResponse[] OwnServers;
|
||||
private ServerDetailResponse[] SharedServers;
|
||||
|
||||
private async Task LoadOwnServersAsync(LazyLoader lazyLoader)
|
||||
{
|
||||
OwnServers = await CountedData.AllAsync<ServerDetailResponse>(async (startIndex, count) =>
|
||||
await ServerService.GetServersAsync(startIndex, count)
|
||||
);
|
||||
}
|
||||
|
||||
private async Task LoadSharedServersAsync(LazyLoader lazyLoader)
|
||||
{
|
||||
SharedServers = await CountedData.AllAsync<ServerDetailResponse>(async (startIndex, count) =>
|
||||
await ServerService.GetSharedServersAsync(startIndex, count)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,347 +0,0 @@
|
||||
@page "/servers/{ServerId:int}"
|
||||
@page "/servers/{ServerId:int}/{TabPath:alpha}"
|
||||
|
||||
@using Microsoft.AspNetCore.SignalR.Client
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonCore.Exceptions
|
||||
@using MoonCore.Helpers
|
||||
@using MoonlightServers.Frontend.Interfaces
|
||||
@using MoonlightServers.Frontend.Models
|
||||
@using MoonlightServers.Frontend.Services
|
||||
@using MoonlightServers.Shared.Enums
|
||||
@using MoonlightServers.Shared.Http.Responses.Client.Servers
|
||||
|
||||
@inject ServerService ServerService
|
||||
@inject NavigationManager Navigation
|
||||
@inject IEnumerable<IServerTabProvider> TabProviders
|
||||
|
||||
@implements IAsyncDisposable
|
||||
|
||||
<LazyLoader Load="LoadAsync">
|
||||
@if (NotFound)
|
||||
{
|
||||
<IconAlert Title="Server not found" Icon="icon-search" Color="text-primary">
|
||||
The requested server could not be found
|
||||
</IconAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="card card-body justify-between py-2.5 px-5 flex-row">
|
||||
<div class="flex flex-row items-center">
|
||||
@{
|
||||
var statusClass = State switch
|
||||
{
|
||||
ServerState.Installing => "status-primary",
|
||||
ServerState.Offline => "status-error",
|
||||
ServerState.Starting => "status-warning",
|
||||
ServerState.Stopping => "status-warning",
|
||||
ServerState.Online => "status-success",
|
||||
_ => "status-secondary"
|
||||
};
|
||||
}
|
||||
|
||||
<div class="inline-grid *:[grid-area:1/1] me-3">
|
||||
@if (State != ServerState.Offline)
|
||||
{
|
||||
<div class="status status-xl @statusClass animate-ping"></div>
|
||||
}
|
||||
<div class="status status-xl @statusClass"></div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col">
|
||||
<div class="hidden sm:flex text-lg font-semibold">@Server.Name</div>
|
||||
<div class="hidden text-sm text-base-content/60 md:flex gap-x-3">
|
||||
<span>
|
||||
<i class="icon-sparkles me-0.5 align-middle"></i>
|
||||
<span class="align-middle">@Server.StarName</span>
|
||||
</span>
|
||||
|
||||
<span>
|
||||
<i class="icon-database me-0.5 align-middle"></i>
|
||||
<span class="align-middle">@Server.NodeName</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-row items-center">
|
||||
<div class="flex gap-x-1.5">
|
||||
@if (HasPermissionTo("power", ServerPermissionLevel.ReadWrite))
|
||||
{
|
||||
@if (State == ServerState.Offline)
|
||||
{
|
||||
<WButton CssClasses="btn btn-success" OnClick="_ => StartAsync()">
|
||||
<i class="icon-play align-middle"></i>
|
||||
<span class="align-middle">Start</span>
|
||||
</WButton>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button type="button" class="btn btn-success" disabled="disabled">
|
||||
<i class="icon-play align-middle"></i>
|
||||
<span class="align-middle">Start</span>
|
||||
</button>
|
||||
}
|
||||
|
||||
@if (State == ServerState.Online)
|
||||
{
|
||||
<button type="button" class="btn btn-primary">
|
||||
<i class="icon-rotate-ccw align-middle"></i>
|
||||
<span class="align-middle">Restart</span>
|
||||
</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button type="button" class="btn btn-primary" disabled="disabled">
|
||||
<i class="icon-rotate-ccw align-middle"></i>
|
||||
<span class="align-middle">Restart</span>
|
||||
</button>
|
||||
}
|
||||
|
||||
@if (State == ServerState.Starting || State == ServerState.Online || State == ServerState.Stopping)
|
||||
{
|
||||
if (State == ServerState.Stopping)
|
||||
{
|
||||
<WButton CssClasses="btn btn-error" OnClick="_ => KillAsync()">
|
||||
<i class="icon-bomb align-middle"></i>
|
||||
<span class="align-middle">Kill</span>
|
||||
</WButton>
|
||||
}
|
||||
else
|
||||
{
|
||||
<WButton CssClasses="btn btn-error" OnClick="_ => StopAsync()">
|
||||
<i class="icon-squircle align-middle"></i>
|
||||
<span class="align-middle">Stop</span>
|
||||
</WButton>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<button type="button" class="btn btn-error" disabled="disabled">
|
||||
<i class="icon-squircle align-middle"></i>
|
||||
<span class="align-middle">Stop</span>
|
||||
</button>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<button type="button" class="btn btn-success" disabled="disabled">
|
||||
<i class="icon-play align-middle"></i>
|
||||
<span class="align-middle">Start</span>
|
||||
</button>
|
||||
|
||||
<button type="button" class="btn btn-primary" disabled="disabled">
|
||||
<i class="icon-rotate-ccw align-middle"></i>
|
||||
<span class="align-middle">Restart</span>
|
||||
</button>
|
||||
|
||||
<button type="button" class="btn btn-error" disabled="disabled">
|
||||
<i class="icon-squircle align-middle"></i>
|
||||
<span class="align-middle">Stop</span>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
|
||||
<nav class="tabs space-x-2 overflow-x-auto" aria-label="Tabs" role="tablist" aria-orientation="horizontal">
|
||||
@foreach (var tab in Tabs)
|
||||
{
|
||||
<a href="/servers/@(ServerId)/@(tab.Path)"
|
||||
class="btn btn-text active-tab:bg-primary active-tab:text-primary-content hover:text-primary hover:bg-primary/20 bg-base-150 text-sm py-0.5 px-3 rounded-xl @(tab == CurrentTab ? "active" : "")"
|
||||
data-tab="na"
|
||||
role="tab"
|
||||
@onclick:preventDefault
|
||||
@onclick="() => SwitchTabAsync(tab)">
|
||||
@tab.Name
|
||||
</a>
|
||||
}
|
||||
</nav>
|
||||
|
||||
<div class="mt-5">
|
||||
@if (CurrentTab == null)
|
||||
{
|
||||
<IconAlert Title="No tabs found" Color="text-primary" Icon="icon-app-window">
|
||||
Seems like you are missing access to all tabs or no tabs for this server could be found
|
||||
</IconAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
var rf = ComponentHelper.FromType(CurrentTab!.ComponentType, parameters =>
|
||||
{
|
||||
parameters.Add("Server", Server);
|
||||
parameters.Add("State", State);
|
||||
parameters.Add("InitialConsoleMessage", InitialConsoleMessage);
|
||||
parameters.Add("HubConnection", HubConnection!);
|
||||
parameters.Add("Parent", this);
|
||||
});
|
||||
|
||||
@rf
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</LazyLoader>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public int ServerId { get; set; }
|
||||
[Parameter] public string? TabPath { get; set; }
|
||||
|
||||
private ServerTab[] Tabs;
|
||||
private ServerTab? CurrentTab;
|
||||
|
||||
private ServerDetailResponse Server;
|
||||
private bool NotFound = false;
|
||||
private ServerState State;
|
||||
private string InitialConsoleMessage = "";
|
||||
|
||||
private HubConnection? HubConnection;
|
||||
|
||||
public ConcurrentList<string> CommandHistory = new();
|
||||
|
||||
private async Task LoadAsync(LazyLoader _)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Load meta data
|
||||
Server = await ServerService.GetServerAsync(ServerId);
|
||||
|
||||
// Load server tabs
|
||||
var tmpTabs = new List<ServerTab>();
|
||||
|
||||
foreach (var serverTabProvider in TabProviders)
|
||||
tmpTabs.AddRange(await serverTabProvider.GetTabsAsync(Server));
|
||||
|
||||
// If we are accessing a shared server, we need to handle permissions
|
||||
if (Server.Share != null)
|
||||
{
|
||||
// This removes all tabs where the user doesn't have the required permissions
|
||||
tmpTabs.RemoveAll(tab =>
|
||||
{
|
||||
if (string.IsNullOrEmpty(tab.PermissionId) || tab.PermissionLevel == ServerPermissionLevel.None)
|
||||
return false;
|
||||
|
||||
// If permission is required but not set, we don't have access to it
|
||||
if (!Server.Share.Permissions.TryGetValue(tab.PermissionId, out var level))
|
||||
return true;
|
||||
|
||||
// False if the acquired level is higher or equal than the required permission level for the tab so it won't get removed
|
||||
return level < tab.PermissionLevel;
|
||||
});
|
||||
}
|
||||
|
||||
Tabs = tmpTabs.OrderBy(x => x.Priority).ToArray();
|
||||
|
||||
// Find current tab
|
||||
if (!string.IsNullOrEmpty(TabPath))
|
||||
{
|
||||
CurrentTab = Tabs.FirstOrDefault(x => TabPath.Equals(x.Path, StringComparison.InvariantCultureIgnoreCase)
|
||||
);
|
||||
}
|
||||
|
||||
if (CurrentTab == null)
|
||||
CurrentTab = Tabs.FirstOrDefault();
|
||||
|
||||
// Load initial status for first render
|
||||
var status = await ServerService.GetStatusAsync(ServerId);
|
||||
|
||||
State = status.State;
|
||||
|
||||
if (!HasPermissionTo("console", ServerPermissionLevel.Read))
|
||||
return; // Exit early if we don't have permissions to load the console
|
||||
|
||||
// Load initial messages
|
||||
var initialLogs = await ServerService.GetLogsAsync(ServerId);
|
||||
|
||||
InitialConsoleMessage = "";
|
||||
|
||||
foreach (var message in initialLogs.Messages)
|
||||
InitialConsoleMessage += message;
|
||||
|
||||
// Load websocket meta
|
||||
var websocketDetails = await ServerService.GetWebSocketAsync(ServerId);
|
||||
|
||||
// Build signal r
|
||||
HubConnection = new HubConnectionBuilder()
|
||||
.WithUrl(websocketDetails.Target, options =>
|
||||
{
|
||||
options.AccessTokenProvider = async () =>
|
||||
{
|
||||
var details = await ServerService.GetWebSocketAsync(ServerId);
|
||||
return details.AccessToken;
|
||||
};
|
||||
})
|
||||
.WithAutomaticReconnect()
|
||||
.Build();
|
||||
|
||||
// Define handlers
|
||||
HubConnection.On<string>("StateChanged", async stateStr =>
|
||||
{
|
||||
if (!Enum.TryParse(stateStr, out ServerState receivedState))
|
||||
return;
|
||||
|
||||
State = receivedState;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
});
|
||||
|
||||
HubConnection.On<string>("ConsoleOutput", async content =>
|
||||
{
|
||||
// Update initial message
|
||||
InitialConsoleMessage += content;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
});
|
||||
|
||||
// Connect
|
||||
await HubConnection.StartAsync();
|
||||
}
|
||||
catch (HttpApiException e)
|
||||
{
|
||||
if (e.Status == 404)
|
||||
NotFound = true;
|
||||
else
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private bool HasPermissionTo(string id, ServerPermissionLevel level)
|
||||
{
|
||||
// All non shares have permissions
|
||||
if (Server.Share == null)
|
||||
return true;
|
||||
|
||||
if (!Server.Share.Permissions.TryGetValue(id, out var acquiredLevel))
|
||||
return false;
|
||||
|
||||
return acquiredLevel >= level;
|
||||
}
|
||||
|
||||
private async Task SwitchTabAsync(ServerTab tab)
|
||||
{
|
||||
CurrentTab = tab;
|
||||
Navigation.NavigateTo($"/servers/{ServerId}/{tab.Path}");
|
||||
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
private async Task StartAsync()
|
||||
=> await ServerService.StartAsync(ServerId);
|
||||
|
||||
private async Task StopAsync()
|
||||
=> await ServerService.StopAsync(ServerId);
|
||||
|
||||
private async Task KillAsync()
|
||||
=> await ServerService.KillAsync(ServerId);
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
if (HubConnection != null)
|
||||
{
|
||||
if (HubConnection.State == HubConnectionState.Connected)
|
||||
await HubConnection.StopAsync();
|
||||
|
||||
await HubConnection.DisposeAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
43
MoonlightServers.Frontend/UI/Views/Demo.razor
Normal file
43
MoonlightServers.Frontend/UI/Views/Demo.razor
Normal file
@@ -0,0 +1,43 @@
|
||||
@page "/demo"
|
||||
@using LucideBlazor
|
||||
@using MoonlightServers.Frontend.UI.Components
|
||||
@using ShadcnBlazor.Buttons
|
||||
@using ShadcnBlazor.Cards
|
||||
@using ShadcnBlazor.Extras.Dialogs
|
||||
|
||||
@inject DialogService DialogService
|
||||
|
||||
<div class="grid grid-cols-1 lg:grid-cols-2 gap-5">
|
||||
<Card ClassName="col-span-1">
|
||||
<CardHeader>
|
||||
<CardTitle>Demo</CardTitle>
|
||||
<CardDescription>A cool demo page</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
You successfully used the plugin template to create your moonlight plugin :)
|
||||
</CardContent>
|
||||
<CardFooter>
|
||||
<Button>
|
||||
<Slot>
|
||||
<a @attributes="context" href="https://moonlightpa.nl/dev">
|
||||
<ExternalLinkIcon/>
|
||||
Visit documentation
|
||||
</a>
|
||||
</Slot>
|
||||
</Button>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardContent>
|
||||
<Button @onclick="LaunchFormAsync" Variant="ButtonVariant.Outline">
|
||||
Open Form
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
private async Task LaunchFormAsync()
|
||||
=> await DialogService.LaunchAsync<FormDialog>();
|
||||
}
|
||||
Reference in New Issue
Block a user