Recreated plugin with new project template. Started implementing server system daemon
This commit is contained in:
74
MoonlightServers.Frontend/UI/Components/FormDialog.razor
Normal file
74
MoonlightServers.Frontend/UI/Components/FormDialog.razor
Normal file
@@ -0,0 +1,74 @@
|
||||
@using Moonlight.Frontend.Helpers
|
||||
@using MoonlightServers.Shared
|
||||
@using MoonlightServers.Shared.Http.Requests
|
||||
@using MoonlightServers.Shared.Http.Responses
|
||||
@using ShadcnBlazor.Buttons
|
||||
@using ShadcnBlazor.Dialogs
|
||||
@using ShadcnBlazor.Extras.AlertDialogs
|
||||
@using ShadcnBlazor.Extras.Forms
|
||||
@using ShadcnBlazor.Fields
|
||||
@using ShadcnBlazor.Inputs
|
||||
|
||||
@inherits ShadcnBlazor.Extras.Dialogs.DialogBase
|
||||
|
||||
@inject HttpClient HttpClient
|
||||
@inject AlertDialogService AlertDialogService
|
||||
|
||||
<DialogHeader>
|
||||
<DialogTitle>Example Form</DialogTitle>
|
||||
<DialogDescription>This forms removes all spaces from the input</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<EnhancedEditForm @ref="Form" OnValidSubmit="OnSubmit" Model="Dto">
|
||||
<DataAnnotationsValidator/>
|
||||
|
||||
<FieldSet>
|
||||
<FormValidationSummary/>
|
||||
|
||||
<FieldGroup>
|
||||
<Field>
|
||||
<FieldLabel for="formInput">Form Input</FieldLabel>
|
||||
<TextInputField id="formInput" @bind-Value="Dto.TextField"/>
|
||||
<FieldDescription>Input you want to remove the spaces from</FieldDescription>
|
||||
</Field>
|
||||
</FieldGroup>
|
||||
</FieldSet>
|
||||
</EnhancedEditForm>
|
||||
|
||||
<DialogFooter>
|
||||
<Button @onclick="() => Form.SubmitAsync()">Submit</Button>
|
||||
<DialogClose/>
|
||||
</DialogFooter>
|
||||
|
||||
@code
|
||||
{
|
||||
private FormSubmitDto Dto = new();
|
||||
private EnhancedEditForm Form;
|
||||
|
||||
private async Task<bool> OnSubmit(EditContext editContext, ValidationMessageStore validationMessageStore)
|
||||
{
|
||||
var response = await HttpClient.PostAsJsonAsync(
|
||||
"api/form",
|
||||
Dto,
|
||||
SerializationContext.Default.Options
|
||||
);
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
var data = await response.Content.ReadFromJsonAsync<FormResultDto>(
|
||||
SerializationContext.Default.Options
|
||||
);
|
||||
|
||||
if (data == null)
|
||||
return true;
|
||||
|
||||
await AlertDialogService.InfoAsync("Result", data.Result);
|
||||
|
||||
await CloseAsync();
|
||||
return true;
|
||||
}
|
||||
|
||||
await ProblemDetailsHelper.HandleProblemDetailsAsync(response, Dto, validationMessageStore);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
@using System.Diagnostics.CodeAnalysis
|
||||
|
||||
@* TODO: Extract to mooncore? *@
|
||||
|
||||
@inherits InputBase<bool>
|
||||
|
||||
<div class="flex items-center gap-1">
|
||||
<input @bind="CurrentValue" type="checkbox" class="switch switch-primary" id="switch-@GetHashCode()" />
|
||||
<label class="label-text text-base" for="switch-@GetHashCode()">
|
||||
@if (CurrentValue)
|
||||
{
|
||||
<span>On</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>Off</span>
|
||||
}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
protected override bool TryParseValueFromString(string? value, out bool result, [NotNullWhen(false)] out string? validationErrorMessage)
|
||||
{
|
||||
validationErrorMessage = null;
|
||||
result = string.Equals(value, "true", StringComparison.OrdinalIgnoreCase);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
@using Microsoft.Extensions.Logging
|
||||
@using XtermBlazor
|
||||
@inherits MoonCore.Blazor.FlyonUi.Modals.BaseModal
|
||||
|
||||
@inject IJSRuntime JsRuntime
|
||||
@inject ILogger<FullScreenModal> Logger
|
||||
|
||||
@implements IAsyncDisposable
|
||||
|
||||
<div class="bg-black p-2 relative w-full h-[90vh] rounded-lg">
|
||||
@if (IsInitialized)
|
||||
{
|
||||
<Xterm @ref="Terminal"
|
||||
Addons="Parent.Addons"
|
||||
Options="Parent.Options"
|
||||
Class="h-full w-full"
|
||||
OnFirstRender="HandleFirstRenderAsync"/>
|
||||
}
|
||||
|
||||
<div class="absolute top-4 right-4">
|
||||
<button @onclick="HideAsync" class="btn btn-error btn-square">
|
||||
<i class="icon-x text-lg"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public XtermConsole Parent { get; set; }
|
||||
|
||||
private bool IsInitialized = false;
|
||||
private bool IsReadyToWrite = false;
|
||||
private Xterm Terminal;
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (!firstRender)
|
||||
return;
|
||||
|
||||
// Initialize addons
|
||||
|
||||
try
|
||||
{
|
||||
await JsRuntime.InvokeVoidAsync("moonlightServers.loadAddons");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError("An error occured while initializing addons: {e}", e);
|
||||
}
|
||||
|
||||
// Subscribe to parent events
|
||||
Parent.OnWrite += HandleWriteAsync;
|
||||
|
||||
IsInitialized = true;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
private async Task HandleFirstRenderAsync()
|
||||
{
|
||||
IsReadyToWrite = true;
|
||||
|
||||
try
|
||||
{
|
||||
await Terminal.Addon("addon-fit").InvokeVoidAsync("fit");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError("An error occured while calling addons: {e}", e);
|
||||
}
|
||||
|
||||
var outputToWrite = string.Concat(Parent.OutputCache.ToArray());
|
||||
await Terminal.Write(outputToWrite);
|
||||
}
|
||||
|
||||
private async Task HandleWriteAsync(string content)
|
||||
{
|
||||
if (!IsReadyToWrite)
|
||||
return;
|
||||
|
||||
await Terminal.Write(content);
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
Parent.OnWrite -= HandleWriteAsync;
|
||||
await Terminal.DisposeAsync();
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.NodeAllocations
|
||||
|
||||
@inherits MoonCore.Blazor.FlyonUi.Modals.BaseModal
|
||||
|
||||
<div class="p-5">
|
||||
<div class="flex items-center gap-4">
|
||||
<div class="avatar avatar-placeholder max-sm:hidden">
|
||||
<div class="border-base-content/20 rounded-box w-13 border-1">
|
||||
<span class="icon-ethernet-port text-xl"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="space-y-1">
|
||||
<h3 class="text-base-content text-2xl font-semibold">Add a new allocation</h3>
|
||||
<p class="text-base-content/80">Add a new allocation to the selected node</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-5">
|
||||
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
|
||||
<div class="mt-2">
|
||||
<label class="label-text">IP Address</label>
|
||||
<input class="input" @bind="Form.IpAddress" type="text"/>
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
<label class="label-text">Port</label>
|
||||
<input class="input" @bind="Form.Port" type="number"/>
|
||||
</div>
|
||||
</HandleForm>
|
||||
</div>
|
||||
<div class="mt-5 flex justify-end">
|
||||
<button @onclick="HideAsync" type="button" class="btn btn-secondary me-2">
|
||||
Cancel
|
||||
</button>
|
||||
<WButton OnClick="SubmitAsync">
|
||||
Create
|
||||
</WButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public Func<CreateNodeAllocationRequest, Task> OnSubmit { get; set; }
|
||||
|
||||
private CreateNodeAllocationRequest Form;
|
||||
private HandleForm HandleForm;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
Form = new()
|
||||
{
|
||||
IpAddress = "0.0.0.0"
|
||||
};
|
||||
}
|
||||
|
||||
private async Task OnValidSubmit()
|
||||
{
|
||||
await OnSubmit.Invoke(Form);
|
||||
await HideAsync();
|
||||
}
|
||||
|
||||
private Task SubmitAsync() => HandleForm.SubmitAsync();
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.NodeAllocations
|
||||
|
||||
@inherits MoonCore.Blazor.FlyonUi.Modals.BaseModal
|
||||
|
||||
<div class="p-5">
|
||||
<div class="flex items-center gap-4">
|
||||
<div class="avatar avatar-placeholder max-sm:hidden">
|
||||
<div class="border-base-content/20 rounded-box w-13 border-1">
|
||||
<span class="icon-ethernet-port text-xl"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="space-y-1">
|
||||
<h3 class="text-base-content text-2xl font-semibold">Add multiple allocations</h3>
|
||||
<p class="text-base-content/80">Add a range of new allocations to the selected node</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-5">
|
||||
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
|
||||
<div class="mt-2">
|
||||
<label class="label-text">IP Address</label>
|
||||
<input class="input" @bind="Form.IpAddress" type="text"/>
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
<label class="label-text">Start Port</label>
|
||||
<input class="input" @bind="Form.Start" type="number"/>
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
<label class="label-text">End Port</label>
|
||||
<input class="input" @bind="Form.End" type="number"/>
|
||||
</div>
|
||||
</HandleForm>
|
||||
</div>
|
||||
<div class="mt-5 flex justify-end">
|
||||
<button @onclick="HideAsync" type="button" class="btn btn-secondary me-2">
|
||||
Cancel
|
||||
</button>
|
||||
<WButton OnClick="SubmitAsync">
|
||||
Create
|
||||
</WButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public Func<CreateNodeAllocationRangeRequest, Task> OnSubmit { get; set; }
|
||||
|
||||
private CreateNodeAllocationRangeRequest Form;
|
||||
private HandleForm HandleForm;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
Form = new()
|
||||
{
|
||||
IpAddress = "0.0.0.0",
|
||||
Start = 2000,
|
||||
End = 3000
|
||||
};
|
||||
}
|
||||
|
||||
private async Task OnValidSubmit()
|
||||
{
|
||||
await OnSubmit.Invoke(Form);
|
||||
await HideAsync();
|
||||
}
|
||||
|
||||
private Task SubmitAsync() => HandleForm.SubmitAsync();
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.NodeAllocations
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.NodeAllocations
|
||||
|
||||
@inherits MoonCore.Blazor.FlyonUi.Modals.BaseModal
|
||||
|
||||
<div class="p-5">
|
||||
<div class="flex items-center gap-4">
|
||||
<div class="avatar avatar-placeholder max-sm:hidden">
|
||||
<div class="border-base-content/20 rounded-box w-13 border-1">
|
||||
<span class="icon-ethernet-port text-xl"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="space-y-1">
|
||||
<h3 class="text-base-content text-2xl font-semibold">Update allocation</h3>
|
||||
<p class="text-base-content/80">Update an existing allocation</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-5">
|
||||
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
|
||||
<div class="mt-2">
|
||||
<label class="label-text">IP Address</label>
|
||||
<input class="input" @bind="Form.IpAddress" type="text"/>
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
<label class="label-text">Port</label>
|
||||
<input class="input" @bind="Form.Port" type="number"/>
|
||||
</div>
|
||||
</HandleForm>
|
||||
</div>
|
||||
<div class="mt-5 flex justify-end">
|
||||
<button @onclick="HideAsync" type="button" class="btn btn-secondary me-2">
|
||||
Cancel
|
||||
</button>
|
||||
<WButton OnClick="SubmitAsync">
|
||||
Update
|
||||
</WButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public Func<UpdateNodeAllocationRequest, Task> OnSubmit { get; set; }
|
||||
[Parameter] public NodeAllocationResponse Allocation { get; set; }
|
||||
|
||||
private UpdateNodeAllocationRequest Form;
|
||||
private HandleForm HandleForm;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
Form = new UpdateNodeAllocationRequest()
|
||||
{
|
||||
IpAddress = Allocation.IpAddress,
|
||||
Port = Allocation.Port
|
||||
};
|
||||
}
|
||||
|
||||
private async Task OnValidSubmit()
|
||||
{
|
||||
await OnSubmit.Invoke(Form);
|
||||
await HideAsync();
|
||||
}
|
||||
|
||||
private Task SubmitAsync() => HandleForm.SubmitAsync();
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Nodes
|
||||
|
||||
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
|
||||
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public UpdateNodeRequest Request { get; set; }
|
||||
}
|
||||
@@ -1,150 +0,0 @@
|
||||
@using MoonCore.Blazor.FlyonUi.Alerts
|
||||
@using MoonCore.Blazor.FlyonUi.Common
|
||||
@using MoonCore.Blazor.FlyonUi.Grid
|
||||
@using MoonCore.Blazor.FlyonUi.Grid.Columns
|
||||
@using MoonCore.Blazor.FlyonUi.Modals
|
||||
@using MoonCore.Blazor.FlyonUi.Toasts
|
||||
@using MoonCore.Common
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes
|
||||
@using MoonCore.Helpers
|
||||
@using MoonlightServers.Frontend.UI.Components.Nodes.Modals
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.NodeAllocations
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.NodeAllocations
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject ModalService ModalService
|
||||
@inject ToastService ToastService
|
||||
@inject AlertService AlertService
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 md:gap-x-5">
|
||||
<div class="col-span-1">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<span class="card-title">Actions</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="flex flex-col gap-y-3">
|
||||
<button type="button" @onclick="AddAllocationAsync" class="btn btn-primary">Create</button>
|
||||
<button type="button" @onclick="AddAllocationRangeAsync" class="btn btn-accent">Create multiple
|
||||
</button>
|
||||
<button type="button" @onclick="DeleteAllAllocationsAsync" class="btn btn-error">Delete all</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-span-1 md:col-span-2 -mb-3">
|
||||
<DataGrid @ref="Grid"
|
||||
TGridItem="NodeAllocationResponse"
|
||||
ItemSource="ItemSource">
|
||||
<PropertyColumn Field="x => x.IpAddress" Title="IP Address"/>
|
||||
<PropertyColumn Field="x => x.Port"/>
|
||||
<TemplateColumn>
|
||||
<td>
|
||||
<div class="flex justify-end items-center">
|
||||
<a @onclick="() => UpdateAllocationAsync(context)"
|
||||
@onclick:preventDefault href="#"
|
||||
class="text-primary mr-2 sm:mr-3">
|
||||
<i class="icon-pencil text-base"></i>
|
||||
</a>
|
||||
<a @onclick="() => DeleteAllocationAsync(context)"
|
||||
@onclick:preventDefault href="#"
|
||||
class="text-error">
|
||||
<i class="icon-trash text-base"></i>
|
||||
</a>
|
||||
</div>
|
||||
</td>
|
||||
</TemplateColumn>
|
||||
</DataGrid>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public NodeResponse Node { get; set; }
|
||||
|
||||
private DataGrid<NodeAllocationResponse> Grid;
|
||||
|
||||
private ItemSource<NodeAllocationResponse> ItemSource => ItemSourceFactory.From(LoadAsync);
|
||||
|
||||
private async Task<IEnumerable<NodeAllocationResponse>> LoadAsync(int startIndex, int count)
|
||||
{
|
||||
var query = $"?startIndex={startIndex}&count={count}";
|
||||
|
||||
return await ApiClient.GetJson<CountedData<NodeAllocationResponse>>(
|
||||
$"api/admin/servers/nodes/{Node.Id}/allocations{query}"
|
||||
);
|
||||
}
|
||||
|
||||
private async Task AddAllocationRangeAsync()
|
||||
{
|
||||
Func<CreateNodeAllocationRangeRequest, Task> onSubmit = async request =>
|
||||
{
|
||||
await ApiClient.Post($"api/admin/servers/nodes/{Node.Id}/allocations/range", request);
|
||||
|
||||
await ToastService.SuccessAsync("Successfully created allocations");
|
||||
await Grid.RefreshAsync();
|
||||
};
|
||||
|
||||
await ModalService.LaunchAsync<CreateMultipleAllocationModal>(parameters => { parameters.Add("OnSubmit", onSubmit); });
|
||||
}
|
||||
|
||||
private async Task AddAllocationAsync()
|
||||
{
|
||||
Func<CreateNodeAllocationRequest, Task> onSubmit = async request =>
|
||||
{
|
||||
await ApiClient.Post($"api/admin/servers/nodes/{Node.Id}/allocations", request);
|
||||
|
||||
await ToastService.SuccessAsync("Successfully created allocation");
|
||||
await Grid.RefreshAsync();
|
||||
};
|
||||
|
||||
await ModalService.LaunchAsync<CreateAllocationModal>(parameters => { parameters.Add("OnSubmit", onSubmit); });
|
||||
}
|
||||
|
||||
private async Task UpdateAllocationAsync(NodeAllocationResponse allocation)
|
||||
{
|
||||
Func<UpdateNodeAllocationRequest, Task> onSubmit = async request =>
|
||||
{
|
||||
await ApiClient.Patch($"api/admin/servers/nodes/{Node.Id}/allocations/{allocation.Id}", request);
|
||||
|
||||
await ToastService.SuccessAsync("Successfully updated allocation");
|
||||
await Grid.RefreshAsync();
|
||||
};
|
||||
|
||||
await ModalService.LaunchAsync<UpdateAllocationModal>(parameters =>
|
||||
{
|
||||
parameters.Add("OnSubmit", onSubmit);
|
||||
parameters.Add("Allocation", allocation);
|
||||
});
|
||||
}
|
||||
|
||||
private async Task DeleteAllocationAsync(NodeAllocationResponse allocation)
|
||||
{
|
||||
await AlertService.ConfirmDangerAsync(
|
||||
"Delete allocation",
|
||||
"Do you really want to delete the selected allocation? This cannot be undone",
|
||||
async () =>
|
||||
{
|
||||
await ApiClient.Delete($"api/admin/servers/nodes/{Node.Id}/allocations/{allocation.Id}");
|
||||
|
||||
await ToastService.SuccessAsync("Successfully deleted allocation");
|
||||
await Grid.RefreshAsync();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private async Task DeleteAllAllocationsAsync()
|
||||
{
|
||||
await AlertService.ConfirmDangerAsync(
|
||||
"Delete all allocations",
|
||||
"Do you really want to delete all allocations? This cannot be undone",
|
||||
async () =>
|
||||
{
|
||||
await ApiClient.Delete($"api/admin/servers/nodes/{Node.Id}/allocations/all");
|
||||
|
||||
await ToastService.SuccessAsync("Successfully deleted allocations");
|
||||
await Grid.RefreshAsync();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Nodes
|
||||
|
||||
<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">Http Port</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">Ftp Port</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.FtpPort" type="number" autocomplete="off" class="input w-full">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public UpdateNodeRequest Request { get; set; }
|
||||
}
|
||||
@@ -1,217 +0,0 @@
|
||||
@using Microsoft.Extensions.Logging
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonCore.Blazor.FlyonUi.Toasts
|
||||
@using MoonCore.Helpers
|
||||
@using MoonlightServers.Frontend.Services
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes.Statistics
|
||||
|
||||
@inject NodeService NodeService
|
||||
@inject ToastService ToastService
|
||||
@inject ILogger<Overview> Logger
|
||||
|
||||
@implements IDisposable
|
||||
|
||||
<LazyLoader Load="LoadAsync">
|
||||
|
||||
<div class="mb-3 mt-5 text-xl font-semibold">
|
||||
Overview
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 lg:grid-cols-3 gap-5">
|
||||
<div class="col-span-1 card card-body">
|
||||
<div class="flex justify-between">
|
||||
<p class="text-xl font-semibold text-base-content">
|
||||
@(Math.Round(Statistics.Cpu.Usage, 2))%
|
||||
</p>
|
||||
<i class="icon-cpu text-4xl text-primary"></i>
|
||||
</div>
|
||||
<div class="text-base text-base-content/90">
|
||||
<span class="truncate">
|
||||
CPU: @Statistics.Cpu.Model
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1 card card-body">
|
||||
<div class="flex justify-between">
|
||||
<p class="text-xl font-semibold text-base-content">
|
||||
@(Formatter.FormatSize(Statistics.Memory.Total - Statistics.Memory.Available))
|
||||
/
|
||||
@(Formatter.FormatSize(Statistics.Memory.Total))
|
||||
</p>
|
||||
<i class="icon-memory-stick text-4xl text-primary"></i>
|
||||
</div>
|
||||
<div class="text-base text-base-content/90">
|
||||
Memory
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1 card card-body">
|
||||
<div class="flex justify-between">
|
||||
<div class="text-xl font-semibold text-base-content">
|
||||
@(Formatter.FormatSize(Statistics.Memory.SwapTotal - Statistics.Memory.SwapFree))
|
||||
/
|
||||
@(Formatter.FormatSize(Statistics.Memory.SwapTotal))
|
||||
</div>
|
||||
<i class="icon-shapes text-4xl text-primary"></i>
|
||||
</div>
|
||||
<div class="text-base text-base-content/90">
|
||||
Swap
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3 mt-5 text-xl font-semibold">
|
||||
CPU
|
||||
</div>
|
||||
|
||||
<div class="card card-body grid grid-cols-1 lg:grid-cols-2 gap-y-2 gap-x-5">
|
||||
@{
|
||||
var i = 0;
|
||||
}
|
||||
|
||||
@foreach (var usage in Statistics.Cpu.UsagePerCore)
|
||||
{
|
||||
var percentRounded = Math.Round(usage, 2);
|
||||
|
||||
<div class="flex flex-row items-center col-span-1">
|
||||
<div class="text-sm text-base-content/90 me-1.5 grow-0 flex flex-col">
|
||||
<span>#@(i)</span>
|
||||
</div>
|
||||
<div class="grow">
|
||||
<div class="progress h-2" role="progressbar">
|
||||
<div class="progress-bar transition-all duration-300 ease-in-out @(GetBackgroundColorByPercent(percentRounded))" style="width: @(usage)%"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
i++;
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="mb-3 mt-5 text-xl font-semibold">
|
||||
Disks
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 lg:grid-cols-3 gap-5">
|
||||
@foreach (var disk in Statistics.Disks)
|
||||
{
|
||||
var usedPercent = Math.Round((disk.DiskTotal - disk.DiskFree) / (double)disk.DiskTotal * 100, 2);
|
||||
var iNodesPercent = Math.Round((disk.InodesTotal - disk.InodesFree) / (double)disk.InodesTotal * 100, 2);
|
||||
|
||||
<div class="col-span-1 card card-body">
|
||||
<div class="flex items-center">
|
||||
<div class="grow">
|
||||
<div class="progress h-2" role="progressbar">
|
||||
<div class="progress-bar transition-all duration-300 ease-in-out @(GetBackgroundColorByPercent(usedPercent))" style="width: @(usedPercent)%"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-sm text-base-content/90 mt-2.5 flex flex-col">
|
||||
<div>
|
||||
Device: <span class="font-semibold">@disk.Device</span> - Mounted at: <span class="font-semibold truncate">@disk.MountPath</span>
|
||||
</div>
|
||||
<div>
|
||||
Used: <span class="font-semibold">@Formatter.FormatSize(disk.DiskTotal - disk.DiskFree)</span>
|
||||
Total: <span class="font-semibold">@Formatter.FormatSize(disk.DiskTotal)</span>
|
||||
</div>
|
||||
<div>
|
||||
INodes: <span class="font-semibold">@(iNodesPercent)%</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="mb-3 mt-5 text-xl font-semibold">
|
||||
Docker
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 lg:grid-cols-3 gap-5">
|
||||
<div class="col-span-1 card card-body">
|
||||
<div class="flex justify-between">
|
||||
<p class="text-xl font-semibold text-base-content">
|
||||
@Formatter.FormatSize(DockerStatistics.ImagesUsed) (@Formatter.FormatSize(DockerStatistics.ImagesReclaimable) unused)
|
||||
</p>
|
||||
<i class="icon-gallery-horizontal-end text-4xl text-primary"></i>
|
||||
</div>
|
||||
<div class="text-base text-base-content/90">
|
||||
Images
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1 card card-body">
|
||||
<div class="flex justify-between">
|
||||
<p class="text-xl font-semibold text-base-content">
|
||||
@Formatter.FormatSize(DockerStatistics.ContainersUsed) ( @Formatter.FormatSize(DockerStatistics.ContainersReclaimable) unused)
|
||||
</p>
|
||||
<i class="icon-container text-4xl text-primary"></i>
|
||||
</div>
|
||||
<div class="text-base text-base-content/90">
|
||||
Containers
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1 card card-body">
|
||||
<div class="flex justify-between">
|
||||
<p class="text-xl font-semibold text-base-content">
|
||||
@Formatter.FormatSize(DockerStatistics.BuildCacheUsed) (@Formatter.FormatSize(DockerStatistics.BuildCacheReclaimable) unused)
|
||||
</p>
|
||||
<i class="icon-hard-hat text-4xl text-primary"></i>
|
||||
</div>
|
||||
<div class="text-base text-base-content/90">
|
||||
Build Cache
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</LazyLoader>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public NodeResponse Node { get; set; }
|
||||
|
||||
private StatisticsResponse Statistics;
|
||||
private DockerStatisticsResponse DockerStatistics;
|
||||
|
||||
private Timer? UpdateTimer;
|
||||
|
||||
private async Task LoadAsync(LazyLoader _)
|
||||
{
|
||||
Statistics = await NodeService.GetStatisticsAsync(Node.Id);
|
||||
DockerStatistics = await NodeService.GetDockerStatisticsAsync(Node.Id);
|
||||
|
||||
UpdateTimer = new Timer(HandleUpdateAsync, null, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(3));
|
||||
}
|
||||
|
||||
private async void HandleUpdateAsync(object? _)
|
||||
{
|
||||
try
|
||||
{
|
||||
Statistics = await NodeService.GetStatisticsAsync(Node.Id);
|
||||
DockerStatistics = await NodeService.GetDockerStatisticsAsync(Node.Id);
|
||||
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogWarning("An error occured while fetching status update: {e}", e);
|
||||
await ToastService.ErrorAsync("Unable to fetch status update", e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private string GetBackgroundColorByPercent(double percent)
|
||||
{
|
||||
if (percent < 70)
|
||||
return "bg-success";
|
||||
else if (percent < 80)
|
||||
return "bg-warning";
|
||||
else
|
||||
return "bg-error";
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
UpdateTimer?.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Servers
|
||||
|
||||
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
|
||||
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public CreateServerRequest Request { get; set; }
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
@using MoonCore.Blazor.FlyonUi.Common
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Servers
|
||||
@using MoonCore.Helpers
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.NodeAllocations
|
||||
@using MoonCore.Blazor.FlyonUi.Forms
|
||||
@using MoonCore.Common
|
||||
@using MoonlightServers.Frontend.UI.Views.Admin.All
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
|
||||
<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">Allocations</label>
|
||||
<div class="mt-2">
|
||||
<InputMultipleItem TItem="NodeAllocationResponse"
|
||||
DisplayField="@(x => $"{x.IpAddress}:{x.Port}")"
|
||||
Value="Parent.Allocations"
|
||||
ItemSource="ItemSource">
|
||||
</InputMultipleItem>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public CreateServerRequest Request { get; set; }
|
||||
[Parameter] public Create Parent { get; set; }
|
||||
|
||||
private ItemSource<NodeAllocationResponse> ItemSource => ItemSourceFactory.From(LoadAsync);
|
||||
|
||||
private async Task<IEnumerable<NodeAllocationResponse>> LoadAsync(int startIndex, int count)
|
||||
{
|
||||
// Handle unselected node
|
||||
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
|
||||
if (Parent.Node == null)
|
||||
return [];
|
||||
|
||||
return await ApiClient.GetJson<CountedData<NodeAllocationResponse>>(
|
||||
$"api/admin/servers/nodes/{Parent.Node.Id}/allocations/free?startIndex={startIndex}&count={count}"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
@using MoonCore.Blazor.FlyonUi.Common
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Servers
|
||||
@using MoonCore.Helpers
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Stars
|
||||
@using Moonlight.Shared.Http.Responses.Admin.Users
|
||||
@using MoonCore.Blazor.FlyonUi.Forms
|
||||
@using MoonCore.Common
|
||||
@using MoonlightServers.Frontend.UI.Views.Admin.All
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
|
||||
<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">Owner</label>
|
||||
<div class="mt-2">
|
||||
<InputItem TItem="UserResponse"
|
||||
DisplayField="@(x => x.Username)"
|
||||
ItemSource="UsersItemSource"
|
||||
@bind-Value="Parent.Owner">
|
||||
</InputItem>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-base-content">Star</label>
|
||||
<div class="mt-2">
|
||||
<InputItem TItem="StarResponse"
|
||||
DisplayField="@(x => x.Name)"
|
||||
ItemSource="StarsItemSource"
|
||||
@bind-Value="Parent.Star">
|
||||
</InputItem>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-base-content">Node</label>
|
||||
<div class="mt-2">
|
||||
<InputItem TItem="NodeResponse"
|
||||
DisplayField="@(x => x.Name)"
|
||||
ItemSource="NodesItemSource"
|
||||
@bind-Value="Parent.Node">
|
||||
</InputItem>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="border-t border-base-content/20 pt-6 my-8">
|
||||
<div class="mb-8">
|
||||
<h2 class="text-base font-semibold leading-7 text-base-content">
|
||||
Resources
|
||||
</h2>
|
||||
<p class="mt-1 text-sm leading-6 text-base-content/60">Define the servers resource limit</p>
|
||||
</div>
|
||||
|
||||
<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">Cpu</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.Cpu" 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">Memory</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.Memory" 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">Disk</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.Disk" type="number" autocomplete="off" class="input w-full">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public CreateServerRequest Request { get; set; }
|
||||
[Parameter] public Create Parent { get; set; }
|
||||
|
||||
private ItemSource<StarResponse> StarsItemSource => ItemSourceFactory.From(LoadStarsAsync);
|
||||
private ItemSource<NodeResponse> NodesItemSource => ItemSourceFactory.From(LoadNodesAsync);
|
||||
private ItemSource<UserResponse> UsersItemSource => ItemSourceFactory.From(LoadUsersAsync);
|
||||
|
||||
private async Task<IEnumerable<StarResponse>> LoadStarsAsync(int startIndex, int count)
|
||||
{
|
||||
return await ApiClient.GetJson<CountedData<StarResponse>>(
|
||||
$"api/admin/servers/stars?startIndex={startIndex}&count={count}"
|
||||
);
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<NodeResponse>> LoadNodesAsync(int startIndex, int count)
|
||||
{
|
||||
return await ApiClient.GetJson<CountedData<NodeResponse>>(
|
||||
$"api/admin/servers/nodes?startIndex={startIndex}&count={count}"
|
||||
);
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<UserResponse>> LoadUsersAsync(int startIndex, int count)
|
||||
{
|
||||
return await ApiClient.GetJson<CountedData<UserResponse>>(
|
||||
$"api/admin/users?startIndex={startIndex}&count={count}"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonCore.Common
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Servers
|
||||
@using MoonCore.Helpers
|
||||
@using MoonlightServers.Frontend.UI.Views.Admin.All
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.ServerVariables
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.StarVariables
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
|
||||
<LazyLoader Load="LoadAsync">
|
||||
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
|
||||
@foreach (var variable in StarVariables)
|
||||
{
|
||||
// Load value of default
|
||||
var requestVar = Request.Variables.FirstOrDefault(x => x.Key == variable.Key);
|
||||
var value = requestVar != null
|
||||
? requestVar.Value
|
||||
: variable.DefaultValue;
|
||||
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-base-content">
|
||||
@variable.Name
|
||||
</label>
|
||||
<div class="mt-2">
|
||||
<input type="text"
|
||||
class="input placeholder-base-content/50 w-full"
|
||||
value="@value"
|
||||
placeholder="@variable.DefaultValue"
|
||||
@onchange="@(args => UpdateValueAsync(variable, args))"/>
|
||||
</div>
|
||||
<p class="mt-1 text-sm leading-6 text-base-content/60">
|
||||
@variable.Description
|
||||
</p>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</LazyLoader>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public CreateServerRequest Request { get; set; }
|
||||
[Parameter] public Create Parent { get; set; }
|
||||
|
||||
private StarVariableResponse[] StarVariables;
|
||||
|
||||
private async Task LoadAsync(LazyLoader _)
|
||||
{
|
||||
if (Parent.Star == null)
|
||||
{
|
||||
StarVariables = [];
|
||||
return;
|
||||
}
|
||||
|
||||
StarVariables = await CountedData.AllAsync(async (index, count) =>
|
||||
await ApiClient.GetJson<CountedData<StarVariableResponse>>(
|
||||
$"api/admin/servers/stars/{Parent.Star.Id}/variables?startIndex={index}&count={count}"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private async Task UpdateValueAsync(StarVariableResponse starVariable, ChangeEventArgs args)
|
||||
{
|
||||
var value = args.Value?.ToString() ?? "";
|
||||
|
||||
// Remove variable from request when set to its default value
|
||||
if (value == starVariable.DefaultValue && Request.Variables.Any(x => x.Key == starVariable.Key))
|
||||
Request.Variables.RemoveAll(x => x.Key == starVariable.Key);
|
||||
else
|
||||
{
|
||||
var serverVar = Request.Variables
|
||||
.FirstOrDefault(x => x.Key == starVariable.Key);
|
||||
|
||||
if (serverVar == null)
|
||||
{
|
||||
serverVar = new CreateServerVariableRequest()
|
||||
{
|
||||
Key = starVariable.Key
|
||||
};
|
||||
|
||||
Request.Variables.Add(serverVar);
|
||||
}
|
||||
|
||||
serverVar.Value = value;
|
||||
}
|
||||
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonlightServers.Shared.Enums
|
||||
@using MoonlightServers.Shared.Http.Requests.Client.Servers.Shares
|
||||
@using MoonlightServers.Shared.Http.Responses.Client.Servers
|
||||
|
||||
@inherits MoonCore.Blazor.FlyonUi.Modals.BaseModal
|
||||
|
||||
<div class="p-5">
|
||||
<div class="flex items-center gap-4">
|
||||
<div class="avatar avatar-placeholder max-sm:hidden">
|
||||
<div class="border-base-content/20 rounded-box w-13 border-1">
|
||||
<span class="icon-share-2 text-xl"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="space-y-1">
|
||||
<h3 class="text-base-content text-2xl font-semibold">Create a new share</h3>
|
||||
<p class="text-base-content/80">Grant access to this server to other users</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-5">
|
||||
<HandleForm @ref="HandleForm" Model="Request" OnValidSubmit="OnValidSubmit">
|
||||
<div class="mt-2">
|
||||
<label class="label-text">Username</label>
|
||||
<input class="input" @bind="Request.Username" type="text"/>
|
||||
</div>
|
||||
<div class="mt-5">
|
||||
<PermissionEditor Server="Server" PermissionLevels="Permissions" />
|
||||
</div>
|
||||
</HandleForm>
|
||||
</div>
|
||||
<div class="mt-5 flex justify-end">
|
||||
<button @onclick="HideAsync" type="button" class="btn btn-secondary me-2">
|
||||
Cancel
|
||||
</button>
|
||||
<WButton OnClick="SubmitAsync">
|
||||
Create
|
||||
</WButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public ServerDetailResponse Server { get; set; }
|
||||
[Parameter] public string Username { get; set; }
|
||||
[Parameter] public Func<CreateShareRequest, Task> OnSubmit { get; set; }
|
||||
|
||||
private HandleForm HandleForm;
|
||||
private CreateShareRequest Request;
|
||||
|
||||
private Dictionary<string, ServerPermissionLevel> Permissions = new();
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
Request = new()
|
||||
{
|
||||
Username = Username
|
||||
};
|
||||
}
|
||||
|
||||
private async Task SetAsync(string name, ServerPermissionLevel level)
|
||||
{
|
||||
Permissions[name] = level;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
private async Task SubmitAsync()
|
||||
=> await HandleForm.SubmitAsync();
|
||||
|
||||
private async Task OnValidSubmit()
|
||||
{
|
||||
Request.Permissions = Permissions;
|
||||
|
||||
await OnSubmit.Invoke(Request);
|
||||
await HideAsync();
|
||||
}
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
@using MoonlightServers.Frontend.Interfaces
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonlightServers.Frontend.Models
|
||||
@using MoonlightServers.Shared.Enums
|
||||
@using MoonlightServers.Shared.Http.Responses.Client.Servers
|
||||
|
||||
@inject IEnumerable<IServerPermissionProvider> PermissionProviders
|
||||
|
||||
<LazyLoader Load="LoadAsync">
|
||||
<div class="grid grid-cols-1 lg:grid-cols-2 gap-y-3">
|
||||
@foreach (var permission in AvailablePermissions)
|
||||
{
|
||||
var level = PermissionLevels.GetValueOrDefault(permission.Identifier, ServerPermissionLevel.None);
|
||||
|
||||
<div class="col-span-1 flex flex-row items-center justify-start text-base-content">
|
||||
<i class="text-lg @permission.Icon me-4"></i>
|
||||
<div class="flex flex-col">
|
||||
<span>@permission.DisplayName</span>
|
||||
<span class="text-base-content/60 text-sm">@permission.Description</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1 flex justify-start lg:justify-end mb-5 lg:mb-0">
|
||||
<div class="join drop-shadow">
|
||||
@if (level == ServerPermissionLevel.None)
|
||||
{
|
||||
<input class="join-item btn btn-soft" type="radio" name="share-@permission.Identifier"
|
||||
aria-label="None"
|
||||
checked="checked"/>
|
||||
}
|
||||
else
|
||||
{
|
||||
<input @onclick="() => SetAsync(permission.Identifier, ServerPermissionLevel.None)"
|
||||
class="join-item btn btn-soft"
|
||||
type="radio" name="share-@permission.Identifier" aria-label="None"/>
|
||||
}
|
||||
|
||||
@if (level == ServerPermissionLevel.Read)
|
||||
{
|
||||
<input class="join-item btn btn-soft" type="radio" name="share-@permission.Identifier"
|
||||
aria-label="Read"
|
||||
checked="checked"/>
|
||||
}
|
||||
else
|
||||
{
|
||||
<input @onclick="() => SetAsync(permission.Identifier, ServerPermissionLevel.Read)"
|
||||
class="join-item btn btn-soft"
|
||||
type="radio" name="share-@permission.Identifier" aria-label="Read"/>
|
||||
}
|
||||
|
||||
@if (level == ServerPermissionLevel.ReadWrite)
|
||||
{
|
||||
<input class="join-item btn btn-soft" type="radio" name="share-@permission.Identifier"
|
||||
aria-label="Read & Write"
|
||||
checked="checked"/>
|
||||
}
|
||||
else
|
||||
{
|
||||
<input @onclick="() => SetAsync(permission.Identifier, ServerPermissionLevel.ReadWrite)"
|
||||
class="join-item btn btn-soft"
|
||||
type="radio" name="share-@permission.Identifier" aria-label="Read & Write"/>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</LazyLoader>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public ServerDetailResponse Server { get; set; }
|
||||
[Parameter] public Dictionary<string, ServerPermissionLevel> PermissionLevels { get; set; }
|
||||
|
||||
private ServerPermission[] AvailablePermissions;
|
||||
|
||||
private async Task LoadAsync(LazyLoader _)
|
||||
{
|
||||
var permissions = new List<ServerPermission>();
|
||||
|
||||
foreach (var provider in PermissionProviders)
|
||||
{
|
||||
permissions.AddRange(
|
||||
await provider.GetPermissionsAsync(Server)
|
||||
);
|
||||
}
|
||||
|
||||
AvailablePermissions = permissions.ToArray();
|
||||
}
|
||||
|
||||
private async Task SetAsync(string name, ServerPermissionLevel level)
|
||||
{
|
||||
PermissionLevels[name] = level;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
@@ -1,189 +0,0 @@
|
||||
@using Microsoft.Extensions.Logging
|
||||
@using MoonCore.Helpers
|
||||
@using MoonlightServers.Frontend.Services
|
||||
@using MoonlightServers.Shared.Enums
|
||||
@using MoonlightServers.Shared.Http.Responses.Client.Servers
|
||||
|
||||
@inject ServerService ServerService
|
||||
@inject ILogger<ServerCard> Logger
|
||||
|
||||
@{
|
||||
var gradient = "from-base-100/20";
|
||||
var border = "border-base-content/80";
|
||||
|
||||
if (IsLoaded && !IsFailed)
|
||||
{
|
||||
gradient = Status.State switch
|
||||
{
|
||||
ServerState.Installing => "from-primary/20",
|
||||
ServerState.Offline => "from-error/20",
|
||||
ServerState.Starting => "from-warning/20",
|
||||
ServerState.Stopping => "from-warning/20",
|
||||
ServerState.Online => "from-success/20",
|
||||
_ => "from-base-100"
|
||||
};
|
||||
|
||||
border = Status.State switch
|
||||
{
|
||||
ServerState.Installing => "border-primary",
|
||||
ServerState.Offline => "border-error",
|
||||
ServerState.Starting => "border-warning",
|
||||
ServerState.Stopping => "border-warning",
|
||||
ServerState.Online => "border-success",
|
||||
_ => "border-base-content/80"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
<a href="/servers/@Server.Id"
|
||||
class="w-full bg-gradient-to-r @gradient to-base-100/75 to-25% px-5 py-3.5 rounded-xl border-l-8 @border">
|
||||
<div class="grid grid-cols-6">
|
||||
<div class="flex items-center col-span-6 sm:col-span-2 2xl:col-span-1">
|
||||
<div class="bg-base-content/10 bg-opacity-45 py-1 px-2 rounded-lg flex items-center">
|
||||
<i class="icon-server me-3 align-middle"></i>
|
||||
<div class="text-lg align-middle">
|
||||
@Server.Name
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hidden sm:flex items-center justify-end gap-x-3 sm:col-span-4 2xl:col-span-3">
|
||||
@if (
|
||||
IsLoaded &&
|
||||
!IsFailed &&
|
||||
Status.State is ServerState.Starting or ServerState.Stopping or ServerState.Online
|
||||
)
|
||||
{
|
||||
<div class="bg-base-200/75 py-1 px-2 rounded-lg flex flex-row">
|
||||
<div>
|
||||
<i class="icon-cpu"></i>
|
||||
</div>
|
||||
|
||||
<div class="ms-3">@(Stats.CpuUsage)%</div>
|
||||
</div>
|
||||
|
||||
<div class="bg-base-200/75 py-1 px-2 rounded-lg flex flex-row">
|
||||
<div>
|
||||
<i class="icon-memory-stick"></i>
|
||||
</div>
|
||||
|
||||
<div class="ms-3">@(Formatter.FormatSize(Stats.MemoryUsage)) / @(Formatter.FormatSize(ByteConverter.FromMegaBytes(Server.Memory).Bytes))</div>
|
||||
</div>
|
||||
|
||||
<div class="bg-base-200/75 py-1 px-2 rounded-lg flex flex-row">
|
||||
<div>
|
||||
<i class="icon-hard-drive"></i>
|
||||
</div>
|
||||
|
||||
<div class="ms-3">53 GB / 100GB</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!IsLoaded)
|
||||
{
|
||||
<div class="bg-base-200/75 py-1 px-2 rounded-lg flex flex-row text-gray-700">
|
||||
<div>
|
||||
<i class="icon-loader"></i>
|
||||
</div>
|
||||
|
||||
<div class="ms-3">Loading</div>
|
||||
</div>
|
||||
}
|
||||
else if (IsFailed)
|
||||
{
|
||||
<div class="bg-base-200/75 py-1 px-2 rounded-lg flex flex-row text-error">
|
||||
<div>
|
||||
<i class="icon-cable"></i>
|
||||
</div>
|
||||
|
||||
<div class="ms-3">Unreachable</div>
|
||||
</div>
|
||||
}
|
||||
else if (IsLoaded && !IsFailed && Status.State is ServerState.Offline)
|
||||
{
|
||||
<div class="bg-base-200/75 py-1 px-2 rounded-lg flex flex-row text-error">
|
||||
<div>
|
||||
<i class="icon-power-off"></i>
|
||||
</div>
|
||||
|
||||
<div class="ms-3">Offline</div>
|
||||
</div>
|
||||
}
|
||||
else if (IsLoaded && !IsFailed && Status.State is ServerState.Installing)
|
||||
{
|
||||
<div class="bg-base-200/75 py-1 px-2 rounded-lg flex flex-row text-primary">
|
||||
<div>
|
||||
<i class="icon-hammer"></i>
|
||||
</div>
|
||||
|
||||
<div class="ms-3">Installing</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="hidden 2xl:flex items-center justify-end gap-x-3 2xl:col-span-2">
|
||||
|
||||
@if (Server.Share != null)
|
||||
{
|
||||
<div class="bg-base-200/75 py-1 px-2 rounded-lg flex flex-row col-span-2">
|
||||
<div>
|
||||
<i class="icon-share-2"></i>
|
||||
</div>
|
||||
|
||||
<div class="ms-3">Shared by <span class="text-primary">@Server.Share.SharedBy</span></div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="bg-base-200/75 py-1 px-2 rounded-lg flex flex-row">
|
||||
<div>
|
||||
<i class="icon-sparkles"></i>
|
||||
</div>
|
||||
|
||||
<div class="ms-3">@Server.StarName</div>
|
||||
</div>
|
||||
|
||||
<div class="bg-base-200/75 py-1 px-2 rounded-lg flex flex-row">
|
||||
<div>
|
||||
<i class="icon-database"></i>
|
||||
</div>
|
||||
|
||||
<div class="ms-3">@Server.NodeName</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public ServerDetailResponse Server { get; set; }
|
||||
|
||||
private ServerStatusResponse Status;
|
||||
private ServerStatsResponse Stats;
|
||||
|
||||
private bool IsFailed = false;
|
||||
private bool IsLoaded = false;
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (!firstRender)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
Status = await ServerService.GetStatusAsync(Server.Id);
|
||||
Stats = await ServerService.GetStatsAsync(Server.Id);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
IsFailed = true;
|
||||
Logger.LogWarning("Unable to fetch status from server {id}: {e}", Server.Id, e);
|
||||
}
|
||||
|
||||
IsLoaded = true;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
@using Microsoft.AspNetCore.SignalR.Client
|
||||
@using MoonlightServers.Frontend.UI.Views.Client
|
||||
@using MoonlightServers.Shared.Enums
|
||||
@using MoonlightServers.Shared.Http.Responses.Client.Servers
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public ServerDetailResponse Server { get; set; }
|
||||
[Parameter] public ServerState State { get; set; }
|
||||
[Parameter] public string InitialConsoleMessage { get; set; }
|
||||
[Parameter] public HubConnection? HubConnection { get; set; }
|
||||
[Parameter] public Manage Parent { get; set; }
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
@using Microsoft.AspNetCore.SignalR.Client
|
||||
@using MoonlightServers.Frontend.Services
|
||||
|
||||
@inherits BaseServerTab
|
||||
|
||||
@inject ServerService ServerService
|
||||
|
||||
<div class="h-44">
|
||||
<XtermConsole @ref="XtermConsole"
|
||||
OnAfterInitialized="OnAfterConsoleInitialized"
|
||||
CommandHistory="Parent.CommandHistory"
|
||||
OnCommand="OnCommand"/>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
private XtermConsole? XtermConsole;
|
||||
|
||||
protected override Task OnInitializedAsync()
|
||||
{
|
||||
// We are already connected to the hub at this point
|
||||
|
||||
HubConnection.On<string>("ConsoleOutput", async content =>
|
||||
{
|
||||
if (XtermConsole != null)
|
||||
await XtermConsole.WriteAsync(content);
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task OnAfterConsoleInitialized()
|
||||
{
|
||||
await XtermConsole!.WriteAsync(InitialConsoleMessage);
|
||||
}
|
||||
|
||||
private async Task OnCommand(string command)
|
||||
=> await ServerService.RunCommandAsync(Server.Id, command + "\n");
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
@using MoonlightServers.Frontend.Services
|
||||
@using MoonCore.Blazor.FlyonUi.Files.Manager
|
||||
@using MoonlightServers.Frontend.Helpers
|
||||
|
||||
@inherits BaseServerTab
|
||||
|
||||
@inject ServerFileSystemService FileSystemService
|
||||
|
||||
<FileManager FsAccess="FsAccess" />
|
||||
|
||||
@code
|
||||
{
|
||||
private IFsAccess FsAccess;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
FsAccess = new ServerFsAccess(
|
||||
Server.Id,
|
||||
FileSystemService
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
@using MoonCore.Blazor.FlyonUi.Alerts
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonlightServers.Frontend.Services
|
||||
@using MoonlightServers.Shared.Enums
|
||||
|
||||
@inherits BaseServerTab
|
||||
|
||||
@inject ServerService ServerService
|
||||
@inject AlertService AlertService
|
||||
|
||||
<div class="grid grid-cols-1 md:col-span-2 lg:grid-cols-3">
|
||||
<div class="col-span-1 card card-body">
|
||||
@if (State != ServerState.Offline)
|
||||
{
|
||||
<button class="btn btn-primary" disabled="disabled">
|
||||
<i class="align-middle icon-hammer me-1"></i>
|
||||
<span class="align-middle">Reinstall</span>
|
||||
</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<WButton CssClasses="btn btn-primary" OnClick="ReinstallAsync">
|
||||
<i class="align-middle icon-hammer"></i>
|
||||
<span class="align-middle">Reinstall</span>
|
||||
</WButton>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
private async Task ReinstallAsync(WButton _)
|
||||
{
|
||||
await AlertService.ConfirmDangerAsync(
|
||||
"Server installation",
|
||||
"Do you really want to reinstall the server? This can potentially lead to loss of data",
|
||||
() => ServerService.InstallAsync(Server.Id)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
@using MoonCore.Blazor.FlyonUi.Alerts
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonCore.Blazor.FlyonUi.Modals
|
||||
@using MoonCore.Blazor.FlyonUi.Toasts
|
||||
@using MoonCore.Common
|
||||
@using MoonlightServers.Frontend.Services
|
||||
@using MoonlightServers.Shared.Http.Requests.Client.Servers.Shares
|
||||
@using MoonlightServers.Shared.Http.Responses.Client.Servers.Shares
|
||||
|
||||
@inherits BaseServerTab
|
||||
|
||||
@inject ServerShareService ShareService
|
||||
@inject ModalService ModalService
|
||||
@inject ToastService ToastService
|
||||
@inject AlertService AlertService
|
||||
|
||||
<div class="flex flex-row mb-5">
|
||||
<input @bind="UsernameInput" class="input grow placeholder-base-content/50 me-1.5" autocomplete="none" placeholder="Enter a username"/>
|
||||
<button @onclick="OpenCreateModalAsync" class="btn btn-primary">
|
||||
<i class="icon-send me-1"></i>
|
||||
<span>Invite</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<LazyLoader @ref="LazyLoader" Load="LoadAsync">
|
||||
@if (Shares.Length == 0)
|
||||
{
|
||||
<IconAlert Title="No shares found" Color="text-primary" Icon="icon-search">
|
||||
Enter a username and press invite to share this server to another user
|
||||
</IconAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="grid grid-col-1 gap-y-3">
|
||||
@foreach (var share in Shares)
|
||||
{
|
||||
<div class="col-span-1 card card-body py-3 flex flex-row items-center justify-between">
|
||||
<div class="flex justify-start font-semibold">
|
||||
<i class="icon-user-round me-2"></i>
|
||||
<span>@share.Username</span>
|
||||
</div>
|
||||
<div class="flex justify-end">
|
||||
<WButton OnClick="_ => OpenUpdateModalAsync(share)" CssClasses="btn btn-primary me-1.5">
|
||||
<i class="icon-settings-2 me-1"></i>
|
||||
<span>Edit</span>
|
||||
</WButton>
|
||||
<WButton OnClick="_ => DeleteAsync(share)" CssClasses="btn btn-error">
|
||||
<i class="icon-trash-2 me-1"></i>
|
||||
<span>Delete</span>
|
||||
</WButton>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</LazyLoader>
|
||||
|
||||
@code
|
||||
{
|
||||
private ServerShareResponse[] Shares;
|
||||
|
||||
private string UsernameInput = "";
|
||||
|
||||
private LazyLoader LazyLoader;
|
||||
|
||||
private async Task LoadAsync(LazyLoader _)
|
||||
{
|
||||
Shares = await CountedData.AllAsync<ServerShareResponse>(async (startIndex, count)
|
||||
=> await ShareService.GetAsync(Server.Id, startIndex, count)
|
||||
);
|
||||
}
|
||||
|
||||
private async Task OpenCreateModalAsync()
|
||||
{
|
||||
await ModalService.LaunchAsync<CreateShareModal>(parameters =>
|
||||
{
|
||||
parameters["Username"] = UsernameInput;
|
||||
parameters["Server"] = Server;
|
||||
parameters["OnSubmit"] = SubmitCreateAsync;
|
||||
}, size: "max-w-2xl");
|
||||
}
|
||||
|
||||
private async Task SubmitCreateAsync(CreateShareRequest request)
|
||||
{
|
||||
await ShareService.CreateAsync(Server.Id, request);
|
||||
|
||||
await ToastService.SuccessAsync("Share successfully created");
|
||||
await LazyLoader.ReloadAsync();
|
||||
}
|
||||
|
||||
private async Task OpenUpdateModalAsync(ServerShareResponse share)
|
||||
{
|
||||
await ModalService.LaunchAsync<UpdateShareModal>(parameters =>
|
||||
{
|
||||
parameters["Share"] = share;
|
||||
parameters["Server"] = Server;
|
||||
parameters["OnSubmit"] = (UpdateShareRequest request) => SubmitUpdateAsync(share.Id, request);
|
||||
}, size: "max-w-2xl");
|
||||
}
|
||||
|
||||
private async Task SubmitUpdateAsync(int shareId, UpdateShareRequest request)
|
||||
{
|
||||
await ShareService.UpdateAsync(Server.Id, shareId, request);
|
||||
|
||||
await ToastService.SuccessAsync("Share successfully updated");
|
||||
await LazyLoader.ReloadAsync();
|
||||
}
|
||||
|
||||
private async Task DeleteAsync(ServerShareResponse share)
|
||||
{
|
||||
await AlertService.ConfirmDangerAsync(
|
||||
"Share deletion",
|
||||
$"Do you really want to delete the share for the user '{share.Username}'? This cannot be undone",
|
||||
async () =>
|
||||
{
|
||||
await ShareService.DeleteAsync(Server.Id, share.Id);
|
||||
|
||||
await ToastService.SuccessAsync("Successfully deleted share");
|
||||
await LazyLoader.ReloadAsync();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonCore.Blazor.FlyonUi.Toasts
|
||||
@using MoonCore.Common
|
||||
@using MoonlightServers.Frontend.Services
|
||||
@using MoonlightServers.Shared.Http.Responses.Client.Servers.Variables
|
||||
|
||||
@inherits BaseServerTab
|
||||
|
||||
@inject ServerService ServerService
|
||||
@inject ToastService ToastService
|
||||
|
||||
<LazyLoader @ref="LazyLoader" Load="LoadAsync">
|
||||
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
|
||||
@foreach (var variable in Variables)
|
||||
{
|
||||
<div class="sm:col-span-2 card card-sm">
|
||||
<div class="card-header pb-1">
|
||||
<h5 class="text-base font-semibold">
|
||||
@variable.Name
|
||||
</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="mb-2.5 text-sm leading-6 text-base-content/60">
|
||||
@variable.Description
|
||||
</p>
|
||||
<div class="mt-auto">
|
||||
<input @onchange="e => UpdateVariableAsync(variable, e)"
|
||||
value="@variable.Value"
|
||||
type="text"
|
||||
class="input w-full">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</LazyLoader>
|
||||
|
||||
@code
|
||||
{
|
||||
private ServerVariableDetailResponse[] Variables;
|
||||
private LazyLoader LazyLoader;
|
||||
|
||||
private async Task LoadAsync(LazyLoader _)
|
||||
{
|
||||
Variables = await CountedData.AllAsync<ServerVariableDetailResponse>(async (startIndex, count)
|
||||
=> await ServerService.GetVariablesAsync(Server.Id, startIndex, count)
|
||||
);
|
||||
}
|
||||
|
||||
private async Task UpdateVariableAsync(ServerVariableDetailResponse variable, ChangeEventArgs args)
|
||||
{
|
||||
var value = args.Value?.ToString() ?? "";
|
||||
|
||||
await ServerService.UpdateVariableAsync(Server.Id, new()
|
||||
{
|
||||
Key = variable.Key,
|
||||
Value = value
|
||||
});
|
||||
|
||||
// Fetch the current data to make sure the user sees the latest data
|
||||
await LazyLoader.ReloadAsync();
|
||||
|
||||
await ToastService.SuccessAsync("Successfully updated variable");
|
||||
}
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
@using MoonlightServers.Shared.Http.Responses.Client.Servers
|
||||
@{
|
||||
var gradient = Status switch
|
||||
{
|
||||
4 => "from-primary/20",
|
||||
3 => "from-danger/20",
|
||||
2 => "from-warning/20",
|
||||
1 => "from-success/20",
|
||||
_ => "from-gray-600/20"
|
||||
};
|
||||
|
||||
var border = Status switch
|
||||
{
|
||||
4 => "border-primary",
|
||||
3 => "border-danger",
|
||||
2 => "border-warning",
|
||||
1 => "border-success",
|
||||
_ => "border-gray-600"
|
||||
};
|
||||
}
|
||||
|
||||
<a href="/servers/@Server.Id" class="w-full bg-gradient-to-r @gradient to-gray-750/65 to-25% px-5 py-3.5 rounded-xl border-l-8 @border">
|
||||
<div class="grid grid-cols-6">
|
||||
<div class="flex items-center col-span-6 sm:col-span-2 2xl:col-span-1">
|
||||
<div class="bg-gray-900 bg-opacity-45 py-1 px-2 rounded-lg flex items-center">
|
||||
<i class="icon-server me-3 align-middle"></i>
|
||||
<div class="text-lg align-middle">
|
||||
@Server.Name
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hidden sm:flex items-center justify-end gap-x-3 sm:col-span-4 2xl:col-span-3">
|
||||
@if (Status >= 1 && Status <= 2)
|
||||
{
|
||||
<div class="bg-gray-900 bg-opacity-45 py-1 px-2 rounded-lg flex flex-row">
|
||||
<div>
|
||||
<i class="icon-cpu"></i>
|
||||
</div>
|
||||
|
||||
<div class="ms-3">56,8%</div>
|
||||
</div>
|
||||
|
||||
<div class="bg-gray-900 bg-opacity-45 py-1 px-2 rounded-lg flex flex-row">
|
||||
<div>
|
||||
<i class="icon-memory-stick"></i>
|
||||
</div>
|
||||
|
||||
<div class="ms-3">4,2 GB / 8 GB</div>
|
||||
</div>
|
||||
|
||||
<div class="bg-gray-900 bg-opacity-45 py-1 px-2 rounded-lg flex flex-row">
|
||||
<div>
|
||||
<i class="icon-hard-drive"></i>
|
||||
</div>
|
||||
|
||||
<div class="ms-3">53 GB / 100GB</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Status == 0)
|
||||
{
|
||||
<div class="bg-gray-900 bg-opacity-45 py-1 px-2 rounded-lg flex flex-row text-gray-700">
|
||||
<div>
|
||||
<i class="icon-loader"></i>
|
||||
</div>
|
||||
|
||||
<div class="ms-3">Loading</div>
|
||||
</div>
|
||||
}
|
||||
else if (Status == 3)
|
||||
{
|
||||
<div class="bg-gray-900 bg-opacity-45 py-1 px-2 rounded-lg flex flex-row text-error">
|
||||
<div>
|
||||
<i class="icon-power-off"></i>
|
||||
</div>
|
||||
|
||||
<div class="ms-3">Offline</div>
|
||||
</div>
|
||||
}
|
||||
else if (Status == 4)
|
||||
{
|
||||
<div class="bg-gray-900 bg-opacity-45 py-1 px-2 rounded-lg flex flex-row text-primary">
|
||||
<div>
|
||||
<i class="icon-hammer"></i>
|
||||
</div>
|
||||
|
||||
<div class="ms-3">Installing</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="hidden 2xl:flex items-center justify-end gap-x-3 2xl:col-span-2">
|
||||
|
||||
<div class="bg-gray-900 bg-opacity-45 py-1 px-2 rounded-lg flex flex-row">
|
||||
<div>
|
||||
<i class="icon-sparkles"></i>
|
||||
</div>
|
||||
|
||||
<div class="ms-3">@Server.StarName</div>
|
||||
</div>
|
||||
|
||||
<div class="bg-gray-900 bg-opacity-45 py-1 px-2 rounded-lg flex flex-row">
|
||||
<div>
|
||||
<i class="icon-database"></i>
|
||||
</div>
|
||||
|
||||
<div class="ms-3">@Server.NodeName</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</a>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter]
|
||||
public ServerDetailResponse Server { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public int Status { get; set; }
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Servers
|
||||
|
||||
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public UpdateServerRequest Request { get; set; }
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
@using MoonCore.Blazor.FlyonUi.Common
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Servers
|
||||
@using MoonCore.Helpers
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.NodeAllocations
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Servers
|
||||
@using MoonCore.Blazor.FlyonUi.Forms
|
||||
@using MoonCore.Common
|
||||
@using MoonlightServers.Frontend.UI.Views.Admin.All
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
|
||||
<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">Allocations</label>
|
||||
<div class="mt-2">
|
||||
<InputMultipleItem TItem="NodeAllocationResponse"
|
||||
Value="Parent.Allocations"
|
||||
DisplayField="@(x => $"{x.IpAddress}:{x.Port}")"
|
||||
ItemSource="ItemSource">
|
||||
</InputMultipleItem>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public UpdateServerRequest Request { get; set; }
|
||||
[Parameter] public ServerResponse Server { get; set; }
|
||||
[Parameter] public Update Parent { get; set; }
|
||||
|
||||
private ItemSource<NodeAllocationResponse> ItemSource => ItemSourceFactory.From(LoadAsync);
|
||||
|
||||
private async Task<IEnumerable<NodeAllocationResponse>> LoadAsync(int startIndex, int count)
|
||||
{
|
||||
return await ApiClient.GetJson<CountedData<NodeAllocationResponse>>(
|
||||
$"api/admin/servers/nodes/{Server.NodeId}/allocations/free?startIndex={startIndex}&count={count}&serverId={Server.Id}"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
@using MoonCore.Blazor.FlyonUi.Common
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Servers
|
||||
@using MoonCore.Helpers
|
||||
@using Moonlight.Shared.Http.Responses.Admin.Users
|
||||
@using MoonCore.Blazor.FlyonUi.Forms
|
||||
@using MoonCore.Common
|
||||
@using MoonlightServers.Frontend.UI.Views.Admin.All
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
|
||||
<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">Owner</label>
|
||||
<div class="mt-2">
|
||||
<InputItem TItem="UserResponse"
|
||||
DisplayField="@(x => x.Username)"
|
||||
@bind-Value="Parent.Owner"
|
||||
ItemSource="UserItemSource">
|
||||
</InputItem>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="border-t border-base-content/10 pt-6 my-8">
|
||||
<div class="mb-8"><h2 class="text-base font-semibold leading-7 text-base-content">
|
||||
Resources
|
||||
</h2>
|
||||
<p class="mt-1 text-sm leading-6 text-base-content/60">Define the servers resource limit</p></div>
|
||||
|
||||
<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">Cpu</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.Cpu" 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">Memory</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.Memory" 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">Disk</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.Disk" type="number" autocomplete="off" class="input w-full">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public UpdateServerRequest Request { get; set; }
|
||||
[Parameter] public Update Parent { get; set; }
|
||||
|
||||
private ItemSource<UserResponse> UserItemSource => ItemSourceFactory.From(LoadAsync);
|
||||
|
||||
private async Task<IEnumerable<UserResponse>> LoadAsync(int startIndex, int count)
|
||||
{
|
||||
return await ApiClient.GetJson<CountedData<UserResponse>>(
|
||||
$"api/admin/users?startIndex={startIndex}&count={count}"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonCore.Common
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Servers
|
||||
@using MoonCore.Helpers
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.ServerVariables
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Servers
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.ServerVariables
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.StarVariables
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
|
||||
<LazyLoader Load="LoadAsync">
|
||||
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
|
||||
@foreach (var variable in ServerVariables)
|
||||
{
|
||||
var reqVariable = Request.Variables.FirstOrDefault(x => x.Key == variable.Key);
|
||||
var starVariable = StarVariables.FirstOrDefault(x => x.Key == variable.Key);
|
||||
|
||||
// Ignore all variables which aren't defined in the star
|
||||
if (starVariable == null)
|
||||
continue;
|
||||
|
||||
var value = reqVariable != null
|
||||
? reqVariable.Value
|
||||
: variable.Value;
|
||||
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-base-content">
|
||||
@starVariable.Name
|
||||
</label>
|
||||
<div class="mt-2">
|
||||
<input type="text" class="input w-full" value="@value"
|
||||
@onchange="@(args => UpdateValueAsync(variable, args))"/>
|
||||
</div>
|
||||
<p class="mt-1 text-sm leading-6 text-base-content/60">
|
||||
@starVariable.Description
|
||||
</p>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</LazyLoader>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public UpdateServerRequest Request { get; set; }
|
||||
[Parameter] public ServerResponse Server { get; set; }
|
||||
|
||||
private StarVariableResponse[] StarVariables;
|
||||
private ServerVariableResponse[] ServerVariables;
|
||||
|
||||
private async Task LoadAsync(LazyLoader _)
|
||||
{
|
||||
StarVariables = await CountedData.AllAsync<StarVariableResponse>(async (startIndex, count) =>
|
||||
await ApiClient.GetJson<CountedData<StarVariableResponse>>(
|
||||
$"api/admin/servers/stars/{Server.StarId}/variables?startIndex={startIndex}&count={count}"
|
||||
)
|
||||
);
|
||||
|
||||
ServerVariables = await CountedData.AllAsync<ServerVariableResponse>(async (startIndex, count) =>
|
||||
await ApiClient.GetJson<CountedData<ServerVariableResponse>>(
|
||||
$"api/admin/servers/{Server.Id}/variables?startIndex={startIndex}&count={count}"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private async Task UpdateValueAsync(ServerVariableResponse serverVariable, ChangeEventArgs args)
|
||||
{
|
||||
var value = args.Value?.ToString() ?? "";
|
||||
|
||||
// Remove variable from request when set to its default value
|
||||
if (value == serverVariable.Value && Request.Variables.Any(x => x.Key == serverVariable.Key))
|
||||
Request.Variables.RemoveAll(x => x.Key == serverVariable.Key);
|
||||
else
|
||||
{
|
||||
var serverVar = Request.Variables
|
||||
.FirstOrDefault(x => x.Key == serverVariable.Key);
|
||||
|
||||
if (serverVar == null)
|
||||
{
|
||||
serverVar = new UpdateServerVariableRequest()
|
||||
{
|
||||
Key = serverVariable.Key
|
||||
};
|
||||
|
||||
Request.Variables.Add(serverVar);
|
||||
}
|
||||
|
||||
serverVar.Value = value;
|
||||
}
|
||||
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonlightServers.Shared.Enums
|
||||
@using MoonlightServers.Shared.Http.Requests.Client.Servers.Shares
|
||||
@using MoonlightServers.Shared.Http.Responses.Client.Servers
|
||||
@using MoonlightServers.Shared.Http.Responses.Client.Servers.Shares
|
||||
|
||||
@inherits MoonCore.Blazor.FlyonUi.Modals.BaseModal
|
||||
|
||||
<div class="p-5">
|
||||
<div class="flex items-center gap-4">
|
||||
<div class="avatar avatar-placeholder max-sm:hidden">
|
||||
<div class="border-base-content/20 rounded-box w-13 border-1">
|
||||
<span class="icon-share-2 text-xl"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="space-y-1">
|
||||
<h3 class="text-base-content text-2xl font-semibold">Update share for @Share.Username</h3>
|
||||
<p class="text-base-content/80">Grant access to this server to other users</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-5">
|
||||
<HandleForm @ref="HandleForm" Model="Request" OnValidSubmit="OnValidSubmit">
|
||||
<PermissionEditor Server="Server" PermissionLevels="Permissions" />
|
||||
</HandleForm>
|
||||
</div>
|
||||
<div class="mt-5 flex justify-end">
|
||||
<button @onclick="HideAsync" type="button" class="btn btn-secondary me-2">
|
||||
Cancel
|
||||
</button>
|
||||
<WButton OnClick="SubmitAsync">
|
||||
Create
|
||||
</WButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public ServerDetailResponse Server { get; set; }
|
||||
[Parameter] public ServerShareResponse Share { get; set; }
|
||||
[Parameter] public Func<UpdateShareRequest, Task> OnSubmit { get; set; }
|
||||
|
||||
private HandleForm HandleForm;
|
||||
private UpdateShareRequest Request;
|
||||
|
||||
private Dictionary<string, ServerPermissionLevel> Permissions = new();
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
Request = new();
|
||||
|
||||
Permissions = Share.Permissions;
|
||||
}
|
||||
|
||||
private async Task SetAsync(string name, ServerPermissionLevel level)
|
||||
{
|
||||
Permissions[name] = level;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
private async Task SubmitAsync()
|
||||
=> await HandleForm.SubmitAsync();
|
||||
|
||||
private async Task OnValidSubmit()
|
||||
{
|
||||
Request.Permissions = Permissions;
|
||||
|
||||
await OnSubmit.Invoke(Request);
|
||||
await HideAsync();
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonlightServers.Frontend.UI.Components.Forms
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.StarDockerImages
|
||||
|
||||
@inherits MoonCore.Blazor.FlyonUi.Modals.BaseModal
|
||||
|
||||
<div class="p-5">
|
||||
<div class="flex items-center gap-4">
|
||||
<div class="avatar avatar-placeholder max-sm:hidden">
|
||||
<div class="border-base-content/20 rounded-box w-13 border-1">
|
||||
<span class="icon-container text-xl"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="space-y-1">
|
||||
<h3 class="text-base-content text-2xl font-semibold">Add a new docker image</h3>
|
||||
<p class="text-base-content/80">Add a new docker image to the star</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-5">
|
||||
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
|
||||
<div class="mt-2">
|
||||
<label class="label-text">Display Name</label>
|
||||
<input class="input" @bind="Form.DisplayName" type="text"/>
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
<label class="label-text">Identifier</label>
|
||||
<input class="input" @bind="Form.Identifier" type="text"/>
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
<label class="label-text">Automatic pulling</label>
|
||||
<Switch @bind-Value="Form.AutoPulling"/>
|
||||
</div>
|
||||
</HandleForm>
|
||||
</div>
|
||||
<div class="mt-5 flex justify-end">
|
||||
<button @onclick="HideAsync" type="button" class="btn btn-secondary me-2">
|
||||
Cancel
|
||||
</button>
|
||||
<WButton OnClick="SubmitAsync">
|
||||
Create
|
||||
</WButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public Func<CreateStarDockerImageRequest, Task> OnSubmit { get; set; }
|
||||
|
||||
private CreateStarDockerImageRequest Form;
|
||||
private HandleForm HandleForm;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
// Set default values
|
||||
Form = new()
|
||||
{
|
||||
AutoPulling = true
|
||||
};
|
||||
}
|
||||
|
||||
private async Task OnValidSubmit()
|
||||
{
|
||||
await OnSubmit.Invoke(Form);
|
||||
await HideAsync();
|
||||
}
|
||||
|
||||
private Task SubmitAsync() => HandleForm.SubmitAsync();
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonlightServers.Shared.Enums
|
||||
@using MoonlightServers.Shared.Models
|
||||
|
||||
@inherits MoonCore.Blazor.FlyonUi.Modals.BaseModal
|
||||
|
||||
<div class="p-5">
|
||||
<div class="flex items-center gap-4">
|
||||
<div class="avatar avatar-placeholder max-sm:hidden">
|
||||
<div class="border-base-content/20 rounded-box w-13 border-1">
|
||||
<span class="icon-braces text-xl"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="space-y-1">
|
||||
<h3 class="text-base-content text-2xl font-semibold">Add a parse configuration</h3>
|
||||
<p class="text-base-content/80">Add a new parse configuration to the star</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-5">
|
||||
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
|
||||
<div class="mt-2">
|
||||
<label class="label-text">File</label>
|
||||
<input class="input" @bind="Form.File" type="text"/>
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
<label class="label-text">Parser</label>
|
||||
<select @bind="Form.Parser" class="select w-full">
|
||||
@foreach (var val in Enum.GetValues<FileParsers>())
|
||||
{
|
||||
<option value="@val">@val</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
<button type="button" @onclick="AddEntryAsync" class="btn btn-primary w-full">Add entry</button>
|
||||
</div>
|
||||
|
||||
@foreach (var entry in Form.Entries)
|
||||
{
|
||||
<div class="flex flex-row mt-2">
|
||||
<input @bind="entry.Key" placeholder="Key" class="input placeholder-base-content/50 grow rounded-r-none"/>
|
||||
<input @bind="entry.Value" placeholder="Value" class="input placeholder-base-content/50 grow rounded-none"/>
|
||||
<button type="button" @onclick="() => RemoveEntryAsync(entry)" class="btn btn-error grow-0 rounded-l-none">
|
||||
<i class="icon-x"></i>
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
</HandleForm>
|
||||
</div>
|
||||
<div class="mt-5 flex justify-end">
|
||||
<button @onclick="HideAsync" type="button" class="btn btn-secondary me-2">
|
||||
Cancel
|
||||
</button>
|
||||
<WButton OnClick="SubmitAsync">
|
||||
Create
|
||||
</WButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public Func<ParseConfiguration, Task> OnSubmit { get; set; }
|
||||
|
||||
private ParseConfiguration Form = new();
|
||||
private HandleForm HandleForm;
|
||||
|
||||
private async Task OnValidSubmit()
|
||||
{
|
||||
await OnSubmit.Invoke(Form);
|
||||
await HideAsync();
|
||||
}
|
||||
|
||||
private Task SubmitAsync() => HandleForm.SubmitAsync();
|
||||
|
||||
private async Task AddEntryAsync()
|
||||
{
|
||||
Form.Entries.Add(new());
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
private async Task RemoveEntryAsync(ParseConfiguration.ParseConfigurationEntry entry)
|
||||
{
|
||||
Form.Entries.Remove(entry);
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonlightServers.Shared.Enums
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.StarVariables
|
||||
@using MoonlightServers.Frontend.UI.Components.Forms
|
||||
|
||||
@inherits MoonCore.Blazor.FlyonUi.Modals.BaseModal
|
||||
|
||||
<div class="p-5">
|
||||
<div class="flex items-center gap-4">
|
||||
<div class="avatar avatar-placeholder max-sm:hidden">
|
||||
<div class="border-base-content/20 rounded-box w-13 border-1">
|
||||
<span class="icon-variable text-xl"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="space-y-1">
|
||||
<h3 class="text-base-content text-2xl font-semibold">Add a new variable</h3>
|
||||
<p class="text-base-content/80">Add a new variable to the star</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-5">
|
||||
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
|
||||
<div class="grid grid-cols-2 gap-2">
|
||||
<div class="col-span-1">
|
||||
<label class="label-text">Name</label>
|
||||
<input @bind="Form.Name" type="text" class="input w-full"/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="label-text">Description</label>
|
||||
<input @bind="Form.Description" type="text" class="input w-full"/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="label-text">Key</label>
|
||||
<input @bind="Form.Key" type="text" class="input w-full"/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="label-text">Default Value</label>
|
||||
<input @bind="Form.DefaultValue" type="text" class="input w-full"/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="label-text">Allow Viewing</label>
|
||||
<Switch @bind-Value="Form.AllowViewing"/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="label-text">Allow Editing</label>
|
||||
<Switch @bind-Value="Form.AllowEditing"/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="label-text">Type</label>
|
||||
<select @bind="Form.Type" class="select w-full">
|
||||
@foreach (var val in Enum.GetValues<StarVariableType>())
|
||||
{
|
||||
<option value="@val">@val</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="label-text">Filter</label>
|
||||
<input @bind="Form.Filter" type="text" class="input w-full"/>
|
||||
</div>
|
||||
</div>
|
||||
</HandleForm>
|
||||
</div>
|
||||
<div class="mt-5 flex justify-end">
|
||||
<button @onclick="HideAsync" type="button" class="btn btn-secondary me-2">
|
||||
Cancel
|
||||
</button>
|
||||
<WButton OnClick="SubmitAsync">
|
||||
Create
|
||||
</WButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public Func<CreateStarVariableRequest, Task> OnSubmit { get; set; }
|
||||
|
||||
private CreateStarVariableRequest Form = new();
|
||||
private HandleForm HandleForm;
|
||||
|
||||
private async Task OnValidSubmit()
|
||||
{
|
||||
await OnSubmit.Invoke(Form);
|
||||
await HideAsync();
|
||||
}
|
||||
|
||||
private Task SubmitAsync() => HandleForm.SubmitAsync();
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonlightServers.Frontend.UI.Components.Forms
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.StarDockerImages
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.StarDockerImages
|
||||
|
||||
@inherits MoonCore.Blazor.FlyonUi.Modals.BaseModal
|
||||
|
||||
<div class="p-5">
|
||||
<div class="flex items-center gap-4">
|
||||
<div class="avatar avatar-placeholder max-sm:hidden">
|
||||
<div class="border-base-content/20 rounded-box w-13 border-1">
|
||||
<span class="icon-container text-xl"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="space-y-1">
|
||||
<h3 class="text-base-content text-2xl font-semibold">Update docker image</h3>
|
||||
<p class="text-base-content/80">Update docker image properties</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-5">
|
||||
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
|
||||
<div class="mt-2">
|
||||
<label class="label-text">Display Name</label>
|
||||
<input class="input" @bind="Form.DisplayName" type="text"/>
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
<label class="label-text">Identifier</label>
|
||||
<input class="input" @bind="Form.Identifier" type="text"/>
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
<label class="label-text">Automatic pulling</label>
|
||||
<Switch @bind-Value="Form.AutoPulling"/>
|
||||
</div>
|
||||
</HandleForm>
|
||||
</div>
|
||||
<div class="mt-5 flex justify-end">
|
||||
<button @onclick="HideAsync" type="button" class="btn btn-secondary me-2">
|
||||
Cancel
|
||||
</button>
|
||||
<WButton OnClick="SubmitAsync">
|
||||
Update
|
||||
</WButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public Func<UpdateStarDockerImageRequest, Task> OnSubmit { get; set; }
|
||||
[Parameter] public StarDockerImageResponse DockerImage { get; set; }
|
||||
|
||||
private UpdateStarDockerImageRequest Form;
|
||||
private HandleForm HandleForm;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
Form = new UpdateStarDockerImageRequest()
|
||||
{
|
||||
AutoPulling = DockerImage.AutoPulling,
|
||||
DisplayName = DockerImage.DisplayName,
|
||||
Identifier = DockerImage.Identifier
|
||||
};
|
||||
}
|
||||
|
||||
private async Task OnValidSubmit()
|
||||
{
|
||||
await OnSubmit.Invoke(Form);
|
||||
await HideAsync();
|
||||
}
|
||||
|
||||
private Task SubmitAsync() => HandleForm.SubmitAsync();
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonlightServers.Shared.Enums
|
||||
@using MoonlightServers.Shared.Models
|
||||
|
||||
@inherits MoonCore.Blazor.FlyonUi.Modals.BaseModal
|
||||
|
||||
<div class="p-5">
|
||||
<div class="flex items-center gap-4">
|
||||
<div class="avatar avatar-placeholder max-sm:hidden">
|
||||
<div class="border-base-content/20 rounded-box w-13 border-1">
|
||||
<span class="icon-braces text-xl"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="space-y-1">
|
||||
<h3 class="text-base-content text-2xl font-semibold">Update parse configuration</h3>
|
||||
<p class="text-base-content/80">Update parse configuration properties</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-5">
|
||||
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
|
||||
<div class="mt-2">
|
||||
<label class="label-text">File</label>
|
||||
<input class="input" @bind="Form.File" type="text"/>
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
<label class="label-text">Parser</label>
|
||||
<select @bind="Form.Parser" class="select w-full">
|
||||
@foreach (var val in Enum.GetValues<FileParsers>())
|
||||
{
|
||||
<option value="@val">@val</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
<button type="button" @onclick="AddEntryAsync" class="btn btn-primary w-full">Add entry</button>
|
||||
</div>
|
||||
|
||||
@foreach (var entry in Form.Entries)
|
||||
{
|
||||
<div class="flex flex-row mt-2">
|
||||
<input @bind="entry.Key" placeholder="Key" class="input placeholder-base-content/50 grow rounded-r-none"/>
|
||||
<input @bind="entry.Value" placeholder="Value" class="input placeholder-base-content/50 grow rounded-none"/>
|
||||
<button type="button" @onclick="() => RemoveEntryAsync(entry)" class="btn btn-error grow-0 rounded-l-none">
|
||||
<i class="icon-x"></i>
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
</HandleForm>
|
||||
</div>
|
||||
<div class="mt-5 flex justify-end">
|
||||
<button @onclick="HideAsync" type="button" class="btn btn-secondary me-2">
|
||||
Cancel
|
||||
</button>
|
||||
<WButton OnClick="SubmitAsync">
|
||||
Update
|
||||
</WButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public Func<ParseConfiguration, Task> OnSubmit { get; set; }
|
||||
[Parameter] public ParseConfiguration Configuration { get; set; }
|
||||
|
||||
private ParseConfiguration Form;
|
||||
private HandleForm HandleForm;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
// Manual mapping :(
|
||||
Form = Configuration;
|
||||
}
|
||||
|
||||
private async Task OnValidSubmit()
|
||||
{
|
||||
await OnSubmit.Invoke(Form);
|
||||
await HideAsync();
|
||||
}
|
||||
|
||||
private Task SubmitAsync() => HandleForm.SubmitAsync();
|
||||
|
||||
private async Task AddEntryAsync()
|
||||
{
|
||||
Form.Entries.Add(new());
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
private async Task RemoveEntryAsync(ParseConfiguration.ParseConfigurationEntry entry)
|
||||
{
|
||||
Form.Entries.Remove(entry);
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonlightServers.Shared.Enums
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.StarVariables
|
||||
@using MoonlightServers.Frontend.UI.Components.Forms
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.StarVariables
|
||||
|
||||
@inherits MoonCore.Blazor.FlyonUi.Modals.BaseModal
|
||||
|
||||
<div class="p-5">
|
||||
<div class="flex items-center gap-4">
|
||||
<div class="avatar avatar-placeholder max-sm:hidden">
|
||||
<div class="border-base-content/20 rounded-box w-13 border-1">
|
||||
<span class="icon-variable text-xl"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="space-y-1">
|
||||
<h3 class="text-base-content text-2xl font-semibold">Update variable</h3>
|
||||
<p class="text-base-content/80">Update variable properties</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-5">
|
||||
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
|
||||
<div class="grid grid-cols-2 gap-2">
|
||||
<div class="col-span-1">
|
||||
<label class="label-text">Name</label>
|
||||
<input @bind="Form.Name" type="text" class="input w-full"/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="label-text">Description</label>
|
||||
<input @bind="Form.Description" type="text" class="input w-full"/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="label-text">Key</label>
|
||||
<input @bind="Form.Key" type="text" class="input w-full"/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="label-text">Default Value</label>
|
||||
<input @bind="Form.DefaultValue" type="text" class="input w-full"/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="label-text">Allow Viewing</label>
|
||||
<Switch @bind-Value="Form.AllowViewing"/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="label-text">Allow Editing</label>
|
||||
<Switch @bind-Value="Form.AllowEditing"/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="label-text">Type</label>
|
||||
<select @bind="Form.Type" class="select w-full">
|
||||
@foreach (var val in Enum.GetValues<StarVariableType>())
|
||||
{
|
||||
<option value="@val">@val</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="label-text">Filter</label>
|
||||
<input @bind="Form.Filter" type="text" class="input w-full"/>
|
||||
</div>
|
||||
</div>
|
||||
</HandleForm>
|
||||
</div>
|
||||
<div class="mt-5 flex justify-end">
|
||||
<button @onclick="HideAsync" type="button" class="btn btn-secondary me-2">
|
||||
Cancel
|
||||
</button>
|
||||
<WButton OnClick="SubmitAsync">
|
||||
Update
|
||||
</WButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public Func<UpdateStarVariableRequest, Task> OnSubmit { get; set; }
|
||||
[Parameter] public StarVariableResponse Variable { get; set; }
|
||||
|
||||
private UpdateStarVariableRequest Form;
|
||||
private HandleForm HandleForm;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
Form = new()
|
||||
{
|
||||
Name = Variable.Name,
|
||||
AllowEditing = Variable.AllowEditing,
|
||||
AllowViewing = Variable.AllowViewing,
|
||||
DefaultValue = Variable.DefaultValue,
|
||||
Description = Variable.Description,
|
||||
Filter = Variable.Filter,
|
||||
Key = Variable.Key,
|
||||
Type = Variable.Type
|
||||
};
|
||||
}
|
||||
|
||||
private async Task OnValidSubmit()
|
||||
{
|
||||
await OnSubmit.Invoke(Form);
|
||||
await HideAsync();
|
||||
}
|
||||
|
||||
private Task SubmitAsync() => HandleForm.SubmitAsync();
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
@using MoonCore.Blazor.FlyonUi.Alerts
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonCore.Blazor.FlyonUi.Modals
|
||||
@using MoonCore.Blazor.FlyonUi.Toasts
|
||||
@using MoonCore.Common
|
||||
@using MoonCore.Helpers
|
||||
@using MoonlightServers.Frontend.UI.Components.Stars.Modals
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.StarDockerImages
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.StarDockerImages
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Stars
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject ModalService ModalService
|
||||
@inject ToastService ToastService
|
||||
@inject AlertService AlertService
|
||||
|
||||
<LazyLoader @ref="LazyLoader" Load="LoadAsync">
|
||||
<div class="flex justify-end">
|
||||
<button type="button" @onclick="AddDockerImageAsync" class="btn btn-primary">Add docker image</button>
|
||||
</div>
|
||||
|
||||
<div class="grid sm:grid-cols-2 xl:grid-cols-3 gap-4 mt-5">
|
||||
@foreach (var dockerImage in DockerImages)
|
||||
{
|
||||
<div class="col-span-1 card card-body p-2.5">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="ml-3">
|
||||
<i class="icon-container text-xl align-middle mr-2"></i>
|
||||
<span class="align-middle text-lg">@dockerImage.DisplayName</span>
|
||||
</div>
|
||||
|
||||
<div class="gap-x-2">
|
||||
<button type="button" @onclick="() => UpdateDockerImageAsync(dockerImage)"
|
||||
class="btn btn-primary">
|
||||
<i class="icon-settings text-base"></i>
|
||||
</button>
|
||||
|
||||
<button type="button" @onclick="() => DeleteDockerImageAsync(dockerImage)"
|
||||
class="btn btn-error">
|
||||
<i class="icon-trash text-base"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</LazyLoader>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public StarResponse Star { get; set; }
|
||||
|
||||
private StarDockerImageResponse[] DockerImages;
|
||||
private LazyLoader LazyLoader;
|
||||
|
||||
private async Task LoadAsync(LazyLoader _)
|
||||
{
|
||||
DockerImages = await CountedData.AllAsync<StarDockerImageResponse>(async (startIndex, count) =>
|
||||
await ApiClient.GetJson<CountedData<StarDockerImageResponse>>(
|
||||
$"api/admin/servers/stars/{Star.Id}/dockerImages?startIndex={startIndex}&count={count}"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private async Task AddDockerImageAsync()
|
||||
{
|
||||
Func<CreateStarDockerImageRequest, Task> onSubmit = async request =>
|
||||
{
|
||||
await ApiClient.Post($"api/admin/servers/stars/{Star.Id}/dockerImages", request);
|
||||
|
||||
await ToastService.SuccessAsync("Successfully created docker image");
|
||||
await LazyLoader.ReloadAsync();
|
||||
};
|
||||
|
||||
await ModalService.LaunchAsync<CreateDockerImageModal>(parameters => { parameters.Add("OnSubmit", onSubmit); });
|
||||
}
|
||||
|
||||
private async Task UpdateDockerImageAsync(StarDockerImageResponse dockerImage)
|
||||
{
|
||||
Func<UpdateStarDockerImageRequest, Task> onSubmit = async request =>
|
||||
{
|
||||
await ApiClient.Patch($"api/admin/servers/stars/{Star.Id}/dockerImages/{dockerImage.Id}", request);
|
||||
|
||||
await ToastService.SuccessAsync("Successfully updated docker image");
|
||||
await LazyLoader.ReloadAsync();
|
||||
};
|
||||
|
||||
await ModalService.LaunchAsync<UpdateDockerImageModal>(parameters =>
|
||||
{
|
||||
parameters.Add("OnSubmit", onSubmit);
|
||||
parameters.Add("DockerImage", dockerImage);
|
||||
});
|
||||
}
|
||||
|
||||
private async Task DeleteDockerImageAsync(StarDockerImageResponse dockerImage)
|
||||
{
|
||||
await AlertService.ConfirmDangerAsync(
|
||||
"Delete docker image",
|
||||
"Do you really want to delete the selected docker image? This cannot be undone",
|
||||
async () =>
|
||||
{
|
||||
await ApiClient.Delete($"api/admin/servers/stars/{Star.Id}/dockerImages/{dockerImage.Id}");
|
||||
|
||||
await ToastService.SuccessAsync("Successfully deleted docker image");
|
||||
await LazyLoader.ReloadAsync();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Stars
|
||||
|
||||
<div>
|
||||
<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">Version</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.Version" 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 class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-base-content">Donate Url</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.DonateUrl" 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">Update Url</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.UpdateUrl" type="text" autocomplete="off" class="input w-full">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public UpdateStarRequest Request { get; set; }
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
@using MoonCore.Blazor.FlyonUi.Ace
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Stars
|
||||
|
||||
<div>
|
||||
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
|
||||
<div class="sm:col-span-3">
|
||||
<label class="block text-sm font-medium leading-6 text-base-content">Docker Image</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.InstallDockerImage" type="text" autocomplete="off" class="input w-full">
|
||||
</div>
|
||||
</div>
|
||||
<div class="sm:col-span-3">
|
||||
<label class="block text-sm font-medium leading-6 text-base-content">Shell</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.InstallShell" type="text" autocomplete="off" class="input w-full">
|
||||
</div>
|
||||
</div>
|
||||
<div class="sm:col-span-6">
|
||||
<label class="block text-sm font-medium leading-6 text-base-content">Script</label>
|
||||
<div class="mt-2" @onfocusout="OnFocusOut">
|
||||
<CodeEditor @ref="CodeEditor" InitialContent="@Request.InstallScript" OnConfigure="OnConfigure" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public UpdateStarRequest Request { get; set; }
|
||||
|
||||
private CodeEditor CodeEditor;
|
||||
|
||||
private void OnConfigure(CodeEditorOptions options)
|
||||
{
|
||||
options.Mode = "ace/mode/sh";
|
||||
}
|
||||
|
||||
private async Task OnFocusOut()
|
||||
{
|
||||
Request.InstallScript = await CodeEditor.GetValueAsync();
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonCore.Common
|
||||
@using MoonCore.Helpers
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Stars
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.StarDockerImages
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Stars
|
||||
@using MoonlightServers.Frontend.UI.Components.Forms
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
|
||||
<LazyLoader Load="LoadAsync">
|
||||
<div>
|
||||
<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">Allow docker image change</label>
|
||||
<div class="mt-2">
|
||||
<Switch @bind-Value="Request.AllowDockerImageChange" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-base-content">Default docker image</label>
|
||||
<div class="mt-2">
|
||||
<select @bind="Request.DefaultDockerImage" class="select w-full">
|
||||
@foreach (var dockerImage in DockerImages)
|
||||
{
|
||||
var index = DockerImages.IndexOf(dockerImage);
|
||||
|
||||
if (Request.DefaultDockerImage == index)
|
||||
{
|
||||
<option selected="selected"
|
||||
value="@index">
|
||||
@dockerImage.DisplayName
|
||||
</option>
|
||||
}
|
||||
else
|
||||
{
|
||||
<option value="@index">
|
||||
@dockerImage.DisplayName
|
||||
</option>
|
||||
}
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</LazyLoader>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public UpdateStarRequest Request { get; set; }
|
||||
[Parameter] public StarResponse Star { get; set; }
|
||||
|
||||
private List<StarDockerImageResponse> DockerImages;
|
||||
|
||||
private async Task LoadAsync(LazyLoader _)
|
||||
{
|
||||
var pagedVariables = await ApiClient.GetJson<CountedData<StarDockerImageResponse>>(
|
||||
$"api/admin/servers/stars/{Star.Id}/dockerImages?startIndex=0&count=100"
|
||||
);
|
||||
|
||||
// TODO: Fix this
|
||||
|
||||
DockerImages = pagedVariables
|
||||
.Items
|
||||
.OrderBy(x => x.Id) // Make sure its in the correct order every time
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
@using System.Text.Json
|
||||
@using Microsoft.Extensions.Logging
|
||||
@using MoonCore.Blazor.FlyonUi.Alerts
|
||||
@using MoonCore.Blazor.FlyonUi.Modals
|
||||
@using MoonCore.Blazor.FlyonUi.Toasts
|
||||
@using MoonlightServers.Frontend.UI.Components.Stars.Modals
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Stars
|
||||
@using MoonlightServers.Shared.Models
|
||||
|
||||
@inject ILogger<ParseConfig> Logger
|
||||
@inject ModalService ModalService
|
||||
@inject AlertService AlertService
|
||||
@inject ToastService ToastService
|
||||
|
||||
<div class="flex justify-end mb-5">
|
||||
<button type="button" @onclick="AddConfigAsync" class="btn btn-primary">Add parse configuration</button>
|
||||
</div>
|
||||
|
||||
@if (HasParseError)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="grid sm:grid-cols-2 xl:grid-cols-3 gap-4">
|
||||
@foreach (var configuration in Configurations)
|
||||
{
|
||||
<div class="col-span-1 card card-body p-2.5">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="ml-3">
|
||||
<i class="icon-file-cog text-xl align-middle mr-2"></i>
|
||||
<span class="align-middle text-lg">@configuration.File</span>
|
||||
</div>
|
||||
|
||||
<div class="gap-x-2">
|
||||
<button type="button" @onclick="() => UpdateConfigAsync(configuration)" class="btn btn-primary">
|
||||
<i class="icon-settings text-base"></i>
|
||||
</button>
|
||||
|
||||
<button type="button" @onclick="() => DeleteConfigAsync(configuration)" class="btn btn-error">
|
||||
<i class="icon-trash text-base"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public UpdateStarRequest Request { get; set; }
|
||||
|
||||
private List<ParseConfiguration> Configurations;
|
||||
private bool HasParseError = false;
|
||||
|
||||
protected override Task OnInitializedAsync()
|
||||
{
|
||||
ReadFromJson();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task AddConfigAsync()
|
||||
{
|
||||
Func<ParseConfiguration, Task> onSubmit = async configuration =>
|
||||
{
|
||||
Configurations.Add(configuration);
|
||||
SaveChanges();
|
||||
|
||||
await InvokeAsync(StateHasChanged);
|
||||
await ToastService.SuccessAsync("Successfully created parse configuration");
|
||||
};
|
||||
|
||||
await ModalService.LaunchAsync<CreateParseConfigModal>(parameters =>
|
||||
{
|
||||
parameters.Add("OnSubmit", onSubmit);
|
||||
}, "max-w-xl");
|
||||
}
|
||||
|
||||
private async Task UpdateConfigAsync(ParseConfiguration configuration)
|
||||
{
|
||||
Func<ParseConfiguration, Task> onSubmit = async _ =>
|
||||
{
|
||||
SaveChanges();
|
||||
|
||||
await InvokeAsync(StateHasChanged);
|
||||
await ToastService.SuccessAsync("Successfully updated parse configuration");
|
||||
};
|
||||
|
||||
await ModalService.LaunchAsync<UpdateParseConfigModal>(parameters =>
|
||||
{
|
||||
parameters.Add("OnSubmit", onSubmit);
|
||||
parameters.Add("Configuration", configuration);
|
||||
}, "max-w-xl");
|
||||
}
|
||||
|
||||
private async Task DeleteConfigAsync(ParseConfiguration configuration)
|
||||
{
|
||||
await AlertService.ConfirmDangerAsync(
|
||||
"Parse configuration deletion",
|
||||
"Do you really want to delete the selected parse configuration",
|
||||
async () =>
|
||||
{
|
||||
Configurations.Remove(configuration);
|
||||
SaveChanges();
|
||||
|
||||
await InvokeAsync(StateHasChanged);
|
||||
await ToastService.SuccessAsync("Successfully deleted parse configuration");
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private void SaveChanges()
|
||||
{
|
||||
Request.ParseConfiguration = JsonSerializer.Serialize(Configurations);
|
||||
ReadFromJson();
|
||||
}
|
||||
|
||||
private void ReadFromJson()
|
||||
{
|
||||
try
|
||||
{
|
||||
Configurations = JsonSerializer.Deserialize<List<ParseConfiguration>>(Request.ParseConfiguration)
|
||||
?? throw new ArgumentNullException();
|
||||
|
||||
HasParseError = false;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogWarning("An error occured while reading parse configuration: {e}", e);
|
||||
HasParseError = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Stars
|
||||
<div>
|
||||
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
|
||||
<div class="sm:col-span-4">
|
||||
<label class="block text-sm font-medium leading-6 text-base-content">Startup Command</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.StartupCommand" 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">Stop Command</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.StopCommand" 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">Online Detection</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.OnlineDetection" type="text" autocomplete="off" class="input w-full">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public UpdateStarRequest Request { get; set; }
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
@using MoonCore.Blazor.FlyonUi.Alerts
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonCore.Blazor.FlyonUi.Modals
|
||||
@using MoonCore.Blazor.FlyonUi.Toasts
|
||||
@using MoonCore.Common
|
||||
@using MoonCore.Helpers
|
||||
@using MoonlightServers.Frontend.UI.Components.Stars.Modals
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.StarVariables
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Stars
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.StarVariables
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject ModalService ModalService
|
||||
@inject AlertService AlertService
|
||||
@inject ToastService ToastService
|
||||
|
||||
<div class="flex justify-end mb-5">
|
||||
<button type="button" @onclick="AddVariableAsync" class="btn btn-primary">Add variable</button>
|
||||
</div>
|
||||
|
||||
<LazyLoader @ref="LazyLoader" Load="LoadAsync">
|
||||
<div class="grid sm:grid-cols-2 xl:grid-cols-3 gap-4">
|
||||
@foreach (var variable in CurrentVariables)
|
||||
{
|
||||
<div class="col-span-1 card card-body p-2.5">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="ml-3">
|
||||
<i class="icon-variable text-xl align-middle mr-2"></i>
|
||||
<span class="align-middle text-lg">@variable.Name</span>
|
||||
</div>
|
||||
|
||||
<div class="gap-x-2">
|
||||
<button type="button" @onclick="() => UpdateVariableAsync(variable)" class="btn btn-primary">
|
||||
<i class="icon-settings text-base"></i>
|
||||
</button>
|
||||
|
||||
<button type="button" @onclick="() => DeleteVariableAsync(variable)" class="btn btn-error">
|
||||
<i class="icon-trash text-base"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</LazyLoader>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public StarResponse Star { get; set; }
|
||||
|
||||
private StarVariableResponse[] CurrentVariables;
|
||||
private LazyLoader LazyLoader;
|
||||
|
||||
private async Task LoadAsync(LazyLoader arg)
|
||||
{
|
||||
CurrentVariables = await CountedData.AllAsync<StarVariableResponse>(async (startIndex, count) =>
|
||||
await ApiClient.GetJson<CountedData<StarVariableResponse>>(
|
||||
$"api/admin/servers/stars/{Star.Id}/variables?startIndex={startIndex}&count={count}"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private async Task AddVariableAsync()
|
||||
{
|
||||
Func<CreateStarVariableRequest, Task> onSubmit = async request =>
|
||||
{
|
||||
await ApiClient.Post($"api/admin/servers/stars/{Star.Id}/variables", request);
|
||||
|
||||
await ToastService.SuccessAsync("Successfully created variable");
|
||||
await LazyLoader.ReloadAsync();
|
||||
};
|
||||
|
||||
await ModalService.LaunchAsync<CreateVariableModal>(parameters => { parameters.Add("OnSubmit", onSubmit); }, "max-w-xl");
|
||||
}
|
||||
|
||||
private async Task UpdateVariableAsync(StarVariableResponse variable)
|
||||
{
|
||||
Func<UpdateStarVariableRequest, Task> onSubmit = async request =>
|
||||
{
|
||||
await ApiClient.Patch($"api/admin/servers/stars/{Star.Id}/variables/{variable.Id}", request);
|
||||
|
||||
await ToastService.SuccessAsync("Successfully updated variable");
|
||||
await LazyLoader.ReloadAsync();
|
||||
};
|
||||
|
||||
await ModalService.LaunchAsync<UpdateVariableModal>(parameters =>
|
||||
{
|
||||
parameters.Add("OnSubmit", onSubmit);
|
||||
parameters.Add("Variable", variable);
|
||||
}, "max-w-xl");
|
||||
}
|
||||
|
||||
private async Task DeleteVariableAsync(StarVariableResponse variable)
|
||||
{
|
||||
await AlertService.ConfirmDangerAsync(
|
||||
"Delete variable",
|
||||
"Do you really want to delete the selected variable? This cannot be undone",
|
||||
async () =>
|
||||
{
|
||||
await ApiClient.Delete($"api/admin/servers/stars/{Star.Id}/variables/{variable.Id}");
|
||||
|
||||
await ToastService.SuccessAsync("Successfully deleted variable");
|
||||
await LazyLoader.ReloadAsync();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,237 +0,0 @@
|
||||
@using Microsoft.Extensions.Logging
|
||||
@using MoonCore.Blazor.FlyonUi.Modals
|
||||
@using MoonCore.Helpers
|
||||
@using XtermBlazor
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
|
||||
@inject IJSRuntime JsRuntime
|
||||
@inject ModalService ModalService
|
||||
@inject ILogger<XtermConsole> Logger
|
||||
|
||||
@implements IAsyncDisposable
|
||||
|
||||
<div class="bg-black rounded-lg p-2 relative">
|
||||
@if (IsInitialized)
|
||||
{
|
||||
<Xterm @ref="Terminal"
|
||||
Addons="Addons"
|
||||
Options="Options"
|
||||
Class="h-full w-full"
|
||||
OnFirstRender="HandleFirstRenderAsync"/>
|
||||
}
|
||||
|
||||
<div class="flex flex-row w-full mt-1.5">
|
||||
<input @bind="CommandInput" @onkeyup="HandleKeyAsync" type="text" placeholder="Type here..." class="input grow"/>
|
||||
<WButton OnClick="_ => SubmitCommandAsync()" CssClasses="btn btn-square btn-primary grow-0 ms-1.5">
|
||||
<i class="icon-send-horizontal text-lg"></i>
|
||||
</WButton>
|
||||
</div>
|
||||
|
||||
<div class="absolute top-4 right-4">
|
||||
<div class="flex flex-col gap-y-1.5">
|
||||
@if (IsPaused)
|
||||
{
|
||||
<button @onclick="TogglePauseAsync" class="btn btn-primary btn-square">
|
||||
<i class="icon-play text-lg"></i>
|
||||
</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button @onclick="TogglePauseAsync" class="btn btn-secondary btn-square">
|
||||
<i class="icon-pause text-lg"></i>
|
||||
</button>
|
||||
}
|
||||
|
||||
<button @onclick="OpenFullscreenAsync" class="btn btn-secondary btn-square">
|
||||
<i class="icon-maximize text-lg"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public Func<Task>? OnAfterInitialized { get; set; }
|
||||
[Parameter] public Func<Task>? OnFirstRender { get; set; }
|
||||
[Parameter] public bool ShowActions { get; set; } = true;
|
||||
[Parameter] public bool ShowInput { get; set; } = false;
|
||||
[Parameter] public int MaxOutputCacheSize { get; set; } = 250;
|
||||
[Parameter] public Func<string, Task>? OnCommand { get; set; }
|
||||
|
||||
[Parameter] public IList<string> CommandHistory { get; set; } = new ConcurrentList<string>();
|
||||
|
||||
public event Func<string, Task>? OnWrite;
|
||||
|
||||
private Xterm Terminal;
|
||||
public HashSet<string> Addons { get; } = ["addon-fit"];
|
||||
|
||||
public TerminalOptions Options { get; } = new()
|
||||
{
|
||||
CursorBlink = false,
|
||||
CursorStyle = CursorStyle.Bar,
|
||||
CursorWidth = 1,
|
||||
FontFamily = "Space Mono, monospace",
|
||||
DisableStdin = true,
|
||||
CursorInactiveStyle = CursorInactiveStyle.None,
|
||||
Theme =
|
||||
{
|
||||
Background = "#000000"
|
||||
},
|
||||
};
|
||||
|
||||
public ConcurrentList<string> OutputCache { get; private set; } = new();
|
||||
public ConcurrentList<string> WriteQueue { get; private set; } = new();
|
||||
private int CommandIndex = -1;
|
||||
private bool IsReadyToWrite = false;
|
||||
private bool IsPaused = false;
|
||||
private bool IsInitialized = false;
|
||||
|
||||
private string CommandInput = "";
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (!firstRender)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
await JsRuntime.InvokeVoidAsync("moonlightServers.loadAddons");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError("An error occured while initializing addons: {e}", e);
|
||||
}
|
||||
|
||||
IsInitialized = true;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
|
||||
if (OnAfterInitialized != null)
|
||||
await OnAfterInitialized.Invoke();
|
||||
}
|
||||
|
||||
private async Task HandleFirstRenderAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
await Terminal.Addon("addon-fit").InvokeVoidAsync("fit");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError("An error occured while calling addons: {e}", e);
|
||||
}
|
||||
|
||||
IsReadyToWrite = true;
|
||||
|
||||
// Write queued content since initialisation started
|
||||
var queueContent = string.Concat(WriteQueue);
|
||||
WriteQueue.Clear();
|
||||
|
||||
await Terminal.Write(queueContent);
|
||||
|
||||
if (OnFirstRender != null)
|
||||
await OnFirstRender.Invoke();
|
||||
}
|
||||
|
||||
public async Task WriteAsync(string content)
|
||||
{
|
||||
// We cache messages here as there is the chance that the console isn't ready for input while receiving write tasks
|
||||
|
||||
if (IsReadyToWrite && !IsPaused)
|
||||
await HandleWriteAsync(content);
|
||||
else
|
||||
WriteQueue.Add(content);
|
||||
}
|
||||
|
||||
private async Task HandleWriteAsync(string content)
|
||||
{
|
||||
// Update output cache and prune it if required
|
||||
if (OutputCache.Count > MaxOutputCacheSize)
|
||||
{
|
||||
for (var i = 0; i < 50; i++)
|
||||
OutputCache.RemoveAt(i);
|
||||
}
|
||||
|
||||
OutputCache.Add(content);
|
||||
|
||||
// Trigger events
|
||||
if (OnWrite != null)
|
||||
await OnWrite.Invoke(content);
|
||||
|
||||
// Write in own terminal
|
||||
await Terminal.Write(content);
|
||||
}
|
||||
|
||||
private async Task OpenFullscreenAsync()
|
||||
{
|
||||
await ModalService.LaunchAsync<FullScreenModal>(parameters => { parameters["Parent"] = this; }, size: "max-w-none");
|
||||
}
|
||||
|
||||
private async Task TogglePauseAsync()
|
||||
{
|
||||
IsPaused = !IsPaused;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
|
||||
if (IsPaused)
|
||||
return;
|
||||
|
||||
var queueContent = string.Concat(WriteQueue);
|
||||
WriteQueue.Clear();
|
||||
|
||||
await HandleWriteAsync(queueContent);
|
||||
}
|
||||
|
||||
private async Task SubmitCommandAsync()
|
||||
{
|
||||
CommandHistory.Add(CommandInput);
|
||||
|
||||
if (OnCommand != null)
|
||||
await OnCommand.Invoke(CommandInput);
|
||||
|
||||
CommandIndex = -1;
|
||||
CommandInput = "";
|
||||
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
private async Task HandleKeyAsync(KeyboardEventArgs keyboard)
|
||||
{
|
||||
switch (keyboard.Code)
|
||||
{
|
||||
case "Enter":
|
||||
await SubmitCommandAsync();
|
||||
break;
|
||||
|
||||
case "ArrowUp" or "ArrowDown":
|
||||
{
|
||||
var highestIndex = CommandHistory.Count - 1;
|
||||
|
||||
if (CommandIndex == -1)
|
||||
CommandIndex = highestIndex;
|
||||
else
|
||||
{
|
||||
if (keyboard.Code is "ArrowUp")
|
||||
CommandIndex++;
|
||||
else if (keyboard.Code is "ArrowDown")
|
||||
CommandIndex--;
|
||||
}
|
||||
|
||||
if (CommandIndex > highestIndex)
|
||||
CommandIndex = highestIndex;
|
||||
|
||||
if (CommandIndex < 0)
|
||||
CommandIndex = 0;
|
||||
|
||||
if (CommandIndex <= highestIndex || CommandHistory.Count > 0)
|
||||
CommandInput = CommandHistory[CommandIndex];
|
||||
|
||||
await InvokeAsync(StateHasChanged);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
await Terminal.DisposeAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user