From a6975fc0aa9a313e7679389dce97893308e2d36f Mon Sep 17 00:00:00 2001 From: Daniel Balk <67603460+Daniel-Balk@users.noreply.github.com> Date: Fri, 5 May 2023 17:11:44 +0200 Subject: [PATCH] added version and main jar setting --- .../ServerControl/ServerSettings.razor | 6 ++ .../Settings/JavaFileSetting.razor | 85 ++++++++++++++++++ .../Settings/JavaRuntimeVersionSetting.razor | 89 +++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 Moonlight/Shared/Components/ServerControl/Settings/JavaFileSetting.razor create mode 100644 Moonlight/Shared/Components/ServerControl/Settings/JavaRuntimeVersionSetting.razor diff --git a/Moonlight/Shared/Components/ServerControl/ServerSettings.razor b/Moonlight/Shared/Components/ServerControl/ServerSettings.razor index ee212b86..e76bdef4 100644 --- a/Moonlight/Shared/Components/ServerControl/ServerSettings.razor +++ b/Moonlight/Shared/Components/ServerControl/ServerSettings.razor @@ -55,9 +55,15 @@ if(Tags.Contains("pythonversion")) Settings.Add("Python version", typeof(PythonVersionSetting)); + if(Tags.Contains("javaversion")) + Settings.Add("Java version", typeof(JavaRuntimeVersionSetting)); + if(Tags.Contains("pythonfile")) Settings.Add("Python file", typeof(PythonFileSetting)); + if(Tags.Contains("javafile")) + Settings.Add("Jar file", typeof(JavaFileSetting)); + Settings.Add("Rename", typeof(ServerRenameSetting)); Settings.Add("Reset", typeof(ServerResetSetting)); diff --git a/Moonlight/Shared/Components/ServerControl/Settings/JavaFileSetting.razor b/Moonlight/Shared/Components/ServerControl/Settings/JavaFileSetting.razor new file mode 100644 index 00000000..b8fb9f88 --- /dev/null +++ b/Moonlight/Shared/Components/ServerControl/Settings/JavaFileSetting.razor @@ -0,0 +1,85 @@ +@using Task = System.Threading.Tasks.Task +@using Moonlight.App.Repositories.Servers +@using Moonlight.Shared.Components.FileManagerPartials +@using Moonlight.App.Database.Entities +@using Moonlight.App.Helpers +@using Moonlight.App.Helpers.Files +@using Moonlight.App.Services + +@inject ServerRepository ServerRepository +@inject ServerService ServerService +@inject SmartTranslateService SmartTranslateService + +
+
+ + + + + + + +
+ + + +
+
+
+
+ + + + +@code +{ + [CascadingParameter] + public Server CurrentServer { get; set; } + + private string PathAndFile; + private FileAccess Access; + + private FileSelectModal FileSelectModal; + private LazyLoader LazyLoader; + + protected override async Task OnInitializedAsync() + { + Access = await ServerService.CreateFileAccess(CurrentServer, null!); + } + + private async Task Load(LazyLoader lazyLoader) + { + var v = CurrentServer.Variables.FirstOrDefault(x => x.Key == "JARFILE"); + + PathAndFile = v != null ? v.Value : ""; + + await InvokeAsync(StateHasChanged); + } + + private async Task Show() + { + await FileSelectModal.Show(); + } + + private async Task OnSubmit(string path) + { + var v = CurrentServer.Variables.FirstOrDefault(x => x.Key == "JARFILE"); + + if (v != null) + { + v.Value = path.TrimStart("/"[0]); + + ServerRepository.Update(CurrentServer); + } + + await LazyLoader.Reload(); + } +} \ No newline at end of file diff --git a/Moonlight/Shared/Components/ServerControl/Settings/JavaRuntimeVersionSetting.razor b/Moonlight/Shared/Components/ServerControl/Settings/JavaRuntimeVersionSetting.razor new file mode 100644 index 00000000..e892ac83 --- /dev/null +++ b/Moonlight/Shared/Components/ServerControl/Settings/JavaRuntimeVersionSetting.razor @@ -0,0 +1,89 @@ +@using Moonlight.App.Services +@using Moonlight.App.Helpers +@using Moonlight.App.Repositories +@using Moonlight.App.Repositories.Servers +@using Microsoft.EntityFrameworkCore +@using Moonlight.App.Database.Entities + +@inject ServerRepository ServerRepository +@inject ImageRepository ImageRepository +@inject SmartTranslateService TranslationService + +
+
+ + + + + + + +
+ + + + +
+ +
+
+
+ +@code +{ + [CascadingParameter] + public Server CurrentServer { get; set; } + + private LazyLoader LazyLoader; + private List DockerImages; + private DockerImage SelectedImage; + + private int ImageIndex + { + get => SelectedImage.Id; + set { SelectedImage = DockerImages.First(x => x.Id == value); } + } + + private Task Load(LazyLoader lazyLoader) + { + var image = ImageRepository + .Get() + .Include(x => x.DockerImages) + .First(x => x.Id == CurrentServer.Image.Id); + + DockerImages = image.DockerImages; + + SelectedImage = DockerImages[CurrentServer.DockerImageIndex]; + + return Task.CompletedTask; + } + + private async Task Save() + { + CurrentServer.DockerImageIndex = DockerImages.IndexOf(SelectedImage); + + ServerRepository.Update(CurrentServer); + + await LazyLoader.Reload(); + } +} \ No newline at end of file