From 514f862a9dbdd7560e286ca10b7bebbfffe3c544 Mon Sep 17 00:00:00 2001 From: ChiaraBm Date: Tue, 15 Jul 2025 19:21:44 +0200 Subject: [PATCH] Started refactoring to be compatible with the changed nuget packages and the mooncore changes --- .../DevPluginLoader.cs | 10 ++ .../MoonlightServers.ApiServer.Runtime.csproj | 21 ++++ MoonlightServers.ApiServer.Runtime/Program.cs | 31 +++++ .../Helpers/NodeAuthScheme.cs | 2 + .../Admin/Nodes/NodeAllocationsController.cs | 84 +++++-------- .../Admin/Nodes/NodesController.cs | 76 +++++++++--- .../Servers/ServerVariablesController.cs | 30 +++-- .../Admin/Servers/ServersController.cs | 116 ++++++++++++------ .../Admin/Stars/StarDockerImagesController.cs | 70 ++++++----- .../Admin/Stars/StarImportExportController.cs | 1 + .../Controllers/Remote/ServersController.cs | 1 + .../Mappers/AllocationMapper.cs | 14 +++ .../Mappers/DockerImageMapper.cs | 15 +++ .../Mappers/NodeMapper.cs | 14 +++ .../Mappers/ServerMapper.cs | 25 ++++ .../Mappers/ServerVariableMapper.cs | 11 ++ .../Mappers/StarVariableMapper.cs | 14 +++ .../MoonlightServers.ApiServer.csproj | 8 +- MoonlightServers.ApiServer/Program.cs | 18 --- .../Services/NodeBootService.cs | 2 + .../Services/StarImportExportService.cs | 1 + .../Startup/PluginStartup.cs | 4 + .../DevPluginLoader.cs | 10 ++ .../MoonlightServers.Frontend.Runtime.csproj | 23 ++++ MoonlightServers.Frontend.Runtime/Program.cs | 20 +++ .../Helpers/ServerFileSystemProvider.cs | 2 + .../MoonlightServers.Frontend.csproj | 5 +- MoonlightServers.Frontend/Program.cs | 1 + .../Nodes/Modals/CreateAllocationModal.razor | 3 +- .../CreateMultipleAllocationModal.razor | 3 +- .../Nodes/Modals/UpdateAllocationModal.razor | 5 +- .../AllocationsNodeUpdate.razor | 26 ++-- .../OverviewNodeUpdate.razor | 4 +- .../AllocationsServerCreate.razor | 6 +- .../GeneralServerCreate.razor | 6 +- .../VariablesServerCreate.razor | 1 + .../Components/Servers/CreateShareModal.razor | 1 + .../Servers/ServerTabs/FilesTab.razor | 1 + .../Servers/ServerTabs/SettingsTab.razor | 2 + .../Servers/ServerTabs/SharesTab.razor | 4 + .../Servers/ServerTabs/VariablesTab.razor | 2 + .../AllocationsServerUpdate.razor | 8 +- .../VariablesServerUpdate.razor | 11 +- .../Components/Servers/UpdateShareModal.razor | 1 + .../Stars/Modals/CreateDockerImageModal.razor | 3 +- .../Stars/Modals/CreateParseConfigModal.razor | 3 +- .../Stars/Modals/CreateVariableModal.razor | 3 +- .../Stars/Modals/UpdateDockerImageModal.razor | 3 +- .../Stars/Modals/UpdateParseConfigModal.razor | 3 +- .../Stars/Modals/UpdateVariableModal.razor | 3 +- .../DockerImageStarUpdate.razor | 4 + .../InstallationStarUpdate.razor | 1 + .../UpdateStarPartials/MiscStarUpdate.razor | 1 + .../ParseConfigStarUpdate.razor | 3 + .../VariablesStarUpdate.razor | 4 + .../UI/Views/Admin/All/Create.razor | 2 + .../UI/Views/Admin/All/Index.razor | 33 ++--- .../UI/Views/Admin/All/Update.razor | 6 +- .../UI/Views/Admin/Nodes/Create.razor | 2 + .../UI/Views/Admin/Nodes/Index.razor | 31 ++--- .../UI/Views/Admin/Nodes/Update.razor | 6 +- .../UI/Views/Admin/Stars/Create.razor | 2 + .../UI/Views/Admin/Stars/Index.razor | 4 + .../UI/Views/Admin/Stars/Update.razor | 2 + .../UI/Views/Client/Index.razor | 1 + .../UI/Views/Client/Manage.razor | 1 + ...lResponse.cs => NodeAllocationResponse.cs} | 2 +- ...{NodeDetailResponse.cs => NodeResponse.cs} | 2 +- ...lResponse.cs => ServerVariableResponse.cs} | 2 +- ...verDetailResponse.cs => ServerResponse.cs} | 5 +- MoonlightServers.sln | 18 +++ 71 files changed, 616 insertions(+), 247 deletions(-) create mode 100644 MoonlightServers.ApiServer.Runtime/DevPluginLoader.cs create mode 100644 MoonlightServers.ApiServer.Runtime/MoonlightServers.ApiServer.Runtime.csproj create mode 100644 MoonlightServers.ApiServer.Runtime/Program.cs create mode 100644 MoonlightServers.ApiServer/Mappers/AllocationMapper.cs create mode 100644 MoonlightServers.ApiServer/Mappers/DockerImageMapper.cs create mode 100644 MoonlightServers.ApiServer/Mappers/NodeMapper.cs create mode 100644 MoonlightServers.ApiServer/Mappers/ServerMapper.cs create mode 100644 MoonlightServers.ApiServer/Mappers/ServerVariableMapper.cs create mode 100644 MoonlightServers.ApiServer/Mappers/StarVariableMapper.cs delete mode 100644 MoonlightServers.ApiServer/Program.cs create mode 100644 MoonlightServers.Frontend.Runtime/DevPluginLoader.cs create mode 100644 MoonlightServers.Frontend.Runtime/MoonlightServers.Frontend.Runtime.csproj create mode 100644 MoonlightServers.Frontend.Runtime/Program.cs rename MoonlightServers.Shared/Http/Responses/Admin/NodeAllocations/{NodeAllocationDetailResponse.cs => NodeAllocationResponse.cs} (81%) rename MoonlightServers.Shared/Http/Responses/Admin/Nodes/{NodeDetailResponse.cs => NodeResponse.cs} (91%) rename MoonlightServers.Shared/Http/Responses/Admin/ServerVariables/{ServerVariableDetailResponse.cs => ServerVariableResponse.cs} (81%) rename MoonlightServers.Shared/Http/Responses/Admin/Servers/{ServerDetailResponse.cs => ServerResponse.cs} (77%) diff --git a/MoonlightServers.ApiServer.Runtime/DevPluginLoader.cs b/MoonlightServers.ApiServer.Runtime/DevPluginLoader.cs new file mode 100644 index 0000000..61a7b17 --- /dev/null +++ b/MoonlightServers.ApiServer.Runtime/DevPluginLoader.cs @@ -0,0 +1,10 @@ +using MoonCore.PluginFramework; +using Moonlight.ApiServer.Plugins; + +namespace MoonlightServers.ApiServer.Runtime; + +[PluginLoader] +public partial class DevPluginLoader : IPluginStartup +{ + +} \ No newline at end of file diff --git a/MoonlightServers.ApiServer.Runtime/MoonlightServers.ApiServer.Runtime.csproj b/MoonlightServers.ApiServer.Runtime/MoonlightServers.ApiServer.Runtime.csproj new file mode 100644 index 0000000..ea514a0 --- /dev/null +++ b/MoonlightServers.ApiServer.Runtime/MoonlightServers.ApiServer.Runtime.csproj @@ -0,0 +1,21 @@ + + + + net9.0 + enable + enable + True + + + + + + + + + + + + + + diff --git a/MoonlightServers.ApiServer.Runtime/Program.cs b/MoonlightServers.ApiServer.Runtime/Program.cs new file mode 100644 index 0000000..944f9a0 --- /dev/null +++ b/MoonlightServers.ApiServer.Runtime/Program.cs @@ -0,0 +1,31 @@ +using Moonlight.ApiServer.Startup; +using MoonlightServers.ApiServer.Runtime; + +var pluginLoader = new DevPluginLoader(); +pluginLoader.Initialize(); + +var cs = new Startup(); + +await cs.Initialize(args, pluginLoader.Instances); + +var builder = WebApplication.CreateBuilder(args); + +await cs.AddMoonlight(builder); + +var app = builder.Build(); + +await cs.AddMoonlight(app); + +// Handle setup of wasm app hosting in the runtime +// so the Moonlight.ApiServer doesn't need the wasm package +if (cs.Configuration.Frontend.EnableHosting) +{ + if (app.Environment.IsDevelopment()) + app.UseWebAssemblyDebugging(); + + app.UseBlazorFrameworkFiles(); + app.UseStaticFiles(); +} + + +await app.RunAsync(); \ No newline at end of file diff --git a/MoonlightServers.ApiServer/Helpers/NodeAuthScheme.cs b/MoonlightServers.ApiServer/Helpers/NodeAuthScheme.cs index bdceace..7f32baf 100644 --- a/MoonlightServers.ApiServer/Helpers/NodeAuthScheme.cs +++ b/MoonlightServers.ApiServer/Helpers/NodeAuthScheme.cs @@ -2,6 +2,8 @@ using System.Security.Claims; using System.Text.Encodings.Web; using Microsoft.AspNetCore.Authentication; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using MoonCore.Extended.Abstractions; using MoonlightServers.ApiServer.Database.Entities; diff --git a/MoonlightServers.ApiServer/Http/Controllers/Admin/Nodes/NodeAllocationsController.cs b/MoonlightServers.ApiServer/Http/Controllers/Admin/Nodes/NodeAllocationsController.cs index 6e8b4fa..e6eacd8 100644 --- a/MoonlightServers.ApiServer/Http/Controllers/Admin/Nodes/NodeAllocationsController.cs +++ b/MoonlightServers.ApiServer/Http/Controllers/Admin/Nodes/NodeAllocationsController.cs @@ -6,6 +6,7 @@ using MoonCore.Exceptions; using MoonCore.Extended.Abstractions; using MoonCore.Models; using MoonlightServers.ApiServer.Database.Entities; +using MoonlightServers.ApiServer.Mappers; using MoonlightServers.Shared.Http.Requests.Admin.NodeAllocations; using MoonlightServers.Shared.Http.Responses.Admin.NodeAllocations; @@ -29,9 +30,9 @@ public class NodeAllocationsController : Controller [HttpGet("{nodeId:int}/allocations")] [Authorize(Policy = "permissions:admin.servers.nodes.get")] - public async Task> Get( + public async Task> Get( [FromRoute] int nodeId, - [FromQuery] int page, + [FromQuery] [Range(0, int.MaxValue)] int page, [FromQuery] [Range(1, 100)] int pageSize ) { @@ -44,14 +45,11 @@ public class NodeAllocationsController : Controller .Where(x => x.Node.Id == nodeId) .ToArrayAsync(); - var mappedAllocations = allocations.Select(x => new NodeAllocationDetailResponse() - { - Id = x.Id, - IpAddress = x.IpAddress, - Port = x.Port - }).ToArray(); + var mappedAllocations = allocations + .Select(AllocationMapper.ToNodeAllocation) + .ToArray(); - return new PagedData() + return new PagedData() { Items = mappedAllocations, CurrentPage = page, @@ -63,7 +61,7 @@ public class NodeAllocationsController : Controller [HttpGet("{nodeId:int}/allocations/{id:int}")] [Authorize(Policy = "permissions:admin.servers.nodes.get")] - public async Task GetSingle([FromRoute] int nodeId, [FromRoute] int id) + public async Task GetSingle([FromRoute] int nodeId, [FromRoute] int id) { var allocation = await AllocationRepository .Get() @@ -73,17 +71,12 @@ public class NodeAllocationsController : Controller if (allocation == null) throw new HttpApiException("No allocation with that id found", 404); - return new() - { - Id = allocation.Id, - IpAddress = allocation.IpAddress, - Port = allocation.Port - }; + return AllocationMapper.ToNodeAllocation(allocation); } [HttpPost("{nodeId:int}/allocations")] [Authorize(Policy = "permissions:admin.servers.nodes.create")] - public async Task Create( + public async Task Create( [FromRoute] int nodeId, [FromBody] CreateNodeAllocationRequest request ) @@ -95,26 +88,19 @@ public class NodeAllocationsController : Controller if (node == null) throw new HttpApiException("No node with that id found", 404); - var allocation = new Allocation - { - IpAddress = request.IpAddress, - Port = request.Port, - Node = node - }; + var allocation = AllocationMapper.ToAllocation(request); - var finalVariable = await AllocationRepository.Add(allocation); + var finalAllocation = await AllocationRepository.Add(allocation); - return new() - { - Id = finalVariable.Id, - IpAddress = finalVariable.IpAddress, - Port = finalVariable.Port - }; + return AllocationMapper.ToNodeAllocation(finalAllocation); } [HttpPatch("{nodeId:int}/allocations/{id:int}")] - public async Task Update([FromRoute] int nodeId, [FromRoute] int id, - [FromBody] UpdateNodeAllocationRequest request) + public async Task Update( + [FromRoute] int nodeId, + [FromRoute] int id, + [FromBody] UpdateNodeAllocationRequest request + ) { var allocation = await AllocationRepository .Get() @@ -124,17 +110,10 @@ public class NodeAllocationsController : Controller if (allocation == null) throw new HttpApiException("No allocation with that id found", 404); - allocation.IpAddress = request.IpAddress; - allocation.Port = request.Port; - + AllocationMapper.Merge(request, allocation); await AllocationRepository.Update(allocation); - - return new() - { - Id = allocation.Id, - IpAddress = allocation.IpAddress, - Port = allocation.Port - }; + + return AllocationMapper.ToNodeAllocation(allocation); } [HttpDelete("{nodeId:int}/allocations/{id:int}")] @@ -160,7 +139,7 @@ public class NodeAllocationsController : Controller if (node == null) throw new HttpApiException("No node with that id found", 404); - + var existingAllocations = AllocationRepository .Get() .Where(x => x.Node.Id == nodeId) @@ -202,8 +181,12 @@ public class NodeAllocationsController : Controller [HttpGet("{nodeId:int}/allocations/free")] [Authorize(Policy = "permissions:admin.servers.nodes.get")] - public async Task> GetFree([FromRoute] int nodeId, [FromQuery] int page, - [FromQuery][Range(1, 100)] int pageSize, [FromQuery] int serverId = -1) + public async Task> GetFree( + [FromRoute] int nodeId, + [FromQuery] int page, + [FromQuery] [Range(1, 100)] int pageSize, + [FromQuery] int serverId = -1 + ) { var node = NodeRepository .Get() @@ -220,14 +203,11 @@ public class NodeAllocationsController : Controller var count = await freeAllocationsQuery.CountAsync(); var allocations = await freeAllocationsQuery.ToArrayAsync(); - var mappedAllocations = allocations.Select(x => new NodeAllocationDetailResponse() - { - Id = x.Id, - IpAddress = x.IpAddress, - Port = x.Port - }).ToArray(); + var mappedAllocations = allocations + .Select(AllocationMapper.ToNodeAllocation) + .ToArray(); - return new PagedData() + return new PagedData() { Items = mappedAllocations, CurrentPage = page, diff --git a/MoonlightServers.ApiServer/Http/Controllers/Admin/Nodes/NodesController.cs b/MoonlightServers.ApiServer/Http/Controllers/Admin/Nodes/NodesController.cs index c399916..becf41b 100644 --- a/MoonlightServers.ApiServer/Http/Controllers/Admin/Nodes/NodesController.cs +++ b/MoonlightServers.ApiServer/Http/Controllers/Admin/Nodes/NodesController.cs @@ -1,13 +1,14 @@ +using System.ComponentModel.DataAnnotations; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using MoonCore.Extended.Abstractions; -using MoonCore.Extended.Helpers; using Microsoft.AspNetCore.Authorization; +using MoonCore.Exceptions; using MoonCore.Helpers; using MoonCore.Models; using MoonlightServers.ApiServer.Database.Entities; +using MoonlightServers.ApiServer.Mappers; using MoonlightServers.Shared.Http.Requests.Admin.Nodes; -using MoonlightServers.Shared.Http.Responses.Admin.NodeAllocations; using MoonlightServers.Shared.Http.Responses.Admin.Nodes; namespace MoonlightServers.ApiServer.Http.Controllers.Admin.Nodes; @@ -16,57 +17,102 @@ namespace MoonlightServers.ApiServer.Http.Controllers.Admin.Nodes; [Route("api/admin/servers/nodes")] public class NodesController : Controller { - private readonly CrudHelper CrudHelper; private readonly DatabaseRepository NodeRepository; public NodesController( - CrudHelper crudHelper, DatabaseRepository nodeRepository ) { - CrudHelper = crudHelper; NodeRepository = nodeRepository; } [HttpGet] [Authorize(Policy = "permissions:admin.servers.nodes.get")] - public async Task> Get([FromQuery] int page, [FromQuery] int pageSize) + public async Task> Get( + [FromQuery] [Range(0, int.MaxValue)] int page, + [FromQuery] [Range(1, 100)] int pageSize + ) { - return await CrudHelper.Get(page, pageSize); + var query = NodeRepository + .Get(); + + var count = await query.CountAsync(); + + var items = await query + .Skip(page * pageSize) + .Take(pageSize) + .ToArrayAsync(); + + var mappedItems = items + .Select(NodeMapper.ToAdminNodeResponse) + .ToArray(); + + return new PagedData() + { + Items = mappedItems, + CurrentPage = page, + PageSize = pageSize, + TotalItems = count, + TotalPages = count == 0 ? 0 : count / pageSize + }; } [HttpGet("{id:int}")] [Authorize(Policy = "permissions:admin.servers.nodes.get")] - public async Task GetSingle([FromRoute] int id) + public async Task GetSingle([FromRoute] int id) { - return await CrudHelper.GetSingle(id); + var node = await NodeRepository + .Get() + .FirstOrDefaultAsync(x => x.Id == id); + + if (node == null) + throw new HttpApiException("No node with this id found", 404); + + return NodeMapper.ToAdminNodeResponse(node); } [HttpPost] [Authorize(Policy = "permissions:admin.servers.nodes.create")] - public async Task Create([FromBody] CreateNodeRequest request) + public async Task Create([FromBody] CreateNodeRequest request) { - var node = Mapper.Map(request); + var node = NodeMapper.ToNode(request); node.TokenId = Formatter.GenerateString(6); node.Token = Formatter.GenerateString(32); var finalNode = await NodeRepository.Add(node); - return CrudHelper.MapToResult(finalNode); + return NodeMapper.ToAdminNodeResponse(finalNode); } [HttpPatch("{id:int}")] [Authorize(Policy = "permissions:admin.servers.nodes.update")] - public async Task Update([FromRoute] int id, [FromBody] UpdateNodeRequest request) + public async Task Update([FromRoute] int id, [FromBody] UpdateNodeRequest request) { - return await CrudHelper.Update(id, request); + var node = await NodeRepository + .Get() + .FirstOrDefaultAsync(x => x.Id == id); + + if (node == null) + throw new HttpApiException("No node with this id found", 404); + + node = NodeMapper.Merge(request, node); + await NodeRepository.Update(node); + + return NodeMapper.ToAdminNodeResponse(node); } [HttpDelete("{id:int}")] [Authorize(Policy = "permissions:admin.servers.nodes.delete")] public async Task Delete([FromRoute] int id) { - await CrudHelper.Delete(id); + var node = await NodeRepository + .Get() + .FirstOrDefaultAsync(x => x.Id == id); + + if (node == null) + throw new HttpApiException("No node with this id found", 404); + + await NodeRepository.Remove(node); } } \ No newline at end of file diff --git a/MoonlightServers.ApiServer/Http/Controllers/Admin/Servers/ServerVariablesController.cs b/MoonlightServers.ApiServer/Http/Controllers/Admin/Servers/ServerVariablesController.cs index 618f65d..d87459e 100644 --- a/MoonlightServers.ApiServer/Http/Controllers/Admin/Servers/ServerVariablesController.cs +++ b/MoonlightServers.ApiServer/Http/Controllers/Admin/Servers/ServerVariablesController.cs @@ -1,11 +1,12 @@ +using System.ComponentModel.DataAnnotations; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.AspNetCore.Authorization; using MoonCore.Exceptions; using MoonCore.Extended.Abstractions; -using MoonCore.Helpers; using MoonCore.Models; using MoonlightServers.ApiServer.Database.Entities; +using MoonlightServers.ApiServer.Mappers; using MoonlightServers.Shared.Http.Responses.Admin.ServerVariables; namespace MoonlightServers.ApiServer.Http.Controllers.Admin.Servers; @@ -17,32 +18,39 @@ public class ServerVariablesController : Controller private readonly DatabaseRepository VariableRepository; private readonly DatabaseRepository ServerRepository; - public ServerVariablesController(DatabaseRepository variableRepository, DatabaseRepository serverRepository) + public ServerVariablesController(DatabaseRepository variableRepository, + DatabaseRepository serverRepository) { VariableRepository = variableRepository; ServerRepository = serverRepository; } [HttpGet("{serverId}/variables")] - [Authorize(Policy = "permissions:admin.servers.get")] - public async Task> Get([FromRoute] int serverId, [FromQuery] int page, [FromQuery] int pageSize) + [Authorize(Policy = "permissions:admin.servers.read")] + public async Task> Get( + [FromRoute] int serverId, + [FromQuery] [Range(0, int.MaxValue)] int page, + [FromQuery] [Range(1, 100)] int pageSize + ) { - var server = await ServerRepository + var serverExists = await ServerRepository .Get() - .FirstOrDefaultAsync(x => x.Id == serverId); + .AnyAsync(x => x.Id == serverId); - if (server == null) + if (!serverExists) throw new HttpApiException("No server with this id found", 404); - + var variables = await VariableRepository .Get() - .Where(x => x.Server.Id == server.Id) + .Where(x => x.Server.Id == serverId) + .Skip(page * pageSize) + .Take(pageSize) .ToArrayAsync(); var castedVariables = variables - .Select(x => Mapper.Map(x)) + .Select(ServerVariableMapper.ToAdminResponse) .ToArray(); - return PagedData.Create(castedVariables, page, pageSize); + return PagedData.Create(castedVariables, page, pageSize); } } \ No newline at end of file diff --git a/MoonlightServers.ApiServer/Http/Controllers/Admin/Servers/ServersController.cs b/MoonlightServers.ApiServer/Http/Controllers/Admin/Servers/ServersController.cs index 6da1bc4..ea1eb7f 100644 --- a/MoonlightServers.ApiServer/Http/Controllers/Admin/Servers/ServersController.cs +++ b/MoonlightServers.ApiServer/Http/Controllers/Admin/Servers/ServersController.cs @@ -1,6 +1,8 @@ +using System.ComponentModel.DataAnnotations; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.AspNetCore.Authorization; +using Microsoft.Extensions.Logging; using MoonCore.Exceptions; using MoonCore.Extended.Abstractions; using MoonCore.Extended.Helpers; @@ -8,6 +10,7 @@ using MoonCore.Helpers; using MoonCore.Models; using Moonlight.ApiServer.Database.Entities; using MoonlightServers.ApiServer.Database.Entities; +using MoonlightServers.ApiServer.Mappers; using MoonlightServers.ApiServer.Services; using MoonlightServers.Shared.Http.Requests.Admin.Servers; using MoonlightServers.Shared.Http.Responses.Admin.Servers; @@ -18,7 +21,6 @@ namespace MoonlightServers.ApiServer.Http.Controllers.Admin.Servers; [Route("api/admin/servers")] public class ServersController : Controller { - private readonly CrudHelper CrudHelper; private readonly DatabaseRepository StarRepository; private readonly DatabaseRepository NodeRepository; private readonly DatabaseRepository AllocationRepository; @@ -29,7 +31,6 @@ public class ServersController : Controller private readonly ServerService ServerService; public ServersController( - CrudHelper crudHelper, DatabaseRepository starRepository, DatabaseRepository nodeRepository, DatabaseRepository allocationRepository, @@ -40,7 +41,6 @@ public class ServersController : Controller ServerService serverService ) { - CrudHelper = crudHelper; StarRepository = starRepository; NodeRepository = nodeRepository; AllocationRepository = allocationRepository; @@ -49,48 +49,68 @@ public class ServersController : Controller UserRepository = userRepository; ServerService = serverService; Logger = logger; - - CrudHelper.QueryModifier = servers => servers - .Include(x => x.Node) - .Include(x => x.Allocations) - .Include(x => x.Variables) - .Include(x => x.Star); - - CrudHelper.LateMapper = (server, response) => - { - response.NodeId = server.Node.Id; - response.StarId = server.Star.Id; - response.AllocationIds = server.Allocations.Select(x => x.Id).ToArray(); - - return response; - }; } [HttpGet] - [Authorize(Policy = "permissions:admin.servers.get")] - public async Task> Get([FromQuery] int page, [FromQuery] int pageSize) + [Authorize(Policy = "permissions:admin.servers.read")] + public async Task> Get( + [FromQuery] [Range(0, int.MaxValue)] int page, + [FromQuery] [Range(1, 100)] int pageSize + ) { - return await CrudHelper.Get(page, pageSize); + var count = await ServerRepository.Get().CountAsync(); + + var items = await ServerRepository + .Get() + .Include(x => x.Node) + .Include(x => x.Allocations) + .Include(x => x.Variables) + .Include(x => x.Star) + .Skip(page * pageSize) + .Take(pageSize) + .ToArrayAsync(); + + var mappedItems = items + .Select(ServerMapper.ToAdminServerResponse) + .ToArray(); + + return new PagedData() + { + Items = mappedItems, + CurrentPage = page, + PageSize = pageSize, + TotalItems = count, + TotalPages = count == 0 ? 0 : count / pageSize + }; } [HttpGet("{id:int}")] - [Authorize(Policy = "permissions:admin.servers.get")] - public async Task GetSingle([FromRoute] int id) + [Authorize(Policy = "permissions:admin.servers.read")] + public async Task GetSingle([FromRoute] int id) { - return await CrudHelper.GetSingle(id); + var server = await ServerRepository + .Get() + .Include(x => x.Node) + .Include(x => x.Allocations) + .Include(x => x.Variables) + .Include(x => x.Star) + .FirstOrDefaultAsync(x => x.Id == id); + + if (server == null) + throw new HttpApiException("No server with that id found", 404); + + return ServerMapper.ToAdminServerResponse(server); } [HttpPost] - [Authorize(Policy = "permissions:admin.servers.create")] - public async Task Create([FromBody] CreateServerRequest request) + [Authorize(Policy = "permissions:admin.servers.write")] + public async Task Create([FromBody] CreateServerRequest request) { - // Construct model - var server = Mapper.Map(request); - // Check if owner user exist if (UserRepository.Get().All(x => x.Id != request.OwnerId)) throw new HttpApiException("No user with this id found", 400); + // Check if the star exists var star = await StarRepository .Get() .Include(x => x.Variables) @@ -146,6 +166,8 @@ public class ServersController : Controller ); } } + + var server = ServerMapper.ToServer(request); // Set allocations server.Allocations = allocations; @@ -181,23 +203,33 @@ public class ServersController : Controller Logger.LogError("Unable to sync server to node the server is assigned to: {e}", e); // We are deleting the server from the database after the creation has failed - // to ensure we wont have a bugged server in the database which doesnt exist on the node + // to ensure we won't have a bugged server in the database which doesnt exist on the node await ServerRepository.Remove(finalServer); throw; } - return CrudHelper.MapToResult(finalServer); + return ServerMapper.ToAdminServerResponse(finalServer); } [HttpPatch("{id:int}")] - public async Task Update([FromRoute] int id, [FromBody] UpdateServerRequest request) + [Authorize(Policy = "permissions.admin.servers.write")] + public async Task Update([FromRoute] int id, [FromBody] UpdateServerRequest request) { //TODO: Handle shrinking virtual disk - - var server = await CrudHelper.GetSingleModel(id); - server = Mapper.Map(server, request); + var server = await ServerRepository + .Get() + .Include(x => x.Node) + .Include(x => x.Allocations) + .Include(x => x.Variables) + .Include(x => x.Star) + .FirstOrDefaultAsync(x => x.Id == id); + + if (server == null) + throw new HttpApiException("No server with that id found", 404); + + server = ServerMapper.Merge(request, server); var allocations = new List(); @@ -250,14 +282,20 @@ public class ServersController : Controller // Notify the node about the changes await ServerService.Sync(server); - return CrudHelper.MapToResult(server); + return ServerMapper.ToAdminServerResponse(server); } [HttpDelete("{id:int}")] public async Task Delete([FromRoute] int id, [FromQuery] bool force = false) { - var server = await CrudHelper.GetSingleModel(id); - + var server = await ServerRepository + .Get() + .Include(x => x.Node) + .FirstOrDefaultAsync(x => x.Id == id); + + if (server == null) + throw new HttpApiException("No server with that id found", 404); + try { // If the sync fails on the node and we aren't forcing the deletion, @@ -277,6 +315,6 @@ public class ServersController : Controller throw; } - await CrudHelper.Delete(id); + await ServerRepository.Remove(server); } } \ No newline at end of file diff --git a/MoonlightServers.ApiServer/Http/Controllers/Admin/Stars/StarDockerImagesController.cs b/MoonlightServers.ApiServer/Http/Controllers/Admin/Stars/StarDockerImagesController.cs index cedb349..c12c072 100644 --- a/MoonlightServers.ApiServer/Http/Controllers/Admin/Stars/StarDockerImagesController.cs +++ b/MoonlightServers.ApiServer/Http/Controllers/Admin/Stars/StarDockerImagesController.cs @@ -1,3 +1,4 @@ +using System.ComponentModel.DataAnnotations; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using MoonCore.Exceptions; @@ -7,6 +8,7 @@ using Microsoft.AspNetCore.Authorization; using MoonCore.Helpers; using MoonCore.Models; using MoonlightServers.ApiServer.Database.Entities; +using MoonlightServers.ApiServer.Mappers; using MoonlightServers.Shared.Http.Requests.Admin.StarDockerImages; using MoonlightServers.Shared.Http.Responses.Admin.StarDockerImages; @@ -16,45 +18,56 @@ namespace MoonlightServers.ApiServer.Http.Controllers.Admin.Stars; [Route("api/admin/servers/stars")] public class StarDockerImagesController : Controller { - private readonly CrudHelper CrudHelper; private readonly DatabaseRepository StarRepository; private readonly DatabaseRepository StarDockerImageRepository; - - private Star Star; public StarDockerImagesController( - CrudHelper crudHelper, DatabaseRepository starRepository, DatabaseRepository starDockerImageRepository ) { - CrudHelper = crudHelper; StarRepository = starRepository; StarDockerImageRepository = starDockerImageRepository; } - - private async Task ApplyStar(int id) - { - var star = await StarRepository - .Get() - .FirstOrDefaultAsync(x => x.Id == id); - - if (star == null) - throw new HttpApiException("A star with this id could not be found", 404); - - Star = star; - - CrudHelper.QueryModifier = dockerImages => - dockerImages.Where(x => x.Star.Id == star.Id); - } [HttpGet("{starId:int}/dockerImages")] [Authorize(Policy = "permissions:admin.servers.stars.get")] - public async Task> Get([FromRoute] int starId, [FromQuery] int page, [FromQuery] int pageSize) + public async Task> Get( + [FromRoute] int starId, + [FromQuery] [Range(0, int.MaxValue)] int page, + [FromQuery] [Range(1, 100)] int pageSize + ) { - await ApplyStar(starId); + var starExists = StarRepository + .Get() + .Any(x => x.Id == starId); - return await CrudHelper.Get(page, pageSize); + if(starExists) + throw new HttpApiException("No star with this id found", 404); + + var query = StarDockerImageRepository + .Get() + .Where(x => x.Star.Id == starId); + + var count = await query.CountAsync(); + + var items = await query + .Skip(page * pageSize) + .Take(pageSize) + .ToArrayAsync(); + + var mappedItems = items + .Select(DockerImageMapper.ToAdminResponse) + .ToArray(); + + return new PagedData() + { + Items = mappedItems, + CurrentPage = page, + PageSize = pageSize, + TotalItems = count, + TotalPages = count == 0 ? 0 : count / pageSize + }; } [HttpGet("{starId:int}/dockerImages/{id:int}")] @@ -62,16 +75,17 @@ public class StarDockerImagesController : Controller public async Task GetSingle([FromRoute] int starId, [FromRoute] int id) { await ApplyStar(starId); - + return await CrudHelper.GetSingle(id); } [HttpPost("{starId:int}/dockerImages")] [Authorize(Policy = "permissions:admin.servers.stars.create")] - public async Task Create([FromRoute] int starId, [FromBody] CreateStarDockerImageRequest request) + public async Task Create([FromRoute] int starId, + [FromBody] CreateStarDockerImageRequest request) { await ApplyStar(starId); - + var starDockerImage = Mapper.Map(request); starDockerImage.Star = Star; @@ -86,7 +100,7 @@ public class StarDockerImagesController : Controller [FromBody] UpdateStarDockerImageRequest request) { await ApplyStar(starId); - + return await CrudHelper.Update(id, request); } @@ -95,7 +109,7 @@ public class StarDockerImagesController : Controller public async Task Delete([FromRoute] int starId, [FromRoute] int id) { await ApplyStar(starId); - + await CrudHelper.Delete(id); } } \ No newline at end of file diff --git a/MoonlightServers.ApiServer/Http/Controllers/Admin/Stars/StarImportExportController.cs b/MoonlightServers.ApiServer/Http/Controllers/Admin/Stars/StarImportExportController.cs index 3256272..cd57b9e 100644 --- a/MoonlightServers.ApiServer/Http/Controllers/Admin/Stars/StarImportExportController.cs +++ b/MoonlightServers.ApiServer/Http/Controllers/Admin/Stars/StarImportExportController.cs @@ -1,6 +1,7 @@ using System.Text; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; using MoonCore.Exceptions; using MoonCore.Helpers; using MoonlightServers.ApiServer.Services; diff --git a/MoonlightServers.ApiServer/Http/Controllers/Remote/ServersController.cs b/MoonlightServers.ApiServer/Http/Controllers/Remote/ServersController.cs index 48ff11e..f4d6096 100644 --- a/MoonlightServers.ApiServer/Http/Controllers/Remote/ServersController.cs +++ b/MoonlightServers.ApiServer/Http/Controllers/Remote/ServersController.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; using MoonCore.Exceptions; using MoonCore.Extended.Abstractions; using MoonCore.Models; diff --git a/MoonlightServers.ApiServer/Mappers/AllocationMapper.cs b/MoonlightServers.ApiServer/Mappers/AllocationMapper.cs new file mode 100644 index 0000000..588afc5 --- /dev/null +++ b/MoonlightServers.ApiServer/Mappers/AllocationMapper.cs @@ -0,0 +1,14 @@ +using MoonlightServers.ApiServer.Database.Entities; +using MoonlightServers.Shared.Http.Requests.Admin.NodeAllocations; +using MoonlightServers.Shared.Http.Responses.Admin.NodeAllocations; +using Riok.Mapperly.Abstractions; + +namespace MoonlightServers.ApiServer.Mappers; + +[Mapper(AllowNullPropertyAssignment = false)] +public static partial class AllocationMapper +{ + public static partial NodeAllocationResponse ToNodeAllocation(Allocation allocation); + public static partial Allocation ToAllocation(CreateNodeAllocationRequest request); + public static partial Allocation Merge(UpdateNodeAllocationRequest request, Allocation allocation); +} \ No newline at end of file diff --git a/MoonlightServers.ApiServer/Mappers/DockerImageMapper.cs b/MoonlightServers.ApiServer/Mappers/DockerImageMapper.cs new file mode 100644 index 0000000..d4f7b1a --- /dev/null +++ b/MoonlightServers.ApiServer/Mappers/DockerImageMapper.cs @@ -0,0 +1,15 @@ +using MoonlightServers.ApiServer.Database.Entities; +using MoonlightServers.Shared.Http.Requests.Admin.StarDockerImages; +using MoonlightServers.Shared.Http.Requests.Admin.StarVariables; +using MoonlightServers.Shared.Http.Responses.Admin.StarDockerImages; +using Riok.Mapperly.Abstractions; + +namespace MoonlightServers.ApiServer.Mappers; + +[Mapper(AllowNullPropertyAssignment = false)] +public static partial class DockerImageMapper +{ + public static partial StarDockerImageDetailResponse ToAdminResponse(StarDockerImage dockerImage); + public static partial StarDockerImage ToDockerImage(CreateStarDockerImageRequest request); + public static partial StarDockerImage Merge(UpdateStarVariableRequest request, StarDockerImage variable); +} \ No newline at end of file diff --git a/MoonlightServers.ApiServer/Mappers/NodeMapper.cs b/MoonlightServers.ApiServer/Mappers/NodeMapper.cs new file mode 100644 index 0000000..046bcf8 --- /dev/null +++ b/MoonlightServers.ApiServer/Mappers/NodeMapper.cs @@ -0,0 +1,14 @@ +using MoonlightServers.ApiServer.Database.Entities; +using MoonlightServers.Shared.Http.Requests.Admin.Nodes; +using MoonlightServers.Shared.Http.Responses.Admin.Nodes; +using Riok.Mapperly.Abstractions; + +namespace MoonlightServers.ApiServer.Mappers; + +[Mapper(AllowNullPropertyAssignment = false)] +public static partial class NodeMapper +{ + public static partial NodeResponse ToAdminNodeResponse(Node node); + public static partial Node ToNode(CreateNodeRequest request); + public static partial Node Merge(UpdateNodeRequest request, Node node); +} \ No newline at end of file diff --git a/MoonlightServers.ApiServer/Mappers/ServerMapper.cs b/MoonlightServers.ApiServer/Mappers/ServerMapper.cs new file mode 100644 index 0000000..8a890a7 --- /dev/null +++ b/MoonlightServers.ApiServer/Mappers/ServerMapper.cs @@ -0,0 +1,25 @@ +using MoonlightServers.ApiServer.Database.Entities; +using MoonlightServers.Shared.Http.Requests.Admin.Servers; +using MoonlightServers.Shared.Http.Responses.Admin.Servers; +using Riok.Mapperly.Abstractions; + +namespace MoonlightServers.ApiServer.Mappers; + +[Mapper(AllowNullPropertyAssignment = false)] +public static partial class ServerMapper +{ + [UserMapping(Default = true)] + public static ServerResponse ToAdminServerResponse(Server server) + { + var response = ToAdminServerResponse_Internal(server); + + response.AllocationIds = server.Allocations.Select(x => x.Id).ToArray(); + + return response; + } + + private static partial ServerResponse ToAdminServerResponse_Internal(Server server); + + public static partial Server ToServer(CreateServerRequest request); + public static partial Server Merge(UpdateServerRequest request, Server server); +} \ No newline at end of file diff --git a/MoonlightServers.ApiServer/Mappers/ServerVariableMapper.cs b/MoonlightServers.ApiServer/Mappers/ServerVariableMapper.cs new file mode 100644 index 0000000..2c8fd3a --- /dev/null +++ b/MoonlightServers.ApiServer/Mappers/ServerVariableMapper.cs @@ -0,0 +1,11 @@ +using MoonlightServers.ApiServer.Database.Entities; +using MoonlightServers.Shared.Http.Responses.Admin.ServerVariables; +using Riok.Mapperly.Abstractions; + +namespace MoonlightServers.ApiServer.Mappers; + +[Mapper(AllowNullPropertyAssignment = false)] +public static partial class ServerVariableMapper +{ + public static partial ServerVariableResponse ToAdminResponse(ServerVariable serverVariable); +} \ No newline at end of file diff --git a/MoonlightServers.ApiServer/Mappers/StarVariableMapper.cs b/MoonlightServers.ApiServer/Mappers/StarVariableMapper.cs new file mode 100644 index 0000000..b368787 --- /dev/null +++ b/MoonlightServers.ApiServer/Mappers/StarVariableMapper.cs @@ -0,0 +1,14 @@ +using MoonlightServers.ApiServer.Database.Entities; +using MoonlightServers.Shared.Http.Requests.Admin.StarVariables; +using MoonlightServers.Shared.Http.Responses.Admin.StarVariables; +using Riok.Mapperly.Abstractions; + +namespace MoonlightServers.ApiServer.Mappers; + +[Mapper(AllowNullPropertyAssignment = false)] +public static partial class StarVariableMapper +{ + public static partial StarVariableDetailResponse ToAdminResponse(StarVariable variable); + public static partial StarVariable ToStarVariable(CreateStarVariableRequest request); + public static partial StarVariable Merge(UpdateStarVariableRequest request, StarVariable variable); +} \ No newline at end of file diff --git a/MoonlightServers.ApiServer/MoonlightServers.ApiServer.csproj b/MoonlightServers.ApiServer/MoonlightServers.ApiServer.csproj index 5da5e64..de03d3d 100644 --- a/MoonlightServers.ApiServer/MoonlightServers.ApiServer.csproj +++ b/MoonlightServers.ApiServer/MoonlightServers.ApiServer.csproj @@ -1,4 +1,4 @@ - + net9.0 @@ -16,13 +16,13 @@ - - + + + - diff --git a/MoonlightServers.ApiServer/Program.cs b/MoonlightServers.ApiServer/Program.cs deleted file mode 100644 index a05be36..0000000 --- a/MoonlightServers.ApiServer/Program.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Text.Json; -using Moonlight.ApiServer; -using Moonlight.ApiServer.Models; -using MoonlightServers.ApiServer.Startup; - -// Development Server Startup - -// This file is a small helper for development instances for moonlight. -// It calls the moonlight startup with the current project loaded as a plugin. -// This allows you to develop and debug projects without any hassle - -// !!! DO NOT HARDCORE ANY SECRETS HERE !!! - -var startup = new Startup(); - -await startup.Run(args, [ - new PluginStartup() -]); \ No newline at end of file diff --git a/MoonlightServers.ApiServer/Services/NodeBootService.cs b/MoonlightServers.ApiServer/Services/NodeBootService.cs index a9c8ac6..ec77091 100644 --- a/MoonlightServers.ApiServer/Services/NodeBootService.cs +++ b/MoonlightServers.ApiServer/Services/NodeBootService.cs @@ -1,3 +1,5 @@ +using Microsoft.Extensions.Hosting; + namespace MoonlightServers.ApiServer.Services; public class NodeBootService : IHostedLifecycleService diff --git a/MoonlightServers.ApiServer/Services/StarImportExportService.cs b/MoonlightServers.ApiServer/Services/StarImportExportService.cs index 9b4a335..91825a4 100644 --- a/MoonlightServers.ApiServer/Services/StarImportExportService.cs +++ b/MoonlightServers.ApiServer/Services/StarImportExportService.cs @@ -1,5 +1,6 @@ using System.Text.Json; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; using MoonCore.Attributes; using MoonCore.Exceptions; using MoonCore.Extended.Abstractions; diff --git a/MoonlightServers.ApiServer/Startup/PluginStartup.cs b/MoonlightServers.ApiServer/Startup/PluginStartup.cs index ef6bef3..4e3ae67 100644 --- a/MoonlightServers.ApiServer/Startup/PluginStartup.cs +++ b/MoonlightServers.ApiServer/Startup/PluginStartup.cs @@ -1,3 +1,7 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Routing; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using MoonCore.Extensions; using Moonlight.ApiServer.Configuration; using Moonlight.ApiServer.Models; diff --git a/MoonlightServers.Frontend.Runtime/DevPluginLoader.cs b/MoonlightServers.Frontend.Runtime/DevPluginLoader.cs new file mode 100644 index 0000000..f3692cd --- /dev/null +++ b/MoonlightServers.Frontend.Runtime/DevPluginLoader.cs @@ -0,0 +1,10 @@ +using MoonCore.PluginFramework; +using Moonlight.Client.Plugins; + +namespace MoonlightServers.Frontend.Runtime; + +[PluginLoader] +public partial class DevPluginLoader : IPluginStartup +{ + +} \ No newline at end of file diff --git a/MoonlightServers.Frontend.Runtime/MoonlightServers.Frontend.Runtime.csproj b/MoonlightServers.Frontend.Runtime/MoonlightServers.Frontend.Runtime.csproj new file mode 100644 index 0000000..a21e3f5 --- /dev/null +++ b/MoonlightServers.Frontend.Runtime/MoonlightServers.Frontend.Runtime.csproj @@ -0,0 +1,23 @@ + + + + net9.0 + enable + enable + + + + + + + + + + + + + + + + + diff --git a/MoonlightServers.Frontend.Runtime/Program.cs b/MoonlightServers.Frontend.Runtime/Program.cs new file mode 100644 index 0000000..0f6664c --- /dev/null +++ b/MoonlightServers.Frontend.Runtime/Program.cs @@ -0,0 +1,20 @@ +using Microsoft.AspNetCore.Components.WebAssembly.Hosting; +using Moonlight.Client.Startup; +using MoonlightServers.Frontend.Runtime; + +var pluginLoader = new DevPluginLoader(); +pluginLoader.Initialize(); + +var startup = new Startup(); + +await startup.Initialize(pluginLoader.Instances); + +var wasmHostBuilder = WebAssemblyHostBuilder.CreateDefault(args); + +await startup.AddMoonlight(wasmHostBuilder); + +var wasmApp = wasmHostBuilder.Build(); + +await startup.AddMoonlight(wasmApp); + +await wasmApp.RunAsync(); \ No newline at end of file diff --git a/MoonlightServers.Frontend/Helpers/ServerFileSystemProvider.cs b/MoonlightServers.Frontend/Helpers/ServerFileSystemProvider.cs index 6d37d9b..f188bf2 100644 --- a/MoonlightServers.Frontend/Helpers/ServerFileSystemProvider.cs +++ b/MoonlightServers.Frontend/Helpers/ServerFileSystemProvider.cs @@ -1,3 +1,5 @@ +using System.IO.Enumeration; +using MoonCore.Blazor.FlyonUi.Helpers; using MoonCore.Blazor.Tailwind.Fm; using MoonCore.Blazor.Tailwind.Fm.Models; using MoonCore.Blazor.Tailwind.Services; diff --git a/MoonlightServers.Frontend/MoonlightServers.Frontend.csproj b/MoonlightServers.Frontend/MoonlightServers.Frontend.csproj index 1732c43..e5ba353 100644 --- a/MoonlightServers.Frontend/MoonlightServers.Frontend.csproj +++ b/MoonlightServers.Frontend/MoonlightServers.Frontend.csproj @@ -16,10 +16,9 @@ - - + - + diff --git a/MoonlightServers.Frontend/Program.cs b/MoonlightServers.Frontend/Program.cs index 9d8fe98..6f19c1a 100644 --- a/MoonlightServers.Frontend/Program.cs +++ b/MoonlightServers.Frontend/Program.cs @@ -1,4 +1,5 @@ using Moonlight.Client; +using Moonlight.Client.Startup; using MoonlightServers.Frontend.Startup; // Development Client Startup diff --git a/MoonlightServers.Frontend/UI/Components/Nodes/Modals/CreateAllocationModal.razor b/MoonlightServers.Frontend/UI/Components/Nodes/Modals/CreateAllocationModal.razor index 6fa5ad4..6da11d7 100644 --- a/MoonlightServers.Frontend/UI/Components/Nodes/Modals/CreateAllocationModal.razor +++ b/MoonlightServers.Frontend/UI/Components/Nodes/Modals/CreateAllocationModal.razor @@ -1,8 +1,9 @@ +@using MoonCore.Blazor.FlyonUi.Components @using MoonCore.Blazor.Tailwind.Modals.Components @using MoonCore.Blazor.Tailwind.Components @using MoonlightServers.Shared.Http.Requests.Admin.NodeAllocations -@inherits BaseModal +@inherits MoonCore.Blazor.FlyonUi.Modals.Components.BaseModal

