diff --git a/Moonlight/Features/Servers/Actions/ServerServiceDefinition.cs b/Moonlight/Features/Servers/Actions/ServerServiceDefinition.cs index 2220671..35ef8dc 100644 --- a/Moonlight/Features/Servers/Actions/ServerServiceDefinition.cs +++ b/Moonlight/Features/Servers/Actions/ServerServiceDefinition.cs @@ -17,6 +17,7 @@ public class ServerServiceDefinition : ServiceDefinition await context.AddPage("Console", "/console", "bx bx-sm bxs-terminal"); await context.AddPage("Files", "/files", "bx bx-sm bxs-folder"); await context.AddPage("Reset", "/reset", "bx bx-sm bx-revision"); + await context.AddPage("Variables", "/variables", "bx bx-sm bx-slider"); } public override Task BuildAdminView(ServiceViewContext context) diff --git a/Moonlight/Features/Servers/UI/UserViews/Variables.razor b/Moonlight/Features/Servers/UI/UserViews/Variables.razor new file mode 100644 index 0000000..6345a75 --- /dev/null +++ b/Moonlight/Features/Servers/UI/UserViews/Variables.razor @@ -0,0 +1,108 @@ +@using Moonlight.Features.Servers.Entities +@using MoonCore.Abstractions +@using Microsoft.EntityFrameworkCore +@using MoonCoreUI.Services + +@inject Repository ServerRepository +@inject Repository ImageRepository +@inject Repository ServerVariableRepository +@inject ToastService ToastService + + +
+
+
+ + @if (Image.AllowUserToChangeDockerImage) + { + + } + else + { + + } +
+
+
+
+ @foreach (var variable in Server.Variables) + { + var imageVariable = Image.Variables.FirstOrDefault(x => x.Key == variable.Key); + + if (imageVariable != null && imageVariable.AllowUserToView) + { +
+
+ +
+ @imageVariable.Description +
+ @if (imageVariable.AllowUserToEdit) + { +
+ + + + +
+ } + else + { +
+ +
+ } +
+
+ } + } +
+
+ +@code +{ + [CascadingParameter] public Server Server { get; set; } + + private ServerImage Image; + private LazyLoader LazyLoader; + + private ServerDockerImage SelectedDockerImage; + + private async Task Load(LazyLoader lazyLoader) + { + await lazyLoader.SetText("Loading server image data"); + + Image = ImageRepository + .Get() + .Include(x => x.Variables) + .Include(x => x.DockerImages) + .First(x => x.Id == Server.Image.Id); + + if (Server.DockerImageIndex >= Image.DockerImages.Count || Server.DockerImageIndex == -1) + SelectedDockerImage = Image.DockerImages.Last(); + else + SelectedDockerImage = Image.DockerImages[Server.DockerImageIndex]; + } + + private async Task OnDockerImageChanged() + { + Server.DockerImageIndex = Image.DockerImages.IndexOf(SelectedDockerImage); + ServerRepository.Update(Server); + + await ToastService.Success("Successfully changed docker image"); + await LazyLoader.Reload(); + } + + private async Task UpdateVariable(ServerVariable variable) + { + ServerVariableRepository.Update(variable); + + await ToastService.Success("Successfully changed variable"); + await LazyLoader.Reload(); + } +} \ No newline at end of file