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 @Name @@ -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 @@ -17,21 +16,9 @@ @code { - private int Lines; - private string Mode; + [Parameter] public string Mode { get; set; } = "sh"; - protected override void OnInitialized() - { - if (AdditionalOptions == null) - { - Lines = 25; - Mode = "sh"; - return; - } - - Lines = AdditionalOptions.GetNullable("Lines") ?? 25; - Mode = AdditionalOptions.GetNullable("Mode") ?? "sh"; - } + [Parameter] public int Lines { get; set; } = 25; private Task OnValueChanged(string val) { diff --git a/Moonlight/Features/Servers/UI/ImageComponents/ImageDockerImages.razor b/Moonlight/Features/Servers/UI/ImageComponents/ImageDockerImages.razor index 0e9c70e6..ac891219 100644 --- a/Moonlight/Features/Servers/UI/ImageComponents/ImageDockerImages.razor +++ b/Moonlight/Features/Servers/UI/ImageComponents/ImageDockerImages.razor @@ -1,35 +1,10 @@ @using MoonCore.Abstractions -@using MoonCore.Blazor.Forms.Fast.Components -@using MoonCore.Blazor.Models.Fast -@using MoonCore.Blazor.Models.Fast.Validators @using MoonCore.Exceptions @using Moonlight.Features.Servers.Entities @inject Repository ImageRepository @inject Repository DockerImageRepository -@* - - - - - Default docker image - - - - Allow user to change the docker image - - - - - - -*@ - configuration, ServerDockerImage _) + private void OnConfigureForm(FastFormConfiguration configuration, ServerDockerImage _) { configuration.AddProperty(x => x.Name) .WithDefaultComponent() - .WithValidation(FastValidators.Required) + .WithValidation(FastFormValidators.Required) .WithValidation(RegexValidator.Create("^(?:[a-zA-Z0-9\\-\\.]+\\/)?[a-zA-Z0-9\\-]+(?:\\/[a-zA-Z0-9\\-]+)*(?::[a-zA-Z0-9_\\.-]+)?$", "You need to provide a valid docker image name")) .WithDescription("This is the name of the docker image. E.g. moonlightpanel/moonlight:canary"); configuration.AddProperty(x => x.DisplayName) .WithDefaultComponent() - .WithValidation(FastValidators.Required) + .WithValidation(FastFormValidators.Required) .WithDescription("This will be shown if the user is able to change the docker image as the image name"); configuration.AddProperty(x => x.AutoPull) - .WithComponent() + .WithComponent() .WithDescription("Specifies if the docker image should be pulled/updated when creating a server instance. Disable this for only local existing docker images"); } } \ No newline at end of file diff --git a/Moonlight/Features/Servers/UI/ImageComponents/ImageParseConfigEditor.razor b/Moonlight/Features/Servers/UI/ImageComponents/ImageParseConfigEditor.razor index c2e5e595..5efa036f 100644 --- a/Moonlight/Features/Servers/UI/ImageComponents/ImageParseConfigEditor.razor +++ b/Moonlight/Features/Servers/UI/ImageComponents/ImageParseConfigEditor.razor @@ -1,10 +1,9 @@ @using Mappy.Net -@using MoonCore.Blazor.Forms.Fast.Components @using Moonlight.Features.Servers.Models @using Moonlight.Features.Servers.Models.Forms.Admin.Images.Parsing @using Newtonsoft.Json -@inherits BaseFastFormComponent +@inherits FastFormBaseComponent diff --git a/Moonlight/Features/Servers/UI/ImageComponents/ImageVariables.razor b/Moonlight/Features/Servers/UI/ImageComponents/ImageVariables.razor index 5b9e50c8..e9e4dff5 100644 --- a/Moonlight/Features/Servers/UI/ImageComponents/ImageVariables.razor +++ b/Moonlight/Features/Servers/UI/ImageComponents/ImageVariables.razor @@ -1,7 +1,5 @@ @using Moonlight.Features.Servers.Entities @using MoonCore.Abstractions -@using MoonCore.Blazor.Forms.Fast.Components -@using MoonCore.Blazor.Models.Fast @using MoonCore.Exceptions @using Moonlight.Features.Servers.Entities.Enums @@ -99,11 +97,11 @@ }; } - private void OnConfigureForm(FastConfiguration configuration, ServerImageVariable _) + private void OnConfigureForm(FastFormConfiguration configuration, ServerImageVariable _) { configuration.AddProperty(x => x.Key) .WithDefaultComponent() - .WithValidation(FastValidators.Required) + .WithValidation(FastFormValidators.Required) .WithDescription("This is the environment variable name"); configuration.AddProperty(x => x.DefaultValue) @@ -112,24 +110,24 @@ configuration.AddProperty(x => x.DisplayName) .WithDefaultComponent() - .WithValidation(FastValidators.Required) + .WithValidation(FastFormValidators.Required) .WithDescription("This is the display name of the variable which will be shown to the user if enabled to edit/view the variable"); configuration.AddProperty(x => x.Description) .WithDefaultComponent() - .WithValidation(FastValidators.Required) + .WithValidation(FastFormValidators.Required) .WithDescription("This text should describe what the variable does for the user if allowed to view and/or change"); configuration.AddProperty(x => x.AllowView) - .WithComponent() + .WithComponent() .WithDescription("Allow the user to view the variable but not edit it unless specified otherwise"); configuration.AddProperty(x => x.AllowEdit) - .WithComponent() + .WithComponent() .WithDescription("Allow the user to edit the variable. Wont work if view is disabled"); configuration.AddProperty(x => x.Type) - .WithComponent>() + .WithComponent>() .WithDescription("Specifies the type of the variable. This specifies what ui the user will see for the variable. You can also specify the options which are available using the filter field"); configuration.AddProperty(x => x.Filter) diff --git a/Moonlight/Features/Servers/UI/NodeComponents/NodeAllocations.razor b/Moonlight/Features/Servers/UI/NodeComponents/NodeAllocations.razor index ae24d78d..4e54c513 100644 --- a/Moonlight/Features/Servers/UI/NodeComponents/NodeAllocations.razor +++ b/Moonlight/Features/Servers/UI/NodeComponents/NodeAllocations.razor @@ -1,8 +1,6 @@ @using System.ComponentModel.DataAnnotations @using Moonlight.Features.Servers.Entities @using MoonCore.Abstractions -@using MoonCore.Blazor.Models.Fast -@using MoonCore.Blazor.Models.Fast.Validators @using MoonCore.Exceptions @@ -192,15 +190,15 @@ }; } - private void OnConfigureForm(FastConfiguration configuration, ServerAllocation _) + private void OnConfigureForm(FastFormConfiguration configuration, ServerAllocation _) { configuration.AddProperty(x => x.IpAddress) .WithDefaultComponent() - .WithValidation(FastValidators.Required) + .WithValidation(FastFormValidators.Required) .WithValidation(RegexValidator.Create("^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$", "You need to provide a valid ipv4 address")); configuration.AddProperty(x => x.Port) .WithDefaultComponent() - .WithValidation(x => x >= 1 && x <= 65535 ? ValidationResult.Success : new ValidationResult("You need to provide a valid port")); + .WithValidation(x => x >= 1 && x <= 65535 ? ValidationResult.Success : new ValidationResult("You need to provide a valid port")); } } \ No newline at end of file diff --git a/Moonlight/Features/Servers/UI/Views/Admin/Images/Index.razor b/Moonlight/Features/Servers/UI/Views/Admin/Images/Index.razor index 7b0dd8d1..120dc80b 100644 --- a/Moonlight/Features/Servers/UI/Views/Admin/Images/Index.razor +++ b/Moonlight/Features/Servers/UI/Views/Admin/Images/Index.razor @@ -9,9 +9,6 @@ @using Moonlight.Features.Servers.Entities @using Moonlight.Features.Servers.Helpers @using Microsoft.AspNetCore.Components.Forms -@using MoonCore.Blazor.Forms.Fast.Components -@using MoonCore.Blazor.Models.Fast -@using MoonCore.Blazor.Models.Fast.Validators @using Moonlight.Features.Servers.UI.ImageComponents @inject Repository ServerRepository @@ -111,18 +108,18 @@ configuration.CustomDelete = CustomDelete; } - private void OnConfigureForm(FastConfiguration configuration, ServerImage image) + private void OnConfigureForm(FastFormConfiguration configuration, ServerImage image) { // General configuration.AddProperty(x => x.Name) .WithDefaultComponent() .WithPage("General") - .WithValidation(FastValidators.Required); + .WithValidation(FastFormValidators.Required); configuration.AddProperty(x => x.Author) .WithDefaultComponent() .WithPage("General") - .WithValidation(FastValidators.Required); + .WithValidation(FastFormValidators.Required); configuration.AddProperty(x => x.DonateUrl) .WithDefaultComponent() @@ -137,25 +134,25 @@ // Power configuration.AddProperty(x => x.StartupCommand) .WithDefaultComponent() - .WithValidation(FastValidators.Required) + .WithValidation(FastFormValidators.Required) .WithPage("Start, Stop & Status") .WithDescription("This command will be executed at the start of a server. You can use environment variables in a {} here"); configuration.AddProperty(x => x.OnlineDetection) .WithDefaultComponent() - .WithValidation(FastValidators.Required) + .WithValidation(FastFormValidators.Required) .WithPage("Start, Stop & Status") .WithDescription("A regex string specifying that a server is online when the daemon finds a match in the console output matching this expression"); configuration.AddProperty(x => x.StopCommand) .WithDefaultComponent() - .WithValidation(FastValidators.Required) + .WithValidation(FastFormValidators.Required) .WithPage("Start, Stop & Status") .WithDescription("A command which will be sent to the servers stdin when it should get stopped. Power signals can be achived by using ^. E.g. ^C"); // Parsing configuration.AddProperty(x => x.ParseConfiguration) - .WithComponent() + .WithComponent() .WithPage("Parsing"); configuration.AddCustomPage("Variables", ComponentHelper.FromType(parameters => @@ -169,38 +166,40 @@ })); configuration.AddProperty(x => x.AllowDockerImageChange) - .WithComponent() + .WithComponent() .WithPage("Miscellaneous") .WithDescription("This toggle specifies if a user is allowed to change the docker image from the list of docker images associated to the image"); configuration.AddProperty(x => x.DefaultDockerImage) - .WithComponent() - .WithAdditionalOption("Image", image) + .WithComponent(dockerImage => + { + dockerImage.Image = image; + }) .WithPage("Miscellaneous"); configuration.AddProperty(x => x.AllocationsNeeded) .WithDefaultComponent() .WithPage("Miscellaneous") - .WithValidation(x => x > 1 ? ValidationResult.Success : new ValidationResult("This specifies the amount of allocations needed for this image in order to create a server")); + .WithValidation(x => x > 1 ? ValidationResult.Success : new ValidationResult("This specifies the amount of allocations needed for this image in order to create a server")); configuration.AddProperty(x => x.InstallDockerImage) .WithDefaultComponent() .WithPage("Installation") .WithName("Docker Image") - .WithValidation(FastValidators.Required) + .WithValidation(FastFormValidators.Required) .WithValidation(RegexValidator.Create("^(?:[a-zA-Z0-9\\-\\.]+\\/)?[a-zA-Z0-9\\-]+(?:\\/[a-zA-Z0-9\\-]+)*(?::[a-zA-Z0-9_\\.-]+)?$", "You need to provide a valid docker image name")); configuration.AddProperty(x => x.InstallShell) .WithDefaultComponent() .WithPage("Installation") .WithName("Shell") - .WithValidation(FastValidators.Required); + .WithValidation(FastFormValidators.Required); configuration.AddProperty(x => x.InstallScript) - .WithComponent() + .WithComponent() .WithPage("Installation") .WithName("Script") - .WithValidation(FastValidators.Required); + .WithValidation(FastFormValidators.Required); } private Task CustomDelete(ServerImage serverImage) diff --git a/Moonlight/Features/Servers/UI/Views/Admin/Index.razor b/Moonlight/Features/Servers/UI/Views/Admin/Index.razor index 965fd648..c64d9a18 100644 --- a/Moonlight/Features/Servers/UI/Views/Admin/Index.razor +++ b/Moonlight/Features/Servers/UI/Views/Admin/Index.razor @@ -4,9 +4,6 @@ @using Moonlight.Features.Servers.UI.Components @using Microsoft.EntityFrameworkCore @using MoonCore.Abstractions -@using MoonCore.Blazor.Extensions -@using MoonCore.Blazor.Forms.Fast.Components -@using MoonCore.Blazor.Models.Fast @using MoonCore.Exceptions @using Moonlight.Core.Database.Entities @@ -154,102 +151,104 @@ } // Shared form - private void OnConfigureBase(FastConfiguration configuration, Server server) + private void OnConfigureBase(FastFormConfiguration configuration, Server server) { configuration.AddProperty(x => x.Name) .WithDefaultComponent() - .WithValidation(FastValidators.Required); - - Func usernameFunc = x => x.Username; + .WithValidation(FastFormValidators.Required); configuration.AddProperty(x => x.Owner) - .WithComponent>() - .WithAdditionalOption("SearchFunc", usernameFunc) - .WithAdditionalOption("DisplayFunc", usernameFunc) - .WithValidation(FastValidators.Required); - - Func imageNameFunc = x => x.Name; + .WithComponent>(component => + { + component.SearchFunc = x => x.Username; + component.DisplayFunc = x => x.Username; + }) + .WithValidation(FastFormValidators.Required); configuration.AddProperty(x => x.Image) - .WithComponent>() - .WithAdditionalOption("SearchFunc", imageNameFunc) - .WithAdditionalOption("DisplayFunc", imageNameFunc) - .WithValidation(FastValidators.Required); + .WithComponent>(component => + { + component.SearchFunc = x => x.Name; + component.DisplayFunc = x => x.Name; + }) + .WithValidation(FastFormValidators.Required); configuration.AddProperty(x => x.Cpu) .WithDefaultComponent() - .WithValidation(x => x > 0 ? ValidationResult.Success : new("You need to provide a valid value")) + .WithValidation(x => x > 0 ? ValidationResult.Success : new("You need to provide a valid value")) .WithSection("Resources", "bxs-chip") .WithDescription("The cores the server will be able to use. 100 = 1 Core"); configuration.AddProperty(x => x.Memory) - .WithComponent() - .WithAdditionalOption("MinimumUnit", "MB") - .WithAdditionalOption("DefaultUnit", "GB") - .WithValidation(x => x > 0 ? ValidationResult.Success : new("You need to provide a valid value")) + .WithComponent(component => + { + component.MinimumUnit = "MB"; + component.DefaultUnit = "GB"; + }) + .WithValidation(x => x > 0 ? ValidationResult.Success : new("You need to provide a valid value")) .WithSection("Resources") .WithDescription("The amount of memory this server will be able to use"); configuration.AddProperty(x => x.Disk) - .WithComponent() - .WithAdditionalOption("MinimumUnit", "MB") - .WithAdditionalOption("DefaultUnit", "GB") - .WithValidation(x => x > 0 ? ValidationResult.Success : new("You need to provide a valid value")) + .WithComponent(component => + { + component.MinimumUnit = "MB"; + component.DefaultUnit = "GB"; + }) + .WithValidation(x => x > 0 ? ValidationResult.Success : new("You need to provide a valid value")) .WithSection("Resources") .WithDescription("The amount of disk space this server will be able to use"); - Func nodeNameFunc = x => x.Name; - - configuration.AddProperty(x => x.Node) - .WithComponent>() - .WithAdditionalOption("SearchFunc", nodeNameFunc) - .WithAdditionalOption("DisplayFunc", nodeNameFunc) - .WithValidation(FastValidators.Required); - configuration.AddProperty(x => x.UseVirtualDisk) - .WithComponent() + .WithComponent() .WithPage("Advanced options") .WithDescription("Whether to use a virtual disk for storing server files. Dont use this if you want to overallocate as the virtual disks will fill out the space you allocate"); configuration.AddProperty(x => x.DisablePublicNetwork) - .WithComponent() + .WithComponent() .WithPage("Network") .WithDescription("Whether to block all incoming connections to this server from the internet"); + + configuration.AddProperty(x => x.Allocations) + .WithComponent>(component => + { + component.SearchFunc = x => $"{x.IpAddress}:{x.Port}"; + component.DisplayFunc = x => $"{x.IpAddress}:{x.Port}"; + component.ItemsCallback = () =>GetAllocation(server); + }) + .WithPage("Network"); } // Specific form - private void OnConfigureCreate(FastConfiguration configuration, Server server) + private void OnConfigureCreate(FastFormConfiguration configuration, Server server) { OnConfigureBase(configuration, server); - // Allocations - var items = AllocRepository - .Get() - .FromSqlRaw("SELECT * FROM `ServerAllocations` WHERE ServerId IS NULL") - .AsEnumerable(); - - Func buildDisplay = x => $"{x.IpAddress}:{x.Port}"; - - configuration.AddProperty(x => x.Allocations) - .WithMultiSelect(buildDisplay, buildDisplay, items) - .WithPage("Network"); + configuration.AddProperty(x => x.Node) + .WithComponent>(component => + { + component.SearchFunc = x => x.Name; + component.DisplayFunc = x => x.Name; + }) + .WithValidation(FastFormValidators.Required); } - private void OnConfigureEdit(FastConfiguration configuration, Server server) + private void OnConfigureEdit(FastFormConfiguration configuration, Server server) { OnConfigureBase(configuration, server); + } - // Allocations - var items = server.Allocations.Concat( + private IEnumerable GetAllocation(Server server) + { + if (server == null) + return Array.Empty(); + + if (server.Node == null) + return Array.Empty(); + + return server.Allocations.Concat( AllocRepository .Get() - .FromSqlRaw($"SELECT * FROM `ServerAllocations` WHERE ServerId IS NULL AND ServerNodeId = {server.Node.Id}") - .AsEnumerable()); - - Func buildDisplay = x => $"{x.IpAddress}:{x.Port}"; - - configuration.AddProperty(x => x.Allocations) - .WithMultiSelect(buildDisplay, buildDisplay, items) - .WithPage("Network"); + .FromSqlRaw($"SELECT * FROM `ServerAllocations` WHERE ServerId IS NULL AND ServerNodeId = {server.Node.Id}")); } } \ No newline at end of file diff --git a/Moonlight/Features/Servers/UI/Views/Admin/Nodes/Index.razor b/Moonlight/Features/Servers/UI/Views/Admin/Nodes/Index.razor index dd8f4ffd..7183a53f 100644 --- a/Moonlight/Features/Servers/UI/Views/Admin/Nodes/Index.razor +++ b/Moonlight/Features/Servers/UI/Views/Admin/Nodes/Index.razor @@ -1,7 +1,4 @@ @page "/admin/servers/nodes" - -@using System.ComponentModel.DataAnnotations -@using Moonlight.Features.Servers.Models.Forms.Admin.Nodes @using Moonlight.Features.Servers.UI.Components @using Moonlight.Features.Servers.Entities @using MoonCore.Abstractions @@ -9,8 +6,6 @@ @using MoonCore.Exceptions @using MoonCore.Helpers @using System.Text.RegularExpressions; -@using MoonCore.Blazor.Forms.Fast.Components -@using MoonCore.Blazor.Models.Fast @using Moonlight.Features.Servers.Api.Resources @using Moonlight.Features.Servers.Services @using Moonlight.Features.Servers.UI.NodeComponents @@ -207,19 +202,19 @@ }; } - private void OnConfigureCreate(FastConfiguration configuration, ServerNode _) + private void OnConfigureCreate(FastFormConfiguration configuration, ServerNode _) { configuration.AddProperty(x => x.Name) .WithDefaultComponent() - .WithValidation(FastValidators.Required); + .WithValidation(FastFormValidators.Required); configuration.AddProperty(x => x.Fqdn) .WithDefaultComponent() .WithDescription("This needs to be the ip or domain of the node depending on the ssl settings") - .WithValidation(FastValidators.Required); + .WithValidation(FastFormValidators.Required); configuration.AddProperty(x => x.Ssl) - .WithComponent() + .WithComponent() .WithDescription("This enables ssl for the http connections to the node. Only enable this if you have the cert installed on the node"); configuration.AddProperty(x => x.HttpPort) @@ -231,21 +226,21 @@ .WithDescription("This is the ftp port users can use to access their servers filesystem via their ftp client"); } - private void OnConfigureEdit(FastConfiguration configuration, ServerNode node) + private void OnConfigureEdit(FastFormConfiguration configuration, ServerNode node) { configuration.AddProperty(x => x.Name) .WithDefaultComponent() .WithPage("Settings") - .WithValidation(FastValidators.Required); + .WithValidation(FastFormValidators.Required); configuration.AddProperty(x => x.Fqdn) .WithDefaultComponent() .WithPage("Settings") .WithDescription("This needs to be the ip or domain of the node depending on the ssl settings") - .WithValidation(FastValidators.Required); + .WithValidation(FastFormValidators.Required); configuration.AddProperty(x => x.Ssl) - .WithComponent() + .WithComponent() .WithPage("Settings") .WithDescription("This enables ssl for the http connections to the node. Only enable this if you have the cert installed on the node"); diff --git a/Moonlight/Features/Servers/UI/Views/Servers/Networks.razor b/Moonlight/Features/Servers/UI/Views/Servers/Networks.razor index 3815f758..9bd2e5da 100644 --- a/Moonlight/Features/Servers/UI/Views/Servers/Networks.razor +++ b/Moonlight/Features/Servers/UI/Views/Servers/Networks.razor @@ -3,12 +3,9 @@ @using System.ComponentModel.DataAnnotations @using Moonlight.Features.Servers.UI.Components @using Moonlight.Features.Servers.Entities -@using Moonlight.Features.Servers.Models.Forms.Users.Networks @using MoonCore.Abstractions @using Moonlight.Core.Services @using Microsoft.EntityFrameworkCore -@using MoonCore.Blazor.Forms.Fast.Components -@using MoonCore.Blazor.Models.Fast @using MoonCore.Exceptions @inject IdentityService IdentityService @@ -92,24 +89,24 @@ }; } - private void OnConfigureCreate(FastConfiguration configuration, ServerNetwork _) + private void OnConfigureCreate(FastFormConfiguration configuration, ServerNetwork _) { configuration.AddProperty(x => x.Name) .WithDefaultComponent() - .WithValidation(FastValidators.Required); - - Func nodeDisplayField = x => x.Name; + .WithValidation(FastFormValidators.Required); configuration.AddProperty(x => x.Node) - .WithComponent>() - .WithAdditionalOption("DisplayField", nodeDisplayField) - .WithValidation(x => x != null ? ValidationResult.Success : new ValidationResult("You need to specify a node")); + .WithComponent>(component => + { + component.DisplayField = x => x.Name; + }) + .WithValidation(x => x != null ? ValidationResult.Success : new ValidationResult("You need to specify a node")); } - private void OnConfigureEdit(FastConfiguration configuration, ServerNetwork _) + private void OnConfigureEdit(FastFormConfiguration configuration, ServerNetwork _) { configuration.AddProperty(x => x.Name) .WithDefaultComponent() - .WithValidation(FastValidators.Required); + .WithValidation(FastFormValidators.Required); } } \ No newline at end of file diff --git a/Moonlight/Moonlight.csproj b/Moonlight/Moonlight.csproj index 41cc40cc..eef9b2c1 100644 --- a/Moonlight/Moonlight.csproj +++ b/Moonlight/Moonlight.csproj @@ -94,11 +94,16 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + + + + ..\..\..\Masu-Baumgartner\MoonCore\MoonCore\MoonCore.Blazor\bin\Debug\net8.0\MoonCore.Blazor.dll + + diff --git a/Moonlight/_Imports.razor b/Moonlight/_Imports.razor index 8704dafb..d6fc220f 100644 --- a/Moonlight/_Imports.razor +++ b/Moonlight/_Imports.razor @@ -9,7 +9,10 @@ @using MoonCore.Blazor.Helpers @using MoonCore.Blazor.Forms.Table @using MoonCore.Blazor.Forms.Auto -@using MoonCore.Blazor.Forms.Fast +@using MoonCore.Blazor.Models.FastForms +@using MoonCore.Blazor.Models.FastForms.Validators +@using MoonCore.Blazor.Forms.FastForms +@using MoonCore.Blazor.Forms.FastForms.Components @using Moonlight.Core.UI @using Moonlight.Core.Attributes