From de1b54d652f224957e6b2277de9573ae8ff43347 Mon Sep 17 00:00:00 2001 From: ChiaraBm Date: Fri, 6 Dec 2024 15:03:28 +0100 Subject: [PATCH] Add version field to star entity. Implemented a lot of the star crud --- .../Database/Entities/Star.cs | 1 + ...6083153_AddedVersionTagForStar.Designer.cs | 431 ++++++++++++++++++ .../20241206083153_AddedVersionTagForStar.cs | 31 ++ .../ServersDataContextModelSnapshot.cs | 4 + .../Admin/Stars/StarVariablesController.cs | 106 +++++ .../{StarController.cs => StarsController.cs} | 27 +- .../Forms/StarVariableComponent.razor | 90 ---- .../Stars/Modals/CreateParseConfigModal.razor | 77 ++++ .../Modals/CreateStarVariableModal.razor | 79 ++++ .../Stars/Modals/UpdateParseConfigModal.razor | 84 ++++ .../Modals/UpdateStarVariableModel.razor | 87 ++++ .../GeneralStarUpdate.razor | 41 ++ .../InstallationStarUpdate.razor | 28 ++ .../ParseConfigStarUpdate.razor | 133 ++++++ .../StartStopStatusStarUpdate.razor | 28 ++ .../VariablesStarUpdate.razor | 112 +++++ .../UI/Views/Admin/Stars/Create.razor | 46 +- .../UI/Views/Admin/Stars/Index.razor | 20 + .../UI/Views/Admin/Stars/Update.razor | 67 ++- MoonlightServers.Shared/Enums/FileParsers.cs | 7 + .../CreateStarVariableRequest.cs | 3 +- .../UpdateStarVariableRequest.cs | 25 + .../Requests/Admin/Stars/CreateStarRequest.cs | 35 -- .../Requests/Admin/Stars/UpdateStarRequest.cs | 42 ++ .../Admin/Stars/StarDetailResponse.cs | 1 + .../Interfaces/IStarVariable.cs | 20 - .../Models/ParseConfiguration.cs | 17 + 27 files changed, 1448 insertions(+), 194 deletions(-) create mode 100644 MoonlightServers.ApiServer/Database/Migrations/20241206083153_AddedVersionTagForStar.Designer.cs create mode 100644 MoonlightServers.ApiServer/Database/Migrations/20241206083153_AddedVersionTagForStar.cs create mode 100644 MoonlightServers.ApiServer/Http/Controllers/Admin/Stars/StarVariablesController.cs rename MoonlightServers.ApiServer/Http/Controllers/Admin/Stars/{StarController.cs => StarsController.cs} (70%) delete mode 100644 MoonlightServers.Frontend/UI/Components/Forms/StarVariableComponent.razor create mode 100644 MoonlightServers.Frontend/UI/Components/Stars/Modals/CreateParseConfigModal.razor create mode 100644 MoonlightServers.Frontend/UI/Components/Stars/Modals/CreateStarVariableModal.razor create mode 100644 MoonlightServers.Frontend/UI/Components/Stars/Modals/UpdateParseConfigModal.razor create mode 100644 MoonlightServers.Frontend/UI/Components/Stars/Modals/UpdateStarVariableModel.razor create mode 100644 MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/GeneralStarUpdate.razor create mode 100644 MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/InstallationStarUpdate.razor create mode 100644 MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/ParseConfigStarUpdate.razor create mode 100644 MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/StartStopStatusStarUpdate.razor create mode 100644 MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/VariablesStarUpdate.razor create mode 100644 MoonlightServers.Shared/Enums/FileParsers.cs create mode 100644 MoonlightServers.Shared/Http/Requests/Admin/StarVariables/UpdateStarVariableRequest.cs delete mode 100644 MoonlightServers.Shared/Interfaces/IStarVariable.cs create mode 100644 MoonlightServers.Shared/Models/ParseConfiguration.cs diff --git a/MoonlightServers.ApiServer/Database/Entities/Star.cs b/MoonlightServers.ApiServer/Database/Entities/Star.cs index 163c1e7..1bc15b0 100644 --- a/MoonlightServers.ApiServer/Database/Entities/Star.cs +++ b/MoonlightServers.ApiServer/Database/Entities/Star.cs @@ -10,6 +10,7 @@ public class Star // Meta public string Name { get; set; } + public string Version { get; set; } public string Author { get; set; } public string? UpdateUrl { get; set; } public string? DonateUrl { get; set; } diff --git a/MoonlightServers.ApiServer/Database/Migrations/20241206083153_AddedVersionTagForStar.Designer.cs b/MoonlightServers.ApiServer/Database/Migrations/20241206083153_AddedVersionTagForStar.Designer.cs new file mode 100644 index 0000000..1834021 --- /dev/null +++ b/MoonlightServers.ApiServer/Database/Migrations/20241206083153_AddedVersionTagForStar.Designer.cs @@ -0,0 +1,431 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using MoonlightServers.ApiServer.Database; + +#nullable disable + +namespace MoonlightServers.ApiServer.Database.Migrations +{ + [DbContext(typeof(ServersDataContext))] + [Migration("20241206083153_AddedVersionTagForStar")] + partial class AddedVersionTagForStar + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasDefaultSchema("Servers") + .HasAnnotation("ProductVersion", "8.0.11") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Allocation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("IpAddress") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("NodeId") + .HasColumnType("int"); + + b.Property("Port") + .HasColumnType("int"); + + b.Property("ServerId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("NodeId"); + + b.HasIndex("ServerId"); + + b.ToTable("Allocations", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Node", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("EnableDynamicFirewall") + .HasColumnType("tinyint(1)"); + + b.Property("EnableTransparentMode") + .HasColumnType("tinyint(1)"); + + b.Property("Fqdn") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("FtpPort") + .HasColumnType("int"); + + b.Property("HttpPort") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Token") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("Nodes", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Server", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("Bandwidth") + .HasColumnType("int"); + + b.Property("Cpu") + .HasColumnType("int"); + + b.Property("Disk") + .HasColumnType("int"); + + b.Property("DockerImageIndex") + .HasColumnType("int"); + + b.Property("Memory") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("NodeId") + .HasColumnType("int"); + + b.Property("OwnerId") + .HasColumnType("int"); + + b.Property("StarId") + .HasColumnType("int"); + + b.Property("StartupOverride") + .HasColumnType("longtext"); + + b.Property("UseVirtualDisk") + .HasColumnType("tinyint(1)"); + + b.HasKey("Id"); + + b.HasIndex("NodeId"); + + b.HasIndex("StarId"); + + b.ToTable("Servers", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerBackup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("Completed") + .HasColumnType("tinyint(1)"); + + b.Property("CompletedAt") + .HasColumnType("datetime(6)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("Size") + .HasColumnType("bigint"); + + b.Property("Successful") + .HasColumnType("tinyint(1)"); + + b.HasKey("Id"); + + b.ToTable("ServerBackups", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerVariable", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("Key") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ServerId") + .HasColumnType("int"); + + b.Property("Value") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.HasIndex("ServerId"); + + b.ToTable("ServerVariables", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Star", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("AllowDockerImageChange") + .HasColumnType("tinyint(1)"); + + b.Property("Author") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("DonateUrl") + .HasColumnType("longtext"); + + b.Property("InstallDockerImage") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("InstallScript") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("InstallShell") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("OnlineDetection") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ParseConfiguration") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("RequiredAllocations") + .HasColumnType("int"); + + b.Property("StartupCommand") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StopCommand") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("UpdateUrl") + .HasColumnType("longtext"); + + b.Property("Version") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("Stars", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarDockerImage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("AutoPulling") + .HasColumnType("tinyint(1)"); + + b.Property("DisplayName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Identifier") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StarId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("StarId"); + + b.ToTable("StarDockerImages", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarVariable", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("AllowEditing") + .HasColumnType("tinyint(1)"); + + b.Property("AllowViewing") + .HasColumnType("tinyint(1)"); + + b.Property("DefaultValue") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Description") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Filter") + .HasColumnType("longtext"); + + b.Property("Key") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StarId") + .HasColumnType("int"); + + b.Property("Type") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("StarId"); + + b.ToTable("StarVariables", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Allocation", b => + { + b.HasOne("MoonlightServers.ApiServer.Database.Entities.Node", "Node") + .WithMany("Allocations") + .HasForeignKey("NodeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("MoonlightServers.ApiServer.Database.Entities.Server", "Server") + .WithMany("Allocations") + .HasForeignKey("ServerId"); + + b.Navigation("Node"); + + b.Navigation("Server"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Server", b => + { + b.HasOne("MoonlightServers.ApiServer.Database.Entities.Node", "Node") + .WithMany("Servers") + .HasForeignKey("NodeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("MoonlightServers.ApiServer.Database.Entities.Star", "Star") + .WithMany() + .HasForeignKey("StarId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Node"); + + b.Navigation("Star"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerVariable", b => + { + b.HasOne("MoonlightServers.ApiServer.Database.Entities.Server", "Server") + .WithMany() + .HasForeignKey("ServerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Server"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarDockerImage", b => + { + b.HasOne("MoonlightServers.ApiServer.Database.Entities.Star", "Star") + .WithMany("DockerImages") + .HasForeignKey("StarId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Star"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarVariable", b => + { + b.HasOne("MoonlightServers.ApiServer.Database.Entities.Star", "Star") + .WithMany("Variables") + .HasForeignKey("StarId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Star"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Node", b => + { + b.Navigation("Allocations"); + + b.Navigation("Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Server", b => + { + b.Navigation("Allocations"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Star", b => + { + b.Navigation("DockerImages"); + + b.Navigation("Variables"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/MoonlightServers.ApiServer/Database/Migrations/20241206083153_AddedVersionTagForStar.cs b/MoonlightServers.ApiServer/Database/Migrations/20241206083153_AddedVersionTagForStar.cs new file mode 100644 index 0000000..60778f5 --- /dev/null +++ b/MoonlightServers.ApiServer/Database/Migrations/20241206083153_AddedVersionTagForStar.cs @@ -0,0 +1,31 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace MoonlightServers.ApiServer.Database.Migrations +{ + /// + public partial class AddedVersionTagForStar : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Version", + schema: "Servers", + table: "Stars", + type: "longtext", + nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Version", + schema: "Servers", + table: "Stars"); + } + } +} diff --git a/MoonlightServers.ApiServer/Database/Migrations/ServersDataContextModelSnapshot.cs b/MoonlightServers.ApiServer/Database/Migrations/ServersDataContextModelSnapshot.cs index cedcf20..2696ba2 100644 --- a/MoonlightServers.ApiServer/Database/Migrations/ServersDataContextModelSnapshot.cs +++ b/MoonlightServers.ApiServer/Database/Migrations/ServersDataContextModelSnapshot.cs @@ -251,6 +251,10 @@ namespace MoonlightServers.ApiServer.Database.Migrations b.Property("UpdateUrl") .HasColumnType("longtext"); + b.Property("Version") + .IsRequired() + .HasColumnType("longtext"); + b.HasKey("Id"); b.ToTable("Stars", "Servers"); diff --git a/MoonlightServers.ApiServer/Http/Controllers/Admin/Stars/StarVariablesController.cs b/MoonlightServers.ApiServer/Http/Controllers/Admin/Stars/StarVariablesController.cs new file mode 100644 index 0000000..7e8fd53 --- /dev/null +++ b/MoonlightServers.ApiServer/Http/Controllers/Admin/Stars/StarVariablesController.cs @@ -0,0 +1,106 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using MoonCore.Attributes; +using MoonCore.Exceptions; +using MoonCore.Extended.Abstractions; +using MoonCore.Extended.Helpers; +using MoonCore.Helpers; +using MoonCore.Models; +using MoonlightServers.ApiServer.Database.Entities; +using MoonlightServers.Shared.Http.Requests.Admin.StarVariables; +using MoonlightServers.Shared.Http.Responses.Admin.StarVariables; + +namespace MoonlightServers.ApiServer.Http.Controllers.Admin.Stars; + +[ApiController] +[Route("api/admin/servers/stars")] +public class StarVariablesController : Controller +{ + private readonly CrudHelper CrudHelper; + private readonly DatabaseRepository StarRepository; + private readonly DatabaseRepository StarVariableRepository; + + private Star Star; + + public StarVariablesController( + CrudHelper crudHelper, + DatabaseRepository starRepository, + DatabaseRepository starVariableRepository) + { + CrudHelper = crudHelper; + StarRepository = starRepository; + StarVariableRepository = starVariableRepository; + } + + private void ApplyStar(int id) + { + var star = StarRepository + .Get() + .FirstOrDefault(x => x.Id == id); + + if (star == null) + throw new HttpApiException("A star with this id could not be found", 404); + + Star = star; + + CrudHelper.QueryModifier = variables => + variables.Where(x => x.Star.Id == star.Id); + } + + [HttpGet("{starId:int}/variables")] + [RequirePermission("admin.servers.stars.get")] + public async Task> Get([FromRoute] int starId, [FromQuery] int page, [FromQuery] int pageSize) + { + ApplyStar(starId); + + return await CrudHelper.Get(page, pageSize); + } + + [HttpGet("{starId:int}/variables/{id:int}")] + [RequirePermission("admin.servers.stars.get")] + public async Task GetSingle([FromRoute] int starId, [FromRoute] int id) + { + ApplyStar(starId); + + return await CrudHelper.GetSingle(id); + } + + [HttpPost("{starId:int}/variables")] + [RequirePermission("admin.servers.stars.create")] + public async Task Create([FromRoute] int starId, [FromBody] CreateStarVariableRequest request) + { + ApplyStar(starId); + + var starVariable = Mapper.Map(request); + starVariable.Star = Star; + + var finalVariable = StarVariableRepository.Add(starVariable); + + return CrudHelper.MapToResult(finalVariable); + } + + [HttpPatch("{starId:int}/variables/{id:int}")] + [RequirePermission("admin.servers.stars.update")] + public async Task Update([FromRoute] int starId, [FromRoute] int id, + [FromBody] UpdateStarVariableRequest request) + { + ApplyStar(starId); + + var variable = await CrudHelper.GetSingleModel(id); + + variable = Mapper.Map(variable, request); + + StarVariableRepository.Update(variable); + + return CrudHelper.MapToResult(variable); + } + + [HttpDelete("{starId:int}/variables/{id:int}")] + [RequirePermission("admin.servers.stars.delete")] + public async Task Delete([FromRoute] int starId, [FromRoute] int id) + { + ApplyStar(starId); + + await CrudHelper.Delete(id); + } +} \ No newline at end of file diff --git a/MoonlightServers.ApiServer/Http/Controllers/Admin/Stars/StarController.cs b/MoonlightServers.ApiServer/Http/Controllers/Admin/Stars/StarsController.cs similarity index 70% rename from MoonlightServers.ApiServer/Http/Controllers/Admin/Stars/StarController.cs rename to MoonlightServers.ApiServer/Http/Controllers/Admin/Stars/StarsController.cs index 2a039fe..d62e043 100644 --- a/MoonlightServers.ApiServer/Http/Controllers/Admin/Stars/StarController.cs +++ b/MoonlightServers.ApiServer/Http/Controllers/Admin/Stars/StarsController.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using MoonCore.Attributes; +using MoonCore.Extended.Abstractions; using MoonCore.Extended.Helpers; using MoonCore.Helpers; using MoonCore.Models; @@ -14,13 +15,15 @@ namespace MoonlightServers.ApiServer.Http.Controllers.Admin.Stars; [ApiController] [Route("api/admin/servers/stars")] -public class StarController : Controller +public class StarsController : Controller { private readonly CrudHelper CrudHelper; + private readonly DatabaseRepository StarRepository; - public StarController(CrudHelper crudHelper) + public StarsController(CrudHelper crudHelper, DatabaseRepository starRepository) { CrudHelper = crudHelper; + StarRepository = starRepository; CrudHelper.QueryModifier = stars => stars .Include(x => x.Variables) @@ -58,7 +61,25 @@ public class StarController : Controller [RequirePermission("admin.servers.stars.create")] public async Task Create([FromBody] CreateStarRequest request) { - return await CrudHelper.Create(request); + var star = Mapper.Map(request); + + // Default values + star.DonateUrl = null; + star.UpdateUrl = null; + star.Version = "1.0.0"; + star.StartupCommand = "echo Starting up :)"; + star.StopCommand = "^C"; + star.OnlineDetection = "Online text"; + star.InstallShell = "/bin/bash"; + star.InstallDockerImage = "debian:latest"; + star.InstallScript = "echo Installing..."; + star.RequiredAllocations = 1; + star.AllowDockerImageChange = false; + star.ParseConfiguration = "[]"; + + var finalStar = StarRepository.Add(star); + + return CrudHelper.MapToResult(finalStar); } [HttpPatch("{id:int}")] diff --git a/MoonlightServers.Frontend/UI/Components/Forms/StarVariableComponent.razor b/MoonlightServers.Frontend/UI/Components/Forms/StarVariableComponent.razor deleted file mode 100644 index c97a1fe..0000000 --- a/MoonlightServers.Frontend/UI/Components/Forms/StarVariableComponent.razor +++ /dev/null @@ -1,90 +0,0 @@ -@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/Stars/Modals/CreateParseConfigModal.razor b/MoonlightServers.Frontend/UI/Components/Stars/Modals/CreateParseConfigModal.razor new file mode 100644 index 0000000..8761b1e --- /dev/null +++ b/MoonlightServers.Frontend/UI/Components/Stars/Modals/CreateParseConfigModal.razor @@ -0,0 +1,77 @@ +@using MoonCore.Blazor.Tailwind.Modals.Components +@using MoonlightServers.Shared.Enums +@using MoonCore.Blazor.Tailwind.Components +@using MoonlightServers.Shared.Models + +@inherits BaseModal + +