Add a new allocation

diff --git a/MoonlightServers.Frontend/UI/Components/Nodes/Modals/CreateMultipleAllocationModal.razor b/MoonlightServers.Frontend/UI/Components/Nodes/Modals/CreateMultipleAllocationModal.razor index 5e3e297..65318be 100644 --- a/MoonlightServers.Frontend/UI/Components/Nodes/Modals/CreateMultipleAllocationModal.razor +++ b/MoonlightServers.Frontend/UI/Components/Nodes/Modals/CreateMultipleAllocationModal.razor @@ -1,8 +1,9 @@ +@using MoonCore.Blazor.FlyonUi.Components @using MoonCore.Blazor.Tailwind.Modals.Components @using MoonCore.Blazor.Tailwind.Components @using MoonlightServers.Shared.Http.Requests.Admin.NodeAllocations -@inherits BaseModal +@inherits MoonCore.Blazor.FlyonUi.Modals.Components.BaseModal

Add a range of new allocations

diff --git a/MoonlightServers.Frontend/UI/Components/Nodes/Modals/UpdateAllocationModal.razor b/MoonlightServers.Frontend/UI/Components/Nodes/Modals/UpdateAllocationModal.razor index b34d7b0..4bc09c4 100644 --- a/MoonlightServers.Frontend/UI/Components/Nodes/Modals/UpdateAllocationModal.razor +++ b/MoonlightServers.Frontend/UI/Components/Nodes/Modals/UpdateAllocationModal.razor @@ -1,10 +1,11 @@ +@using MoonCore.Blazor.FlyonUi.Components @using MoonCore.Blazor.Tailwind.Modals.Components @using MoonCore.Blazor.Tailwind.Components @using MoonCore.Helpers @using MoonlightServers.Shared.Http.Requests.Admin.NodeAllocations @using MoonlightServers.Shared.Http.Responses.Admin.NodeAllocations -@inherits BaseModal +@inherits MoonCore.Blazor.FlyonUi.Modals.Components.BaseModal

