Updated the usage of mooncore components
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MoonCore.Attributes;
|
||||
using MoonCore.Extended.PermFilter;
|
||||
using MoonCore.Exceptions;
|
||||
using MoonCore.Extended.Abstractions;
|
||||
using MoonCore.Extended.Helpers;
|
||||
|
||||
@@ -2,7 +2,7 @@ using System.Diagnostics;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MoonCore.Exceptions;
|
||||
using MoonCore.Extended.Abstractions;
|
||||
using MoonCore.Helpers;
|
||||
using MoonCore.Extended.PermFilter;
|
||||
using MoonlightServers.ApiServer.Database.Entities;
|
||||
using MoonlightServers.ApiServer.Services;
|
||||
using MoonlightServers.Shared.Http.Responses.Admin.Nodes.Sys;
|
||||
@@ -11,18 +11,19 @@ namespace MoonlightServers.ApiServer.Http.Controllers.Admin.Nodes;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/admin/servers/nodes")]
|
||||
public class NodeSystemController : Controller
|
||||
public class NodeStatusController : Controller
|
||||
{
|
||||
private readonly DatabaseRepository<Node> NodeRepository;
|
||||
private readonly NodeService NodeService;
|
||||
|
||||
public NodeSystemController(DatabaseRepository<Node> nodeRepository, NodeService nodeService)
|
||||
public NodeStatusController(DatabaseRepository<Node> nodeRepository, NodeService nodeService)
|
||||
{
|
||||
NodeRepository = nodeRepository;
|
||||
NodeService = nodeService;
|
||||
}
|
||||
|
||||
[HttpGet("{nodeId}/system/status")]
|
||||
[RequirePermission("admin.servers.nodes.status")]
|
||||
public async Task<NodeSystemStatusResponse> GetStatus([FromRoute] int nodeId)
|
||||
{
|
||||
var node = GetNode(nodeId);
|
||||
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MoonCore.Extended.Abstractions;
|
||||
using MoonCore.Extended.Helpers;
|
||||
using MoonCore.Extended.PermFilter;
|
||||
using MoonCore.Helpers;
|
||||
using MoonCore.Models;
|
||||
using MoonlightServers.ApiServer.Database.Entities;
|
||||
@@ -28,18 +29,21 @@ public class NodesController : Controller
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[RequirePermission("admin.servers.nodes.get")]
|
||||
public async Task<IPagedData<NodeDetailResponse>> Get([FromQuery] int page, [FromQuery] int pageSize)
|
||||
{
|
||||
return await CrudHelper.Get(page, pageSize);
|
||||
}
|
||||
|
||||
[HttpGet("{id:int}")]
|
||||
[RequirePermission("admin.servers.nodes.get")]
|
||||
public async Task<NodeDetailResponse> GetSingle([FromRoute] int id)
|
||||
{
|
||||
return await CrudHelper.GetSingle(id);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[RequirePermission("admin.servers.nodes.create")]
|
||||
public async Task<NodeDetailResponse> Create([FromBody] CreateNodeRequest request)
|
||||
{
|
||||
var node = Mapper.Map<Node>(request);
|
||||
@@ -52,12 +56,14 @@ public class NodesController : Controller
|
||||
}
|
||||
|
||||
[HttpPatch("{id:int}")]
|
||||
[RequirePermission("admin.servers.nodes.update")]
|
||||
public async Task<NodeDetailResponse> Update([FromRoute] int id, [FromBody] UpdateNodeRequest request)
|
||||
{
|
||||
return await CrudHelper.Update(id, request);
|
||||
}
|
||||
|
||||
[HttpDelete("{id:int}")]
|
||||
[RequirePermission("admin.servers.nodes.delete")]
|
||||
public async Task Delete([FromRoute] int id)
|
||||
{
|
||||
await CrudHelper.Delete(id);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MoonCore.Attributes;
|
||||
using MoonCore.Extended.PermFilter;
|
||||
using MoonCore.Exceptions;
|
||||
using MoonCore.Extended.Abstractions;
|
||||
using MoonCore.Helpers;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MoonCore.Attributes;
|
||||
using MoonCore.Extended.PermFilter;
|
||||
using MoonCore.Exceptions;
|
||||
using MoonCore.Extended.Abstractions;
|
||||
using MoonCore.Extended.Helpers;
|
||||
|
||||
@@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using MoonCore.Exceptions;
|
||||
using MoonCore.Extended.Abstractions;
|
||||
using MoonCore.Extended.Helpers;
|
||||
using MoonCore.Extended.PermFilter;
|
||||
using MoonCore.Helpers;
|
||||
using MoonCore.Models;
|
||||
using MoonlightServers.ApiServer.Database.Entities;
|
||||
@@ -48,6 +49,7 @@ public class StarDockerImagesController : Controller
|
||||
}
|
||||
|
||||
[HttpGet("{starId:int}/dockerImages")]
|
||||
[RequirePermission("admin.servers.stars.get")]
|
||||
public async Task<IPagedData<StarDockerImageDetailResponse>> Get([FromRoute] int starId, [FromQuery] int page, [FromQuery] int pageSize)
|
||||
{
|
||||
await ApplyStar(starId);
|
||||
@@ -56,6 +58,7 @@ public class StarDockerImagesController : Controller
|
||||
}
|
||||
|
||||
[HttpGet("{starId:int}/dockerImages/{id:int}")]
|
||||
[RequirePermission("admin.servers.stars.get")]
|
||||
public async Task<StarDockerImageDetailResponse> GetSingle([FromRoute] int starId, [FromRoute] int id)
|
||||
{
|
||||
await ApplyStar(starId);
|
||||
@@ -64,6 +67,7 @@ public class StarDockerImagesController : Controller
|
||||
}
|
||||
|
||||
[HttpPost("{starId:int}/dockerImages")]
|
||||
[RequirePermission("admin.servers.stars.create")]
|
||||
public async Task<StarDockerImageDetailResponse> Create([FromRoute] int starId, [FromBody] CreateStarDockerImageRequest request)
|
||||
{
|
||||
await ApplyStar(starId);
|
||||
@@ -77,6 +81,7 @@ public class StarDockerImagesController : Controller
|
||||
}
|
||||
|
||||
[HttpPatch("{starId:int}/dockerImages/{id:int}")]
|
||||
[RequirePermission("admin.servers.stars.update")]
|
||||
public async Task<StarDockerImageDetailResponse> Update([FromRoute] int starId, [FromRoute] int id,
|
||||
[FromBody] UpdateStarDockerImageRequest request)
|
||||
{
|
||||
@@ -86,6 +91,7 @@ public class StarDockerImagesController : Controller
|
||||
}
|
||||
|
||||
[HttpDelete("{starId:int}/dockerImages/{id:int}")]
|
||||
[RequirePermission("admin.servers.stars.delete")]
|
||||
public async Task Delete([FromRoute] int starId, [FromRoute] int id)
|
||||
{
|
||||
await ApplyStar(starId);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MoonCore.Attributes;
|
||||
using MoonCore.Extended.PermFilter;
|
||||
using MoonCore.Exceptions;
|
||||
using MoonCore.Helpers;
|
||||
using MoonlightServers.ApiServer.Services;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MoonCore.Attributes;
|
||||
using MoonCore.Extended.PermFilter;
|
||||
using MoonCore.Exceptions;
|
||||
using MoonCore.Extended.Abstractions;
|
||||
using MoonCore.Extended.Helpers;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MoonCore.Attributes;
|
||||
using MoonCore.Extended.PermFilter;
|
||||
using MoonCore.Extended.Abstractions;
|
||||
using MoonCore.Extended.Helpers;
|
||||
using MoonCore.Helpers;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MoonCore.Attributes;
|
||||
using MoonCore.Extended.PermFilter;
|
||||
using MoonCore.Exceptions;
|
||||
using MoonCore.Extended.Abstractions;
|
||||
using MoonCore.Extensions;
|
||||
@@ -31,14 +31,15 @@ public class ServersController : Controller
|
||||
[RequirePermission("meta.authenticated")]
|
||||
public async Task<PagedData<ServerDetailResponse>> GetAll([FromQuery] int page, [FromQuery] int pageSize)
|
||||
{
|
||||
var user = User.AsIdentity<User>();
|
||||
var userIdClaim = User.Claims.First(x => x.Type == "userId");
|
||||
var userId = int.Parse(userIdClaim.Value);
|
||||
|
||||
var query = ServerRepository
|
||||
.Get()
|
||||
.Include(x => x.Allocations)
|
||||
.Include(x => x.Star)
|
||||
.Include(x => x.Node)
|
||||
.Where(x => x.OwnerId == user.Id);
|
||||
.Where(x => x.OwnerId == userId);
|
||||
|
||||
var count = await query.CountAsync();
|
||||
var items = await query.Skip(page * pageSize).Take(pageSize).ToArrayAsync();
|
||||
@@ -177,7 +178,8 @@ public class ServersController : Controller
|
||||
private async Task<Server> GetServerWithPermCheck(int serverId,
|
||||
Func<IQueryable<Server>, IQueryable<Server>>? queryModifier = null)
|
||||
{
|
||||
var user = User.AsIdentity<User>();
|
||||
var userIdClaim = User.Claims.First(x => x.Type == "userId");
|
||||
var userId = int.Parse(userIdClaim.Value);
|
||||
|
||||
var query = ServerRepository
|
||||
.Get()
|
||||
@@ -192,7 +194,7 @@ public class ServersController : Controller
|
||||
if (server == null)
|
||||
throw new HttpApiException("No server with this id found", 404);
|
||||
|
||||
if (server.OwnerId == user.Id) // The current user is the owner
|
||||
if (server.OwnerId == userId) // The current user is the owner
|
||||
return server;
|
||||
|
||||
if (User.HasPermission("admin.servers.get")) // The current user is an admin
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
"applicationUrl": "http://localhost:5269",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||
"MOONLIGHT_APP_PUBLICURL": "http://localhost:5269"
|
||||
"MOONLIGHT_APP_PUBLICURL": "http://localhost:5269",
|
||||
"HTTP_PROXY": "",
|
||||
"HTTPS_PROXY": ""
|
||||
},
|
||||
"commandLineArgs": "--frontend-asset js/XtermBlazor.min.js --frontend-asset js/moonlightServers.js --frontend-asset js/addon-fit.js"
|
||||
}
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
using MoonCore.Blazor.Tailwind.Forms;
|
||||
using MoonCore.Blazor.Tailwind.Forms.Components;
|
||||
using Moonlight.Client;
|
||||
|
||||
FormComponentRepository.Set<bool, SwitchComponent>();
|
||||
|
||||
var startup = new Startup();
|
||||
|
||||
await startup.Run(args, [
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
@using MoonCore.Blazor.Tailwind.Alerts
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes
|
||||
@using MoonCore.Blazor.Tailwind.DataTable
|
||||
@using MoonCore.Blazor.Tailwind.Dt
|
||||
@using MoonCore.Blazor.Tailwind.Modals
|
||||
@using MoonCore.Blazor.Tailwind.Toasts
|
||||
@using MoonCore.Helpers
|
||||
@@ -31,15 +31,12 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-span-1 md:col-span-2 -mb-3">
|
||||
<ItemDataTable @ref="Table"
|
||||
TItem="NodeAllocationDetailResponse"
|
||||
Title=""
|
||||
ItemLoader="Load">
|
||||
<ChildContent>
|
||||
<DataColumn TItem="NodeAllocationDetailResponse" Field="@(x => x.IpAddress)" Title="IP Address"/>
|
||||
<DataColumn TItem="NodeAllocationDetailResponse" Field="@(x => x.Port)" Title="Port"/>
|
||||
<DataColumn TItem="NodeAllocationDetailResponse" Title="">
|
||||
<Template>
|
||||
<DataTable @ref="Table" TItem="NodeAllocationDetailResponse" LoadItemsPaginatedAsync="LoadData">
|
||||
<Configuration>
|
||||
<DataTableColumn TItem="NodeAllocationDetailResponse" Field="@(x => x.IpAddress)" Name="IP Address"/>
|
||||
<DataTableColumn TItem="NodeAllocationDetailResponse" Field="@(x => x.Port)" Name="Port"/>
|
||||
<DataTableColumn TItem="NodeAllocationDetailResponse">
|
||||
<ColumnTemplate>
|
||||
<div class="flex justify-end items-center">
|
||||
<a @onclick="() => UpdateAllocation(context)" @onclick:preventDefault href="#"
|
||||
class="text-primary-500 mr-2 sm:mr-3">
|
||||
@@ -50,10 +47,10 @@
|
||||
<i class="icon-trash text-base"></i>
|
||||
</a>
|
||||
</div>
|
||||
</Template>
|
||||
</DataColumn>
|
||||
</ChildContent>
|
||||
</ItemDataTable>
|
||||
</ColumnTemplate>
|
||||
</DataTableColumn>
|
||||
</Configuration>
|
||||
</DataTable>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -61,12 +58,12 @@
|
||||
{
|
||||
[Parameter] public NodeDetailResponse Node { get; set; }
|
||||
|
||||
private ItemDataTable<NodeAllocationDetailResponse> Table;
|
||||
private DataTable<NodeAllocationDetailResponse> Table;
|
||||
|
||||
private async Task<IPagedData<NodeAllocationDetailResponse>> Load(int page, int pageSize)
|
||||
private async Task<IPagedData<NodeAllocationDetailResponse>> LoadData(PaginationOptions options)
|
||||
{
|
||||
return await ApiClient.GetJson<PagedData<NodeAllocationDetailResponse>>(
|
||||
$"api/admin/servers/nodes/{Node.Id}/allocations?page={page}&pageSize={pageSize}"
|
||||
$"api/admin/servers/nodes/{Node.Id}/allocations?page={options.Page}&pageSize={options.PerPage}"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -77,7 +74,7 @@
|
||||
await ApiClient.Post($"api/admin/servers/nodes/{Node.Id}/allocations/range", request);
|
||||
|
||||
await ToastService.Success("Successfully created allocations");
|
||||
await Table.Refresh(isSilent: false, bypassCache: true);
|
||||
await Table.Refresh();
|
||||
};
|
||||
|
||||
await ModalService.Launch<CreateMultipleAllocationModal>(parameters =>
|
||||
@@ -93,7 +90,7 @@
|
||||
await ApiClient.Post($"api/admin/servers/nodes/{Node.Id}/allocations", request);
|
||||
|
||||
await ToastService.Success("Successfully created allocation");
|
||||
await Table.Refresh(isSilent: false, bypassCache: true);
|
||||
await Table.Refresh();
|
||||
};
|
||||
|
||||
await ModalService.Launch<CreateAllocationModal>(parameters => { parameters.Add("OnSubmit", onSubmit); });
|
||||
@@ -106,7 +103,7 @@
|
||||
await ApiClient.Patch($"api/admin/servers/nodes/{Node.Id}/allocations/{allocation.Id}", request);
|
||||
|
||||
await ToastService.Success("Successfully updated allocation");
|
||||
await Table.Refresh(isSilent: false, bypassCache: true);
|
||||
await Table.Refresh();
|
||||
};
|
||||
|
||||
await ModalService.Launch<UpdateAllocationModal>(parameters =>
|
||||
@@ -126,7 +123,7 @@
|
||||
await ApiClient.Delete($"api/admin/servers/nodes/{Node.Id}/allocations/{allocation.Id}");
|
||||
|
||||
await ToastService.Success("Successfully deleted allocation");
|
||||
await Table.Refresh(isSilent: false, bypassCache: true);
|
||||
await Table.Refresh();
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -141,7 +138,7 @@
|
||||
await ApiClient.Delete($"api/admin/servers/nodes/{Node.Id}/allocations/all");
|
||||
|
||||
await ToastService.Success("Successfully deleted allocations");
|
||||
await Table.Refresh(isSilent: false, bypassCache: true);
|
||||
await Table.Refresh();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Stars
|
||||
@using MoonCore.Blazor.Tailwind.Ace
|
||||
|
||||
<div>
|
||||
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
|
||||
@@ -16,8 +17,8 @@
|
||||
</div>
|
||||
<div class="sm:col-span-6">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Script</label>
|
||||
<div class="mt-2">
|
||||
<textarea @bind="Request.InstallScript" class="form-textarea w-full"></textarea>
|
||||
<div class="mt-2" @onfocusout="OnFocusOut">
|
||||
<CodeEditor @ref="CodeEditor" InitialContent="@Request.InstallScript" OnConfigure="OnConfigure" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -26,4 +27,16 @@
|
||||
@code
|
||||
{
|
||||
[Parameter] public UpdateStarRequest Request { get; set; }
|
||||
|
||||
private CodeEditor CodeEditor;
|
||||
|
||||
private void OnConfigure(CodeEditorOptions options)
|
||||
{
|
||||
options.Mode = "ace/mode/sh";
|
||||
}
|
||||
|
||||
private async Task OnFocusOut()
|
||||
{
|
||||
Request.InstallScript = await CodeEditor.GetValue();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
@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
|
||||
@@ -12,10 +11,10 @@
|
||||
@inject ToastService ToastService
|
||||
|
||||
<PageHeader Title="Create Server">
|
||||
<button @onclick="GoBack" type="button" class="btn btn-secondary">
|
||||
<a href="/admin/servers/all" class="btn btn-secondary">
|
||||
<i class="icon-chevron-left mr-1"></i>
|
||||
Back
|
||||
</button>
|
||||
</a>
|
||||
<WButton OnClick="_ => Form.Submit()" CssClasses="btn btn-primary">
|
||||
<i class="icon-check mr-1"></i>
|
||||
Create
|
||||
@@ -56,9 +55,6 @@
|
||||
await ApiClient.Post("api/admin/servers", Request);
|
||||
|
||||
await ToastService.Success("Successfully created Server");
|
||||
GoBack();
|
||||
Navigation.NavigateTo("/admin/servers/all");
|
||||
}
|
||||
|
||||
private void GoBack()
|
||||
=> Navigation.NavigateTo(ComponentHelper.GetRouteOfComponent<Index>()!);
|
||||
}
|
||||
@@ -1,78 +1,85 @@
|
||||
@page "/admin/servers/all"
|
||||
|
||||
@using MoonCore.Blazor.Tailwind.MinimalCrud
|
||||
@using MoonCore.Blazor.Tailwind.DataTable
|
||||
@using MoonCore.Blazor.Tailwind.Alerts
|
||||
@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
|
||||
@using MoonCore.Blazor.Tailwind.Dt
|
||||
@using MoonCore.Blazor.Tailwind.Toasts
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject AlertService AlertService
|
||||
@inject ToastService ToastService
|
||||
|
||||
<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>
|
||||
<div class="mb-5">
|
||||
<PageHeader Title="Servers">
|
||||
<a href="/admin/servers/all/create" class="btn btn-primary">
|
||||
Create
|
||||
</a>
|
||||
</PageHeader>
|
||||
</div>
|
||||
|
||||
<DataTable @ref="Table" TItem="ServerDetailResponse" PageSize="15" LoadItemsPaginatedAsync="LoadData">
|
||||
<Configuration>
|
||||
<DataTableColumn TItem="ServerDetailResponse" Field="@(x => x.Id)" Name="Id"/>
|
||||
<DataTableColumn TItem="ServerDetailResponse" Field="@(x => x.Name)" Name="Name"/>
|
||||
<DataTableColumn TItem="ServerDetailResponse" Field="@(x => x.NodeId)">
|
||||
<ColumnTemplate>
|
||||
@{
|
||||
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>
|
||||
<span>
|
||||
@(node?.Name ?? "N/A")
|
||||
</span>
|
||||
</ColumnTemplate>
|
||||
</DataTableColumn>
|
||||
<DataTableColumn TItem="ServerDetailResponse" Field="@(x => x.StarId)">
|
||||
<ColumnTemplate>
|
||||
@{
|
||||
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>
|
||||
<span>
|
||||
@(star?.Name ?? "N/A")
|
||||
</span>
|
||||
</ColumnTemplate>
|
||||
</DataTableColumn>
|
||||
<DataTableColumn TItem="ServerDetailResponse">
|
||||
<ColumnTemplate>
|
||||
<div class="flex justify-end">
|
||||
<a href="/admin/servers/all/update/@(context.Id)" class="text-primary-500 mr-2 sm:mr-3">
|
||||
<i class="icon-pencil text-base"></i>
|
||||
</a>
|
||||
|
||||
<a href="#" @onclick="() => Delete(context)" @onclick:preventDefault
|
||||
class="text-danger-500">
|
||||
<i class="icon-trash text-base"></i>
|
||||
</a>
|
||||
</div>
|
||||
</ColumnTemplate>
|
||||
</DataTableColumn>
|
||||
</Configuration>
|
||||
</DataTable>
|
||||
|
||||
@code
|
||||
{
|
||||
private DataTable<ServerDetailResponse> Table;
|
||||
|
||||
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)
|
||||
private async Task<IPagedData<ServerDetailResponse>> LoadData(PaginationOptions options)
|
||||
{
|
||||
// Clear potential previous data
|
||||
var data = await ApiClient.GetJson<PagedData<ServerDetailResponse>>($"api/admin/servers?page={page}&pageSize={pageSize}");
|
||||
var data = await ApiClient.GetJson<PagedData<ServerDetailResponse>>($"api/admin/servers?page={options.Page}&pageSize={options.PerPage}");
|
||||
|
||||
foreach (var item in data.Items)
|
||||
{
|
||||
@@ -91,4 +98,19 @@
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private async Task Delete(ServerDetailResponse detailResponse)
|
||||
{
|
||||
await AlertService.ConfirmDanger(
|
||||
"Server deletion",
|
||||
$"Do you really want to delete the server '{detailResponse.Name}'",
|
||||
async () =>
|
||||
{
|
||||
await ApiClient.Delete($"api/admin/servers/{detailResponse.Id}");
|
||||
await ToastService.Success("Successfully deleted server");
|
||||
|
||||
await Table.Refresh();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
@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
|
||||
@@ -14,10 +13,10 @@
|
||||
|
||||
<LazyLoader Load="Load">
|
||||
<PageHeader Title="Update Server">
|
||||
<button @onclick="GoBack" type="button" class="btn btn-secondary">
|
||||
<a href="/admin/servers/all" class="btn btn-secondary">
|
||||
<i class="icon-chevron-left mr-1"></i>
|
||||
Back
|
||||
</button>
|
||||
</a>
|
||||
<WButton OnClick="_ => Form.Submit()" CssClasses="btn btn-primary">
|
||||
<i class="icon-check mr-1"></i>
|
||||
Update
|
||||
@@ -62,10 +61,7 @@
|
||||
{
|
||||
await ApiClient.Patch($"api/admin/servers/{Id}", Request);
|
||||
|
||||
await ToastService.Success("Successfully updated Server");
|
||||
GoBack();
|
||||
await ToastService.Success("Successfully updated server");
|
||||
Navigation.NavigateTo("/admin/servers/all");
|
||||
}
|
||||
|
||||
private void GoBack()
|
||||
=> Navigation.NavigateTo(ComponentHelper.GetRouteOfComponent<Index>()!);
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
@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
|
||||
@@ -11,10 +10,10 @@
|
||||
@inject ToastService ToastService
|
||||
|
||||
<PageHeader Title="Create Node">
|
||||
<button @onclick="GoBack" type="button" class="btn btn-secondary">
|
||||
<a href="/admin/servers/nodes" class="btn btn-secondary">
|
||||
<i class="icon-chevron-left mr-1"></i>
|
||||
Back
|
||||
</button>
|
||||
</a>
|
||||
<WButton OnClick="_ => Form.Submit()" CssClasses="btn btn-primary">
|
||||
<i class="icon-check mr-1"></i>
|
||||
Create
|
||||
@@ -23,12 +22,40 @@
|
||||
|
||||
<div class="mt-5">
|
||||
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
|
||||
<GeneratedForm TForm="CreateNodeRequest" Model="Request" OnConfigure="OnConfigure"/>
|
||||
<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">Fqdn</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.Fqdn" 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">HttpPort</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.HttpPort" 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">FtpPort</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.FtpPort" type="number" autocomplete="off" class="form-input w-full">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</HandleForm>
|
||||
</div>
|
||||
|
||||
@code
|
||||
@*
|
||||
TODO: EnableTransparentMode, EnableDynamicFirewall
|
||||
*@
|
||||
|
||||
@code
|
||||
{
|
||||
private HandleForm Form;
|
||||
private CreateNodeRequest Request;
|
||||
@@ -38,35 +65,11 @@
|
||||
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();
|
||||
await ToastService.Success("Successfully created node");
|
||||
Navigation.NavigateTo("/admin/servers/nodes");
|
||||
}
|
||||
|
||||
private void GoBack()
|
||||
=> Navigation.NavigateTo(ComponentHelper.GetRouteOfComponent<Index>()!);
|
||||
}
|
||||
@@ -1,39 +1,45 @@
|
||||
@page "/admin/servers/nodes"
|
||||
|
||||
@using System.Diagnostics
|
||||
@using MoonCore.Blazor.Tailwind.Alerts
|
||||
@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
|
||||
@using MoonCore.Blazor.Tailwind.Dt
|
||||
@using MoonCore.Blazor.Tailwind.Toasts
|
||||
@using MoonlightServers.Frontend.Services
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes.Sys
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject NodeService NodeService
|
||||
@inject AlertService AlertService
|
||||
@inject ToastService ToastService
|
||||
|
||||
<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">
|
||||
<Template>
|
||||
@{
|
||||
var url = ComponentHelper.GetRouteOfComponent<Update>(context.Id)!;
|
||||
}
|
||||
<div class="mb-5">
|
||||
<PageHeader Title="Nodes">
|
||||
<a href="/admin/servers/nodes/create" class="btn btn-primary">
|
||||
Create
|
||||
</a>
|
||||
</PageHeader>
|
||||
</div>
|
||||
|
||||
<a class="text-primary-500" href="@url">@context.Name</a>
|
||||
</Template>
|
||||
</DataColumn>
|
||||
<DataColumn TItem="NodeDetailResponse" Field="@(x => x.Fqdn)" Title="Fqdn"/>
|
||||
<DataColumn TItem="NodeDetailResponse" Field="@(x => x.Fqdn)" Title="Status">
|
||||
<Template>
|
||||
<DataTable TItem="NodeDetailResponse" PageSize="15" LoadItemsPaginatedAsync="LoadData">
|
||||
<Configuration>
|
||||
<DataTableColumn TItem="NodeDetailResponse" Field="@(x => x.Id)" Name="Id"/>
|
||||
<DataTableColumn TItem="NodeDetailResponse" Field="@(x => x.Name)" Name="Name">
|
||||
<ColumnTemplate>
|
||||
<a class="text-primary-500" href="/admin/servers/nodes/update/@(context.Id)">
|
||||
@context.Name
|
||||
</a>
|
||||
</ColumnTemplate>
|
||||
</DataTableColumn>
|
||||
<DataTableColumn TItem="NodeDetailResponse" Field="@(x => x.Fqdn)" Name="Fqdn"/>
|
||||
<DataTableColumn TItem="NodeDetailResponse" Field="@(x => x.Fqdn)" Name="Status">
|
||||
<ColumnTemplate>
|
||||
<LazyLoader Load="_ => LoadNodeStatus(context.Id)">
|
||||
@{
|
||||
bool isFetched;
|
||||
@@ -84,48 +90,79 @@
|
||||
</span>
|
||||
}
|
||||
</LazyLoader>
|
||||
</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>
|
||||
</ColumnTemplate>
|
||||
</DataTableColumn>
|
||||
<DataTableColumn TItem="NodeDetailResponse"
|
||||
HeaderCss="p-2 font-semibold text-left hidden xl:table-cell"
|
||||
ColumnCss="p-2 text-left font-normal hidden xl:table-cell">
|
||||
<ColumnTemplate>
|
||||
<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>
|
||||
</ColumnTemplate>
|
||||
</DataTableColumn>
|
||||
<DataTableColumn TItem="NodeDetailResponse"
|
||||
HeaderCss="p-2 font-semibold text-left hidden xl:table-cell"
|
||||
ColumnCss="p-2 text-left font-normal hidden xl:table-cell">
|
||||
<ColumnTemplate>
|
||||
<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>
|
||||
</ColumnTemplate>
|
||||
</DataTableColumn>
|
||||
<DataTableColumn TItem="NodeDetailResponse"
|
||||
HeaderCss="p-2 font-semibold text-left hidden xl:table-cell"
|
||||
ColumnCss="p-2 text-left font-normal hidden xl:table-cell">
|
||||
<ColumnTemplate>
|
||||
<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>
|
||||
</ColumnTemplate>
|
||||
</DataTableColumn>
|
||||
<DataTableColumn TItem="NodeDetailResponse">
|
||||
<ColumnTemplate>
|
||||
<div class="flex justify-end">
|
||||
<a href="/admin/servers/nodes/update/@(context.Id)" class="text-primary-500 mr-2 sm:mr-3">
|
||||
<i class="icon-pencil text-base"></i>
|
||||
</a>
|
||||
|
||||
<a href="#" @onclick="() => Delete(context)" @onclick:preventDefault
|
||||
class="text-danger-500">
|
||||
<i class="icon-trash text-base"></i>
|
||||
</a>
|
||||
</div>
|
||||
</ColumnTemplate>
|
||||
</DataTableColumn>
|
||||
</Configuration>
|
||||
</DataTable>
|
||||
|
||||
@code
|
||||
{
|
||||
private DataTable<NodeDetailResponse> Table;
|
||||
|
||||
private Dictionary<int, NodeSystemStatusResponse?> Responses = new();
|
||||
|
||||
private async Task<IPagedData<NodeDetailResponse>> LoadData(PaginationOptions options)
|
||||
=> await ApiClient.GetJson<PagedData<NodeDetailResponse>>($"api/admin/servers/nodes?page={options.Page}&pageSize={options.PerPage}");
|
||||
|
||||
private async Task Delete(NodeDetailResponse detailResponse)
|
||||
{
|
||||
await AlertService.ConfirmDanger(
|
||||
"Node deletion",
|
||||
$"Do you really want to delete the node '{detailResponse.Name}'",
|
||||
async () =>
|
||||
{
|
||||
await ApiClient.Delete($"api/admin/servers/nodes/{detailResponse.Id}");
|
||||
await ToastService.Success("Successfully deleted node");
|
||||
|
||||
await Table.Refresh();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private Task LoadNodeStatus(int node)
|
||||
{
|
||||
Task.Run(async () =>
|
||||
@@ -165,15 +202,4 @@
|
||||
|
||||
await AlertService.Danger("Node error details", message);
|
||||
}
|
||||
|
||||
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}");
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
@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
|
||||
@@ -14,10 +13,10 @@
|
||||
|
||||
<LazyLoader Load="Load">
|
||||
<PageHeader Title="Update Node">
|
||||
<button @onclick="GoBack" type="button" class="btn btn-secondary">
|
||||
<a href="/admin/servers/nodes" class="btn btn-secondary">
|
||||
<i class="icon-chevron-left mr-1"></i>
|
||||
Back
|
||||
</button>
|
||||
</a>
|
||||
<WButton OnClick="_ => Form.Submit()" CssClasses="btn btn-primary">
|
||||
<i class="icon-check mr-1"></i>
|
||||
Update
|
||||
@@ -59,27 +58,11 @@
|
||||
Request = Mapper.Map<UpdateNodeRequest>(Node);
|
||||
}
|
||||
|
||||
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();
|
||||
Navigation.NavigateTo("/admin/servers/nodes");
|
||||
}
|
||||
|
||||
private void GoBack()
|
||||
=> Navigation.NavigateTo(ComponentHelper.GetRouteOfComponent<Index>()!);
|
||||
}
|
||||
@@ -1,24 +1,20 @@
|
||||
@page "/admin/servers/stars/create"
|
||||
|
||||
@using Microsoft.AspNetCore.Components.Authorization
|
||||
@using MoonCore.Blazor.Tailwind.Components
|
||||
@using MoonCore.Blazor.Tailwind.Forms
|
||||
@using MoonCore.Blazor.Tailwind.Toasts
|
||||
@using MoonCore.Helpers
|
||||
@using Moonlight.Client.Services
|
||||
@using MoonlightServers.Frontend.UI.Components.Forms
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Stars
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.StarVariables
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ToastService ToastService
|
||||
@inject IdentityService IdentityService
|
||||
|
||||
<PageHeader Title="Create Star">
|
||||
<button @onclick="GoBack" class="btn btn-secondary">
|
||||
<a href="/admin/servers/stars" class="btn btn-secondary">
|
||||
<i class="icon-chevron-left mr-1"></i>
|
||||
Back
|
||||
</button>
|
||||
</a>
|
||||
<WButton OnClick="_ => Form.Submit()" CssClasses="btn btn-primary">
|
||||
<i class="icon-check mr-1"></i>
|
||||
Create
|
||||
@@ -27,42 +23,43 @@
|
||||
|
||||
<div class="mt-5">
|
||||
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
|
||||
<GeneratedForm TForm="CreateStarRequest" Model="Request" OnConfigure="OnConfigure"/>
|
||||
<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">Author</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.Author" type="text" autocomplete="off" class="form-input w-full">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</HandleForm>
|
||||
</div>
|
||||
|
||||
@code
|
||||
|
||||
{
|
||||
[CascadingParameter] public Task<AuthenticationState> AuthState { get; set; }
|
||||
|
||||
private HandleForm Form;
|
||||
private CreateStarRequest Request;
|
||||
|
||||
protected override void OnInitialized()
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
Request = new();
|
||||
}
|
||||
|
||||
private void OnConfigure(FormConfiguration<CreateStarRequest> configuration)
|
||||
{
|
||||
configuration.WithField(x => x.Name);
|
||||
|
||||
configuration.WithField(x => x.Author, fieldConfiguration =>
|
||||
{
|
||||
fieldConfiguration.DefaultValue = IdentityService.Email;
|
||||
});
|
||||
var authState = await AuthState;
|
||||
Request.Author = authState.User.Claims.First(x => x.Type == "email").Value;
|
||||
}
|
||||
|
||||
private async Task OnSubmit()
|
||||
{
|
||||
await ApiClient.Post("api/admin/servers/stars", Request);
|
||||
|
||||
await ToastService.Success("Successfully created Star");
|
||||
await GoBack();
|
||||
}
|
||||
|
||||
private Task GoBack()
|
||||
{
|
||||
Navigation.NavigateTo(ComponentHelper.GetRouteOfComponent<Index>()!);
|
||||
return Task.CompletedTask;
|
||||
await ToastService.Success("Successfully created star");
|
||||
Navigation.NavigateTo("/admin/servers/stars");
|
||||
}
|
||||
}
|
||||
@@ -1,82 +1,108 @@
|
||||
@page "/admin/servers/stars"
|
||||
|
||||
@using MoonCore.Blazor.Tailwind.MinimalCrud
|
||||
@using MoonCore.Blazor.Tailwind.Alerts
|
||||
@using MoonCore.Helpers
|
||||
@using MoonCore.Models
|
||||
@using MoonCore.Blazor.Tailwind.DataTable
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Stars
|
||||
@using MoonCore.Blazor.Tailwind.Components
|
||||
@using MoonCore.Blazor.Tailwind.Dt
|
||||
@using MoonCore.Blazor.Tailwind.Services
|
||||
@using MoonCore.Blazor.Tailwind.Toasts
|
||||
@using MoonCore.Exceptions
|
||||
@using Moonlight.Client.Services
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject DownloadService DownloadService
|
||||
@inject ToastService ToastService
|
||||
@inject AlertService AlertService
|
||||
|
||||
<div class="mb-3">
|
||||
<NavTabs Index="3" Names="@UiConstants.AdminNavNames" Links="@UiConstants.AdminNavLinks"/>
|
||||
</div>
|
||||
|
||||
<MinimalCrud @ref="Crud" TItem="StarDetailResponse" OnConfigure="OnConfigure">
|
||||
<ChildContent>
|
||||
<DataColumn TItem="StarDetailResponse" Field="@(x => x.Id)" Title="Id" IsSortable="true" />
|
||||
<DataColumn TItem="StarDetailResponse" Field="@(x => x.Name)" Title="Name" IsSortable="true">
|
||||
<Template>
|
||||
@{
|
||||
var url = ComponentHelper.GetRouteOfComponent<Update>(context.Id)!;
|
||||
}
|
||||
|
||||
<a class="text-primary-500" href="@url">@context.Name</a>
|
||||
</Template>
|
||||
</DataColumn>
|
||||
<DataColumn TItem="StarDetailResponse" Field="@(x => x.Version)" Title="Version" IsSortable="true"/>
|
||||
<DataColumn TItem="StarDetailResponse" Field="@(x => x.Author)" Title="Author"/>
|
||||
</ChildContent>
|
||||
<Actions>
|
||||
<div class="mb-5">
|
||||
<PageHeader Title="Nodes">
|
||||
<InputFile id="import-file" hidden="" multiple OnChange="OnImportFiles"/>
|
||||
<label for="import-file" class="btn btn-tertiary cursor-pointer">
|
||||
<i class="icon-file-up mr-2"></i>
|
||||
Import
|
||||
</label>
|
||||
</Actions>
|
||||
<ItemActions>
|
||||
@if (!string.IsNullOrEmpty(context.DonateUrl))
|
||||
{
|
||||
<a href="@context.DonateUrl" target="_blank" class="text-red-500 mr-3">
|
||||
<i class="icon-heart align-middle"></i>
|
||||
<span class="align-middle">Donate</span>
|
||||
</a>
|
||||
}
|
||||
|
||||
@if (!string.IsNullOrEmpty(context.UpdateUrl))
|
||||
{
|
||||
<a href="#" @onclick:preventDefault class="text-tertiary-500 mr-3">
|
||||
<i class="icon-refresh-cw align-middle"></i>
|
||||
<span class="align-middle">Update</span>
|
||||
</a>
|
||||
}
|
||||
|
||||
<a href="#" @onclick="() => Export(context)" @onclick:preventDefault class="text-success-500 mr-3">
|
||||
<i class="icon-download align-middle"></i>
|
||||
<span class="align-middle">Export</span>
|
||||
<a href="/admin/servers/nodes/create" class="btn btn-primary">
|
||||
Create
|
||||
</a>
|
||||
</ItemActions>
|
||||
</MinimalCrud>
|
||||
</PageHeader>
|
||||
</div>
|
||||
|
||||
<DataTable @ref="Table" TItem="StarDetailResponse" LoadItemsPaginatedAsync="LoadData">
|
||||
<Configuration>
|
||||
<DataTableColumn TItem="StarDetailResponse" Field="@(x => x.Id)" Name="Id" />
|
||||
<DataTableColumn TItem="StarDetailResponse" Field="@(x => x.Name)" Name="Name">
|
||||
<ColumnTemplate>
|
||||
<a class="text-primary-500" href="/admin/servers/stars/update/@(context.Id)">
|
||||
@context.Name
|
||||
</a>
|
||||
</ColumnTemplate>
|
||||
</DataTableColumn>
|
||||
<DataTableColumn TItem="StarDetailResponse" Field="@(x => x.Version)" Name="Version" />
|
||||
<DataTableColumn TItem="StarDetailResponse" Field="@(x => x.Author)" Name="Author" />
|
||||
<DataTableColumn TItem="StarDetailResponse">
|
||||
<ColumnTemplate>
|
||||
<div class="flex justify-end">
|
||||
@if (!string.IsNullOrEmpty(context.DonateUrl))
|
||||
{
|
||||
<a href="@context.DonateUrl" target="_blank" class="text-red-500 mr-3">
|
||||
<i class="icon-heart align-middle"></i>
|
||||
<span class="align-middle">Donate</span>
|
||||
</a>
|
||||
}
|
||||
|
||||
@if (!string.IsNullOrEmpty(context.UpdateUrl))
|
||||
{
|
||||
<a href="#" @onclick:preventDefault class="text-tertiary-500 mr-3">
|
||||
<i class="icon-refresh-cw align-middle"></i>
|
||||
<span class="align-middle">Update</span>
|
||||
</a>
|
||||
}
|
||||
|
||||
<a href="#" @onclick="() => Export(context)" @onclick:preventDefault class="text-success-500 mr-3">
|
||||
<i class="icon-download align-middle"></i>
|
||||
<span class="align-middle">Export</span>
|
||||
</a>
|
||||
|
||||
<a href="/admin/servers/stars/update/@(context.Id)" class="text-primary-500 mr-2 sm:mr-3">
|
||||
<i class="icon-pencil text-base"></i>
|
||||
</a>
|
||||
|
||||
<a href="#" @onclick="() => Delete(context)" @onclick:preventDefault
|
||||
class="text-danger-500">
|
||||
<i class="icon-trash text-base"></i>
|
||||
</a>
|
||||
</div>
|
||||
</ColumnTemplate>
|
||||
</DataTableColumn>
|
||||
</Configuration>
|
||||
</DataTable>
|
||||
|
||||
@code
|
||||
{
|
||||
private MinimalCrud<StarDetailResponse> Crud;
|
||||
private DataTable<StarDetailResponse> Table;
|
||||
|
||||
private void OnConfigure(MinimalCrudOptions<StarDetailResponse> options)
|
||||
private async Task<IPagedData<StarDetailResponse>> LoadData(PaginationOptions options)
|
||||
=> await ApiClient.GetJson<PagedData<StarDetailResponse>>($"api/admin/servers/stars?page={options.Page}&pageSize={options.PerPage}");
|
||||
|
||||
private async Task Delete(StarDetailResponse detailResponse)
|
||||
{
|
||||
options.Title = "Stars";
|
||||
options.ItemLoader = async (page, pageSize) =>
|
||||
await ApiClient.GetJson<PagedData<StarDetailResponse>>($"api/admin/servers/stars?page={page}&pageSize={pageSize}");
|
||||
await AlertService.ConfirmDanger(
|
||||
"Star deletion",
|
||||
$"Do you really want to delete the star '{detailResponse.Name}'",
|
||||
async () =>
|
||||
{
|
||||
await ApiClient.Delete($"api/admin/servers/stars/{detailResponse.Id}");
|
||||
await ToastService.Success("Successfully deleted star");
|
||||
|
||||
options.CreateUrl = ComponentHelper.GetRouteOfComponent<Create>();
|
||||
options.UpdateUrl = item => ComponentHelper.GetRouteOfComponent<Update>(item.Id)!;
|
||||
options.DeleteFunction = async item => await ApiClient.Delete($"api/admin/servers/stars/{item.Id}");
|
||||
await Table.Refresh();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private async Task Export(StarDetailResponse star)
|
||||
@@ -125,6 +151,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
await Crud.Refresh(isSilent: false, bypassCache: true);
|
||||
await Table.Refresh();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
@page "/admin/servers/stars/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.Stars
|
||||
@@ -14,10 +13,10 @@
|
||||
|
||||
<LazyLoader Load="Load">
|
||||
<PageHeader Title="Update Star">
|
||||
<button @onclick="GoBack" type="button" class="btn btn-secondary">
|
||||
<a href="/admin/servers/stars" class="btn btn-secondary">
|
||||
<i class="icon-chevron-left mr-1"></i>
|
||||
Back
|
||||
</button>
|
||||
</a>
|
||||
<WButton OnClick="_ => Form.Submit()" CssClasses="btn btn-primary">
|
||||
<i class="icon-check mr-1"></i>
|
||||
Update
|
||||
@@ -75,52 +74,11 @@
|
||||
Request = Mapper.Map<UpdateStarRequest>(Detail);
|
||||
}
|
||||
|
||||
private void OnConfigure(FormConfiguration<UpdateStarRequest> configuration)
|
||||
{
|
||||
var generalPage = configuration.WithPage("General");
|
||||
|
||||
generalPage.WithField(x => x.Name);
|
||||
generalPage.WithField(x => x.Version);
|
||||
generalPage.WithField(x => x.Author);
|
||||
generalPage.WithField(x => x.DonateUrl);
|
||||
generalPage.WithField(x => x.UpdateUrl);
|
||||
|
||||
var startStopStatusPage = configuration.WithPage("Start, Stop & Status");
|
||||
|
||||
startStopStatusPage.WithField(x => x.StartupCommand);
|
||||
startStopStatusPage.WithField(x => x.StopCommand);
|
||||
startStopStatusPage.WithField(x => x.OnlineDetection);
|
||||
|
||||
var installationPage = configuration.WithPage("Installation");
|
||||
|
||||
installationPage.WithField(x => x.InstallShell);
|
||||
installationPage.WithField(x => x.InstallDockerImage);
|
||||
|
||||
installationPage.WithField(x => x.InstallScript, fieldConfiguration =>
|
||||
{
|
||||
fieldConfiguration.Columns = 6;
|
||||
});
|
||||
|
||||
var parseConfigurationPage = configuration.WithPage("Parse configuration");
|
||||
|
||||
parseConfigurationPage.WithField(x => x.ParseConfiguration);
|
||||
|
||||
var variablesPage = configuration.WithPage("Variables");
|
||||
|
||||
var miscPage = configuration.WithPage("Miscellaneous");
|
||||
|
||||
miscPage.WithField(x => x.AllowDockerImageChange);
|
||||
miscPage.WithField(x => x.RequiredAllocations);
|
||||
}
|
||||
|
||||
private async Task OnSubmit()
|
||||
{
|
||||
await ApiClient.Patch($"api/admin/servers/stars/{Id}", Request);
|
||||
|
||||
await ToastService.Success("Successfully updated Star");
|
||||
GoBack();
|
||||
Navigation.NavigateTo("/admin/servers/stars");
|
||||
}
|
||||
|
||||
private void GoBack()
|
||||
=> Navigation.NavigateTo(ComponentHelper.GetRouteOfComponent<Index>()!);
|
||||
}
|
||||
@@ -12,11 +12,11 @@ public class CreateNodeRequest
|
||||
|
||||
[Required(ErrorMessage = "You need to provide a http port")]
|
||||
[Range(1, 65535, ErrorMessage = "You need to provide a valid http port")]
|
||||
public int HttpPort { get; set; }
|
||||
public int HttpPort { get; set; } = 8080;
|
||||
|
||||
[Required(ErrorMessage = "You need to provide a ftp port")]
|
||||
[Range(1, 65535, ErrorMessage = "You need to provide a valid ftp port")]
|
||||
public int FtpPort { get; set; }
|
||||
public int FtpPort { get; set; } = 2021;
|
||||
|
||||
public bool EnableTransparentMode { get; set; }
|
||||
public bool EnableDynamicFirewall { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user