diff --git a/Moonlight/Core/UI/Components/Partials/Route.razor b/Moonlight/Core/UI/Components/Partials/Route.razor new file mode 100644 index 0000000..d5a05e8 --- /dev/null +++ b/Moonlight/Core/UI/Components/Partials/Route.razor @@ -0,0 +1,20 @@ +@{ + var route = "/" + (Router.Route ?? ""); +} + +@if (route == Path) +{ + @ChildContent +} + +@code +{ + [CascadingParameter] + public SmartRouter Router { get; set; } + + [Parameter] + public RenderFragment ChildContent { get; set; } + + [Parameter] + public string Path { get; set; } +} \ No newline at end of file diff --git a/Moonlight/Core/UI/Components/Partials/SmartRouter.razor b/Moonlight/Core/UI/Components/Partials/SmartRouter.razor new file mode 100644 index 0000000..2b151d6 --- /dev/null +++ b/Moonlight/Core/UI/Components/Partials/SmartRouter.razor @@ -0,0 +1,12 @@ + + @ChildContent + + +@code +{ + [Parameter] + public string? Route { get; set; } + + [Parameter] + public RenderFragment ChildContent { get; set; } +} \ No newline at end of file diff --git a/Moonlight/Features/Servers/Actions/ServerServiceDefinition.cs b/Moonlight/Features/Servers/Actions/ServerServiceDefinition.cs index 9b405c4..14e0410 100644 --- a/Moonlight/Features/Servers/Actions/ServerServiceDefinition.cs +++ b/Moonlight/Features/Servers/Actions/ServerServiceDefinition.cs @@ -1,4 +1,5 @@ using Moonlight.Features.Servers.UI.Layouts; +using Moonlight.Features.Servers.UI.UserViews; using Moonlight.Features.ServiceManagement.Models.Abstractions; using Console = Moonlight.Features.Servers.UI.UserViews.Console; @@ -14,6 +15,7 @@ public class ServerServiceDefinition : ServiceDefinition context.Layout = typeof(UserLayout); await context.AddPage("Console", "/console", "bx bx-sm bxs-terminal"); + await context.AddPage("Reset", "/reset", "bx bx-sm bx-revision"); } public override Task BuildAdminView(ServiceViewContext context) diff --git a/Moonlight/Features/Servers/Models/Packets/ServerOutputMessage.cs b/Moonlight/Features/Servers/Api/Packets/ServerOutputMessage.cs similarity index 66% rename from Moonlight/Features/Servers/Models/Packets/ServerOutputMessage.cs rename to Moonlight/Features/Servers/Api/Packets/ServerOutputMessage.cs index 6809dbb..fb870b0 100644 --- a/Moonlight/Features/Servers/Models/Packets/ServerOutputMessage.cs +++ b/Moonlight/Features/Servers/Api/Packets/ServerOutputMessage.cs @@ -1,4 +1,4 @@ -namespace Moonlight.Features.Servers.Models.Packets; +namespace Moonlight.Features.Servers.Api.Packets; public class ServerOutputMessage { diff --git a/Moonlight/Features/Servers/Models/Packets/ServerStateUpdate.cs b/Moonlight/Features/Servers/Api/Packets/ServerStateUpdate.cs similarity index 74% rename from Moonlight/Features/Servers/Models/Packets/ServerStateUpdate.cs rename to Moonlight/Features/Servers/Api/Packets/ServerStateUpdate.cs index 9b971ab..79304aa 100644 --- a/Moonlight/Features/Servers/Models/Packets/ServerStateUpdate.cs +++ b/Moonlight/Features/Servers/Api/Packets/ServerStateUpdate.cs @@ -1,6 +1,6 @@ using Moonlight.Features.Servers.Models.Enums; -namespace Moonlight.Features.Servers.Models.Packets; +namespace Moonlight.Features.Servers.Api.Packets; public class ServerStateUpdate { diff --git a/Moonlight/Features/Servers/Api/Requests/EnterCommand.cs b/Moonlight/Features/Servers/Api/Requests/EnterCommand.cs new file mode 100644 index 0000000..5f7392f --- /dev/null +++ b/Moonlight/Features/Servers/Api/Requests/EnterCommand.cs @@ -0,0 +1,6 @@ +namespace Moonlight.Features.Servers.Api.Requests; + +public class EnterCommand +{ + public string Command { get; set; } +} \ No newline at end of file diff --git a/Moonlight/Features/Servers/Http/Controllers/NodeController.cs b/Moonlight/Features/Servers/Http/Controllers/NodeController.cs index 8bbfc64..e613f06 100644 --- a/Moonlight/Features/Servers/Http/Controllers/NodeController.cs +++ b/Moonlight/Features/Servers/Http/Controllers/NodeController.cs @@ -1,9 +1,9 @@ using System.Net.WebSockets; using Microsoft.AspNetCore.Mvc; using MoonCore.Helpers; +using Moonlight.Features.Servers.Api.Packets; using Moonlight.Features.Servers.Entities; using Moonlight.Features.Servers.Extensions.Attributes; -using Moonlight.Features.Servers.Models.Packets; using Moonlight.Features.Servers.Services; namespace Moonlight.Features.Servers.Http.Controllers; @@ -82,8 +82,6 @@ public class NodeController : Controller { lock (meta.ConsoleMessages) meta.ConsoleMessages.Add(serverOutputMessage.Message); - - meta.LastChangeTimestamp = DateTime.UtcNow; }); await (await ServerService.Meta.Get(serverOutputMessage.Id)).OnConsoleMessage.Invoke(serverOutputMessage diff --git a/Moonlight/Features/Servers/Services/ServerService.cs b/Moonlight/Features/Servers/Services/ServerService.cs index 4caccfb..4db3213 100644 --- a/Moonlight/Features/Servers/Services/ServerService.cs +++ b/Moonlight/Features/Servers/Services/ServerService.cs @@ -2,8 +2,7 @@ using Microsoft.EntityFrameworkCore; using MoonCore.Abstractions; using MoonCore.Attributes; using MoonCore.Helpers; - - +using Moonlight.Features.Servers.Api.Requests; using Moonlight.Features.Servers.Entities; using Moonlight.Features.Servers.Exceptions; using Moonlight.Features.Servers.Helpers; @@ -47,6 +46,16 @@ public class ServerService await httpClient.Post($"servers/{server.Id}/subscribe"); } + public async Task SendCommand(Server server, string command) + { + using var httpClient = CreateHttpClient(server); + + await httpClient.Post($"servers/{server.Id}/command", new EnterCommand() + { + Command = command + }); + } + private HttpApiClient CreateHttpClient(Server server) { using var scope = ServiceProvider.CreateScope(); diff --git a/Moonlight/Features/Servers/UI/Components/Terminal.razor b/Moonlight/Features/Servers/UI/Components/Terminal.razor index ec3a420..d92a0dc 100644 --- a/Moonlight/Features/Servers/UI/Components/Terminal.razor +++ b/Moonlight/Features/Servers/UI/Components/Terminal.razor @@ -5,7 +5,7 @@ @inject ClipboardService ClipboardService @inject ToastService ToastService - + @code { @@ -25,13 +25,6 @@ FontFamily = "monospace" }; - private readonly string[] AddonIds = new[] - { - "xterm-addon-fit", - "xterm-addon-web-links", - "xterm-addon-search" - }; - private bool HasBeenRendered = false; private readonly List UnRenderedMessageCache = new(); diff --git a/Moonlight/Features/Servers/UI/UserViews/Console.razor b/Moonlight/Features/Servers/UI/UserViews/Console.razor index 478e546..e42a4f5 100644 --- a/Moonlight/Features/Servers/UI/UserViews/Console.razor +++ b/Moonlight/Features/Servers/UI/UserViews/Console.razor @@ -1,5 +1,9 @@ @using Moonlight.Features.Servers.Models.Abstractions +@using Moonlight.Features.Servers.Services @using Moonlight.Features.Servers.UI.Components +@using Moonlight.Features.Servers.Entities + +@inject ServerService ServerService @implements IDisposable @@ -7,8 +11,8 @@
- - + +
@@ -17,8 +21,12 @@ { [CascadingParameter] public ServerMeta Meta { get; set; } + + [CascadingParameter] + public Server Server { get; set; } private Terminal Terminal; + private string CommandInput = ""; protected override async Task OnAfterRenderAsync(bool firstRender) { @@ -40,10 +48,19 @@ { await Terminal.WriteLine(message); } + + private async Task SendCommand() + { + await ServerService.SendCommand(Server, CommandInput); + CommandInput = ""; + + await InvokeAsync(StateHasChanged); + } public void Dispose() { if(Meta != null) Meta.OnConsoleMessage -= OnConsoleMessage; } + } \ No newline at end of file diff --git a/Moonlight/Features/Servers/UI/UserViews/Reset.razor b/Moonlight/Features/Servers/UI/UserViews/Reset.razor new file mode 100644 index 0000000..ccddd2e --- /dev/null +++ b/Moonlight/Features/Servers/UI/UserViews/Reset.razor @@ -0,0 +1,53 @@ +@using Moonlight.Features.Servers.Entities +@using Moonlight.Features.Servers.Models.Abstractions +@using Moonlight.Features.Servers.Models.Enums +@using Moonlight.Features.Servers.Services + +@implements IDisposable + +@inject ServerService ServerService + +
+ @if (Meta.State == ServerState.Offline) + { + + } + else + { + + } +
+ +@code +{ + [CascadingParameter] + public Server Server { get; set; } + + [CascadingParameter] + public ServerMeta Meta { get; set; } + + protected override Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + Meta.OnStateChanged += OnStateChanged; + } + + return Task.CompletedTask; + } + + private async Task ResetServer() + { + await ServerService.SendPowerAction(Server, PowerAction.Install); + } + + private async Task OnStateChanged() + { + await InvokeAsync(StateHasChanged); + } + + public void Dispose() + { + Meta.OnStateChanged -= OnStateChanged; + } +} \ No newline at end of file diff --git a/Moonlight/Moonlight.csproj b/Moonlight/Moonlight.csproj index 18a8ea8..ccf47d0 100644 --- a/Moonlight/Moonlight.csproj +++ b/Moonlight/Moonlight.csproj @@ -34,6 +34,7 @@ + @@ -56,7 +57,7 @@ - + diff --git a/Moonlight/Pages/_Host.cshtml b/Moonlight/Pages/_Host.cshtml index ee93fdb..14df0eb 100644 --- a/Moonlight/Pages/_Host.cshtml +++ b/Moonlight/Pages/_Host.cshtml @@ -60,9 +60,6 @@ - - - @foreach (var theme in themes) {