Add a new parse configuration

+ + +
+
+ + +
+ +
+ + +
+ +
+ +
+ + @foreach (var entry in Form.Entries) + { +
+
+ + + +
+
+ } +
+
+ +
+ Cancel + Create +
+ +@code +{ + [Parameter] public Func OnSubmit { get; set; } + + private ParseConfiguration Form = new(); + private HandleForm HandleForm; + + private async Task OnValidSubmit() + { + await OnSubmit.Invoke(Form); + await Hide(); + } + + private Task Submit() => HandleForm.Submit(); + + private async Task AddEntry() + { + Form.Entries.Add(new()); + await InvokeAsync(StateHasChanged); + } + + private async Task RemoveEntry(ParseConfiguration.ParseConfigurationEntry entry) + { + Form.Entries.Remove(entry); + await InvokeAsync(StateHasChanged); + } +} diff --git a/MoonlightServers.Frontend/UI/Components/Stars/Modals/CreateStarVariableModal.razor b/MoonlightServers.Frontend/UI/Components/Stars/Modals/CreateStarVariableModal.razor new file mode 100644 index 0000000..075e094 --- /dev/null +++ b/MoonlightServers.Frontend/UI/Components/Stars/Modals/CreateStarVariableModal.razor @@ -0,0 +1,79 @@ +@using MoonCore.Blazor.Tailwind.Modals.Components +@using MoonlightServers.Shared.Enums +@using MoonlightServers.Shared.Http.Requests.Admin.StarVariables +@using MoonlightServers.Frontend.UI.Components.Forms +@using MoonCore.Blazor.Tailwind.Components + +@inherits BaseModal + +

