From 9602a201ce63f3e0bedef5f52e6d4598e0c72888 Mon Sep 17 00:00:00 2001 From: Marcel Baumgartner Date: Wed, 3 Jul 2024 22:38:40 +0200 Subject: [PATCH] Switched to final fast forms implementation. Changed some stuff --- Moonlight/Core/UI/Components/Auth/Login.razor | 4 +- Moonlight/Core/UI/Views/Admin/Api/Keys.razor | 6 +- .../Core/UI/Views/Admin/Sys/Settings.razor | 6 +- .../Core/UI/Views/Admin/Users/Index.razor | 33 +++-- .../ImageComponents/DefaultDockerImage.razor | 12 +- .../UI/ImageComponents/EditorComponent.razor | 19 +-- .../ImageComponents/ImageDockerImages.razor | 33 +---- .../ImageParseConfigEditor.razor | 3 +- .../UI/ImageComponents/ImageVariables.razor | 16 ++- .../UI/NodeComponents/NodeAllocations.razor | 8 +- .../Servers/UI/Views/Admin/Images/Index.razor | 35 +++--- .../Servers/UI/Views/Admin/Index.razor | 117 +++++++++--------- .../Servers/UI/Views/Admin/Nodes/Index.razor | 21 ++-- .../Servers/UI/Views/Servers/Networks.razor | 21 ++-- Moonlight/Moonlight.csproj | 7 +- Moonlight/_Imports.razor | 5 +- 16 files changed, 146 insertions(+), 200 deletions(-) diff --git a/Moonlight/Core/UI/Components/Auth/Login.razor b/Moonlight/Core/UI/Components/Auth/Login.razor index acf58eef..3402f97a 100644 --- a/Moonlight/Core/UI/Components/Auth/Login.razor +++ b/Moonlight/Core/UI/Components/Auth/Login.razor @@ -23,7 +23,7 @@ - + @if (RequiresTwoFactor) {
@@ -57,7 +57,7 @@ @* OAuth2 Providers here *@
-
+ diff --git a/Moonlight/Core/UI/Views/Admin/Api/Keys.razor b/Moonlight/Core/UI/Views/Admin/Api/Keys.razor index ce9546a9..d88630ca 100644 --- a/Moonlight/Core/UI/Views/Admin/Api/Keys.razor +++ b/Moonlight/Core/UI/Views/Admin/Api/Keys.razor @@ -1,6 +1,6 @@ @page "/admin/api/keys" -@using MoonCore.Blazor.Models.Fast +@using MoonCore.Blazor.Models.FastForms @using MoonCore.Helpers @using Moonlight.Core.Database.Entities @using Moonlight.Core.UI.Components.Navigations @@ -66,12 +66,12 @@ }; } - private void OnConfigureFrom(FastConfiguration configuration, ApiKey _) + private void OnConfigureFrom(FastFormConfiguration configuration, ApiKey _) { configuration.AddProperty(x => x.Description) .WithDefaultComponent() .WithDescription("Write a note here for which application the api key is used for") - .WithValidation(FastValidators.Required); + .WithValidation(FastFormValidators.Required); configuration.AddProperty(x => x.ExpiresAt) .WithDefaultComponent() diff --git a/Moonlight/Core/UI/Views/Admin/Sys/Settings.razor b/Moonlight/Core/UI/Views/Admin/Sys/Settings.razor index f4079d13..11a925dc 100644 --- a/Moonlight/Core/UI/Views/Admin/Sys/Settings.razor +++ b/Moonlight/Core/UI/Views/Admin/Sys/Settings.razor @@ -4,8 +4,6 @@ @using System.Linq.Expressions @using Moonlight.Core.UI.Components.Navigations @using System.Reflection -@using MoonCore.Blazor.Models.Fast -@using MoonCore.Helpers @using MoonCore.Services @using Moonlight.Core.Configuration @@ -140,7 +138,7 @@ else Properties = props .Where(x => !x.PropertyType.Namespace.StartsWith("Moonlight") && - DefaultComponentSelector.GetDefault(x.PropertyType) != null // Check if a component has been registered for that type + DefaultComponentRegistry.Get(x.PropertyType) != null // Check if a component has been registered for that type ) .ToArray(); } @@ -151,7 +149,7 @@ else await LazyLoader.Reload(); } - private void OnFormConfigure(FastConfiguration configuration) + private void OnFormConfigure(FastFormConfiguration configuration) { if(CurrentModel == null) // This will technically never be true because of the ui logic return; diff --git a/Moonlight/Core/UI/Views/Admin/Users/Index.razor b/Moonlight/Core/UI/Views/Admin/Users/Index.razor index 82e29603..0bb30809 100644 --- a/Moonlight/Core/UI/Views/Admin/Users/Index.razor +++ b/Moonlight/Core/UI/Views/Admin/Users/Index.razor @@ -2,14 +2,9 @@ @using System.ComponentModel.DataAnnotations @using Moonlight.Core.UI.Components.Navigations -@using MoonCore.Abstractions -@using MoonCore.Blazor.Forms.Fast.Components -@using MoonCore.Blazor.Models.Fast -@using MoonCore.Blazor.Models.Fast.Validators @using Moonlight.Core.Database.Entities @using MoonCore.Exceptions @using Moonlight.Core.Models.Abstractions -@using Moonlight.Core.Models.Forms.Users @inject AlertService AlertService @inject IAuthenticationProvider AuthenticationProvider @@ -67,43 +62,43 @@ }; } - private void OnConfigureCreate(FastConfiguration configuration, User _) + private void OnConfigureCreate(FastFormConfiguration configuration, User _) { configuration.AddProperty(x => x.Username) .WithDefaultComponent() - .WithValidation(FastValidators.Required) + .WithValidation(FastFormValidators.Required) .WithValidation(RegexValidator.Create("^[a-z][a-z0-9]*$", "Usernames can only contain lowercase characters and numbers and should not start with a number")) - .WithValidation(x => x.Length >= 6 ? ValidationResult.Success : new ValidationResult("The username is too short")) - .WithValidation(x => x.Length <= 20 ? ValidationResult.Success : new ValidationResult("The username cannot be longer than 20 characters")); + .WithValidation(x => x.Length >= 6 ? ValidationResult.Success : new ValidationResult("The username is too short")) + .WithValidation(x => x.Length <= 20 ? ValidationResult.Success : new ValidationResult("The username cannot be longer than 20 characters")); configuration.AddProperty(x => x.Email) .WithDefaultComponent() - .WithValidation(FastValidators.Required) + .WithValidation(FastFormValidators.Required) .WithValidation(RegexValidator.Create("^.+@.+$", "You need to enter a valid email address")); configuration.AddProperty(x => x.Password) .WithDefaultComponent() - .WithValidation(FastValidators.Required) - .WithValidation(x => x.Length >= 8 ? ValidationResult.Success : new ValidationResult("The password must be at least 8 characters long")) - .WithValidation(x => x.Length <= 256 ? ValidationResult.Success : new ValidationResult("The password must not be longer than 256 characters")); + .WithValidation(FastFormValidators.Required) + .WithValidation(x => x.Length >= 8 ? ValidationResult.Success : new ValidationResult("The password must be at least 8 characters long")) + .WithValidation(x => x.Length <= 256 ? ValidationResult.Success : new ValidationResult("The password must not be longer than 256 characters")); } - private void OnConfigureEdit(FastConfiguration configuration, User currentUser) + private void OnConfigureEdit(FastFormConfiguration configuration, User currentUser) { configuration.AddProperty(x => x.Username) .WithDefaultComponent() - .WithValidation(FastValidators.Required) + .WithValidation(FastFormValidators.Required) .WithValidation(RegexValidator.Create("^[a-z][a-z0-9]*$", "Usernames can only contain lowercase characters and numbers and should not start with a number")) - .WithValidation(x => x.Length >= 6 ? ValidationResult.Success : new ValidationResult("The username is too short")) - .WithValidation(x => x.Length <= 20 ? ValidationResult.Success : new ValidationResult("The username cannot be longer than 20 characters")); + .WithValidation(x => x.Length >= 6 ? ValidationResult.Success : new ValidationResult("The username is too short")) + .WithValidation(x => x.Length <= 20 ? ValidationResult.Success : new ValidationResult("The username cannot be longer than 20 characters")); configuration.AddProperty(x => x.Email) .WithDefaultComponent() - .WithValidation(FastValidators.Required) + .WithValidation(FastFormValidators.Required) .WithValidation(RegexValidator.Create("^.+@.+$", "You need to enter a valid email address")); configuration.AddProperty(x => x.Totp) - .WithComponent() + .WithComponent() .WithName("Two factor authentication") .WithDescription("This toggles the use of the two factor authentication"); } diff --git a/Moonlight/Features/Servers/UI/ImageComponents/DefaultDockerImage.razor b/Moonlight/Features/Servers/UI/ImageComponents/DefaultDockerImage.razor index 27d9c69f..0269c82b 100644 --- a/Moonlight/Features/Servers/UI/ImageComponents/DefaultDockerImage.razor +++ b/Moonlight/Features/Servers/UI/ImageComponents/DefaultDockerImage.razor @@ -1,7 +1,7 @@ +@using Microsoft.CSharp.RuntimeBinder @using Moonlight.Features.Servers.Entities -@using MoonCore.Blazor.Forms.Fast.Components -@inherits BaseFastFormComponent +@inherits FastFormBaseComponent
@@ -14,6 +14,8 @@ @code { + [Parameter] public ServerImage Image { get; set; } + private ServerDockerImage? SelectedDockerImage { get @@ -42,11 +44,7 @@ protected override void OnInitialized() { - ArgumentNullException.ThrowIfNull(AdditionalOptions); - - var image = AdditionalOptions.Get("Image"); - - SortedImages = image.DockerImages + SortedImages = Image.DockerImages .OrderBy(x => x.Id) .ToList(); } diff --git a/Moonlight/Features/Servers/UI/ImageComponents/EditorComponent.razor b/Moonlight/Features/Servers/UI/ImageComponents/EditorComponent.razor index 419caa38..c7cfe9c0 100644 --- a/Moonlight/Features/Servers/UI/ImageComponents/EditorComponent.razor +++ b/Moonlight/Features/Servers/UI/ImageComponents/EditorComponent.razor @@ -1,7 +1,6 @@ -@using MoonCore.Blazor.Forms.Fast.Components @using Moonlight.Features.FileManager.UI.Components -@inherits BaseFastFormComponent +@inherits FastFormBaseComponent