Added missing relations to server db model. Started with server crud. Removed unused relations from detail responses
This commit is contained in:
@@ -20,7 +20,6 @@
|
||||
<ItemGroup>
|
||||
<Folder Include="Helpers\"/>
|
||||
<Folder Include="Interfaces\"/>
|
||||
<Folder Include="UI\Views\Admin\All\" />
|
||||
<Folder Include="wwwroot\"/>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="flex flex-col gap-y-3">
|
||||
<button @onclick="AddAllocation" class="btn btn-primary">Create allocation</button>
|
||||
<button @onclick="AddAllocationRange" class="btn btn-tertiary">Add multiple</button>
|
||||
<button @onclick="AddAllocation" class="btn btn-primary">Create</button>
|
||||
<button @onclick="AddAllocationRange" class="btn btn-tertiary">Create multiple</button>
|
||||
<button @onclick="DeleteAllAllocations" class="btn btn-danger">Delete all</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Servers
|
||||
@using MoonlightServers.Frontend.UI.Components.Forms
|
||||
|
||||
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Use Virtual Disk</label>
|
||||
<div class="mt-2">
|
||||
<Switch @bind-Value="Request.UseVirtualDisk"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Bandwidth</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.Bandwidth" type="number" autocomplete="off" class="form-input w-full">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public CreateServerRequest Request { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Servers
|
||||
@using MoonlightServers.Frontend.UI.Components.Forms
|
||||
@using MoonCore.Helpers
|
||||
@using MoonCore.Models
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Stars
|
||||
@using MoonCore.Blazor.Tailwind.Inputs
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
|
||||
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Name</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.Name" type="text" autocomplete="off" class="form-input w-full">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Star</label>
|
||||
<div class="mt-2">
|
||||
<InputItemSelect TItem="StarDetailResponse"
|
||||
TProperty="int"
|
||||
@bind-Value="Request.StarId"
|
||||
DisplayProperty="@(x => x.Name)"
|
||||
ValueProperty="@(x => x?.Id ?? -1)"
|
||||
Loader="LoadStars"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Node</label>
|
||||
<div class="mt-2">
|
||||
<InputItemSelect TItem="NodeDetailResponse"
|
||||
TProperty="int"
|
||||
@bind-Value="Request.NodeId"
|
||||
DisplayProperty="@(x => x.Name)"
|
||||
ValueProperty="@(x => x?.Id ?? -1)"
|
||||
Loader="LoadNodes"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="border-t border-gray-100/10 pt-6 my-8">
|
||||
<div class="mb-8"><h2 class="text-base font-semibold leading-7 text-gray-100">
|
||||
Resources
|
||||
</h2>
|
||||
<p class="mt-1 text-sm leading-6 text-gray-400">Define the servers resource limit</p></div>
|
||||
|
||||
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Cpu</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.Cpu" type="number" autocomplete="off" class="form-input w-full">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Memory</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.Memory" type="number" autocomplete="off" class="form-input w-full">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Disk</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.Disk" type="number" autocomplete="off" class="form-input w-full">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public CreateServerRequest Request { get; set; }
|
||||
|
||||
private async Task<StarDetailResponse[]> LoadStars()
|
||||
{
|
||||
var starData = await ApiClient.GetJson<PagedData<StarDetailResponse>>("api/admin/servers/stars?page=0&pageSize=50");
|
||||
return starData.Items;
|
||||
}
|
||||
|
||||
private async Task<NodeDetailResponse[]> LoadNodes()
|
||||
{
|
||||
var nodeData = await ApiClient.GetJson<PagedData<NodeDetailResponse>>("api/admin/servers/nodes?page=0&pageSize=50");
|
||||
return nodeData.Items;
|
||||
}
|
||||
}
|
||||
58
MoonlightServers.Frontend/UI/Views/Admin/All/Create.razor
Normal file
58
MoonlightServers.Frontend/UI/Views/Admin/All/Create.razor
Normal file
@@ -0,0 +1,58 @@
|
||||
@page "/admin/servers/all/create"
|
||||
|
||||
@using MoonCore.Blazor.Tailwind.Components
|
||||
@using MoonCore.Blazor.Tailwind.Forms
|
||||
@using MoonCore.Blazor.Tailwind.Toasts
|
||||
@using MoonCore.Helpers
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Servers
|
||||
@using MoonlightServers.Frontend.UI.Components.Servers.CreateServerPartials
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ToastService ToastService
|
||||
|
||||
<PageHeader Title="Create Server">
|
||||
<button @onclick="GoBack" type="button" class="btn btn-secondary">
|
||||
<i class="icon-chevron-left mr-1"></i>
|
||||
Back
|
||||
</button>
|
||||
<WButton OnClick="_ => Form.Submit()" CssClasses="btn btn-primary">
|
||||
<i class="icon-check mr-1"></i>
|
||||
Create
|
||||
</WButton>
|
||||
</PageHeader>
|
||||
|
||||
<div class="mt-5">
|
||||
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
|
||||
<Tabs>
|
||||
<Tab Name="General">
|
||||
<GeneralServerCreate Request="Request" />
|
||||
</Tab>
|
||||
<Tab Name="Advanced">
|
||||
<AdvancedServerCreate Request="Request" />
|
||||
</Tab>
|
||||
</Tabs>
|
||||
</HandleForm>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
private HandleForm Form;
|
||||
private CreateServerRequest Request;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
Request = new();
|
||||
}
|
||||
|
||||
private async Task OnSubmit()
|
||||
{
|
||||
await ApiClient.Post("api/admin/servers", Request);
|
||||
|
||||
await ToastService.Success("Successfully created Server");
|
||||
GoBack();
|
||||
}
|
||||
|
||||
private void GoBack()
|
||||
=> Navigation.NavigateTo(ComponentHelper.GetRouteOfComponent<Index>()!);
|
||||
}
|
||||
94
MoonlightServers.Frontend/UI/Views/Admin/All/Index.razor
Normal file
94
MoonlightServers.Frontend/UI/Views/Admin/All/Index.razor
Normal file
@@ -0,0 +1,94 @@
|
||||
@page "/admin/servers/all"
|
||||
|
||||
@using MoonCore.Blazor.Tailwind.MinimalCrud
|
||||
@using MoonCore.Blazor.Tailwind.DataTable
|
||||
@using MoonCore.Helpers
|
||||
@using MoonCore.Models
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Servers
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Stars
|
||||
@using MoonCore.Blazor.Tailwind.Components
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
|
||||
<div class="mb-3">
|
||||
<NavTabs Index="1" Names="@UiConstants.AdminNavNames" Links="@UiConstants.AdminNavLinks"/>
|
||||
</div>
|
||||
|
||||
<MinimalCrud TItem="ServerDetailResponse" OnConfigure="OnConfigure">
|
||||
<ChildContent>
|
||||
<DataColumn TItem="ServerDetailResponse" Field="@(x => x.Id)" Title="Id" IsSortable="true"/>
|
||||
<DataColumn TItem="ServerDetailResponse" Field="@(x => x.Name)" Title="Name"/>
|
||||
<DataColumn TItem="ServerDetailResponse" Field="@(x => x.NodeId)" Title="Node">
|
||||
<Template>
|
||||
@{
|
||||
var node = Nodes.FirstOrDefault(x => x.Id == context.NodeId);
|
||||
}
|
||||
|
||||
@if (node != null)
|
||||
{
|
||||
<span>@node.Name</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>N/A</span>
|
||||
}
|
||||
</Template>
|
||||
</DataColumn>
|
||||
<DataColumn TItem="ServerDetailResponse" Field="@(x => x.StarId)" Title="Star">
|
||||
<Template>
|
||||
@{
|
||||
var star = Stars.FirstOrDefault(x => x.Id == context.StarId);
|
||||
}
|
||||
|
||||
@if (star != null)
|
||||
{
|
||||
<span>@star.Name</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>N/A</span>
|
||||
}
|
||||
</Template>
|
||||
</DataColumn>
|
||||
</ChildContent>
|
||||
</MinimalCrud>
|
||||
|
||||
@code
|
||||
{
|
||||
private List<StarDetailResponse> Stars = new();
|
||||
private List<NodeDetailResponse> Nodes = new();
|
||||
|
||||
private void OnConfigure(MinimalCrudOptions<ServerDetailResponse> options)
|
||||
{
|
||||
options.Title = "Servers";
|
||||
options.ItemLoader = LoadItems;
|
||||
|
||||
options.CreateUrl = ComponentHelper.GetRouteOfComponent<Create>();
|
||||
options.UpdateUrl = item => ComponentHelper.GetRouteOfComponent<Update>(item.Id)!;
|
||||
options.DeleteFunction = async item => await ApiClient.Delete($"api/admin/servers/{item.Id}");
|
||||
}
|
||||
|
||||
private async Task<IPagedData<ServerDetailResponse>> LoadItems(int page, int pageSize)
|
||||
{
|
||||
// Clear potential previous data
|
||||
var data = await ApiClient.GetJson<PagedData<ServerDetailResponse>>($"api/admin/servers?page={page}&pageSize={pageSize}");
|
||||
|
||||
foreach (var item in data.Items)
|
||||
{
|
||||
if (Nodes.All(x => x.Id != item.NodeId))
|
||||
{
|
||||
var node = await ApiClient.GetJson<NodeDetailResponse>($"api/admin/servers/nodes/{item.NodeId}");
|
||||
Nodes.Add(node);
|
||||
}
|
||||
|
||||
if (Stars.All(x => x.Id != item.StarId))
|
||||
{
|
||||
var star = await ApiClient.GetJson<StarDetailResponse>($"api/admin/servers/stars/{item.StarId}");
|
||||
Stars.Add(star);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
61
MoonlightServers.Frontend/UI/Views/Admin/All/Update.razor
Normal file
61
MoonlightServers.Frontend/UI/Views/Admin/All/Update.razor
Normal file
@@ -0,0 +1,61 @@
|
||||
@page "/admin/servers/all/update/{Id:int}"
|
||||
|
||||
@using MoonCore.Blazor.Tailwind.Components
|
||||
@using MoonCore.Blazor.Tailwind.Forms
|
||||
@using MoonCore.Blazor.Tailwind.Toasts
|
||||
@using MoonCore.Helpers
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Servers
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Servers
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ToastService ToastService
|
||||
|
||||
<LazyLoader Load="Load">
|
||||
<PageHeader Title="Update Server">
|
||||
<button @onclick="GoBack" type="button" class="btn btn-secondary">
|
||||
<i class="icon-chevron-left mr-1"></i>
|
||||
Back
|
||||
</button>
|
||||
<WButton OnClick="_ => Form.Submit()" CssClasses="btn btn-primary">
|
||||
<i class="icon-check mr-1"></i>
|
||||
Update
|
||||
</WButton>
|
||||
</PageHeader>
|
||||
|
||||
<div class="mt-5">
|
||||
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
|
||||
<GeneratedForm TForm="UpdateServerRequest" Model="Request" OnConfigure="OnConfigure"/>
|
||||
</HandleForm>
|
||||
</div>
|
||||
</LazyLoader>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public int Id { get; set; }
|
||||
|
||||
private HandleForm Form;
|
||||
private UpdateServerRequest Request;
|
||||
|
||||
private async Task Load(LazyLoader _)
|
||||
{
|
||||
var detail = await ApiClient.GetJson<ServerDetailResponse>($"api/admin/servers/{Id}");
|
||||
Request = Mapper.Map<UpdateServerRequest>(detail);
|
||||
}
|
||||
|
||||
private void OnConfigure(FormConfiguration<UpdateServerRequest> configuration)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private async Task OnSubmit()
|
||||
{
|
||||
await ApiClient.Patch($"api/admin/servers/{Id}", Request);
|
||||
|
||||
await ToastService.Success("Successfully updated Server");
|
||||
GoBack();
|
||||
}
|
||||
|
||||
private void GoBack()
|
||||
=> Navigation.NavigateTo(ComponentHelper.GetRouteOfComponent<Index>()!);
|
||||
}
|
||||
Reference in New Issue
Block a user