Add a new variable

+ + +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+
+ +
+ Cancel + Create +
+ +@code +{ + [Parameter] public Func OnSubmit { get; set; } + + private CreateStarVariableRequest Form = new(); + private HandleForm HandleForm; + + private async Task OnValidSubmit() + { + await OnSubmit.Invoke(Form); + await Hide(); + } + + private Task Submit() => HandleForm.Submit(); +} diff --git a/MoonlightServers.Frontend/UI/Components/Stars/Modals/UpdateParseConfigModal.razor b/MoonlightServers.Frontend/UI/Components/Stars/Modals/UpdateParseConfigModal.razor new file mode 100644 index 0000000..7aad328 --- /dev/null +++ b/MoonlightServers.Frontend/UI/Components/Stars/Modals/UpdateParseConfigModal.razor @@ -0,0 +1,84 @@ +@using MoonCore.Blazor.Tailwind.Modals.Components +@using MoonlightServers.Shared.Enums +@using MoonCore.Blazor.Tailwind.Components +@using MoonCore.Helpers +@using MoonlightServers.Shared.Models + +@inherits BaseModal + +

Update parse configuration

+ + +
+
+ + +
+ +
+ + +
+ +
+ +
+ + @foreach (var entry in Form.Entries) + { +
+
+ + + +
+
+ } +
+
+ +
+ Save changes +
+ +@code +{ + [Parameter] public Func OnSubmit { get; set; } + [Parameter] public ParseConfiguration Configuration { get; set; } + + private ParseConfiguration Form; + private HandleForm HandleForm; + + protected override void OnInitialized() + { + // Manual mapping :( + Form = Configuration; + } + + private async Task OnValidSubmit() + { + await OnSubmit.Invoke(Form); + await Hide(); + } + + private Task Submit() => HandleForm.Submit(); + + private async Task AddEntry() + { + Form.Entries.Add(new()); + await InvokeAsync(StateHasChanged); + } + + private async Task RemoveEntry(ParseConfiguration.ParseConfigurationEntry entry) + { + Form.Entries.Remove(entry); + await InvokeAsync(StateHasChanged); + } +} \ No newline at end of file diff --git a/MoonlightServers.Frontend/UI/Components/Stars/Modals/UpdateStarVariableModel.razor b/MoonlightServers.Frontend/UI/Components/Stars/Modals/UpdateStarVariableModel.razor new file mode 100644 index 0000000..9be1f6f --- /dev/null +++ b/MoonlightServers.Frontend/UI/Components/Stars/Modals/UpdateStarVariableModel.razor @@ -0,0 +1,87 @@ +@using MoonCore.Blazor.Tailwind.Modals.Components +@using MoonlightServers.Shared.Enums +@using MoonlightServers.Shared.Http.Requests.Admin.StarVariables +@using MoonlightServers.Frontend.UI.Components.Forms +@using MoonCore.Blazor.Tailwind.Components +@using MoonCore.Helpers +@using MoonlightServers.Shared.Http.Responses.Admin.StarVariables + +@inherits BaseModal + +

Update variable

+ + +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+
+ +
+ Cancel + Update +
+ +@code +{ + [Parameter] public Func OnSubmit { get; set; } + [Parameter] public StarVariableDetailResponse Variable { get; set; } + + private UpdateStarVariableRequest Form; + private HandleForm HandleForm; + + protected override void OnInitialized() + { + Form = Mapper.Map(Variable); + } + + private async Task OnValidSubmit() + { + await OnSubmit.Invoke(Form); + await Hide(); + } + + private Task Submit() => HandleForm.Submit(); +} diff --git a/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/GeneralStarUpdate.razor b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/GeneralStarUpdate.razor new file mode 100644 index 0000000..bb29486 --- /dev/null +++ b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/GeneralStarUpdate.razor @@ -0,0 +1,41 @@ +@using MoonlightServers.Shared.Http.Requests.Admin.Stars + +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +@code +{ + [Parameter] public UpdateStarRequest Request { get; set; } +} \ No newline at end of file diff --git a/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/InstallationStarUpdate.razor b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/InstallationStarUpdate.razor new file mode 100644 index 0000000..22b3913 --- /dev/null +++ b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/InstallationStarUpdate.razor @@ -0,0 +1,28 @@ +@using MoonlightServers.Shared.Http.Requests.Admin.Stars +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +@code +{ + [Parameter] public UpdateStarRequest Request { get; set; } +} \ No newline at end of file diff --git a/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/ParseConfigStarUpdate.razor b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/ParseConfigStarUpdate.razor new file mode 100644 index 0000000..91dc850 --- /dev/null +++ b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/ParseConfigStarUpdate.razor @@ -0,0 +1,133 @@ +@using System.Text.Json +@using MoonCore.Blazor.Tailwind.Alerts +@using MoonCore.Blazor.Tailwind.Modals +@using MoonCore.Blazor.Tailwind.Toasts +@using MoonlightServers.Frontend.UI.Components.Stars.Modals +@using MoonlightServers.Shared.Http.Requests.Admin.Stars +@using MoonlightServers.Shared.Models + +@inject ILogger Logger +@inject ModalService ModalService +@inject AlertService AlertService +@inject ToastService ToastService + +
+ +
+ +@if (HasParseError) +{ + +} +else +{ +
+ @foreach (var configuration in Configurations) + { +
+
+
+ + @configuration.File +
+ +
+ + + +
+
+
+ } +
+} + +@code +{ + [Parameter] public UpdateStarRequest Request { get; set; } + + private List Configurations; + private bool HasParseError = false; + + protected override Task OnInitializedAsync() + { + ReadFromJson(); + return Task.CompletedTask; + } + + private async Task AddConfig() + { + Func onSubmit = async configuration => + { + Configurations.Add(configuration); + SaveChanges(); + + await InvokeAsync(StateHasChanged); + await ToastService.Success("Successfully created parse configuration"); + }; + + await ModalService.Launch(parameters => + { + parameters.Add("OnSubmit", onSubmit); + }, "max-w-xl"); + } + + private async Task UpdateConfig(ParseConfiguration configuration) + { + Func onSubmit = async _ => + { + SaveChanges(); + + await InvokeAsync(StateHasChanged); + await ToastService.Success("Successfully updated parse configuration"); + }; + + await ModalService.Launch(parameters => + { + parameters.Add("OnSubmit", onSubmit); + parameters.Add("Configuration", configuration); + }, "max-w-xl"); + } + + private async Task DeleteConfig(ParseConfiguration configuration) + { + await AlertService.ConfirmDanger( + "Parse configuration deletion", + "Do you really want to delete the selected parse configuration", + async () => + { + Configurations.Remove(configuration); + SaveChanges(); + + await InvokeAsync(StateHasChanged); + await ToastService.Success("Successfully deleted parse configuration"); + } + ); + } + + private void SaveChanges() + { + Request.ParseConfiguration = JsonSerializer.Serialize(Configurations); + ReadFromJson(); + } + + private void ReadFromJson() + { + try + { + Configurations = JsonSerializer.Deserialize>(Request.ParseConfiguration) + ?? throw new ArgumentNullException(); + + HasParseError = false; + } + catch (Exception e) + { + Logger.LogWarning("An error occured while reading parse configuration: {e}", e); + HasParseError = true; + } + } +} \ No newline at end of file diff --git a/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/StartStopStatusStarUpdate.razor b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/StartStopStatusStarUpdate.razor new file mode 100644 index 0000000..8d83ada --- /dev/null +++ b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/StartStopStatusStarUpdate.razor @@ -0,0 +1,28 @@ +@using MoonlightServers.Shared.Http.Requests.Admin.Stars +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +@code +{ + [Parameter] public UpdateStarRequest Request { get; set; } +} \ No newline at end of file diff --git a/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/VariablesStarUpdate.razor b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/VariablesStarUpdate.razor new file mode 100644 index 0000000..6ba2156 --- /dev/null +++ b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/VariablesStarUpdate.razor @@ -0,0 +1,112 @@ +@using MoonCore.Blazor.Tailwind.Alerts +@using MoonlightServers.Shared.Http.Responses.Admin.Stars +@using MoonlightServers.Shared.Http.Responses.Admin.StarVariables +@using MoonCore.Blazor.Tailwind.Components +@using MoonCore.Blazor.Tailwind.Modals +@using MoonCore.Blazor.Tailwind.Toasts +@using MoonCore.Helpers +@using MoonCore.Models +@using MoonlightServers.Frontend.UI.Components.Stars.Modals +@using MoonlightServers.Shared.Http.Requests.Admin.StarVariables + +@inject HttpApiClient ApiClient +@inject ModalService ModalService +@inject AlertService AlertService +@inject ToastService ToastService + +
+ +
+ + +
+ @foreach (var variable in Variables) + { +
+
+
+ + @variable.Name +
+ +
+ + + +
+
+
+ } +
+
+ +@code +{ + [Parameter] public StarDetailResponse Star { get; set; } + + private StarVariableDetailResponse[] Variables; + private LazyLoader LazyLoader; + + private async Task Load(LazyLoader arg) + { + var pagedVariables = await ApiClient.GetJson>( + $"api/admin/servers/stars/{Star.Id}/variables?page=0&pageSize=50" + ); + + Variables = pagedVariables.Items; + } + + private async Task AddVariable() + { + Func onSubmit = async request => + { + await ApiClient.Post($"api/admin/servers/stars/{Star.Id}/variables", request); + + await ToastService.Success("Successfully created variable"); + await LazyLoader.Reload(); + }; + + await ModalService.Launch(parameters => + { + parameters.Add("OnSubmit", onSubmit); + }, "max-w-xl"); + } + + private async Task UpdateVariable(StarVariableDetailResponse variable) + { + Func onSubmit = async request => + { + await ApiClient.Patch($"api/admin/servers/stars/{Star.Id}/variables/{variable.Id}", request); + + await ToastService.Success("Successfully updated variable"); + await LazyLoader.Reload(); + }; + + await ModalService.Launch(parameters => + { + parameters.Add("OnSubmit", onSubmit); + parameters.Add("Variable", variable); + }, "max-w-xl"); + } + + private async Task DeleteVariable(StarVariableDetailResponse variable) + { + await AlertService.ConfirmDanger( + "Delete variable", + "Do you really want to delete the selected variable? This cannot be undone", + async () => + { + await ApiClient.Delete($"api/admin/servers/stars/{Star.Id}/variables/{variable.Id}"); + + await ToastService.Success("Successfully deleted variable"); + await LazyLoader.Reload(); + } + ); + + await InvokeAsync(StateHasChanged); + } +} diff --git a/MoonlightServers.Frontend/UI/Views/Admin/Stars/Create.razor b/MoonlightServers.Frontend/UI/Views/Admin/Stars/Create.razor index d0ddd21..7bc34f2 100644 --- a/MoonlightServers.Frontend/UI/Views/Admin/Stars/Create.razor +++ b/MoonlightServers.Frontend/UI/Views/Admin/Stars/Create.razor @@ -4,6 +4,7 @@ @using MoonCore.Blazor.Tailwind.Forms @using MoonCore.Blazor.Tailwind.Toasts @using MoonCore.Helpers +@using Moonlight.Client.Services @using MoonlightServers.Frontend.UI.Components.Forms @using MoonlightServers.Shared.Http.Requests.Admin.Stars @using MoonlightServers.Shared.Http.Requests.Admin.StarVariables @@ -11,6 +12,7 @@ @inject HttpApiClient ApiClient @inject NavigationManager Navigation @inject ToastService ToastService +@inject IdentityService IdentityService