Added simple node crud
This commit is contained in:
72
MoonlightServers.Frontend/UI/Views/Admin/Nodes/Create.razor
Normal file
72
MoonlightServers.Frontend/UI/Views/Admin/Nodes/Create.razor
Normal file
@@ -0,0 +1,72 @@
|
||||
@page "/admin/servers/nodes/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.Nodes
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ToastService ToastService
|
||||
|
||||
<PageHeader Title="Create Node">
|
||||
<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">
|
||||
<GeneratedForm TForm="CreateNodeRequest" Model="Request" OnConfigure="OnConfigure"/>
|
||||
</HandleForm>
|
||||
</div>
|
||||
|
||||
@code
|
||||
|
||||
{
|
||||
private HandleForm Form;
|
||||
private CreateNodeRequest Request;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
Request = new();
|
||||
}
|
||||
|
||||
private void OnConfigure(FormConfiguration<CreateNodeRequest> configuration)
|
||||
{
|
||||
configuration.WithField(x => x.Name);
|
||||
configuration.WithField(x => x.Fqdn);
|
||||
|
||||
configuration.WithField(x => x.HttpPort, fieldConfiguration =>
|
||||
{
|
||||
fieldConfiguration.DefaultValue = 8080;
|
||||
});
|
||||
|
||||
configuration.WithField(x => x.FtpPort, fieldConfiguration =>
|
||||
{
|
||||
fieldConfiguration.DefaultValue = 2021;
|
||||
});
|
||||
|
||||
var advancedPage = configuration.WithPage("Advanced");
|
||||
|
||||
advancedPage.WithField(x => x.EnableTransparentMode);
|
||||
advancedPage.WithField(x => x.EnableDynamicFirewall);
|
||||
}
|
||||
|
||||
private async Task OnSubmit()
|
||||
{
|
||||
await ApiClient.Post("api/admin/servers/nodes", Request);
|
||||
|
||||
await ToastService.Success("Successfully created Node");
|
||||
GoBack();
|
||||
}
|
||||
|
||||
private void GoBack()
|
||||
=> Navigation.NavigateTo(ComponentHelper.GetRouteOfComponent<Index>()!);
|
||||
}
|
||||
80
MoonlightServers.Frontend/UI/Views/Admin/Nodes/Index.razor
Normal file
80
MoonlightServers.Frontend/UI/Views/Admin/Nodes/Index.razor
Normal file
@@ -0,0 +1,80 @@
|
||||
@page "/admin/servers/nodes"
|
||||
|
||||
@using MoonCore.Blazor.Tailwind.MinimalCrud
|
||||
@using MoonCore.Helpers
|
||||
@using MoonCore.Models
|
||||
@using MoonCore.Blazor.Tailwind.DataTable
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes
|
||||
@using MoonCore.Blazor.Tailwind.Components
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
|
||||
<div class="mb-3">
|
||||
<NavTabs Index="2" Names="@UiConstants.AdminNavNames" Links="@UiConstants.AdminNavLinks"/>
|
||||
</div>
|
||||
|
||||
<MinimalCrud TItem="NodeDetailResponse" OnConfigure="OnConfigure">
|
||||
<ChildContent>
|
||||
<DataColumn TItem="NodeDetailResponse" Field="@(x => x.Id)" Title="Id" IsSortable="true"/>
|
||||
<DataColumn TItem="NodeDetailResponse" Field="@(x => x.Name)" Title="Name" IsSortable="true"/>
|
||||
<DataColumn TItem="NodeDetailResponse" Field="@(x => x.Fqdn)" Title="Fqdn"/>
|
||||
<DataColumn TItem="NodeDetailResponse" Field="@(x => x.Fqdn)" Title="Status">
|
||||
<Template>
|
||||
<span class="text-success-500">
|
||||
<i class="icon-check text-base me-1 align-middle"></i>
|
||||
<span class="align-middle">Online (v.2.1.0)</span>
|
||||
</span>
|
||||
</Template>
|
||||
</DataColumn>
|
||||
<DataColumn TItem="NodeDetailResponse"
|
||||
Title=""
|
||||
HeadCssClasses="p-2 font-semibold text-left hidden xl:table-cell"
|
||||
CssClasses="p-2 text-left font-normal hidden xl:table-cell">
|
||||
<Template>
|
||||
<div>
|
||||
<i class="icon-cpu text-lg me-1 align-middle text-primary-500"></i>
|
||||
<span class="align-middle">33% of 6 Cores</span>
|
||||
</div>
|
||||
</Template>
|
||||
</DataColumn>
|
||||
<DataColumn TItem="NodeDetailResponse"
|
||||
Title=""
|
||||
HeadCssClasses="p-2 font-semibold text-left hidden xl:table-cell"
|
||||
CssClasses="p-2 text-left font-normal hidden xl:table-cell">
|
||||
<Template>
|
||||
<div>
|
||||
<i class="icon-memory-stick text-lg me-1 align-middle text-primary-500"></i>
|
||||
<span class="align-middle">1.56GB / 64GB</span>
|
||||
</div>
|
||||
</Template>
|
||||
</DataColumn>
|
||||
<DataColumn TItem="NodeDetailResponse"
|
||||
Title=""
|
||||
HeadCssClasses="p-2 font-semibold text-left hidden xl:table-cell"
|
||||
CssClasses="p-2 text-left font-normal hidden xl:table-cell">
|
||||
<Template>
|
||||
<div>
|
||||
<i class="icon-hard-drive text-lg me-1 align-middle text-primary-500"></i>
|
||||
<span class="align-middle">78.68GB / 1TB</span>
|
||||
</div>
|
||||
</Template>
|
||||
</DataColumn>
|
||||
</ChildContent>
|
||||
</MinimalCrud>
|
||||
|
||||
@code
|
||||
|
||||
|
||||
|
||||
{
|
||||
private void OnConfigure(MinimalCrudOptions<NodeDetailResponse> options)
|
||||
{
|
||||
options.Title = "Nodes";
|
||||
options.ItemLoader = async (page, pageSize) =>
|
||||
await ApiClient.GetJson<PagedData<NodeDetailResponse>>($"api/admin/servers/nodes?page={page}&pageSize={pageSize}");
|
||||
|
||||
options.CreateUrl = ComponentHelper.GetRouteOfComponent<Create>();
|
||||
options.UpdateUrl = item => ComponentHelper.GetRouteOfComponent<Update>(item.Id)!;
|
||||
options.DeleteFunction = async item => await ApiClient.Delete($"api/admin/servers/nodes/{item.Id}");
|
||||
}
|
||||
}
|
||||
69
MoonlightServers.Frontend/UI/Views/Admin/Nodes/Update.razor
Normal file
69
MoonlightServers.Frontend/UI/Views/Admin/Nodes/Update.razor
Normal file
@@ -0,0 +1,69 @@
|
||||
@page "/admin/servers/nodes/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.Nodes
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ToastService ToastService
|
||||
|
||||
<LazyLoader Load="Load">
|
||||
<PageHeader Title="Update Node">
|
||||
<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="UpdateNodeRequest" Model="Request" OnConfigure="OnConfigure"/>
|
||||
</HandleForm>
|
||||
</div>
|
||||
</LazyLoader>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public int Id { get; set; }
|
||||
|
||||
private HandleForm Form;
|
||||
private UpdateNodeRequest Request;
|
||||
|
||||
private async Task Load(LazyLoader _)
|
||||
{
|
||||
var detail = await ApiClient.GetJson<NodeDetailResponse>($"api/admin/servers/nodes/{Id}");
|
||||
Request = Mapper.Map<UpdateNodeRequest>(detail);
|
||||
}
|
||||
|
||||
private void OnConfigure(FormConfiguration<UpdateNodeRequest> configuration)
|
||||
{
|
||||
configuration.WithField(x => x.Name);
|
||||
configuration.WithField(x => x.Fqdn);
|
||||
configuration.WithField(x => x.HttpPort);
|
||||
configuration.WithField(x => x.FtpPort);
|
||||
|
||||
var advancedPage = configuration.WithPage("Advanced");
|
||||
|
||||
advancedPage.WithField(x => x.EnableTransparentMode);
|
||||
advancedPage.WithField(x => x.EnableDynamicFirewall);
|
||||
}
|
||||
|
||||
private async Task OnSubmit()
|
||||
{
|
||||
await ApiClient.Patch($"api/admin/servers/nodes/{Id}", Request);
|
||||
|
||||
await ToastService.Success("Successfully updated Node");
|
||||
GoBack();
|
||||
}
|
||||
|
||||
private void GoBack()
|
||||
=> Navigation.NavigateTo(ComponentHelper.GetRouteOfComponent<Index>()!);
|
||||
}
|
||||
Reference in New Issue
Block a user