Update allocation

@@ -30,7 +31,7 @@ @code { [Parameter] public Func OnSubmit { get; set; } - [Parameter] public NodeAllocationDetailResponse Allocation { get; set; } + [Parameter] public NodeAllocationResponse Allocation { get; set; } private UpdateNodeAllocationRequest Form; private HandleForm HandleForm; diff --git a/MoonlightServers.Frontend/UI/Components/Nodes/UpdateNodePartials/AllocationsNodeUpdate.razor b/MoonlightServers.Frontend/UI/Components/Nodes/UpdateNodePartials/AllocationsNodeUpdate.razor index 8cf138e..a6bc466 100644 --- a/MoonlightServers.Frontend/UI/Components/Nodes/UpdateNodePartials/AllocationsNodeUpdate.razor +++ b/MoonlightServers.Frontend/UI/Components/Nodes/UpdateNodePartials/AllocationsNodeUpdate.razor @@ -1,3 +1,7 @@ +@using MoonCore.Blazor.FlyonUi.Alerts +@using MoonCore.Blazor.FlyonUi.DataTables +@using MoonCore.Blazor.FlyonUi.Modals +@using MoonCore.Blazor.FlyonUi.Toasts @using MoonCore.Blazor.Tailwind.Alerts @using MoonlightServers.Shared.Http.Responses.Admin.Nodes @using MoonCore.Blazor.Tailwind.Dt @@ -31,13 +35,13 @@
- + - + - - - + + +
Table; + private DataTable Table; - private async Task> LoadData(PaginationOptions options) + private async Task> LoadData(PaginationOptions options) { - return await ApiClient.GetJson>( + return await ApiClient.GetJson>( $"api/admin/servers/nodes/{Node.Id}/allocations?page={options.Page}&pageSize={options.PerPage}" ); } @@ -98,7 +102,7 @@ await ModalService.Launch(parameters => { parameters.Add("OnSubmit", onSubmit); }); } - private async Task UpdateAllocation(NodeAllocationDetailResponse allocation) + private async Task UpdateAllocation(NodeAllocationResponse allocation) { Func onSubmit = async request => { @@ -115,7 +119,7 @@ }); } - private async Task DeleteAllocation(NodeAllocationDetailResponse allocation) + private async Task DeleteAllocation(NodeAllocationResponse allocation) { await AlertService.ConfirmDanger( "Delete allocation", diff --git a/MoonlightServers.Frontend/UI/Components/Nodes/UpdateNodePartials/OverviewNodeUpdate.razor b/MoonlightServers.Frontend/UI/Components/Nodes/UpdateNodePartials/OverviewNodeUpdate.razor index 8cf9b3a..df4bb62 100644 --- a/MoonlightServers.Frontend/UI/Components/Nodes/UpdateNodePartials/OverviewNodeUpdate.razor +++ b/MoonlightServers.Frontend/UI/Components/Nodes/UpdateNodePartials/OverviewNodeUpdate.razor @@ -1,3 +1,5 @@ +@using MoonCore.Blazor.FlyonUi.Components +@using MoonCore.Blazor.FlyonUi.Toasts @using MoonCore.Blazor.Tailwind.Components @using MoonCore.Blazor.Tailwind.Toasts @using MoonCore.Helpers @@ -170,7 +172,7 @@ @code { - [Parameter] public NodeDetailResponse Node { get; set; } + [Parameter] public NodeResponse Node { get; set; } private StatisticsResponse Statistics; private DockerStatisticsResponse DockerStatistics; diff --git a/MoonlightServers.Frontend/UI/Components/Servers/CreateServerPartials/AllocationsServerCreate.razor b/MoonlightServers.Frontend/UI/Components/Servers/CreateServerPartials/AllocationsServerCreate.razor index a322bec..d1cc094 100644 --- a/MoonlightServers.Frontend/UI/Components/Servers/CreateServerPartials/AllocationsServerCreate.razor +++ b/MoonlightServers.Frontend/UI/Components/Servers/CreateServerPartials/AllocationsServerCreate.razor @@ -25,14 +25,14 @@ { [Parameter] public CreateServerRequest Request { get; set; } - private async Task Loader() + private async Task Loader() { // Handle unselected node if (Request.NodeId <= 0) return []; - var items = await PagedData.All(async (page, pageSize) => - await ApiClient.GetJson>( + var items = await PagedData.All(async (page, pageSize) => + await ApiClient.GetJson>( $"api/admin/servers/nodes/{Request.NodeId}/allocations/free?page={page}&pageSize={pageSize}" ) ); diff --git a/MoonlightServers.Frontend/UI/Components/Servers/CreateServerPartials/GeneralServerCreate.razor b/MoonlightServers.Frontend/UI/Components/Servers/CreateServerPartials/GeneralServerCreate.razor index 566b7ed..9c2eabe 100644 --- a/MoonlightServers.Frontend/UI/Components/Servers/CreateServerPartials/GeneralServerCreate.razor +++ b/MoonlightServers.Frontend/UI/Components/Servers/CreateServerPartials/GeneralServerCreate.razor @@ -102,10 +102,10 @@ return items; } - private async Task LoadNodes() + private async Task LoadNodes() { - var items = await PagedData.All(async (page, pageSize) => - await ApiClient.GetJson>( + var items = await PagedData.All(async (page, pageSize) => + await ApiClient.GetJson>( $"api/admin/servers/nodes?page={page}&pageSize={pageSize}" ) ); diff --git a/MoonlightServers.Frontend/UI/Components/Servers/CreateServerPartials/VariablesServerCreate.razor b/MoonlightServers.Frontend/UI/Components/Servers/CreateServerPartials/VariablesServerCreate.razor index 1f866da..6db57ec 100644 --- a/MoonlightServers.Frontend/UI/Components/Servers/CreateServerPartials/VariablesServerCreate.razor +++ b/MoonlightServers.Frontend/UI/Components/Servers/CreateServerPartials/VariablesServerCreate.razor @@ -1,3 +1,4 @@ +@using MoonCore.Blazor.FlyonUi.Components @using MoonlightServers.Shared.Http.Requests.Admin.Servers @using MoonCore.Helpers @using MoonCore.Blazor.Tailwind.Components diff --git a/MoonlightServers.Frontend/UI/Components/Servers/CreateShareModal.razor b/MoonlightServers.Frontend/UI/Components/Servers/CreateShareModal.razor index 55bf752..87aeb2e 100644 --- a/MoonlightServers.Frontend/UI/Components/Servers/CreateShareModal.razor +++ b/MoonlightServers.Frontend/UI/Components/Servers/CreateShareModal.razor @@ -1,3 +1,4 @@ +@using MoonCore.Blazor.FlyonUi.Components @using MoonCore.Blazor.Tailwind.Components @using MoonlightServers.Shared.Enums @using MoonlightServers.Shared.Http.Requests.Client.Servers.Shares diff --git a/MoonlightServers.Frontend/UI/Components/Servers/ServerTabs/FilesTab.razor b/MoonlightServers.Frontend/UI/Components/Servers/ServerTabs/FilesTab.razor index dfe2f8c..ddc8ad3 100644 --- a/MoonlightServers.Frontend/UI/Components/Servers/ServerTabs/FilesTab.razor +++ b/MoonlightServers.Frontend/UI/Components/Servers/ServerTabs/FilesTab.razor @@ -1,3 +1,4 @@ +@using MoonCore.Blazor.FlyonUi.Helpers @using MoonlightServers.Frontend.Services @using MoonCore.Blazor.Tailwind.Fm @using MoonCore.Blazor.Tailwind.Services diff --git a/MoonlightServers.Frontend/UI/Components/Servers/ServerTabs/SettingsTab.razor b/MoonlightServers.Frontend/UI/Components/Servers/ServerTabs/SettingsTab.razor index 9946a2b..e4d72e2 100644 --- a/MoonlightServers.Frontend/UI/Components/Servers/ServerTabs/SettingsTab.razor +++ b/MoonlightServers.Frontend/UI/Components/Servers/ServerTabs/SettingsTab.razor @@ -1,3 +1,5 @@ +@using MoonCore.Blazor.FlyonUi.Alerts +@using MoonCore.Blazor.FlyonUi.Components @using MoonCore.Blazor.Tailwind.Alerts @using MoonCore.Helpers @using MoonCore.Blazor.Tailwind.Components diff --git a/MoonlightServers.Frontend/UI/Components/Servers/ServerTabs/SharesTab.razor b/MoonlightServers.Frontend/UI/Components/Servers/ServerTabs/SharesTab.razor index b54cf84..3d520df 100644 --- a/MoonlightServers.Frontend/UI/Components/Servers/ServerTabs/SharesTab.razor +++ b/MoonlightServers.Frontend/UI/Components/Servers/ServerTabs/SharesTab.razor @@ -1,3 +1,7 @@ +@using MoonCore.Blazor.FlyonUi.Alerts +@using MoonCore.Blazor.FlyonUi.Components +@using MoonCore.Blazor.FlyonUi.Modals +@using MoonCore.Blazor.FlyonUi.Toasts @using MoonCore.Blazor.Tailwind.Alerts @using MoonCore.Blazor.Tailwind.Components @using MoonCore.Blazor.Tailwind.Modals diff --git a/MoonlightServers.Frontend/UI/Components/Servers/ServerTabs/VariablesTab.razor b/MoonlightServers.Frontend/UI/Components/Servers/ServerTabs/VariablesTab.razor index a695f27..9b78952 100644 --- a/MoonlightServers.Frontend/UI/Components/Servers/ServerTabs/VariablesTab.razor +++ b/MoonlightServers.Frontend/UI/Components/Servers/ServerTabs/VariablesTab.razor @@ -1,3 +1,5 @@ +@using MoonCore.Blazor.FlyonUi.Components +@using MoonCore.Blazor.FlyonUi.Toasts @using MoonCore.Blazor.Tailwind.Components @using MoonCore.Blazor.Tailwind.Toasts @using MoonlightServers.Frontend.Services diff --git a/MoonlightServers.Frontend/UI/Components/Servers/UpdateServerPartials/AllocationsServerUpdate.razor b/MoonlightServers.Frontend/UI/Components/Servers/UpdateServerPartials/AllocationsServerUpdate.razor index 1d3618f..bfa3f87 100644 --- a/MoonlightServers.Frontend/UI/Components/Servers/UpdateServerPartials/AllocationsServerUpdate.razor +++ b/MoonlightServers.Frontend/UI/Components/Servers/UpdateServerPartials/AllocationsServerUpdate.razor @@ -25,12 +25,12 @@ @code { [Parameter] public UpdateServerRequest Request { get; set; } - [Parameter] public ServerDetailResponse Server { get; set; } + [Parameter] public ServerResponse Server { get; set; } - private async Task Loader() + private async Task Loader() { - var items = await PagedData.All(async (page, pageSize) => - await ApiClient.GetJson>( + var items = await PagedData.All(async (page, pageSize) => + await ApiClient.GetJson>( $"api/admin/servers/nodes/{Server.NodeId}/allocations/free?page={page}&pageSize={pageSize}&serverId={Server.Id}" ) ); diff --git a/MoonlightServers.Frontend/UI/Components/Servers/UpdateServerPartials/VariablesServerUpdate.razor b/MoonlightServers.Frontend/UI/Components/Servers/UpdateServerPartials/VariablesServerUpdate.razor index 2779ac9..c8707e5 100644 --- a/MoonlightServers.Frontend/UI/Components/Servers/UpdateServerPartials/VariablesServerUpdate.razor +++ b/MoonlightServers.Frontend/UI/Components/Servers/UpdateServerPartials/VariablesServerUpdate.razor @@ -1,3 +1,4 @@ +@using MoonCore.Blazor.FlyonUi.Components @using MoonlightServers.Shared.Http.Requests.Admin.Servers @using MoonCore.Helpers @using MoonCore.Blazor.Tailwind.Components @@ -43,10 +44,10 @@ @code { [Parameter] public UpdateServerRequest Request { get; set; } - [Parameter] public ServerDetailResponse Server { get; set; } + [Parameter] public ServerResponse Server { get; set; } private StarVariableDetailResponse[] StarVariables; - private ServerVariableDetailResponse[] Variables; + private ServerVariableResponse[] Variables; private async Task Load(LazyLoader _) { @@ -56,14 +57,14 @@ ) ); - Variables = await PagedData.All(async (page, pageSize) => - await ApiClient.GetJson>( + Variables = await PagedData.All(async (page, pageSize) => + await ApiClient.GetJson>( $"api/admin/servers/{Server.Id}/variables?page={page}&pageSize={pageSize}" ) ); } - private async Task UpdateValue(ServerVariableDetailResponse serverVariable, ChangeEventArgs args) + private async Task UpdateValue(ServerVariableResponse serverVariable, ChangeEventArgs args) { var value = args.Value?.ToString() ?? ""; diff --git a/MoonlightServers.Frontend/UI/Components/Servers/UpdateShareModal.razor b/MoonlightServers.Frontend/UI/Components/Servers/UpdateShareModal.razor index 0f4b025..8e6fc39 100644 --- a/MoonlightServers.Frontend/UI/Components/Servers/UpdateShareModal.razor +++ b/MoonlightServers.Frontend/UI/Components/Servers/UpdateShareModal.razor @@ -1,3 +1,4 @@ +@using MoonCore.Blazor.FlyonUi.Components @using MoonCore.Blazor.Tailwind.Components @using MoonlightServers.Shared.Enums @using MoonlightServers.Shared.Http.Requests.Client.Servers.Shares diff --git a/MoonlightServers.Frontend/UI/Components/Stars/Modals/CreateDockerImageModal.razor b/MoonlightServers.Frontend/UI/Components/Stars/Modals/CreateDockerImageModal.razor index 7ae71b7..29acbeb 100644 --- a/MoonlightServers.Frontend/UI/Components/Stars/Modals/CreateDockerImageModal.razor +++ b/MoonlightServers.Frontend/UI/Components/Stars/Modals/CreateDockerImageModal.razor @@ -1,10 +1,11 @@ +@using MoonCore.Blazor.FlyonUi.Components @using MoonCore.Blazor.Tailwind.Modals.Components @using MoonlightServers.Shared.Enums @using MoonlightServers.Frontend.UI.Components.Forms @using MoonCore.Blazor.Tailwind.Components @using MoonlightServers.Shared.Http.Requests.Admin.StarDockerImages -@inherits BaseModal +@inherits MoonCore.Blazor.FlyonUi.Modals.Components.BaseModal

Add a new variable

diff --git a/MoonlightServers.Frontend/UI/Components/Stars/Modals/CreateParseConfigModal.razor b/MoonlightServers.Frontend/UI/Components/Stars/Modals/CreateParseConfigModal.razor index 8761b1e..50c8289 100644 --- a/MoonlightServers.Frontend/UI/Components/Stars/Modals/CreateParseConfigModal.razor +++ b/MoonlightServers.Frontend/UI/Components/Stars/Modals/CreateParseConfigModal.razor @@ -1,9 +1,10 @@ +@using MoonCore.Blazor.FlyonUi.Components @using MoonCore.Blazor.Tailwind.Modals.Components @using MoonlightServers.Shared.Enums @using MoonCore.Blazor.Tailwind.Components @using MoonlightServers.Shared.Models -@inherits BaseModal +@inherits MoonCore.Blazor.FlyonUi.Modals.Components.BaseModal

Add a new parse configuration

diff --git a/MoonlightServers.Frontend/UI/Components/Stars/Modals/CreateVariableModal.razor b/MoonlightServers.Frontend/UI/Components/Stars/Modals/CreateVariableModal.razor index 075e094..e9e19f4 100644 --- a/MoonlightServers.Frontend/UI/Components/Stars/Modals/CreateVariableModal.razor +++ b/MoonlightServers.Frontend/UI/Components/Stars/Modals/CreateVariableModal.razor @@ -1,10 +1,11 @@ +@using MoonCore.Blazor.FlyonUi.Components @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 +@inherits MoonCore.Blazor.FlyonUi.Modals.Components.BaseModal

Add a new variable

diff --git a/MoonlightServers.Frontend/UI/Components/Stars/Modals/UpdateDockerImageModal.razor b/MoonlightServers.Frontend/UI/Components/Stars/Modals/UpdateDockerImageModal.razor index 03ad462..9ec6ce9 100644 --- a/MoonlightServers.Frontend/UI/Components/Stars/Modals/UpdateDockerImageModal.razor +++ b/MoonlightServers.Frontend/UI/Components/Stars/Modals/UpdateDockerImageModal.razor @@ -1,3 +1,4 @@ +@using MoonCore.Blazor.FlyonUi.Components @using MoonCore.Blazor.Tailwind.Modals.Components @using MoonlightServers.Frontend.UI.Components.Forms @using MoonCore.Blazor.Tailwind.Components @@ -5,7 +6,7 @@ @using MoonlightServers.Shared.Http.Requests.Admin.StarDockerImages @using MoonlightServers.Shared.Http.Responses.Admin.StarDockerImages -@inherits BaseModal +@inherits MoonCore.Blazor.FlyonUi.Modals.Components.BaseModal

Update variable

diff --git a/MoonlightServers.Frontend/UI/Components/Stars/Modals/UpdateParseConfigModal.razor b/MoonlightServers.Frontend/UI/Components/Stars/Modals/UpdateParseConfigModal.razor index 7aad328..5c7796f 100644 --- a/MoonlightServers.Frontend/UI/Components/Stars/Modals/UpdateParseConfigModal.razor +++ b/MoonlightServers.Frontend/UI/Components/Stars/Modals/UpdateParseConfigModal.razor @@ -1,10 +1,11 @@ +@using MoonCore.Blazor.FlyonUi.Components @using MoonCore.Blazor.Tailwind.Modals.Components @using MoonlightServers.Shared.Enums @using MoonCore.Blazor.Tailwind.Components @using MoonCore.Helpers @using MoonlightServers.Shared.Models -@inherits BaseModal +@inherits MoonCore.Blazor.FlyonUi.Modals.Components.BaseModal

Update parse configuration

diff --git a/MoonlightServers.Frontend/UI/Components/Stars/Modals/UpdateVariableModal.razor b/MoonlightServers.Frontend/UI/Components/Stars/Modals/UpdateVariableModal.razor index e9764a5..8467f7b 100644 --- a/MoonlightServers.Frontend/UI/Components/Stars/Modals/UpdateVariableModal.razor +++ b/MoonlightServers.Frontend/UI/Components/Stars/Modals/UpdateVariableModal.razor @@ -1,3 +1,4 @@ +@using MoonCore.Blazor.FlyonUi.Components @using MoonCore.Blazor.Tailwind.Modals.Components @using MoonlightServers.Shared.Enums @using MoonlightServers.Shared.Http.Requests.Admin.StarVariables @@ -6,7 +7,7 @@ @using MoonCore.Helpers @using MoonlightServers.Shared.Http.Responses.Admin.StarVariables -@inherits BaseModal +@inherits MoonCore.Blazor.FlyonUi.Modals.Components.BaseModal

Update variable

diff --git a/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/DockerImageStarUpdate.razor b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/DockerImageStarUpdate.razor index cebdf3f..af62447 100644 --- a/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/DockerImageStarUpdate.razor +++ b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/DockerImageStarUpdate.razor @@ -1,3 +1,7 @@ +@using MoonCore.Blazor.FlyonUi.Alerts +@using MoonCore.Blazor.FlyonUi.Components +@using MoonCore.Blazor.FlyonUi.Modals +@using MoonCore.Blazor.FlyonUi.Toasts @using MoonCore.Blazor.Tailwind.Alerts @using MoonCore.Blazor.Tailwind.Components @using MoonCore.Blazor.Tailwind.Modals diff --git a/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/InstallationStarUpdate.razor b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/InstallationStarUpdate.razor index b63ec06..1eb2388 100644 --- a/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/InstallationStarUpdate.razor +++ b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/InstallationStarUpdate.razor @@ -1,3 +1,4 @@ +@using MoonCore.Blazor.FlyonUi.Ace @using MoonlightServers.Shared.Http.Requests.Admin.Stars @using MoonCore.Blazor.Tailwind.Ace diff --git a/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/MiscStarUpdate.razor b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/MiscStarUpdate.razor index 2864f06..b1a0b0b 100644 --- a/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/MiscStarUpdate.razor +++ b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/MiscStarUpdate.razor @@ -1,3 +1,4 @@ +@using MoonCore.Blazor.FlyonUi.Components @using MoonCore.Blazor.Tailwind.Components @using MoonCore.Helpers @using MoonCore.Models diff --git a/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/ParseConfigStarUpdate.razor b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/ParseConfigStarUpdate.razor index 9fff3e1..60929a5 100644 --- a/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/ParseConfigStarUpdate.razor +++ b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/ParseConfigStarUpdate.razor @@ -1,4 +1,7 @@ @using System.Text.Json +@using MoonCore.Blazor.FlyonUi.Alerts +@using MoonCore.Blazor.FlyonUi.Modals +@using MoonCore.Blazor.FlyonUi.Toasts @using MoonCore.Blazor.Tailwind.Alerts @using MoonCore.Blazor.Tailwind.Modals @using MoonCore.Blazor.Tailwind.Toasts diff --git a/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/VariablesStarUpdate.razor b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/VariablesStarUpdate.razor index 8f41803..b94af31 100644 --- a/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/VariablesStarUpdate.razor +++ b/MoonlightServers.Frontend/UI/Components/Stars/UpdateStarPartials/VariablesStarUpdate.razor @@ -1,3 +1,7 @@ +@using MoonCore.Blazor.FlyonUi.Alerts +@using MoonCore.Blazor.FlyonUi.Components +@using MoonCore.Blazor.FlyonUi.Modals +@using MoonCore.Blazor.FlyonUi.Toasts @using MoonCore.Blazor.Tailwind.Alerts @using MoonCore.Blazor.Tailwind.Components @using MoonCore.Blazor.Tailwind.Modals diff --git a/MoonlightServers.Frontend/UI/Views/Admin/All/Create.razor b/MoonlightServers.Frontend/UI/Views/Admin/All/Create.razor index f7a4e59..2a5388d 100644 --- a/MoonlightServers.Frontend/UI/Views/Admin/All/Create.razor +++ b/MoonlightServers.Frontend/UI/Views/Admin/All/Create.razor @@ -1,5 +1,7 @@ @page "/admin/servers/all/create" +@using MoonCore.Blazor.FlyonUi.Components +@using MoonCore.Blazor.FlyonUi.Toasts @using MoonCore.Blazor.Tailwind.Components @using MoonCore.Blazor.Tailwind.Toasts @using MoonCore.Helpers diff --git a/MoonlightServers.Frontend/UI/Views/Admin/All/Index.razor b/MoonlightServers.Frontend/UI/Views/Admin/All/Index.razor index f67e6b7..7357a03 100644 --- a/MoonlightServers.Frontend/UI/Views/Admin/All/Index.razor +++ b/MoonlightServers.Frontend/UI/Views/Admin/All/Index.razor @@ -1,5 +1,8 @@ @page "/admin/servers/all" +@using MoonCore.Blazor.FlyonUi.Alerts +@using MoonCore.Blazor.FlyonUi.DataTables +@using MoonCore.Blazor.FlyonUi.Toasts @using MoonCore.Blazor.Tailwind.Alerts @using MoonCore.Helpers @using MoonCore.Models @@ -28,13 +31,13 @@
- + - + - - - + + + @{ var node = Nodes.FirstOrDefault(x => x.Id == context.NodeId); @@ -45,7 +48,7 @@ - + @{ var star = Stars.FirstOrDefault(x => x.Id == context.StarId); @@ -56,7 +59,7 @@ - +
@@ -75,21 +78,21 @@ @code { - private DataTable Table; + private DataTable Table; private List Stars = new(); - private List Nodes = new(); + private List Nodes = new(); - private async Task> LoadData(PaginationOptions options) + private async Task> LoadData(PaginationOptions options) { // Clear potential previous data - var data = await ApiClient.GetJson>($"api/admin/servers?page={options.Page}&pageSize={options.PerPage}"); + var data = await ApiClient.GetJson>($"api/admin/servers?page={options.Page}&pageSize={options.PerPage}"); foreach (var item in data.Items) { if (Nodes.All(x => x.Id != item.NodeId)) { - var node = await ApiClient.GetJson($"api/admin/servers/nodes/{item.NodeId}"); + var node = await ApiClient.GetJson($"api/admin/servers/nodes/{item.NodeId}"); Nodes.Add(node); } @@ -103,14 +106,14 @@ return data; } - private async Task Delete(ServerDetailResponse detailResponse) + private async Task Delete(ServerResponse response) { await AlertService.ConfirmDanger( "Server deletion", - $"Do you really want to delete the server '{detailResponse.Name}'", + $"Do you really want to delete the server '{response.Name}'", async () => { - await ApiClient.Delete($"api/admin/servers/{detailResponse.Id}"); + await ApiClient.Delete($"api/admin/servers/{response.Id}"); await ToastService.Success("Successfully deleted server"); await Table.Refresh(); diff --git a/MoonlightServers.Frontend/UI/Views/Admin/All/Update.razor b/MoonlightServers.Frontend/UI/Views/Admin/All/Update.razor index 7a9e171..47ef7d6 100644 --- a/MoonlightServers.Frontend/UI/Views/Admin/All/Update.razor +++ b/MoonlightServers.Frontend/UI/Views/Admin/All/Update.razor @@ -1,5 +1,7 @@ @page "/admin/servers/all/update/{Id:int}" +@using MoonCore.Blazor.FlyonUi.Components +@using MoonCore.Blazor.FlyonUi.Toasts @using MoonCore.Blazor.Tailwind.Components @using MoonCore.Blazor.Tailwind.Toasts @using MoonCore.Helpers @@ -51,11 +53,11 @@ private HandleForm Form; private UpdateServerRequest Request; - private ServerDetailResponse Server; + private ServerResponse Server; private async Task Load(LazyLoader _) { - Server = await ApiClient.GetJson($"api/admin/servers/{Id}"); + Server = await ApiClient.GetJson($"api/admin/servers/{Id}"); Request = Mapper.Map(Server); } diff --git a/MoonlightServers.Frontend/UI/Views/Admin/Nodes/Create.razor b/MoonlightServers.Frontend/UI/Views/Admin/Nodes/Create.razor index 8dc5676..443f360 100644 --- a/MoonlightServers.Frontend/UI/Views/Admin/Nodes/Create.razor +++ b/MoonlightServers.Frontend/UI/Views/Admin/Nodes/Create.razor @@ -1,5 +1,7 @@ @page "/admin/servers/nodes/create" +@using MoonCore.Blazor.FlyonUi.Components +@using MoonCore.Blazor.FlyonUi.Toasts @using MoonCore.Blazor.Tailwind.Components @using MoonCore.Blazor.Tailwind.Toasts @using MoonCore.Helpers diff --git a/MoonlightServers.Frontend/UI/Views/Admin/Nodes/Index.razor b/MoonlightServers.Frontend/UI/Views/Admin/Nodes/Index.razor index ebf111e..be86df1 100644 --- a/MoonlightServers.Frontend/UI/Views/Admin/Nodes/Index.razor +++ b/MoonlightServers.Frontend/UI/Views/Admin/Nodes/Index.razor @@ -1,5 +1,8 @@ @page "/admin/servers/nodes" +@using MoonCore.Blazor.FlyonUi.Alerts +@using MoonCore.Blazor.FlyonUi.DataTables +@using MoonCore.Blazor.FlyonUi.Toasts @using MoonCore.Blazor.Tailwind.Alerts @using MoonCore.Helpers @using MoonCore.Models @@ -31,20 +34,20 @@
- + - + - - + + @context.Name
- - + + @{ var isFetched = StatusResponses.TryGetValue(context.Id, out var data); @@ -92,7 +95,7 @@ } - @@ -138,7 +141,7 @@ } - +
@@ -157,17 +160,17 @@ @code { - private DataTable Table; + private DataTable Table; private Dictionary StatusResponses = new(); private Dictionary Statistics = new(); - private async Task> LoadData(PaginationOptions options) + private async Task> LoadData(PaginationOptions options) { Statistics.Clear(); StatusResponses.Clear(); - var result = await ApiClient.GetJson>( + var result = await ApiClient.GetJson>( $"api/admin/servers/nodes?page={options.Page}&pageSize={options.PerPage}" ); @@ -214,14 +217,14 @@ return result; } - private async Task Delete(NodeDetailResponse detailResponse) + private async Task Delete(NodeResponse response) { await AlertService.ConfirmDanger( "Node deletion", - $"Do you really want to delete the node '{detailResponse.Name}'", + $"Do you really want to delete the node '{response.Name}'", async () => { - await ApiClient.Delete($"api/admin/servers/nodes/{detailResponse.Id}"); + await ApiClient.Delete($"api/admin/servers/nodes/{response.Id}"); await ToastService.Success("Successfully deleted node"); await Table.Refresh(); diff --git a/MoonlightServers.Frontend/UI/Views/Admin/Nodes/Update.razor b/MoonlightServers.Frontend/UI/Views/Admin/Nodes/Update.razor index ab11ef0..8696847 100644 --- a/MoonlightServers.Frontend/UI/Views/Admin/Nodes/Update.razor +++ b/MoonlightServers.Frontend/UI/Views/Admin/Nodes/Update.razor @@ -1,5 +1,7 @@ @page "/admin/servers/nodes/update/{Id:int}" +@using MoonCore.Blazor.FlyonUi.Components +@using MoonCore.Blazor.FlyonUi.Toasts @using MoonCore.Blazor.Tailwind.Components @using MoonCore.Blazor.Tailwind.Toasts @using MoonCore.Helpers @@ -56,11 +58,11 @@ private HandleForm Form; private UpdateNodeRequest Request; - private NodeDetailResponse Node; + private NodeResponse Node; private async Task Load(LazyLoader _) { - Node = await ApiClient.GetJson($"api/admin/servers/nodes/{Id}"); + Node = await ApiClient.GetJson($"api/admin/servers/nodes/{Id}"); Request = Mapper.Map(Node); } diff --git a/MoonlightServers.Frontend/UI/Views/Admin/Stars/Create.razor b/MoonlightServers.Frontend/UI/Views/Admin/Stars/Create.razor index ad0ecfd..79cf928 100644 --- a/MoonlightServers.Frontend/UI/Views/Admin/Stars/Create.razor +++ b/MoonlightServers.Frontend/UI/Views/Admin/Stars/Create.razor @@ -1,6 +1,8 @@ @page "/admin/servers/stars/create" @using Microsoft.AspNetCore.Components.Authorization +@using MoonCore.Blazor.FlyonUi.Components +@using MoonCore.Blazor.FlyonUi.Toasts @using MoonCore.Blazor.Tailwind.Components @using MoonCore.Blazor.Tailwind.Toasts @using MoonCore.Helpers diff --git a/MoonlightServers.Frontend/UI/Views/Admin/Stars/Index.razor b/MoonlightServers.Frontend/UI/Views/Admin/Stars/Index.razor index 8d132c0..06e6903 100644 --- a/MoonlightServers.Frontend/UI/Views/Admin/Stars/Index.razor +++ b/MoonlightServers.Frontend/UI/Views/Admin/Stars/Index.razor @@ -1,5 +1,9 @@ @page "/admin/servers/stars" +@using MoonCore.Blazor.FlyonUi.Alerts +@using MoonCore.Blazor.FlyonUi.DataTables +@using MoonCore.Blazor.FlyonUi.Helpers +@using MoonCore.Blazor.FlyonUi.Toasts @using MoonCore.Blazor.Tailwind.Alerts @using MoonCore.Helpers @using MoonCore.Models diff --git a/MoonlightServers.Frontend/UI/Views/Admin/Stars/Update.razor b/MoonlightServers.Frontend/UI/Views/Admin/Stars/Update.razor index 57885d0..60e967f 100644 --- a/MoonlightServers.Frontend/UI/Views/Admin/Stars/Update.razor +++ b/MoonlightServers.Frontend/UI/Views/Admin/Stars/Update.razor @@ -1,5 +1,7 @@ @page "/admin/servers/stars/update/{Id:int}" +@using MoonCore.Blazor.FlyonUi.Components +@using MoonCore.Blazor.FlyonUi.Toasts @using MoonCore.Blazor.Tailwind.Components @using MoonCore.Blazor.Tailwind.Toasts @using MoonCore.Helpers diff --git a/MoonlightServers.Frontend/UI/Views/Client/Index.razor b/MoonlightServers.Frontend/UI/Views/Client/Index.razor index 106f321..1311f01 100644 --- a/MoonlightServers.Frontend/UI/Views/Client/Index.razor +++ b/MoonlightServers.Frontend/UI/Views/Client/Index.razor @@ -1,5 +1,6 @@ @page "/servers" +@using MoonCore.Blazor.FlyonUi.Components @using MoonlightServers.Frontend.UI.Components.Servers @using MoonCore.Blazor.Tailwind.Components @using MoonCore.Models diff --git a/MoonlightServers.Frontend/UI/Views/Client/Manage.razor b/MoonlightServers.Frontend/UI/Views/Client/Manage.razor index 390d499..623bcc3 100644 --- a/MoonlightServers.Frontend/UI/Views/Client/Manage.razor +++ b/MoonlightServers.Frontend/UI/Views/Client/Manage.razor @@ -2,6 +2,7 @@ @page "/servers/{ServerId:int}/{TabPath:alpha}" @using Microsoft.AspNetCore.SignalR.Client +@using MoonCore.Blazor.FlyonUi.Components @using MoonCore.Blazor.Tailwind.Components @using MoonCore.Exceptions @using MoonCore.Helpers diff --git a/MoonlightServers.Shared/Http/Responses/Admin/NodeAllocations/NodeAllocationDetailResponse.cs b/MoonlightServers.Shared/Http/Responses/Admin/NodeAllocations/NodeAllocationResponse.cs similarity index 81% rename from MoonlightServers.Shared/Http/Responses/Admin/NodeAllocations/NodeAllocationDetailResponse.cs rename to MoonlightServers.Shared/Http/Responses/Admin/NodeAllocations/NodeAllocationResponse.cs index 477e6e6..b040024 100644 --- a/MoonlightServers.Shared/Http/Responses/Admin/NodeAllocations/NodeAllocationDetailResponse.cs +++ b/MoonlightServers.Shared/Http/Responses/Admin/NodeAllocations/NodeAllocationResponse.cs @@ -1,6 +1,6 @@ namespace MoonlightServers.Shared.Http.Responses.Admin.NodeAllocations; -public class NodeAllocationDetailResponse +public class NodeAllocationResponse { public int Id { get; set; } diff --git a/MoonlightServers.Shared/Http/Responses/Admin/Nodes/NodeDetailResponse.cs b/MoonlightServers.Shared/Http/Responses/Admin/Nodes/NodeResponse.cs similarity index 91% rename from MoonlightServers.Shared/Http/Responses/Admin/Nodes/NodeDetailResponse.cs rename to MoonlightServers.Shared/Http/Responses/Admin/Nodes/NodeResponse.cs index f93c43c..26585bb 100644 --- a/MoonlightServers.Shared/Http/Responses/Admin/Nodes/NodeDetailResponse.cs +++ b/MoonlightServers.Shared/Http/Responses/Admin/Nodes/NodeResponse.cs @@ -1,6 +1,6 @@ namespace MoonlightServers.Shared.Http.Responses.Admin.Nodes; -public class NodeDetailResponse +public class NodeResponse { public int Id { get; set; } diff --git a/MoonlightServers.Shared/Http/Responses/Admin/ServerVariables/ServerVariableDetailResponse.cs b/MoonlightServers.Shared/Http/Responses/Admin/ServerVariables/ServerVariableResponse.cs similarity index 81% rename from MoonlightServers.Shared/Http/Responses/Admin/ServerVariables/ServerVariableDetailResponse.cs rename to MoonlightServers.Shared/Http/Responses/Admin/ServerVariables/ServerVariableResponse.cs index f829c0b..64d6857 100644 --- a/MoonlightServers.Shared/Http/Responses/Admin/ServerVariables/ServerVariableDetailResponse.cs +++ b/MoonlightServers.Shared/Http/Responses/Admin/ServerVariables/ServerVariableResponse.cs @@ -1,6 +1,6 @@ namespace MoonlightServers.Shared.Http.Responses.Admin.ServerVariables; -public class ServerVariableDetailResponse +public class ServerVariableResponse { public int Id { get; set; } public string Key { get; set; } diff --git a/MoonlightServers.Shared/Http/Responses/Admin/Servers/ServerDetailResponse.cs b/MoonlightServers.Shared/Http/Responses/Admin/Servers/ServerResponse.cs similarity index 77% rename from MoonlightServers.Shared/Http/Responses/Admin/Servers/ServerDetailResponse.cs rename to MoonlightServers.Shared/Http/Responses/Admin/Servers/ServerResponse.cs index 67c7296..c8ac9aa 100644 --- a/MoonlightServers.Shared/Http/Responses/Admin/Servers/ServerDetailResponse.cs +++ b/MoonlightServers.Shared/Http/Responses/Admin/Servers/ServerResponse.cs @@ -1,9 +1,6 @@ -using MoonlightServers.Shared.Http.Responses.Admin.NodeAllocations; -using MoonlightServers.Shared.Http.Responses.Admin.ServerVariables; - namespace MoonlightServers.Shared.Http.Responses.Admin.Servers; -public class ServerDetailResponse +public class ServerResponse { public int Id { get; set; } diff --git a/MoonlightServers.sln b/MoonlightServers.sln index 881b1ad..b262b1c 100644 --- a/MoonlightServers.sln +++ b/MoonlightServers.sln @@ -15,6 +15,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution plugin.json = plugin.json EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Runtime", "Runtime", "{7836BC34-096D-440C-9DF9-81116EACAABA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MoonlightServers.ApiServer.Runtime", "MoonlightServers.ApiServer.Runtime\MoonlightServers.ApiServer.Runtime.csproj", "{9F4370FA-C38D-4E84-892F-12ED5DD40FC6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MoonlightServers.Frontend.Runtime", "MoonlightServers.Frontend.Runtime\MoonlightServers.Frontend.Runtime.csproj", "{97BDDD86-6FE1-42E0-BF16-152DFABC8287}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -41,5 +47,17 @@ Global {15EBCC5D-2440-4B5B-A046-F8327E0C1CB8}.Debug|Any CPU.Build.0 = Debug|Any CPU {15EBCC5D-2440-4B5B-A046-F8327E0C1CB8}.Release|Any CPU.ActiveCfg = Release|Any CPU {15EBCC5D-2440-4B5B-A046-F8327E0C1CB8}.Release|Any CPU.Build.0 = Release|Any CPU + {9F4370FA-C38D-4E84-892F-12ED5DD40FC6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9F4370FA-C38D-4E84-892F-12ED5DD40FC6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9F4370FA-C38D-4E84-892F-12ED5DD40FC6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9F4370FA-C38D-4E84-892F-12ED5DD40FC6}.Release|Any CPU.Build.0 = Release|Any CPU + {97BDDD86-6FE1-42E0-BF16-152DFABC8287}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {97BDDD86-6FE1-42E0-BF16-152DFABC8287}.Debug|Any CPU.Build.0 = Debug|Any CPU + {97BDDD86-6FE1-42E0-BF16-152DFABC8287}.Release|Any CPU.ActiveCfg = Release|Any CPU + {97BDDD86-6FE1-42E0-BF16-152DFABC8287}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {9F4370FA-C38D-4E84-892F-12ED5DD40FC6} = {7836BC34-096D-440C-9DF9-81116EACAABA} + {97BDDD86-6FE1-42E0-BF16-152DFABC8287} = {7836BC34-096D-440C-9DF9-81116EACAABA} EndGlobalSection EndGlobal