From 1520d0b2b1da7f38a421cd54429c2bef61f3e045 Mon Sep 17 00:00:00 2001 From: ChiaraBm Date: Thu, 5 Dec 2024 22:17:57 +0100 Subject: [PATCH] Created some request models. Started building create star form together --- .../MoonlightServers.Frontend.csproj | 2 +- MoonlightServers.Frontend/Program.cs | 4 + .../Styles/additions/fonts.css | 3 - MoonlightServers.Frontend/Styles/build.sh | 0 MoonlightServers.Frontend/Styles/style.css | 1 - .../Forms/StarVariableComponent.razor | 90 +++++++++++++++++++ .../UI/Components/Forms/Switch.razor | 38 ++++++++ .../UI/Views/Admin/Index.razor | 4 + .../UI/Views/Admin/Stars/Create.razor | 45 +++++++++- .../UI/Views/Admin/Stars/Index.razor | 5 ++ MoonlightServers.Frontend/UI/_Imports.razor | 6 ++ MoonlightServers.Frontend/UiConstants.cs | 7 ++ .../CreateStarVariableRequest.cs | 26 ++++++ .../Requests/Admin/Stars/CreateStarRequest.cs | 3 + .../Interfaces/IStarVariable.cs | 20 +++++ 15 files changed, 247 insertions(+), 7 deletions(-) delete mode 100644 MoonlightServers.Frontend/Styles/additions/fonts.css mode change 100644 => 100755 MoonlightServers.Frontend/Styles/build.sh create mode 100644 MoonlightServers.Frontend/UI/Components/Forms/StarVariableComponent.razor create mode 100644 MoonlightServers.Frontend/UI/Components/Forms/Switch.razor create mode 100644 MoonlightServers.Frontend/UI/_Imports.razor create mode 100644 MoonlightServers.Frontend/UiConstants.cs create mode 100644 MoonlightServers.Shared/Http/Requests/Admin/StarVariables/CreateStarVariableRequest.cs create mode 100644 MoonlightServers.Shared/Interfaces/IStarVariable.cs diff --git a/MoonlightServers.Frontend/MoonlightServers.Frontend.csproj b/MoonlightServers.Frontend/MoonlightServers.Frontend.csproj index e82c437..1657a57 100644 --- a/MoonlightServers.Frontend/MoonlightServers.Frontend.csproj +++ b/MoonlightServers.Frontend/MoonlightServers.Frontend.csproj @@ -20,7 +20,7 @@ - + diff --git a/MoonlightServers.Frontend/Program.cs b/MoonlightServers.Frontend/Program.cs index 6def57a..959adb2 100644 --- a/MoonlightServers.Frontend/Program.cs +++ b/MoonlightServers.Frontend/Program.cs @@ -1,5 +1,9 @@ +using MoonCore.Blazor.Tailwind.Forms; +using MoonCore.Blazor.Tailwind.Forms.Components; using Moonlight.Client; +FormComponentRepository.Set(); + var startup = new Startup(); await startup.Run(args, [ diff --git a/MoonlightServers.Frontend/Styles/additions/fonts.css b/MoonlightServers.Frontend/Styles/additions/fonts.css deleted file mode 100644 index 1f03944..0000000 --- a/MoonlightServers.Frontend/Styles/additions/fonts.css +++ /dev/null @@ -1,3 +0,0 @@ -@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=fallback'); -@import url('https://fonts.googleapis.com/css2?family=Source+Code+Pro:ital,wght@0,200..900;1,200..900&display=swap'); -@import url("https://cdn.jsdelivr.net/npm/lucide-static@0.460.0/font/lucide.css"); \ No newline at end of file diff --git a/MoonlightServers.Frontend/Styles/build.sh b/MoonlightServers.Frontend/Styles/build.sh old mode 100644 new mode 100755 diff --git a/MoonlightServers.Frontend/Styles/style.css b/MoonlightServers.Frontend/Styles/style.css index ebb7488..d5e5f07 100644 --- a/MoonlightServers.Frontend/Styles/style.css +++ b/MoonlightServers.Frontend/Styles/style.css @@ -2,7 +2,6 @@ @import "tailwindcss/components"; @import "additions/animations.css"; -@import "additions/fonts.css"; @import "additions/buttons.css"; @import "additions/cards.css"; @import "additions/progress.css"; diff --git a/MoonlightServers.Frontend/UI/Components/Forms/StarVariableComponent.razor b/MoonlightServers.Frontend/UI/Components/Forms/StarVariableComponent.razor new file mode 100644 index 0000000..c97a1fe --- /dev/null +++ b/MoonlightServers.Frontend/UI/Components/Forms/StarVariableComponent.razor @@ -0,0 +1,90 @@ +@using MoonCore.Blazor.Tailwind.Forms +@using MoonlightServers.Shared.Enums + +@typeparam TPropertyType where TPropertyType : class, MoonlightServers.Shared.Interfaces.IStarVariable +@inherits BaseFormComponent> + +
+ +
+ +
+ @foreach (var variable in Binder.Value) + { +
+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+ } +
+ +@code +{ + private async Task AddVariable() + { + Binder.Value.Add(Activator.CreateInstance()); + await InvokeAsync(StateHasChanged); + } + + private async Task DeleteVariable(TPropertyType variable) + { + Binder.Value.Remove(variable); + await InvokeAsync(StateHasChanged); + } +} diff --git a/MoonlightServers.Frontend/UI/Components/Forms/Switch.razor b/MoonlightServers.Frontend/UI/Components/Forms/Switch.razor new file mode 100644 index 0000000..05d6f53 --- /dev/null +++ b/MoonlightServers.Frontend/UI/Components/Forms/Switch.razor @@ -0,0 +1,38 @@ +@using System.Diagnostics.CodeAnalysis +@using Microsoft.AspNetCore.Components + +@* TODO: Extract to mooncore? *@ + +@inherits InputBase + +
+
+ + +
+
+ @if (CurrentValue) + { + On + } + else + { + + Off + + } +
+
+ +@code +{ + protected override bool TryParseValueFromString(string? value, out bool result, [NotNullWhen(false)] out string? validationErrorMessage) + { + validationErrorMessage = null; + result = string.Equals(value, "true", StringComparison.OrdinalIgnoreCase); + return true; + } +} diff --git a/MoonlightServers.Frontend/UI/Views/Admin/Index.razor b/MoonlightServers.Frontend/UI/Views/Admin/Index.razor index d475c95..3ba2571 100644 --- a/MoonlightServers.Frontend/UI/Views/Admin/Index.razor +++ b/MoonlightServers.Frontend/UI/Views/Admin/Index.razor @@ -1,2 +1,6 @@ @page "/admin/servers" +@using MoonCore.Blazor.Tailwind.Components + + + diff --git a/MoonlightServers.Frontend/UI/Views/Admin/Stars/Create.razor b/MoonlightServers.Frontend/UI/Views/Admin/Stars/Create.razor index a3ab96f..d0ddd21 100644 --- a/MoonlightServers.Frontend/UI/Views/Admin/Stars/Create.razor +++ b/MoonlightServers.Frontend/UI/Views/Admin/Stars/Create.razor @@ -4,17 +4,19 @@ @using MoonCore.Blazor.Tailwind.Forms @using MoonCore.Blazor.Tailwind.Toasts @using MoonCore.Helpers +@using MoonlightServers.Frontend.UI.Components.Forms @using MoonlightServers.Shared.Http.Requests.Admin.Stars +@using MoonlightServers.Shared.Http.Requests.Admin.StarVariables @inject HttpApiClient ApiClient @inject NavigationManager Navigation @inject ToastService ToastService - + Create @@ -40,7 +42,46 @@ private void OnConfigure(FormConfiguration configuration) { + var generalPage = configuration.WithPage("General"); + + generalPage.WithField(x => x.Name); + generalPage.WithField(x => x.Author); + generalPage.WithField(x => x.DonateUrl); + generalPage.WithField(x => x.UpdateUrl); + + var startStopStatusPage = configuration.WithPage("Start, Stop & Status"); + + startStopStatusPage.WithField(x => x.StartupCommand); + startStopStatusPage.WithField(x => x.StopCommand); + startStopStatusPage.WithField(x => x.OnlineDetection); + + var installationPage = configuration.WithPage("Installation"); + + installationPage.WithField(x => x.InstallShell); + installationPage.WithField(x => x.InstallDockerImage); + + installationPage.WithField(x => x.InstallScript, fieldConfiguration => + { + fieldConfiguration.Columns = 6; + }); + + var parseConfigurationPage = configuration.WithPage("Parse configuration"); + + parseConfigurationPage.WithField(x => x.ParseConfiguration); + + var variablesPage = configuration.WithPage("Variables"); + variablesPage.WithField(x => x.Variables, fieldConfiguration => + { + fieldConfiguration.Columns = 6; + fieldConfiguration.Label = ""; + }) + .WithComponent>(); + + var miscPage = configuration.WithPage("Miscellaneous"); + + miscPage.WithField(x => x.AllowDockerImageChange); + miscPage.WithField(x => x.RequiredAllocations); } private async Task OnSubmit() diff --git a/MoonlightServers.Frontend/UI/Views/Admin/Stars/Index.razor b/MoonlightServers.Frontend/UI/Views/Admin/Stars/Index.razor index fb9f75f..a82989c 100644 --- a/MoonlightServers.Frontend/UI/Views/Admin/Stars/Index.razor +++ b/MoonlightServers.Frontend/UI/Views/Admin/Stars/Index.razor @@ -5,9 +5,14 @@ @using MoonCore.Models @using MoonCore.Blazor.Tailwind.DataTable @using MoonlightServers.Shared.Http.Responses.Admin.Stars +@using MoonCore.Blazor.Tailwind.Components @inject HttpApiClient ApiClient +
+ +
+ diff --git a/MoonlightServers.Frontend/UI/_Imports.razor b/MoonlightServers.Frontend/UI/_Imports.razor new file mode 100644 index 0000000..45f87d6 --- /dev/null +++ b/MoonlightServers.Frontend/UI/_Imports.razor @@ -0,0 +1,6 @@ +@using System.Net.Http +@using Microsoft.AspNetCore.Authorization +@using Microsoft.AspNetCore.Components.Forms +@using Microsoft.AspNetCore.Components.Routing +@using Microsoft.AspNetCore.Components.Web +@using Microsoft.JSInterop \ No newline at end of file diff --git a/MoonlightServers.Frontend/UiConstants.cs b/MoonlightServers.Frontend/UiConstants.cs new file mode 100644 index 0000000..2513bea --- /dev/null +++ b/MoonlightServers.Frontend/UiConstants.cs @@ -0,0 +1,7 @@ +namespace MoonlightServers.Frontend; + +public static class UiConstants +{ + public static readonly string[] AdminNavNames = ["Overview", "Servers", "Nodes", "Stars", "Manager"]; + public static readonly string[] AdminNavLinks = ["/admin/servers", "/admin/servers/all", "/admin/servers/nodes", "/admin/servers/stars", "/admin/servers/manager"]; +} \ No newline at end of file diff --git a/MoonlightServers.Shared/Http/Requests/Admin/StarVariables/CreateStarVariableRequest.cs b/MoonlightServers.Shared/Http/Requests/Admin/StarVariables/CreateStarVariableRequest.cs new file mode 100644 index 0000000..94b0e1c --- /dev/null +++ b/MoonlightServers.Shared/Http/Requests/Admin/StarVariables/CreateStarVariableRequest.cs @@ -0,0 +1,26 @@ +using System.ComponentModel.DataAnnotations; +using MoonlightServers.Shared.Enums; +using MoonlightServers.Shared.Interfaces; + +namespace MoonlightServers.Shared.Http.Requests.Admin.StarVariables; + +public class CreateStarVariableRequest : IStarVariable +{ + [Required(ErrorMessage = "You need to specify a variable name")] + public string Name { get; set; } + + [Required(ErrorMessage = "You need to specify a variable description", AllowEmptyStrings = true)] + public string Description { get; set; } = ""; + + [Required(ErrorMessage = "You need to specify a variable key")] + public string Key { get; set; } + + [Required(ErrorMessage = "You need to specify a variable default value", AllowEmptyStrings = true)] + public string DefaultValue { get; set; } = ""; + + public bool AllowViewing { get; set; } + public bool AllowEditing { get; set; } + + public StarVariableType Type { get; set; } = StarVariableType.Text; + public string? Filter { get; set; } = null; +} \ No newline at end of file diff --git a/MoonlightServers.Shared/Http/Requests/Admin/Stars/CreateStarRequest.cs b/MoonlightServers.Shared/Http/Requests/Admin/Stars/CreateStarRequest.cs index 2ab8f84..2c4c509 100644 --- a/MoonlightServers.Shared/Http/Requests/Admin/Stars/CreateStarRequest.cs +++ b/MoonlightServers.Shared/Http/Requests/Admin/Stars/CreateStarRequest.cs @@ -1,4 +1,5 @@ using System.ComponentModel.DataAnnotations; +using MoonlightServers.Shared.Http.Requests.Admin.StarVariables; namespace MoonlightServers.Shared.Http.Requests.Admin.Stars; @@ -42,4 +43,6 @@ public class CreateStarRequest [Required(ErrorMessage = "You need to provide parse configuration")] public string ParseConfiguration { get; set; } = "[]"; + + public List Variables { get; set; } = new(); } \ No newline at end of file diff --git a/MoonlightServers.Shared/Interfaces/IStarVariable.cs b/MoonlightServers.Shared/Interfaces/IStarVariable.cs new file mode 100644 index 0000000..81b1ae4 --- /dev/null +++ b/MoonlightServers.Shared/Interfaces/IStarVariable.cs @@ -0,0 +1,20 @@ +using MoonlightServers.Shared.Enums; + +namespace MoonlightServers.Shared.Interfaces; + +public interface IStarVariable // For a common abstraction between create and update model to use in a shared form component +{ + public string Name { get; set; } + + public string Description { get; set; } + + public string Key { get; set; } + + public string DefaultValue { get; set; } + + public bool AllowViewing { get; set; } + public bool AllowEditing { get; set; } + + public StarVariableType Type { get; set; } + public string? Filter { get; set; } +} \ No newline at end of file