diff --git a/Moonlight/Core/UI/Views/Admin/Api/Keys.razor b/Moonlight/Core/UI/Views/Admin/Api/Keys.razor
index 03021e46..3bd01e14 100644
--- a/Moonlight/Core/UI/Views/Admin/Api/Keys.razor
+++ b/Moonlight/Core/UI/Views/Admin/Api/Keys.razor
@@ -1,10 +1,8 @@
@page "/admin/api/keys"
-@using MoonCore.Abstractions
-@using MoonCore.Blazor.Models.Forms
+@using MoonCore.Blazor.Models.Fast
@using MoonCore.Helpers
@using Moonlight.Core.Database.Entities
-@using Moonlight.Core.Models.Forms.ApiKeys
@using Moonlight.Core.UI.Components.Navigations
@inject ClipboardService ClipboardService
@@ -15,17 +13,15 @@
-
+
@{
var apiKeyHalf = Formatter.CutInHalf(context!.Key);
- var bogusHalf = Formatter.IntToStringWithLeadingZeros(69, apiKeyHalf.Length);
}
@@ -49,20 +45,19 @@
-
+
@code
{
- private IEnumerable ApiKeysLoader(Repository repository)
+ private void OnConfigure(FastCrudConfiguration configuration)
{
- return repository.Get();
- }
-
- private void OnConfigure(AutoCrudConfiguration configuration)
- {
- configuration.ValidateAdd = async apiKey =>
+ configuration.ValidateCreate = async apiKey =>
{
+ // TODO: Remove this when correct permission editor exists
+ if (string.IsNullOrEmpty(apiKey.PermissionJson))
+ apiKey.PermissionJson = "[]";
+
var key = Formatter.GenerateString(32);
apiKey.Key = key;
@@ -70,4 +65,22 @@
await ToastService.Info("Copied api key into your clipboard");
};
}
+
+ private void OnConfigureCreate(FastConfiguration configuration)
+ {
+ configuration.AddProperty(x => x.Description)
+ .WithDefaultComponent()
+ .WithDescription("Write a note here for which application the api key is used for")
+ .WithValidation(FastValidators.Required);
+
+ configuration.AddProperty(x => x.ExpiresAt)
+ .WithDefaultComponent()
+ .WithDescription("Specify when the api key should expire");
+
+ configuration.AddProperty(x => x.PermissionJson)
+ .WithDefaultComponent()
+ .WithName("Permissions");
+ }
+
+ private void OnConfigureEdit(FastConfiguration configuration, ApiKey _) => OnConfigureCreate(configuration);
}
\ No newline at end of file
diff --git a/Moonlight/Features/Servers/UI/Views/Servers/Networks.razor b/Moonlight/Features/Servers/UI/Views/Servers/Networks.razor
index 9af97c28..38fb1df1 100644
--- a/Moonlight/Features/Servers/UI/Views/Servers/Networks.razor
+++ b/Moonlight/Features/Servers/UI/Views/Servers/Networks.razor
@@ -1,11 +1,14 @@
@page "/servers/networks"
+@using System.ComponentModel.DataAnnotations
@using Moonlight.Features.Servers.UI.Components
@using Moonlight.Features.Servers.Entities
@using Moonlight.Features.Servers.Models.Forms.Users.Networks
@using MoonCore.Abstractions
@using Moonlight.Core.Services
@using Microsoft.EntityFrameworkCore
+@using MoonCore.Blazor.Forms.Fast.Components
+@using MoonCore.Blazor.Models.Fast
@using MoonCore.Exceptions
@inject IdentityService IdentityService
@@ -13,11 +16,11 @@
-
+
@@ -28,30 +31,25 @@
@{
- var servers = UsedByCache.ContainsKey(context.Id) ? UsedByCache[context.Id] : Array.Empty();
+ var servers = UsedByCache.ContainsKey(context.Id) ? UsedByCache[context.Id] : Array.Empty();
}
@foreach (var server in servers)
{
- @(server.Name) @(server != servers.Last() ? "," : "")
+ @(server.Name) @(server != servers.Last() ? "," : "")
}
- @*
-
-
- Create a new private network in order to connect multiple servers on the same node
-
- *@
-
+
+
@code
{
private readonly Dictionary UsedByCache = new();
- private IEnumerable Load(Repository repository)
+ private IEnumerable Loader(Repository repository)
{
var result = repository
.Get()
@@ -74,20 +72,44 @@
return result;
}
- private Task ValidateAdd(ServerNetwork network)
+ private void OnConfigure(FastCrudConfiguration configuration)
{
- if (!ServerRepository
- .Get()
- .Any(x => x.Node.Id == network.Node.Id && x.Owner.Id == IdentityService.CurrentUser.Id))
+ configuration.ValidateCreate += network =>
{
- throw new DisplayException("You need a server on the selected node in order to create a network on the node");
- }
+ if (!ServerRepository
+ .Get()
+ .Any(x => x.Node.Id == network.Node.Id && x.Owner.Id == IdentityService.CurrentUser.Id))
+ {
+ throw new DisplayException("You need a server on the selected node in order to create a network on the node");
+ }
- //TODO: Add config to check the amount of networks created
+ //TODO: Add config to check the amount of networks created
- // Set user as the crud is not allowed to set it (user crud and so on)
- network.User = IdentityService.CurrentUser;
+ // Set user as the crud is not allowed to set it (user crud and so on)
+ network.User = IdentityService.CurrentUser;
+
+ return Task.CompletedTask;
+ };
+ }
+
+ private void OnConfigureCreate(FastConfiguration configuration)
+ {
+ configuration.AddProperty(x => x.Name)
+ .WithDefaultComponent()
+ .WithValidation(FastValidators.Required);
+
+ Func nodeDisplayField = x => x.Name;
- return Task.CompletedTask;
+ configuration.AddProperty(x => x.Node)
+ .WithComponent>()
+ .WithAdditionalOption("DisplayField", nodeDisplayField)
+ .WithValidation(x => x != null ? ValidationResult.Success : new ValidationResult("You need to specify a node"));
+ }
+
+ private void OnConfigureEdit(FastConfiguration configuration, ServerNetwork _)
+ {
+ configuration.AddProperty(x => x.Name)
+ .WithDefaultComponent()
+ .WithValidation(FastValidators.Required);
}
}
\ No newline at end of file
diff --git a/Moonlight/Moonlight.csproj b/Moonlight/Moonlight.csproj
index 58bb91c6..29ffcc6d 100644
--- a/Moonlight/Moonlight.csproj
+++ b/Moonlight/Moonlight.csproj
@@ -93,8 +93,8 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
+
+