Updated mooncore usage to work with the newer version
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using MoonCoreUI.Attributes;
|
||||
|
||||
namespace Moonlight.Core.Models.Forms.Users;
|
||||
|
||||
@@ -16,5 +17,7 @@ public class UpdateUserForm
|
||||
public string Email { get; set; }
|
||||
|
||||
[Description("This toggles the use of the two factor authentication")]
|
||||
[RadioButtonBool("Enabled", "Disabled", TrueIcon = "bx-lock-alt", FalseIcon = "bx-lock-open-alt")]
|
||||
[DisplayName("Two factor authentication")]
|
||||
public bool Totp { get; set; } = false;
|
||||
}
|
||||
@@ -17,30 +17,30 @@
|
||||
<AdminUsersNavigation Index="0"/>
|
||||
|
||||
<AutoCrud TItem="User"
|
||||
TCreateForm="CreateUserForm"
|
||||
TUpdateForm="UpdateUserForm"
|
||||
Title=""
|
||||
Load="Load"
|
||||
CustomAdd="Add"
|
||||
ValidateUpdate="ValidateUpdate">
|
||||
TCreateForm="CreateUserForm"
|
||||
TUpdateForm="UpdateUserForm"
|
||||
Loader="Load"
|
||||
CustomAdd="Add"
|
||||
ValidateUpdate="ValidateUpdate">
|
||||
<View>
|
||||
<CrudColumn TItem="User" Field="@(x => x.Id)" Title="Id" Filterable="true"/>
|
||||
<CrudColumn TItem="User" Field="@(x => x.Email)" Title="Email" Filterable="true"/>
|
||||
<CrudColumn TItem="User" Field="@(x => x.Username)" Title="Username" Filterable="true"/>
|
||||
<CrudColumn TItem="User" Field="@(x => x.CreatedAt)" Title="Created at" />
|
||||
<CrudColumn TItem="User" Field="@(x => x.CreatedAt)" Title="Created at"/>
|
||||
</View>
|
||||
<UpdateActions>
|
||||
<WButton OnClick="() => ChangePassword(context)" CssClasses="btn btn-icon btn-primary">
|
||||
<WButton OnClick="() => ChangePassword(context)" CssClasses="btn btn-info me-2">
|
||||
<i class="bx bx-sm bxs-key"></i>
|
||||
Change password
|
||||
</WButton>
|
||||
</UpdateActions>
|
||||
</AutoCrud>
|
||||
|
||||
@code
|
||||
{
|
||||
private User[] Load(Repository<User> repository)
|
||||
private IEnumerable<User> Load(Repository<User> repository)
|
||||
{
|
||||
return repository.Get().ToArray();
|
||||
return repository.Get();
|
||||
}
|
||||
|
||||
private async Task ChangePassword(User user)
|
||||
|
||||
@@ -22,11 +22,11 @@
|
||||
</Tooltip>
|
||||
|
||||
<div class="card mt-5">
|
||||
<div class="card-body">
|
||||
<div class="card-body px-6 py-4">
|
||||
<LazyLoader Load="Load">
|
||||
<CrudTable @ref="Table"
|
||||
TItem="Session"
|
||||
Items="SessionService.Sessions"
|
||||
ItemSource="SessionService.Sessions"
|
||||
PageSize="50">
|
||||
<CrudColumn TItem="Session" Title="User" Field="@(x => x.CreatedAt)">
|
||||
<Template>
|
||||
@@ -63,8 +63,8 @@
|
||||
<Template>
|
||||
<div class="d-flex justify-content-end">
|
||||
<div class="btn btn-group">
|
||||
<WButton OnClick="() => Message(context)" Text="Message" CssClasses="btn btn-primary" />
|
||||
<WButton OnClick="() => Redirect(context)" Text="Redirect" CssClasses="btn btn-warning" />
|
||||
<WButton OnClick="() => Message(context)" Text="Message" CssClasses="btn btn-primary"/>
|
||||
<WButton OnClick="() => Redirect(context)" Text="Redirect" CssClasses="btn btn-warning"/>
|
||||
</div>
|
||||
</div>
|
||||
</Template>
|
||||
@@ -85,9 +85,7 @@
|
||||
UpdateTimer = new Timer(async _ =>
|
||||
{
|
||||
if (Table != null)
|
||||
await Table.Refresh();
|
||||
|
||||
await InvokeAsync(StateHasChanged);
|
||||
await Table.Refresh(isSilent: true, fullRefresh: true);
|
||||
}, null, TimeSpan.Zero, TimeSpan.FromSeconds(1));
|
||||
|
||||
return Task.CompletedTask;
|
||||
@@ -97,7 +95,7 @@
|
||||
{
|
||||
var url = await AlertService.Text("Enter the target url to redirect to");
|
||||
|
||||
if(string.IsNullOrEmpty(url))
|
||||
if (string.IsNullOrEmpty(url))
|
||||
return;
|
||||
|
||||
try
|
||||
@@ -116,7 +114,7 @@
|
||||
{
|
||||
var message = await AlertService.Text("Enter the message you want to send");
|
||||
|
||||
if(string.IsNullOrEmpty(message))
|
||||
if (string.IsNullOrEmpty(message))
|
||||
return;
|
||||
|
||||
try
|
||||
|
||||
@@ -78,23 +78,53 @@ public class ServerService
|
||||
var user = userRepo.Get().First(x => x.Id == form.Owner.Id);
|
||||
|
||||
// Load and validate server allocations
|
||||
ServerAllocation[] allocations = Array.Empty<ServerAllocation>();
|
||||
List<ServerAllocation> allocations = new();
|
||||
|
||||
if (false)
|
||||
var amountOfAutoAllocations = image.AllocationsNeeded;
|
||||
|
||||
if (form.Allocations.Count > 0)
|
||||
{
|
||||
throw new DisplayException(
|
||||
"The dedicated ip mode has not been implemented yet. Please disable the dedicated ip option in the product configuration");
|
||||
}
|
||||
else
|
||||
{
|
||||
allocations = allocationRepo
|
||||
.Get()
|
||||
.FromSqlRaw(
|
||||
$"SELECT * FROM `ServerAllocations` WHERE ServerId IS NULL AND ServerNodeId={node.Id} LIMIT {image.AllocationsNeeded}")
|
||||
.ToArray();
|
||||
amountOfAutoAllocations -= form.Allocations.Count;
|
||||
|
||||
foreach (var serverAllocation in form.Allocations) // Resolve all allocations specified in the form in the current scope
|
||||
{
|
||||
var allocationInCurrentScope = allocationRepo.Get().First(x => x.Id == serverAllocation.Id);
|
||||
allocations.Add(allocationInCurrentScope);
|
||||
}
|
||||
}
|
||||
|
||||
if (allocations.Length < 1 || allocations.Length < image.AllocationsNeeded)
|
||||
if (amountOfAutoAllocations > 0) // Resolve all other allocations which are required automatically
|
||||
{
|
||||
if (false)
|
||||
{
|
||||
throw new DisplayException(
|
||||
"The dedicated ip mode has not been implemented yet. Please disable the dedicated ip option in the product configuration");
|
||||
}
|
||||
else
|
||||
{
|
||||
var autoAllocations = allocationRepo
|
||||
.Get()
|
||||
.FromSqlRaw(
|
||||
$"SELECT * FROM `ServerAllocations` WHERE ServerId IS NULL AND ServerNodeId={node.Id} LIMIT {image.AllocationsNeeded + form.Allocations.Count}")
|
||||
.ToArray();
|
||||
|
||||
var addedAutoAllocations = 0;
|
||||
|
||||
foreach (var autoAllocation in autoAllocations)
|
||||
{
|
||||
if(addedAutoAllocations >= amountOfAutoAllocations)
|
||||
break;
|
||||
|
||||
if(form.Allocations.Any(x => x.Id == autoAllocation.Id))
|
||||
continue;
|
||||
|
||||
allocations.Add(autoAllocation);
|
||||
addedAutoAllocations++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (allocations.Count < 1 || allocations.Count < image.AllocationsNeeded)
|
||||
throw new DisplayException($"Not enough free allocations found on node '{node.Name}'");
|
||||
|
||||
// Build server db model
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<div class="card card-body mb-15 py-3 px-5">
|
||||
@if (!Server.DisablePublicNetwork)
|
||||
{
|
||||
<CrudTable TItem="ServerAllocation" Items="Server.Allocations" PageSize="25" ShowPagination="false">
|
||||
<CrudTable TItem="ServerAllocation" ItemSource="Server.Allocations" PageSize="25" ShowPagination="false">
|
||||
<CrudColumn TItem="ServerAllocation" Field="@(x => x.IpAddress)" Title="FQDN or dedicated IP">
|
||||
<Template>
|
||||
@if (context!.IpAddress == "0.0.0.0")
|
||||
|
||||
@@ -28,43 +28,43 @@
|
||||
<AutoCrud TItem="ServerImage"
|
||||
TCreateForm="CreateImageForm"
|
||||
TUpdateForm="UpdateImageForm"
|
||||
Title=""
|
||||
Load="Load"
|
||||
Loader="Load"
|
||||
ValidateDelete="ValidateDelete"
|
||||
ValidateAdd="ValidateAdd"
|
||||
CustomDelete="CustomDelete"
|
||||
@ref="Crud">
|
||||
<UpdateActions>
|
||||
<a href="/admin/servers/images/view/@(context.Id)" class="btn btn-icon btn-info">
|
||||
<i class="bx bx-sm bx-wrench"></i>
|
||||
</a>
|
||||
</UpdateActions>
|
||||
<View>
|
||||
<CrudColumn TItem="ServerImage" Field="@(x => x.Id)" Title="Id" Filterable="true"/>
|
||||
<CrudColumn TItem="ServerImage" Field="@(x => x.Name)" Title="Name" Filterable="true"/>
|
||||
<CrudColumn TItem="ServerImage" Field="@(x => x.Name)" Title="Name" Filterable="true">
|
||||
<Template>
|
||||
<a href="/admin/servers/images/view/@context!.Id">@context.Name</a>
|
||||
</Template>
|
||||
</CrudColumn>
|
||||
<CrudColumn TItem="ServerImage" Field="@(x => x.Author)" Title="Author" Filterable="true"/>
|
||||
<CrudColumn TItem="ServerImage">
|
||||
<Template>
|
||||
@if (!string.IsNullOrEmpty(context.UpdateUrl))
|
||||
{
|
||||
<WButton CssClasses="btn btn-sm btn-info me-3">
|
||||
<i class="bx bx-refresh"></i>
|
||||
Update
|
||||
</WButton>
|
||||
}
|
||||
<div class="text-end">
|
||||
@if (!string.IsNullOrEmpty(context.UpdateUrl))
|
||||
{
|
||||
<a class="me-2" href="#" @onclick:preventDefault>
|
||||
<i class="bx bx-refresh"></i>
|
||||
Update
|
||||
</a>
|
||||
}
|
||||
|
||||
@if (!string.IsNullOrEmpty(context.DonateUrl))
|
||||
{
|
||||
<a class="btn btn-sm btn-primary me-3" href="@(context.DonateUrl)" target="_blank">
|
||||
<i class="bx bxs-heart text-danger"></i>
|
||||
Donate
|
||||
@if (!string.IsNullOrEmpty(context.DonateUrl))
|
||||
{
|
||||
<a class="me-2" href="@(context.DonateUrl)" target="_blank">
|
||||
<i class="bx bxs-heart text-danger"></i>
|
||||
Donate
|
||||
</a>
|
||||
}
|
||||
|
||||
<a href="#" class="me-2" @onclick:preventDefault @onclick="() => Export(context)">
|
||||
<i class="bx bx-download"></i>
|
||||
Export
|
||||
</a>
|
||||
}
|
||||
|
||||
<WButton OnClick="() => Export(context)" CssClasses="btn btn-sm btn-warning">
|
||||
<i class="bx bx-download"></i>
|
||||
Export
|
||||
</WButton>
|
||||
</div>
|
||||
</Template>
|
||||
</CrudColumn>
|
||||
</View>
|
||||
@@ -93,9 +93,9 @@
|
||||
private SmartCustomFileSelect ImageUpload;
|
||||
private SmartCustomFileSelect EggUpload;
|
||||
|
||||
private ServerImage[] Load(Repository<ServerImage> repository)
|
||||
private IEnumerable<ServerImage> Load(Repository<ServerImage> repository)
|
||||
{
|
||||
return repository.Get().ToArray();
|
||||
return repository.Get();
|
||||
}
|
||||
|
||||
private Task ValidateDelete(ServerImage serverImage)
|
||||
|
||||
@@ -26,8 +26,7 @@
|
||||
<AutoCrud TItem="ServerNode"
|
||||
TCreateForm="CreateNodeForm"
|
||||
TUpdateForm="UpdateNodeForm"
|
||||
Title=""
|
||||
Load="LoadData"
|
||||
Loader="LoadData"
|
||||
ValidateAdd="ValidateAdd"
|
||||
ValidateUpdate="ValidateUpdate"
|
||||
ValidateDelete="ValidateDelete">
|
||||
@@ -154,11 +153,10 @@
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private ServerNode[] LoadData(Repository<ServerNode> repository)
|
||||
private IEnumerable<ServerNode> LoadData(Repository<ServerNode> repository)
|
||||
{
|
||||
return repository
|
||||
.Get()
|
||||
.ToArray();
|
||||
.Get();
|
||||
}
|
||||
|
||||
private Task ValidateDelete(ServerNode node)
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<AutoCrud TItem="ServerNetwork"
|
||||
TCreateForm="CreateNetworkForm"
|
||||
TUpdateForm="UpdateNetworkForm"
|
||||
Load="Load"
|
||||
Loader="Load"
|
||||
ValidateAdd="ValidateAdd">
|
||||
<View>
|
||||
<CrudColumn TItem="ServerNetwork" Field="@(x => x.Name)" Title="Name"/>
|
||||
@@ -28,7 +28,7 @@
|
||||
<CrudColumn TItem="ServerNetwork" Title="Used by">
|
||||
<Template>
|
||||
@{
|
||||
var servers = UsedByCache[context.Id];
|
||||
var servers = UsedByCache.ContainsKey(context.Id) ? UsedByCache[context.Id] : Array.Empty<Server>();
|
||||
}
|
||||
|
||||
<span>
|
||||
@@ -51,13 +51,12 @@
|
||||
{
|
||||
private readonly Dictionary<int, Server[]> UsedByCache = new();
|
||||
|
||||
private ServerNetwork[] Load(Repository<ServerNetwork> repository)
|
||||
private IEnumerable<ServerNetwork> Load(Repository<ServerNetwork> repository)
|
||||
{
|
||||
var result = repository
|
||||
.Get()
|
||||
.Include(x => x.Node)
|
||||
.Where(x => x.User.Id == IdentityService.CurrentUser.Id)
|
||||
.ToArray();
|
||||
.Where(x => x.User.Id == IdentityService.CurrentUser.Id);
|
||||
|
||||
UsedByCache.Clear();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user