Recreated plugin with new project template. Started implementing server system daemon

This commit is contained in:
2026-03-01 21:09:29 +01:00
parent f6b71f4de6
commit 52dbd13fb5
350 changed files with 2795 additions and 21553 deletions

View File

@@ -1,147 +0,0 @@
/*
using System.IO.Enumeration;
using MoonCore.Blazor.FlyonUi.Helpers;
using MoonCore.Helpers;
using MoonlightServers.Frontend.Services;
namespace MoonlightServers.Frontend.Helpers;
public class ServerFileSystemProvider : IFileSystemProvider, ICompressFileSystemProvider
{
private readonly DownloadService DownloadService;
private readonly ServerFileSystemService FileSystemService;
public CompressType[] CompressTypes { get; } =
[
new()
{
Extension = "zip",
DisplayName = "ZIP Archive"
},
new()
{
Extension = "tar.gz",
DisplayName = "GZ Compressed Tar Archive"
}
];
private readonly int ServerId;
public ServerFileSystemProvider(
int serverId,
ServerFileSystemService fileSystemService,
DownloadService downloadService
)
{
ServerId = serverId;
FileSystemService = fileSystemService;
DownloadService = downloadService;
}
public async Task<FileSystemEntry[]> List(string path)
{
var result = await FileSystemService.List(ServerId, path);
return result
.Select(x => new FileSystemEntry()
{
Name = x.Name,
Size = x.Size,
IsFile = x.IsFile,
CreatedAt = x.CreatedAt,
UpdatedAt = x.UpdatedAt
})
.ToArray();
}
public async Task Create(string path, Stream stream)
{
await Upload(_ => Task.CompletedTask, path, stream);
}
public async Task Move(string oldPath, string newPath)
{
await FileSystemService.Move(ServerId, oldPath, newPath);
}
public async Task Delete(string path)
{
await FileSystemService.Delete(ServerId, path);
}
public async Task CreateDirectory(string path)
{
await FileSystemService.Mkdir(ServerId, path);
}
public async Task<Stream> Read(string path)
{
var downloadSession = await FileSystemService.Download(ServerId, path);
using var httpClient = new HttpClient();
return await httpClient.GetStreamAsync(downloadSession.DownloadUrl);
}
public async Task Download(Func<int, Task> updateProgress, string path, string fileName)
{
var downloadSession = await FileSystemService.Download(ServerId, path);
await DownloadService.DownloadUrl(fileName, downloadSession.DownloadUrl,
async (loaded, total) =>
{
var percent = total == 0 ? 0 : (int)Math.Round((float)loaded / total * 100);
await updateProgress.Invoke(percent);
}
);
}
public async Task Upload(Func<int, Task> updateProgress, string path, Stream stream)
{
using var httpClient = new HttpClient();
var uploadSession = await FileSystemService.Upload(ServerId);
var size = stream.Length;
var chunkSize = ByteConverter.FromMegaBytes(20).Bytes;
var chunks = size / chunkSize;
chunks += size % chunkSize > 0 ? 1 : 0;
for (var chunkId = 0; chunkId < chunks; chunkId++)
{
var percent = (int)Math.Round((chunkId + 1f) / chunks * 100);
await updateProgress.Invoke(percent);
var buffer = new byte[chunkSize];
var bytesRead = await stream.ReadAsync(buffer);
var uploadForm = new MultipartFormDataContent();
uploadForm.Add(new ByteArrayContent(buffer, 0, bytesRead), "file", "file");
await httpClient.PostAsync(
$"{uploadSession.UploadUrl}&totalSize={size}&chunkId={chunkId}&path={path}",
uploadForm
);
}
}
public async Task Compress(CompressType type, string path, string[] itemsToCompress)
{
await FileSystemService.Compress(
ServerId,
type.Extension.Replace(".", ""),
itemsToCompress,
path
);
}
public async Task Decompress(CompressType type, string path, string destination)
{
await FileSystemService.Decompress(
ServerId,
type.Extension.Replace(".", ""),
path,
destination
);
}
}*/

View File

@@ -1,63 +0,0 @@
using MoonCore.Blazor.FlyonUi.Files;
using MoonCore.Blazor.FlyonUi.Files.Manager;
using MoonlightServers.Frontend.Services;
namespace MoonlightServers.Frontend.Helpers;
public class ServerFsAccess : IFsAccess
{
private readonly int Id;
private readonly ServerFileSystemService FileSystemService;
public ServerFsAccess(int id, ServerFileSystemService fileSystemService)
{
Id = id;
FileSystemService = fileSystemService;
}
public Task CreateFileAsync(string path)
=> FileSystemService.TouchAsync(Id, path);
public Task CreateDirectoryAsync(string path)
=> FileSystemService.MkdirAsync(Id, path);
public async Task<FsEntry[]> ListAsync(string path)
{
var entries = await FileSystemService.ListAsync(Id, path);
return entries.Select(x => new FsEntry()
{
Name = x.Name,
Size = x.Size,
CreatedAt = x.CreatedAt,
IsFolder = x.IsFolder,
UpdatedAt = x.UpdatedAt
}).ToArray();
}
public Task MoveAsync(string oldPath, string newPath)
=> FileSystemService.MoveAsync(Id, oldPath, newPath);
public Task ReadAsync(string path, Func<Stream, Task> onHandleData)
{
throw new NotImplementedException();
}
public Task WriteAsync(string path, Stream dataStream)
{
throw new NotImplementedException();
}
public Task DeleteAsync(string path)
=> FileSystemService.DeleteAsync(Id, path);
public Task UploadChunkAsync(string path, int chunkId, long chunkSize, long totalSize, byte[] data)
{
throw new NotImplementedException();
}
public Task<byte[]> DownloadChunkAsync(string path, int chunkId, long chunkSize)
{
throw new NotImplementedException();
}
}

View File

@@ -1,59 +0,0 @@
using MoonlightServers.Frontend.Interfaces;
using MoonlightServers.Frontend.Models;
using MoonlightServers.Shared.Constants;
using MoonlightServers.Shared.Http.Responses.Client.Servers;
namespace MoonlightServers.Frontend.Implementations;
public class DefaultPermissionProvider : IServerPermissionProvider
{
public Task<ServerPermission[]> GetPermissionsAsync(ServerDetailResponse server)
{
ServerPermission[] permissions = [
new()
{
Identifier = ServerPermissionConstants.Console,
Description = "Allows access to the console",
DisplayName = "Console",
Icon = "icon-square-terminal"
},
new()
{
Identifier = ServerPermissionConstants.Files,
Description = "Allows access to the files",
DisplayName = "Files",
Icon = "icon-folder"
},
new()
{
Identifier = ServerPermissionConstants.Power,
Description = "Allows actions like turning off the server and starting it",
DisplayName = "Power",
Icon = "icon-power"
},
new()
{
Identifier = ServerPermissionConstants.Settings,
Description = "Gives permissions to perform re-installs or change other general settings",
DisplayName = "Settings",
Icon = "icon-settings"
},
new()
{
Identifier = ServerPermissionConstants.Shares,
Description = "Dangerous! This allows control to the available shares and their access level for a server",
DisplayName = "Shares",
Icon = "icon-users"
},
new()
{
Identifier = ServerPermissionConstants.Variables,
Description = "Allows access to the server software specific settings",
DisplayName = "Variables",
Icon = "icon-variable"
}
];
return Task.FromResult(permissions);
}
}

View File

@@ -1,25 +0,0 @@
using MoonlightServers.Frontend.Interfaces;
using MoonlightServers.Frontend.Models;
using MoonlightServers.Frontend.UI.Components.Servers.ServerTabs;
using MoonlightServers.Shared.Constants;
using MoonlightServers.Shared.Enums;
using MoonlightServers.Shared.Http.Responses.Client.Servers;
namespace MoonlightServers.Frontend.Implementations;
public class DefaultServerTabProvider : IServerTabProvider
{
public Task<ServerTab[]> GetTabsAsync(ServerDetailResponse server)
{
ServerTab[] tabs =
[
ServerTab.CreateFromComponent<ConsoleTab>("Console", "console", 0, ServerPermissionConstants.Console, ServerPermissionLevel.Read),
ServerTab.CreateFromComponent<FilesTab>("Files", "files", 1, ServerPermissionConstants.Files, ServerPermissionLevel.Read),
ServerTab.CreateFromComponent<SharesTab>("Shares", "shares", 2, ServerPermissionConstants.Shares, ServerPermissionLevel.ReadWrite),
ServerTab.CreateFromComponent<VariablesTab>("Variables", "variables", 9, ServerPermissionConstants.Variables, ServerPermissionLevel.Read),
ServerTab.CreateFromComponent<SettingsTab>("Settings", "settings", 10, ServerPermissionConstants.Settings, ServerPermissionLevel.Read),
];
return Task.FromResult(tabs);
}
}

View File

@@ -0,0 +1,17 @@
using LucideBlazor;
using Moonlight.Frontend.Interfaces;
using Moonlight.Frontend.Models;
namespace MoonlightServers.Frontend.Implementations;
public class PermissionProvider : IPermissionProvider
{
public Task<PermissionCategory[]> GetPermissionsAsync()
{
return Task.FromResult<PermissionCategory[]>([
new PermissionCategory("Demo", typeof(SparklesIcon), [
new Permission("Permissions:Demo", "Demo", "Access to demo page")
])
]);
}
}

View File

@@ -1,31 +0,0 @@
using Moonlight.Client.Interfaces;
using Moonlight.Client.Models;
namespace MoonlightServers.Frontend.Implementations;
public class SidebarImplementation : ISidebarItemProvider
{
public void ModifySidebar(List<SidebarItem> items)
{
items.AddRange(
[
new SidebarItem()
{
Name = "Servers",
Path = "/servers",
Icon = "icon-server",
Priority = 4
},
new SidebarItem()
{
Name = "Servers",
Path = "/admin/servers",
Icon = "icon-server",
Group = "Admin",
Policy = "permissions:admin.servers.overview",
Priority = 4
}
]
);
}
}

View File

@@ -0,0 +1,21 @@
using LucideBlazor;
using Moonlight.Frontend.Interfaces;
using Moonlight.Frontend.Models;
namespace MoonlightServers.Frontend.Implementations;
public sealed class SidebarProvider : ISidebarProvider
{
public Task<SidebarItem[]> GetItemsAsync()
{
return Task.FromResult<SidebarItem[]>([
new SidebarItem()
{
Group = "Demo",
Name = "Demo",
IconType = typeof(SparklesIcon),
Path = "/demo"
}
]);
}
}

View File

@@ -1,9 +0,0 @@
using MoonlightServers.Frontend.Models;
using MoonlightServers.Shared.Http.Responses.Client.Servers;
namespace MoonlightServers.Frontend.Interfaces;
public interface IServerPermissionProvider
{
public Task<ServerPermission[]> GetPermissionsAsync(ServerDetailResponse server);
}

View File

@@ -1,9 +0,0 @@
using MoonlightServers.Frontend.Models;
using MoonlightServers.Shared.Http.Responses.Client.Servers;
namespace MoonlightServers.Frontend.Interfaces;
public interface IServerTabProvider
{
public Task<ServerTab[]> GetTabsAsync(ServerDetailResponse server);
}

View File

@@ -1,9 +0,0 @@
namespace MoonlightServers.Frontend.Models;
public record ServerPermission
{
public string Identifier { get; set; }
public string DisplayName { get; set; }
public string Description { get; set; }
public string Icon { get; set; }
}

View File

@@ -1,31 +0,0 @@
using MoonlightServers.Frontend.UI.Components.Servers.ServerTabs;
using MoonlightServers.Shared.Enums;
namespace MoonlightServers.Frontend.Models;
public record ServerTab
{
public string Name { get; private set; }
public string Path { get; private set; }
public string PermissionId { get; set; }
public ServerPermissionLevel PermissionLevel { get; set; }
public int Priority { get; private set; }
public Type ComponentType { get; private set; }
public static ServerTab CreateFromComponent<T>(
string name,
string path,
int priority,
string permissionId = "", ServerPermissionLevel permissionLevel = ServerPermissionLevel.None) where T : BaseServerTab
{
return new()
{
Name = name,
Path = path,
Priority = priority,
ComponentType = typeof(T),
PermissionLevel = permissionLevel,
PermissionId = permissionId
};
}
}

View File

@@ -1,42 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<CompressionEnabled>false</CompressionEnabled>
</PropertyGroup>
<PropertyGroup Label="Nuget Settings">
<PackageId>MoonlightServers.Frontend</PackageId>
<Title>MoonlightServers.Frontend</Title>
<Version>2.1.0</Version>
<IsPackable>true</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.9" />
<PackageReference Include="Moonlight.Client" Version="2.1.*"/>
<PackageReference Include="XtermBlazor" Version="2.1.2" />
<SupportedPlatform Include="browser"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MoonlightServers.Shared\MoonlightServers.Shared.csproj"/>
</ItemGroup>
<ItemGroup Label="Build instruction for nuget package building">
<Compile Remove="storage\**\*" />
<Content Remove="storage\**\*" />
<None Remove="storage\**\*" />
<PackageReference Include="Moonlight.Frontend" Version="2.1.0"/>
</ItemGroup>
<ItemGroup>
<None Include="Styles/mappings/*.map" Pack="true" PackagePath="Styles/" />
<None Include="MoonlightServers.Frontend.targets" Pack="true" PackagePath="build/MoonlightServers.Frontend.targets" />
<Folder Include="wwwroot\"/>
</ItemGroup>
<ItemGroup>
<Folder Include="Startup\" />
<ProjectReference Include="..\MoonlightServers.Shared\MoonlightServers.Shared.csproj" />
</ItemGroup>
<ItemGroup>
<None Include="Styles/*" Pack="true" PackagePath="Styles/"/>
<None Include="Servers.Frontend.targets" Pack="true" PackagePath="build\Servers.Frontend.targets"/>
<None Include="Servers.Frontend.targets" Pack="true" PackagePath="buildTransitive\Servers.Frontend.targets"/>
</ItemGroup>
</Project>

View File

@@ -1,8 +0,0 @@
<Project>
<ItemGroup>
<StylesFilesToCopy Include="$(MSBuildThisFileDirectory)../Styles/**/*.*"/>
</ItemGroup>
<Target Name="CopyContent" BeforeTargets="Build">
<Copy SourceFiles="@(StylesFilesToCopy)" DestinationFolder="$(ProjectDir)Styles/MoonlightServers.Frontend/%(RecursiveDir)" SkipUnchangedFiles="true" />
</Target>
</Project>

View File

@@ -1,26 +0,0 @@
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.DependencyInjection;
using MoonCore.Extensions;
using Moonlight.Client.Interfaces;
using Moonlight.Client.Plugins;
using MoonlightServers.Frontend.Implementations;
using MoonlightServers.Frontend.Interfaces;
namespace MoonlightServers.Frontend;
public class PluginStartup : IPluginStartup
{
public void AddPlugin(WebAssemblyHostBuilder builder)
{
builder.Services.AddSingleton<ISidebarItemProvider, SidebarImplementation>();
builder.Services.AddSingleton<IServerTabProvider, DefaultServerTabProvider>();
builder.Services.AddSingleton<IServerPermissionProvider, DefaultPermissionProvider>();
builder.Services.AutoAddServices<PluginStartup>();
}
public void ConfigurePlugin(WebAssemblyHost app)
{
}
}

View File

@@ -0,0 +1,15 @@
<Project>
<PropertyGroup>
<ServersCssClassDir Condition="'$(ServersCssClassDir)' == ''">
$(MSBuildProjectDirectory)\bin\Servers
</ServersCssClassDir>
</PropertyGroup>
<Target Name="Servers_CopyContents" BeforeTargets="Build">
<ItemGroup>
<Files Include="$(MSBuildThisFileDirectory)..\Styles\**\*" />
</ItemGroup>
<Copy SourceFiles="@(Files)" DestinationFolder="$(ServersCssClassDir)" SkipUnchangedFiles="true" />
</Target>
</Project>

View File

@@ -1,36 +0,0 @@
using MoonCore.Attributes;
using MoonCore.Helpers;
using MoonlightServers.Shared.Http.Responses.Admin.Nodes.Statistics;
using MoonlightServers.Shared.Http.Responses.Admin.Nodes.Sys;
namespace MoonlightServers.Frontend.Services;
[Scoped]
public class NodeService
{
private readonly HttpApiClient HttpApiClient;
public NodeService(HttpApiClient httpApiClient)
{
HttpApiClient = httpApiClient;
}
public async Task<NodeSystemStatusResponse> GetSystemStatusAsync(int nodeId)
{
return await HttpApiClient.GetJson<NodeSystemStatusResponse>($"api/admin/servers/nodes/{nodeId}/system/status");
}
public async Task<StatisticsResponse> GetStatisticsAsync(int nodeId)
{
return await HttpApiClient.GetJson<StatisticsResponse>(
$"api/admin/servers/nodes/{nodeId}/statistics"
);
}
public async Task<DockerStatisticsResponse> GetDockerStatisticsAsync(int nodeId)
{
return await HttpApiClient.GetJson<DockerStatisticsResponse>(
$"api/admin/servers/nodes/{nodeId}/statistics/docker"
);
}
}

View File

@@ -1,92 +0,0 @@
using MoonCore.Attributes;
using MoonCore.Helpers;
using MoonlightServers.Shared.Http.Requests.Client.Servers.Files;
using MoonlightServers.Shared.Http.Responses.Client.Servers.Files;
namespace MoonlightServers.Frontend.Services;
[Scoped]
public class ServerFileSystemService
{
private readonly HttpApiClient ApiClient;
public ServerFileSystemService(HttpApiClient apiClient)
{
ApiClient = apiClient;
}
public async Task<ServerFilesEntryResponse[]> ListAsync(int serverId, string path)
{
return await ApiClient.GetJson<ServerFilesEntryResponse[]>(
$"api/client/servers/{serverId}/files/list?path={path}"
);
}
public async Task MoveAsync(int serverId, string oldPath, string newPath)
{
await ApiClient.Post(
$"api/client/servers/{serverId}/files/move?oldPath={oldPath}&newPath={newPath}"
);
}
public async Task DeleteAsync(int serverId, string path)
{
await ApiClient.Delete(
$"api/client/servers/{serverId}/files/delete?path={path}"
);
}
public async Task MkdirAsync(int serverId, string path)
{
await ApiClient.Post(
$"api/client/servers/{serverId}/files/mkdir?path={path}"
);
}
public async Task TouchAsync(int serverId, string path)
{
await ApiClient.Post(
$"api/client/servers/{serverId}/files/touch?path={path}"
);
}
public async Task<ServerFilesUploadResponse> UploadAsync(int serverId)
{
return await ApiClient.GetJson<ServerFilesUploadResponse>(
$"api/client/servers/{serverId}/files/upload"
);
}
public async Task<ServerFilesDownloadResponse> DownloadAsync(int serverId, string path)
{
return await ApiClient.GetJson<ServerFilesDownloadResponse>(
$"api/client/servers/{serverId}/files/download?path={path}"
);
}
public async Task CompressAsync(int serverId, string type, string[] items, string destination)
{
await ApiClient.Post(
$"api/client/servers/{serverId}/files/compress",
new ServerFilesCompressRequest()
{
Type = type,
Items = items,
Destination = destination
}
);
}
public async Task DecompressAsync(int serverId, string type, string path, string destination)
{
await ApiClient.Post(
$"api/client/servers/{serverId}/files/decompress",
new ServerFilesDecompressRequest()
{
Type = type,
Path = path,
Destination = destination
}
);
}
}

View File

@@ -1,139 +0,0 @@
using MoonCore.Attributes;
using MoonCore.Common;
using MoonCore.Helpers;
using MoonlightServers.Shared.Http.Requests.Client.Servers;
using MoonlightServers.Shared.Http.Requests.Client.Servers.Variables;
using MoonlightServers.Shared.Http.Responses.Client.Servers;
using MoonlightServers.Shared.Http.Responses.Client.Servers.Variables;
namespace MoonlightServers.Frontend.Services;
[Scoped]
public class ServerService
{
private readonly HttpApiClient HttpApiClient;
public ServerService(HttpApiClient httpApiClient)
{
HttpApiClient = httpApiClient;
}
public async Task<CountedData<ServerDetailResponse>> GetServersAsync(int startIndex, int count)
{
return await HttpApiClient.GetJson<CountedData<ServerDetailResponse>>(
$"api/client/servers?startIndex={startIndex}&count={count}"
);
}
public async Task<CountedData<ServerDetailResponse>> GetSharedServersAsync(int startIndex, int count)
{
return await HttpApiClient.GetJson<CountedData<ServerDetailResponse>>(
$"api/client/servers/shared?startIndex={startIndex}&count={count}"
);
}
public async Task<ServerDetailResponse> GetServerAsync(int serverId)
{
return await HttpApiClient.GetJson<ServerDetailResponse>(
$"api/client/servers/{serverId}"
);
}
public async Task<ServerStatusResponse> GetStatusAsync(int serverId)
{
return await HttpApiClient.GetJson<ServerStatusResponse>(
$"api/client/servers/{serverId}/status"
);
}
public async Task<ServerLogsResponse> GetLogsAsync(int serverId)
{
return await HttpApiClient.GetJson<ServerLogsResponse>(
$"api/client/servers/{serverId}/logs"
);
}
public async Task<ServerStatsResponse> GetStatsAsync(int serverId)
{
return await HttpApiClient.GetJson<ServerStatsResponse>(
$"api/client/servers/{serverId}/stats"
);
}
public async Task RunCommandAsync(int serverId, string command)
{
await HttpApiClient.Post(
$"api/client/servers/{serverId}/command",
new ServerCommandRequest()
{
Command = command
}
);
}
public async Task<ServerWebSocketResponse> GetWebSocketAsync(int serverId)
{
return await HttpApiClient.GetJson<ServerWebSocketResponse>(
$"api/client/servers/{serverId}/ws"
);
}
public async Task InstallAsync(int serverId)
{
await HttpApiClient.Post(
$"api/client/servers/{serverId}/install"
);
}
#region Power actions
public async Task StartAsync(int serverId)
{
await HttpApiClient.Post(
$"api/client/servers/{serverId}/start"
);
}
public async Task StopAsync(int serverId)
{
await HttpApiClient.Post(
$"api/client/servers/{serverId}/stop"
);
}
public async Task KillAsync(int serverId)
{
await HttpApiClient.Post(
$"api/client/servers/{serverId}/kill"
);
}
#endregion
#region Variables
public async Task<CountedData<ServerVariableDetailResponse>> GetVariablesAsync(int serverId, int startIndex, int count)
{
return await HttpApiClient.GetJson<CountedData<ServerVariableDetailResponse>>(
$"api/client/servers/{serverId}/variables?startIndex={startIndex}&count={count}"
);
}
public async Task UpdateVariablesAsync(int serverId, UpdateServerVariableRangeRequest request)
{
await HttpApiClient.Patch(
$"api/client/servers/{serverId}/variables",
request
);
}
public async Task UpdateVariableAsync(int serverId, UpdateServerVariableRequest request)
{
await HttpApiClient.Put(
$"api/client/servers/{serverId}/variables",
request
);
}
#endregion
}

View File

@@ -1,34 +0,0 @@
using MoonCore.Attributes;
using MoonCore.Common;
using MoonCore.Helpers;
using MoonlightServers.Shared.Http.Requests.Client.Servers.Shares;
using MoonlightServers.Shared.Http.Responses.Client.Servers.Shares;
namespace MoonlightServers.Frontend.Services;
[Scoped]
public class ServerShareService
{
private readonly HttpApiClient ApiClient;
public ServerShareService(HttpApiClient apiClient)
{
ApiClient = apiClient;
}
public async Task<CountedData<ServerShareResponse>> GetAsync(int id, int startIndex, int count)
=> await ApiClient.GetJson<CountedData<ServerShareResponse>>(
$"api/client/servers/{id}/shares?startIndex={startIndex}&count={count}");
public async Task<ServerShareResponse> GetAsync(int id, int shareId)
=> await ApiClient.GetJson<ServerShareResponse>($"api/client/servers/{id}/shares/{shareId}");
public async Task<ServerShareResponse> CreateAsync(int id, CreateShareRequest request)
=> await ApiClient.PostJson<ServerShareResponse>($"api/client/servers/{id}/shares", request);
public async Task<ServerShareResponse> UpdateAsync(int id, int shareId, UpdateShareRequest request)
=> await ApiClient.PatchJson<ServerShareResponse>($"api/client/servers/{id}/shares/{shareId}", request);
public async Task DeleteAsync(int id, int shareId)
=> await ApiClient.Delete($"api/client/servers/{id}/shares/{shareId}");
}

View File

@@ -0,0 +1,28 @@
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Moonlight.Frontend;
using Moonlight.Frontend.Configuration;
using Moonlight.Frontend.Interfaces;
using MoonlightServers.Frontend.Implementations;
using SimplePlugin.Abstractions;
namespace MoonlightServers.Frontend;
[PluginModule]
public sealed class Startup : MoonlightPlugin
{
public override void PreBuild(WebAssemblyHostBuilder builder)
{
builder.Services.AddSingleton<IPermissionProvider, PermissionProvider>();
builder.Services.AddSingleton<ISidebarProvider, SidebarProvider>();
builder.Services.Configure<NavigationAssemblyOptions>(options =>
{
options.Assemblies.Add(typeof(Startup).Assembly);
});
}
public override void PostBuild(WebAssemblyHost application)
{
}
}

View File

@@ -1,766 +0,0 @@
!bg-base-100
!border-base-content/40
!border-none
!flex
!font-medium
!font-semibold
!h-2.5
!justify-between
!me-1.5
!ms-auto
!px-2.5
!py-0.5
!rounded-full
!rounded-xs
!text-sm
!w-2.5
*:[grid-area:1/1]
*:first:rounded-tl-lg
*:last:rounded-tr-lg
-left-4
-ml-4
-translate-x-full
-translate-y-1/2
[animation-duration:0.8s]
[animation-timing-function:ease]
absolute
accordion
accordion-bordered
accordion-toggle
active
active-tab:bg-primary
active-tab:hover:text-primary-content
active-tab:text-base-content
active-tab:text-primary-content
advance-select-menu
advance-select-option
advance-select-tag
advance-select-toggle
alert
alert-error
alert-outline
alert-primary
alert-soft
align-bottom
align-middle
animate-bounce
animate-ping
animate-spin
aria-[current='page']:text-bg-soft-primary
avatar
avatar-away-bottom
avatar-away-top
avatar-busy-bottom
avatar-busy-top
avatar-offline-bottom
avatar-offline-top
avatar-online-bottom
avatar-online-top
avatar-placeholder
badge
badge-error
badge-info
badge-outline
badge-primary
badge-soft
badge-success
basis-full
bg-background
bg-background/60
bg-base-100
bg-base-150
bg-base-200
bg-base-200!
bg-base-200/50
bg-base-200/60
bg-base-250
bg-base-300
bg-base-300/45
bg-base-300/50
bg-base-300/60
bg-clip-text
bg-error
bg-gradient-to-r
bg-gray-800
bg-gray-900
bg-indigo-600
bg-info
bg-primary
bg-primary/5
bg-red-500
bg-success
bg-transparent
bg-warning
bg-white/5
block
blur
border
border-0
border-1
border-2
border-3
border-accent
border-b
border-b-2
border-b-base-content/20
border-b-primary
border-base-content
border-base-content/20
border-base-content/25
border-base-content/40
border-base-content/5
border-base-content/60
border-base-content/70
border-dashed
border-dotted
border-e-2
border-error/30
border-info/30
border-l-4
border-l-transparent
border-primary
border-r-transparent
border-solid
border-success
border-success/30
border-t
border-t-2
border-t-transparent
border-transparent
border-warning/30
bottom-0
bottom-full
breadcrumbs
breadcrumbs-separator
break-words
btn
btn-accent
btn-active
btn-block
btn-circle
btn-disabled
btn-error
btn-gradient
btn-info
btn-lg
btn-outline
btn-primary
btn-secondary
btn-sm
btn-soft
btn-square
btn-success
btn-text
btn-warning
card
card-alert
card-body
card-border
card-footer
card-header
card-title
carousel
carousel-body
carousel-next
carousel-prev
carousel-slide
chat
chat-avatar
chat-bubble
chat-footer
chat-header
chat-receiver
chat-sender
checkbox
checkbox-primary
checkbox-xs
col-span-1
col-span-12
col-span-2
collapse
combo-box-selected:block
combo-box-selected:dropdown-active
complete
container
contents
cursor-default
cursor-not-allowed
cursor-pointer
cursor-progress
custom-option
diff
disabled
divide-base-150/60
divide-y
divider
drawer
drawer-body
drawer-bottom
drawer-end
drawer-footer
drawer-header
drawer-start
drawer-title
drawer-top
drop-shadow
dropdown
dropdown-active
dropdown-disabled
dropdown-item
dropdown-menu
dropdown-open:opacity-100
dropdown-open:rotate-180
dropdown-toggle
duration-300
duration-500
ease-in-out
ease-linear
end-3
error-message
file-upload-complete:progress-success
fill-base-content
fill-black
fill-gray-200
filter
filter-reset
fixed
flex
flex-1
flex-col
flex-grow
flex-nowrap
flex-row
flex-shrink-0
flex-wrap
focus-visible:outline
focus-visible:outline-2
focus-visible:outline-indigo-600
focus-visible:outline-none
focus-visible:outline-offset-2
focus-within:border-primary
focus:border-primary
focus:outline-1
focus:outline-none
focus:outline-primary
focus:ring-0
focus:ring-2
focus:ring-indigo-600
focus:ring-inset
font-bold
font-inter
font-medium
font-normal
font-semibold
footer
footer-center
from-violet-400
gap-0.5
gap-1
gap-1.5
gap-2
gap-3
gap-4
gap-5
gap-6
gap-x-1
gap-x-2
gap-x-3
gap-x-6
gap-y-1
gap-y-1.5
gap-y-2
gap-y-2.5
gap-y-3
gap-y-8
grid
grid-cols-1
grid-cols-12
grid-cols-2
grid-cols-3
grid-cols-4
grid-flow-col
grow
grow-0
h-0
h-10
h-12
h-14
h-2
h-3
h-32
h-36
h-6
h-64
h-8
h-auto
h-full
h-screen
helper-text
hidden
hover:bg-indigo-500
hover:bg-primary/5
hover:bg-transparent
hover:cursor-pointer
hover:text-base-content
hover:text-base-content/60
hover:text-indigo-500
hover:text-primary
image-full
indicator
indicator-item
inline
inline-block
inline-flex
inline-grid
input
input-floating
input-floating-label
input-lg
input-md
input-sm
input-xl
input-xs
inset-0
inset-y-0
inset-y-2
invisible
is-invalid
is-valid
isolate
italic
items-center
items-end
items-start
join
join-item
justify-between
justify-center
justify-end
justify-start
justify-stretch
label-text
leading-3
leading-3.5
leading-6
leading-9
leading-[1.1]
leading-none
left-0
lg:bg-base-100/20
lg:flex
lg:gap-y-0
lg:grid-cols-2
lg:hidden
lg:justify-end
lg:justify-start
lg:min-w-0
lg:p-10
lg:p-8
lg:pb-5
lg:pl-64
lg:pr-3.5
lg:pt-5
lg:px-8
lg:ring-1
lg:ring-base-content/10
lg:rounded-lg
lg:shadow-xs
lg:table-cell
link
link-animated
link-hover
link-primary
list-disc
list-inside
list-none
loading
loading-lg
loading-sm
loading-spinner
loading-xl
loading-xs
lowercase
m-10
mask
max-h-52
max-lg:flex-col
max-lg:hidden
max-md:flex-wrap
max-md:justify-center
max-md:w-full
max-sm:hidden
max-w-64
max-w-7xl
max-w-8
max-w-80
max-w-full
max-w-lg
max-w-md
max-w-sm
max-w-xl
mb-0.5
mb-1
mb-1.5
mb-2
mb-2.5
mb-25
mb-3
mb-4
mb-5
mb-8
md:col-span-1
md:col-span-6
md:flex
md:gap-2
md:grid-cols-2
md:hidden!
md:items-center
md:min-w-md
md:navbar-end
md:table-cell
md:text-3xl
me-1
me-1.5
me-2
me-2.5
me-5
menu
menu-active
menu-disabled
menu-dropdown
menu-dropdown-show
menu-focus
menu-horizontal
menu-sm
menu-title
min-h-0
min-h-full
min-h-screen
min-h-svh
min-w-0
min-w-28
min-w-48
min-w-60
min-w-[100px]
min-w-full
min-w-sm
mix-blend-exclusion
ml-3
ml-4
modal
modal-content
modal-dialog
modal-middle
modal-title
mr-2
mr-4
ms-0.5
ms-1
ms-1.5
ms-2
ms-2.5
ms-3
ms-auto
mt-1
mt-1.5
mt-10
mt-12
mt-2
mt-2.5
mt-3
mt-3.5
mt-4
mt-5
mt-6
mt-8
mx-1
mx-auto
my-2.5
my-20
my-3
my-5
my-8
my-auto
navbar
navbar-start
object-cover
opacity-0
opacity-100
opacity-75
open
origin-top-left
outline
outline-0
overflow-hidden
overflow-x-auto
overflow-x-hidden
overflow-y-auto
overlay-open:duration-50
overlay-open:opacity-100
overlay-open:translate-x-0
overlay-open:translate-y-0
overscroll-contain
p-0
p-0.5
p-1
p-1.5
p-12
p-2
p-2.5
p-3
p-4
p-5
p-6
p-8
pb-1
pe-1
pe-1.5
pin-input
pin-input-underline
placeholder-base-content/60
placeholder:text-gray-600
pointer-events-auto
pointer-events-none
progress
progress-bar
progress-indeterminate
progress-primary
pt-0
pt-0.5
pt-1.5
pt-2
pt-3
px-1.5
px-2
px-2.5
px-3
px-4
px-5
px-6
py-0.5
py-1.5
py-10
py-12
py-2
py-2.5
py-6
radial-progress
radio
range
relative
resize
right-0
ring
ring-0
ring-1
ring-gray-700
ring-inset
ring-white/10
rounded-box
rounded-field
rounded-full
rounded-lg
rounded-md
rounded-t-lg
rounded-xl
row-active
row-hover
rtl:!mr-0
select
select-disabled:opacity-40
select-disabled:pointer-events-none
select-floating
select-floating-label
select-lg
select-md
select-sm
select-xl
select-xs
selected
selected:select-active
shadow
shadow-base-300/20
shadow-lg
shadow-md
shadow-none
shadow-sm
shadow-xs
shrink-0
size-10
size-12
size-4
size-5
size-7
size-8
size-8.5
skeleton
skeleton-animated
sm:auto-cols-max
sm:col-span-2
sm:flex
sm:flex-nowrap
sm:gap-y-0
sm:grid-cols-3
sm:grid-cols-6
sm:items-center
sm:items-end
sm:justify-between
sm:justify-end
sm:leading-6
sm:max-w-2xl
sm:max-w-3xl
sm:max-w-4xl
sm:max-w-5xl
sm:max-w-6xl
sm:max-w-7xl
sm:max-w-[480px]
sm:max-w-lg
sm:max-w-md
sm:max-w-xl
sm:mb-0
sm:min-w-md
sm:mr-3
sm:mt-5
sm:mt-6
sm:mx-auto
sm:p-6
sm:px-12
sm:px-6
sm:py-2
sm:rounded-lg
sm:text-sm
sm:text-sm/5
sm:w-1/2
sm:w-full
space-x-1
space-x-2.5
space-y-1
space-y-4
space-y-6
sr-only
stack
stat
stat-actions
stat-desc
stat-figure
stat-title
stat-value
static
stats
stats-border
status
status-error
sticky
success-message
switch
tab
tab-active
tab-content
table
table-pin-cols
table-pin-rows
tabs
tabs-bordered
tabs-lg
tabs-lifted
tabs-md
tabs-sm
tabs-vertical
tabs-xl
tabs-xs
text-2xl
text-3xl
text-4xl
text-5xl
text-accent
text-base
text-base-content
text-base-content/40
text-base-content/50
text-base-content/60
text-base-content/70
text-base-content/80
text-base-content/90
text-base/6
text-center
text-error
text-error-content
text-gray-100
text-gray-400
text-gray-500
text-indigo-600
text-info
text-info-content
text-left
text-lg
text-primary
text-primary-content
text-right
text-slate-100
text-sm
text-sm/5
text-success
text-success-content
text-transparent
text-warning
text-warning-content
text-white
text-xl
text-xl!
text-xs
text-xs/5
textarea
textarea-floating
textarea-floating-label
textarea-lg
textarea-md
textarea-sm
textarea-xl
textarea-xs
theme-controller
to-purple-400
tooltip
tooltip-content
top-0
top-1/2
top-3
top-full
tracking-tight
tracking-wide
transform
transition
transition-all
transition-opacity
transition-transform
translate-x-0
translate-x-full
truncate
underline
uppercase
validate
via-sky-400
w-0
w-0.5
w-12
w-13
w-20
w-32
w-4
w-56
w-6
w-64
w-8
w-auto
w-fit
w-full
whitespace-nowrap
xl:flex
xl:grid-cols-2
xl:grid-cols-3
xl:grid-cols-4
z-1
z-10
z-40
z-50
z-69
z-70

View File

@@ -1,516 +0,0 @@
!bg-base-100
!border-base-content/40
!border-none
!flex
!font-medium
!font-semibold
!h-2.5
!justify-between
!me-1.5
!ms-auto
!px-2.5
!rounded-full
!text-sm
!w-2.5
*:[grid-area:1/1]
*:first:rounded-tl-lg
*:last:rounded-tr-lg
-left-4
-ml-4
-translate-x-full
-translate-y-1/2
absolute
accordion
accordion-bordered
accordion-toggle
active
active-tab:bg-primary
active-tab:text-base-content
advance-select-menu
advance-select-option
advance-select-tag
advance-select-toggle
alert
alert-error
alert-outline
alert-soft
align-bottom
align-middle
animate-bounce
animate-ping
aria-[current='page']:text-bg-soft-primary
avatar
avatar-away-bottom
avatar-away-top
avatar-busy-bottom
avatar-busy-top
avatar-offline-bottom
avatar-offline-top
avatar-online-bottom
avatar-online-top
avatar-placeholder
badge
badge-error
badge-info
badge-outline
badge-primary
badge-soft
badge-success
bg-background
bg-background/60
bg-base-100
bg-base-150
bg-base-200
bg-base-200/50
bg-base-300
bg-base-300/45
bg-base-300/50
bg-base-300/60
bg-error
bg-info
bg-primary
bg-primary/5
bg-success
bg-transparent
bg-warning
block
blur
border
border-0
border-2
border-b
border-base-content
border-base-content/20
border-base-content/40
border-base-content/5
border-dashed
border-t
border-transparent
bottom-0
bottom-full
break-words
btn
btn-accent
btn-active
btn-circle
btn-disabled
btn-error
btn-info
btn-outline
btn-primary
btn-secondary
btn-sm
btn-soft
btn-square
btn-success
btn-text
btn-warning
card
card-alert
card-body
card-border
card-footer
card-header
card-title
carousel
carousel-body
carousel-next
carousel-prev
carousel-slide
chat
chat-avatar
chat-bubble
chat-footer
chat-header
chat-receiver
chat-sender
checkbox
checkbox-primary
checkbox-xs
col-span-1
collapse
combo-box-selected:block
combo-box-selected:dropdown-active
complete
container
contents
cursor-default
cursor-not-allowed
cursor-pointer
diff
disabled
divide-base-150/60
divide-y
drop-shadow
dropdown
dropdown-disabled
dropdown-item
dropdown-menu
dropdown-open:opacity-100
dropdown-open:rotate-180
dropdown-toggle
duration-300
duration-500
ease-in-out
ease-linear
end-3
file-upload-complete:progress-success
fill-black
filter
filter-reset
fixed
flex
flex-1
flex-col
flex-grow
flex-nowrap
flex-row
flex-shrink-0
flex-wrap
focus-visible:outline-none
focus-within:border-primary
focus:border-primary
focus:outline-1
focus:outline-none
focus:outline-primary
focus:ring-0
font-bold
font-inter
font-medium
font-normal
font-semibold
gap-0.5
gap-1
gap-1.5
gap-2
gap-3
gap-4
gap-5
gap-6
gap-x-1
gap-x-2
gap-x-3
gap-y-1
gap-y-3
grid
grid-cols-1
grid-flow-col
grow
grow-0
h-12
h-2
h-32
h-64
h-8
h-auto
h-full
h-screen
helper-text
hidden
hover:bg-primary/5
hover:bg-transparent
hover:text-base-content
hover:text-base-content/60
hover:text-primary
image-full
inline
inline-block
inline-flex
inline-grid
input
input-floating
input-floating-label
input-lg
input-md
input-sm
input-xl
inset-0
inset-y-0
inset-y-2
invisible
is-invalid
is-valid
isolate
italic
items-center
items-end
items-start
join
join-item
justify-between
justify-center
justify-end
justify-start
justify-stretch
label-text
leading-3
leading-3.5
leading-6
left-0
lg:bg-base-100/20
lg:flex
lg:gap-y-0
lg:grid-cols-2
lg:hidden
lg:justify-end
lg:justify-start
lg:min-w-0
lg:p-10
lg:pb-5
lg:pl-64
lg:pr-3.5
lg:pt-5
lg:ring-1
lg:ring-base-content/10
lg:rounded-lg
lg:shadow-xs
list-disc
list-inside
loading
loading-lg
loading-sm
loading-spinner
loading-xl
loading-xs
lowercase
m-10
mask
max-h-52
max-lg:flex-col
max-lg:hidden
max-w-7xl
max-w-80
max-w-full
max-w-lg
max-w-sm
max-w-xl
mb-0.5
mb-1
mb-2
mb-3
mb-4
mb-5
md:table-cell
md:text-3xl
me-1
me-1.5
me-2
me-5
menu
menu-active
menu-disabled
menu-dropdown
menu-dropdown-show
menu-focus
menu-horizontal
menu-title
min-h-0
min-h-svh
min-w-0
min-w-28
min-w-48
min-w-60
min-w-[100px]
ml-3
ml-4
modal
modal-content
modal-dialog
modal-middle
modal-title
mr-4
ms-1
ms-2
ms-3
mt-1
mt-1.5
mt-10
mt-12
mt-2
mt-2.5
mt-3
mt-4
mt-5
mt-8
mx-1
mx-auto
my-3
my-auto
opacity-0
opacity-100
open
origin-top-left
outline
outline-0
overflow-hidden
overflow-x-auto
overflow-y-auto
overlay-open:duration-50
overlay-open:opacity-100
p-0.5
p-1
p-2
p-3
p-4
p-5
p-6
p-8
pin-input
pin-input-underline
placeholder-base-content/60
pointer-events-auto
pointer-events-none
progress
progress-bar
progress-indeterminate
progress-primary
pt-0
pt-0.5
pt-3
px-1.5
px-2
px-2.5
px-3
px-4
px-5
py-0.5
py-1.5
py-2
py-2.5
py-6
radio
range
relative
resize
ring-0
ring-1
ring-white/10
rounded-box
rounded-field
rounded-full
rounded-lg
rounded-md
rounded-t-lg
row-active
row-hover
rtl:!mr-0
select
select-disabled:opacity-40
select-disabled:pointer-events-none
select-floating
select-floating-label
selected
selected:select-active
shadow-base-300/20
shadow-lg
shadow-xs
shrink-0
size-10
size-4
size-5
size-8
skeleton
skeleton-animated
sm:auto-cols-max
sm:flex
sm:items-center
sm:items-end
sm:justify-between
sm:justify-end
sm:max-w-2xl
sm:max-w-3xl
sm:max-w-4xl
sm:max-w-5xl
sm:max-w-6xl
sm:max-w-7xl
sm:max-w-lg
sm:max-w-md
sm:max-w-xl
sm:mb-0
sm:mt-5
sm:mt-6
sm:p-6
sm:py-2
sm:text-sm/5
space-x-1
space-y-1
space-y-4
sr-only
static
status
status-error
sticky
switch
tab
tab-active
table
table-pin-cols
table-pin-rows
tabs
tabs-bordered
tabs-lg
tabs-lifted
tabs-md
tabs-sm
tabs-xl
tabs-xs
text-2xl
text-4xl
text-accent
text-base
text-base-content
text-base-content/40
text-base-content/50
text-base-content/60
text-base-content/70
text-base-content/80
text-base/6
text-center
text-error
text-error-content
text-gray-400
text-info
text-info-content
text-left
text-lg
text-primary
text-primary-content
text-sm
text-sm/5
text-success
text-success-content
text-warning
text-warning-content
text-xl
text-xs
text-xs/5
textarea
textarea-floating
textarea-floating-label
theme-controller
tooltip
tooltip-content
top-0
top-1/2
top-full
transform
transition
transition-all
transition-opacity
translate-x-0
truncate
underline
uppercase
validate
w-0
w-0.5
w-12
w-4
w-56
w-64
w-fit
w-full
whitespace-nowrap
z-10
z-40
z-50

View File

@@ -1,790 +0,0 @@
!bg-base-100
!border-base-content/40
!border-none
!flex
!font-medium
!font-semibold
!h-2.5
!justify-between
!me-1.5
!ms-auto
!px-2.5
!py-0.5
!rounded-full
!rounded-xs
!text-sm
!w-2.5
*:[grid-area:1/1]
*:first:rounded-tl-lg
*:last:rounded-tr-lg
-left-4
-mb-3
-ml-4
-translate-x-full
-translate-y-1/2
2xl:col-span-1
2xl:col-span-2
2xl:col-span-3
2xl:flex
[animation-duration:0.8s]
[animation-timing-function:ease]
absolute
accordion
accordion-bordered
accordion-toggle
active
active-tab:bg-primary
active-tab:hover:text-primary-content
active-tab:text-base-content
active-tab:text-primary-content
advance-select-menu
advance-select-option
advance-select-tag
advance-select-toggle
alert
alert-error
alert-outline
alert-primary
alert-soft
align-bottom
align-middle
animate-bounce
animate-ping
animate-spin
aria-[current='page']:text-bg-soft-primary
avatar
avatar-away-bottom
avatar-away-top
avatar-busy-bottom
avatar-busy-top
avatar-offline-bottom
avatar-offline-top
avatar-online-bottom
avatar-online-top
avatar-placeholder
badge
badge-error
badge-info
badge-outline
badge-primary
badge-soft
badge-success
bg-background
bg-background/60
bg-base-100
bg-base-150
bg-base-200
bg-base-200!
bg-base-200/50
bg-base-200/75
bg-base-300
bg-base-300/45
bg-base-300/50
bg-base-300/60
bg-base-content/10
bg-black
bg-clip-text
bg-error
bg-gradient-to-r
bg-gray-800
bg-gray-900
bg-indigo-600
bg-info
bg-primary
bg-primary/5
bg-red-500
bg-success
bg-transparent
bg-warning
bg-white/5
block
blur
border
border-0
border-1
border-2
border-3
border-accent
border-b
border-b-2
border-b-base-content/20
border-b-primary
border-base-content
border-base-content/10
border-base-content/20
border-base-content/25
border-base-content/40
border-base-content/5
border-base-content/60
border-base-content/70
border-base-content/80
border-dashed
border-dotted
border-e-2
border-error
border-error/30
border-gray-600
border-info/30
border-l-4
border-l-8
border-l-transparent
border-primary
border-r-transparent
border-solid
border-success
border-success/30
border-t
border-t-2
border-t-transparent
border-transparent
border-warning
border-warning/30
bottom-0
bottom-full
breadcrumbs
breadcrumbs-separator
break-words
btn
btn-accent
btn-active
btn-block
btn-circle
btn-disabled
btn-error
btn-gradient
btn-info
btn-lg
btn-outline
btn-primary
btn-secondary
btn-sm
btn-soft
btn-square
btn-success
btn-text
btn-warning
card
card-alert
card-body
card-border
card-footer
card-header
card-sm
card-title
carousel
carousel-body
carousel-next
carousel-prev
carousel-slide
chat
chat-avatar
chat-bubble
chat-footer
chat-header
chat-receiver
chat-sender
checkbox
checkbox-primary
checkbox-xs
col-span-1
col-span-12
col-span-2
col-span-6
collapse
combo-box-selected:block
combo-box-selected:dropdown-active
complete
container
contents
cursor-default
cursor-not-allowed
cursor-pointer
custom-option
diff
disabled
divide-base-150/60
divide-y
divider
drop-shadow
dropdown
dropdown-active
dropdown-disabled
dropdown-item
dropdown-menu
dropdown-open:opacity-100
dropdown-open:rotate-180
dropdown-toggle
duration-300
duration-500
ease-in-out
ease-linear
end-3
error-message
file-upload-complete:progress-success
fill-base-content
fill-black
fill-gray-200
filter
filter-reset
fixed
flex
flex-1
flex-col
flex-grow
flex-nowrap
flex-row
flex-shrink-0
flex-wrap
focus-visible:outline
focus-visible:outline-2
focus-visible:outline-indigo-600
focus-visible:outline-none
focus-visible:outline-offset-2
focus-within:border-primary
focus:border-primary
focus:outline-1
focus:outline-none
focus:outline-primary
focus:ring-0
focus:ring-2
focus:ring-indigo-600
focus:ring-inset
font-bold
font-inter
font-medium
font-normal
font-semibold
footer
footer-center
from-base-100
from-base-100/20
from-error/20
from-gray-600/20
from-primary/20
from-success/20
from-violet-400
from-warning/20
gap-0.5
gap-1
gap-1.5
gap-2
gap-3
gap-4
gap-5
gap-6
gap-x-1
gap-x-1.5
gap-x-2
gap-x-3
gap-x-5
gap-x-6
gap-y-1
gap-y-1.5
gap-y-2
gap-y-2.5
gap-y-3
gap-y-4
gap-y-5
gap-y-8
grid
grid-cols-1
grid-cols-12
grid-cols-2
grid-cols-3
grid-cols-4
grid-cols-6
grid-flow-col
grow
grow-0
h-0
h-10
h-12
h-14
h-2
h-3
h-32
h-44
h-6
h-64
h-8
h-[90vh]
h-auto
h-full
h-screen
helper-text
hidden
hover:bg-indigo-500
hover:bg-primary/20
hover:bg-primary/5
hover:bg-transparent
hover:cursor-pointer
hover:text-base-content
hover:text-base-content/60
hover:text-indigo-500
hover:text-primary
image-full
indicator
indicator-item
inline
inline-block
inline-flex
inline-grid
input
input-floating
input-floating-label
input-lg
input-md
input-sm
input-xl
input-xs
inset-0
inset-y-0
inset-y-2
invisible
is-invalid
is-valid
isolate
italic
items-center
items-end
items-start
join
join-item
justify-between
justify-center
justify-end
justify-start
justify-stretch
label-text
leading-3
leading-3.5
leading-6
leading-7
leading-9
leading-[1.1]
leading-none
left-0
lg:bg-base-100/20
lg:flex
lg:gap-y-0
lg:grid-cols-2
lg:grid-cols-3
lg:hidden
lg:justify-end
lg:justify-start
lg:mb-0
lg:min-w-0
lg:p-10
lg:p-8
lg:pb-5
lg:pl-64
lg:pr-3.5
lg:pt-5
lg:px-8
lg:ring-1
lg:ring-base-content/10
lg:rounded-lg
lg:shadow-xs
link
link-animated
link-hover
link-primary
list-disc
list-inside
list-none
loading
loading-lg
loading-sm
loading-spinner
loading-xl
loading-xs
lowercase
m-10
mask
max-h-52
max-lg:flex-col
max-lg:hidden
max-md:flex-wrap
max-md:justify-center
max-sm:hidden
max-w-2xl
max-w-7xl
max-w-8
max-w-80
max-w-full
max-w-lg
max-w-md
max-w-none
max-w-sm
max-w-xl
mb-0.5
mb-1
mb-1.5
mb-2
mb-2.5
mb-3
mb-4
mb-5
mb-8
md:col-span-1
md:col-span-2
md:col-span-6
md:flex
md:gap-x-5
md:grid-cols-2
md:grid-cols-3
md:min-w-md
md:table-cell
md:text-3xl
me-0.5
me-1
me-1.5
me-2
me-2.5
me-3
me-4
me-5
menu
menu-active
menu-disabled
menu-dropdown
menu-dropdown-show
menu-focus
menu-horizontal
menu-title
min-h-0
min-h-full
min-h-screen
min-h-svh
min-w-0
min-w-28
min-w-48
min-w-60
min-w-[100px]
min-w-full
min-w-sm
mix-blend-exclusion
ml-3
ml-4
modal
modal-content
modal-dialog
modal-middle
modal-title
mr-2
mr-3
mr-4
ms-0.5
ms-1
ms-1.5
ms-2
ms-2.5
ms-3
ms-5
ms-auto
mt-1
mt-1.5
mt-10
mt-12
mt-2
mt-2.5
mt-3
mt-3.5
mt-4
mt-5
mt-6
mt-8
mt-auto
mx-1
mx-auto
my-2.5
my-3
my-5
my-8
my-auto
object-cover
opacity-0
opacity-100
opacity-75
open
origin-top-left
outline
outline-0
overflow-hidden
overflow-x-auto
overflow-x-hidden
overflow-y-auto
overlay-open:duration-50
overlay-open:opacity-100
p-0.5
p-1
p-1.5
p-2
p-2.5
p-3
p-4
p-5
p-6
p-8
pb-1
pe-1.5
pin-input
pin-input-underline
placeholder-base-content/50
placeholder-base-content/60
placeholder:text-gray-600
pointer-events-auto
pointer-events-none
progress
progress-bar
progress-indeterminate
progress-primary
pt-0
pt-0.5
pt-1.5
pt-2
pt-3
pt-6
px-1.5
px-2
px-2.5
px-3
px-4
px-5
px-6
py-0.5
py-1
py-1.5
py-10
py-12
py-2
py-2.5
py-3
py-3.5
py-6
radial-progress
radio
range
relative
resize
right-4
ring
ring-0
ring-1
ring-gray-700
ring-inset
ring-white/10
rounded-box
rounded-field
rounded-full
rounded-l-none
rounded-lg
rounded-md
rounded-none
rounded-r-none
rounded-t-lg
rounded-xl
row-active
row-hover
rtl:!mr-0
select
select-disabled:opacity-40
select-disabled:pointer-events-none
select-floating
select-floating-label
select-lg
select-md
select-sm
select-xl
select-xs
selected
selected:select-active
shadow
shadow-base-300/20
shadow-lg
shadow-md
shadow-sm
shadow-xs
shrink-0
size-10
size-12
size-4
size-5
size-7
size-8
skeleton
skeleton-animated
sm:auto-cols-max
sm:col-span-2
sm:col-span-3
sm:col-span-4
sm:col-span-6
sm:flex
sm:flex-nowrap
sm:gap-y-0
sm:grid-cols-2
sm:grid-cols-3
sm:grid-cols-6
sm:items-center
sm:items-end
sm:justify-between
sm:justify-end
sm:leading-6
sm:max-w-2xl
sm:max-w-3xl
sm:max-w-4xl
sm:max-w-5xl
sm:max-w-6xl
sm:max-w-7xl
sm:max-w-[480px]
sm:max-w-lg
sm:max-w-md
sm:max-w-xl
sm:mb-0
sm:min-w-md
sm:mr-3
sm:mt-5
sm:mt-6
sm:mx-auto
sm:p-6
sm:px-12
sm:px-6
sm:py-2
sm:rounded-lg
sm:text-sm
sm:text-sm/5
sm:w-1/2
sm:w-full
space-x-1
space-x-2
space-x-2.5
space-y-1
space-y-4
space-y-6
sr-only
stack
stat
stat-actions
stat-desc
stat-figure
stat-title
stat-value
static
stats
stats-border
status
status-error
status-primary
status-secondary
status-success
status-warning
status-xl
sticky
success-message
switch
switch-primary
tab
tab-active
tab-content
table
table-pin-cols
table-pin-rows
tabs
tabs-bordered
tabs-lg
tabs-lifted
tabs-md
tabs-sm
tabs-vertical
tabs-xl
tabs-xs
text-2xl
text-3xl
text-4xl
text-accent
text-base
text-base-content
text-base-content/40
text-base-content/50
text-base-content/60
text-base-content/70
text-base-content/80
text-base-content/90
text-base/6
text-center
text-error
text-error-content
text-gray-100
text-gray-400
text-gray-500
text-gray-700
text-indigo-600
text-info
text-info-content
text-left
text-lg
text-primary
text-primary-content
text-right
text-slate-100
text-sm
text-sm/5
text-success
text-success-content
text-transparent
text-warning
text-warning-content
text-white
text-xl
text-xl!
text-xs
text-xs/5
textarea
textarea-floating
textarea-floating-label
textarea-lg
textarea-md
textarea-sm
textarea-xl
textarea-xs
theme-controller
to-25%
to-base-100/75
to-purple-400
tooltip
tooltip-content
top-0
top-1/2
top-4
top-full
tracking-tight
tracking-wide
transform
transition
transition-all
transition-opacity
translate-x-0
truncate
underline
uppercase
validate
via-sky-400
w-0
w-0.5
w-12
w-13
w-32
w-4
w-56
w-64
w-8
w-auto
w-fit
w-full
whitespace-nowrap
xl:grid-cols-3
xl:grid-cols-4
z-1
z-10
z-40
z-50

View File

@@ -0,0 +1,74 @@
@using Moonlight.Frontend.Helpers
@using MoonlightServers.Shared
@using MoonlightServers.Shared.Http.Requests
@using MoonlightServers.Shared.Http.Responses
@using ShadcnBlazor.Buttons
@using ShadcnBlazor.Dialogs
@using ShadcnBlazor.Extras.AlertDialogs
@using ShadcnBlazor.Extras.Forms
@using ShadcnBlazor.Fields
@using ShadcnBlazor.Inputs
@inherits ShadcnBlazor.Extras.Dialogs.DialogBase
@inject HttpClient HttpClient
@inject AlertDialogService AlertDialogService
<DialogHeader>
<DialogTitle>Example Form</DialogTitle>
<DialogDescription>This forms removes all spaces from the input</DialogDescription>
</DialogHeader>
<EnhancedEditForm @ref="Form" OnValidSubmit="OnSubmit" Model="Dto">
<DataAnnotationsValidator/>
<FieldSet>
<FormValidationSummary/>
<FieldGroup>
<Field>
<FieldLabel for="formInput">Form Input</FieldLabel>
<TextInputField id="formInput" @bind-Value="Dto.TextField"/>
<FieldDescription>Input you want to remove the spaces from</FieldDescription>
</Field>
</FieldGroup>
</FieldSet>
</EnhancedEditForm>
<DialogFooter>
<Button @onclick="() => Form.SubmitAsync()">Submit</Button>
<DialogClose/>
</DialogFooter>
@code
{
private FormSubmitDto Dto = new();
private EnhancedEditForm Form;
private async Task<bool> OnSubmit(EditContext editContext, ValidationMessageStore validationMessageStore)
{
var response = await HttpClient.PostAsJsonAsync(
"api/form",
Dto,
SerializationContext.Default.Options
);
if (response.IsSuccessStatusCode)
{
var data = await response.Content.ReadFromJsonAsync<FormResultDto>(
SerializationContext.Default.Options
);
if (data == null)
return true;
await AlertDialogService.InfoAsync("Result", data.Result);
await CloseAsync();
return true;
}
await ProblemDetailsHelper.HandleProblemDetailsAsync(response, Dto, validationMessageStore);
return false;
}
}

View File

@@ -1,29 +0,0 @@
@using System.Diagnostics.CodeAnalysis
@* TODO: Extract to mooncore? *@
@inherits InputBase<bool>
<div class="flex items-center gap-1">
<input @bind="CurrentValue" type="checkbox" class="switch switch-primary" id="switch-@GetHashCode()" />
<label class="label-text text-base" for="switch-@GetHashCode()">
@if (CurrentValue)
{
<span>On</span>
}
else
{
<span>Off</span>
}
</label>
</div>
@code
{
protected override bool TryParseValueFromString(string? value, out bool result, [NotNullWhen(false)] out string? validationErrorMessage)
{
validationErrorMessage = null;
result = string.Equals(value, "true", StringComparison.OrdinalIgnoreCase);
return true;
}
}

View File

@@ -1,88 +0,0 @@
@using Microsoft.Extensions.Logging
@using XtermBlazor
@inherits MoonCore.Blazor.FlyonUi.Modals.BaseModal
@inject IJSRuntime JsRuntime
@inject ILogger<FullScreenModal> Logger
@implements IAsyncDisposable
<div class="bg-black p-2 relative w-full h-[90vh] rounded-lg">
@if (IsInitialized)
{
<Xterm @ref="Terminal"
Addons="Parent.Addons"
Options="Parent.Options"
Class="h-full w-full"
OnFirstRender="HandleFirstRenderAsync"/>
}
<div class="absolute top-4 right-4">
<button @onclick="HideAsync" class="btn btn-error btn-square">
<i class="icon-x text-lg"></i>
</button>
</div>
</div>
@code
{
[Parameter] public XtermConsole Parent { get; set; }
private bool IsInitialized = false;
private bool IsReadyToWrite = false;
private Xterm Terminal;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender)
return;
// Initialize addons
try
{
await JsRuntime.InvokeVoidAsync("moonlightServers.loadAddons");
}
catch (Exception e)
{
Logger.LogError("An error occured while initializing addons: {e}", e);
}
// Subscribe to parent events
Parent.OnWrite += HandleWriteAsync;
IsInitialized = true;
await InvokeAsync(StateHasChanged);
}
private async Task HandleFirstRenderAsync()
{
IsReadyToWrite = true;
try
{
await Terminal.Addon("addon-fit").InvokeVoidAsync("fit");
}
catch (Exception e)
{
Logger.LogError("An error occured while calling addons: {e}", e);
}
var outputToWrite = string.Concat(Parent.OutputCache.ToArray());
await Terminal.Write(outputToWrite);
}
private async Task HandleWriteAsync(string content)
{
if (!IsReadyToWrite)
return;
await Terminal.Write(content);
}
public async ValueTask DisposeAsync()
{
Parent.OnWrite -= HandleWriteAsync;
await Terminal.DisposeAsync();
}
}

View File

@@ -1,62 +0,0 @@
@using MoonCore.Blazor.FlyonUi.Components
@using MoonlightServers.Shared.Http.Requests.Admin.NodeAllocations
@inherits MoonCore.Blazor.FlyonUi.Modals.BaseModal
<div class="p-5">
<div class="flex items-center gap-4">
<div class="avatar avatar-placeholder max-sm:hidden">
<div class="border-base-content/20 rounded-box w-13 border-1">
<span class="icon-ethernet-port text-xl"></span>
</div>
</div>
<div class="space-y-1">
<h3 class="text-base-content text-2xl font-semibold">Add a new allocation</h3>
<p class="text-base-content/80">Add a new allocation to the selected node</p>
</div>
</div>
<div class="mt-5">
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
<div class="mt-2">
<label class="label-text">IP Address</label>
<input class="input" @bind="Form.IpAddress" type="text"/>
</div>
<div class="mt-2">
<label class="label-text">Port</label>
<input class="input" @bind="Form.Port" type="number"/>
</div>
</HandleForm>
</div>
<div class="mt-5 flex justify-end">
<button @onclick="HideAsync" type="button" class="btn btn-secondary me-2">
Cancel
</button>
<WButton OnClick="SubmitAsync">
Create
</WButton>
</div>
</div>
@code
{
[Parameter] public Func<CreateNodeAllocationRequest, Task> OnSubmit { get; set; }
private CreateNodeAllocationRequest Form;
private HandleForm HandleForm;
protected override void OnInitialized()
{
Form = new()
{
IpAddress = "0.0.0.0"
};
}
private async Task OnValidSubmit()
{
await OnSubmit.Invoke(Form);
await HideAsync();
}
private Task SubmitAsync() => HandleForm.SubmitAsync();
}

View File

@@ -1,68 +0,0 @@
@using MoonCore.Blazor.FlyonUi.Components
@using MoonlightServers.Shared.Http.Requests.Admin.NodeAllocations
@inherits MoonCore.Blazor.FlyonUi.Modals.BaseModal
<div class="p-5">
<div class="flex items-center gap-4">
<div class="avatar avatar-placeholder max-sm:hidden">
<div class="border-base-content/20 rounded-box w-13 border-1">
<span class="icon-ethernet-port text-xl"></span>
</div>
</div>
<div class="space-y-1">
<h3 class="text-base-content text-2xl font-semibold">Add multiple allocations</h3>
<p class="text-base-content/80">Add a range of new allocations to the selected node</p>
</div>
</div>
<div class="mt-5">
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
<div class="mt-2">
<label class="label-text">IP Address</label>
<input class="input" @bind="Form.IpAddress" type="text"/>
</div>
<div class="mt-2">
<label class="label-text">Start Port</label>
<input class="input" @bind="Form.Start" type="number"/>
</div>
<div class="mt-2">
<label class="label-text">End Port</label>
<input class="input" @bind="Form.End" type="number"/>
</div>
</HandleForm>
</div>
<div class="mt-5 flex justify-end">
<button @onclick="HideAsync" type="button" class="btn btn-secondary me-2">
Cancel
</button>
<WButton OnClick="SubmitAsync">
Create
</WButton>
</div>
</div>
@code
{
[Parameter] public Func<CreateNodeAllocationRangeRequest, Task> OnSubmit { get; set; }
private CreateNodeAllocationRangeRequest Form;
private HandleForm HandleForm;
protected override void OnInitialized()
{
Form = new()
{
IpAddress = "0.0.0.0",
Start = 2000,
End = 3000
};
}
private async Task OnValidSubmit()
{
await OnSubmit.Invoke(Form);
await HideAsync();
}
private Task SubmitAsync() => HandleForm.SubmitAsync();
}

View File

@@ -1,65 +0,0 @@
@using MoonCore.Blazor.FlyonUi.Components
@using MoonlightServers.Shared.Http.Requests.Admin.NodeAllocations
@using MoonlightServers.Shared.Http.Responses.Admin.NodeAllocations
@inherits MoonCore.Blazor.FlyonUi.Modals.BaseModal
<div class="p-5">
<div class="flex items-center gap-4">
<div class="avatar avatar-placeholder max-sm:hidden">
<div class="border-base-content/20 rounded-box w-13 border-1">
<span class="icon-ethernet-port text-xl"></span>
</div>
</div>
<div class="space-y-1">
<h3 class="text-base-content text-2xl font-semibold">Update allocation</h3>
<p class="text-base-content/80">Update an existing allocation</p>
</div>
</div>
<div class="mt-5">
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
<div class="mt-2">
<label class="label-text">IP Address</label>
<input class="input" @bind="Form.IpAddress" type="text"/>
</div>
<div class="mt-2">
<label class="label-text">Port</label>
<input class="input" @bind="Form.Port" type="number"/>
</div>
</HandleForm>
</div>
<div class="mt-5 flex justify-end">
<button @onclick="HideAsync" type="button" class="btn btn-secondary me-2">
Cancel
</button>
<WButton OnClick="SubmitAsync">
Update
</WButton>
</div>
</div>
@code
{
[Parameter] public Func<UpdateNodeAllocationRequest, Task> OnSubmit { get; set; }
[Parameter] public NodeAllocationResponse Allocation { get; set; }
private UpdateNodeAllocationRequest Form;
private HandleForm HandleForm;
protected override void OnInitialized()
{
Form = new UpdateNodeAllocationRequest()
{
IpAddress = Allocation.IpAddress,
Port = Allocation.Port
};
}
private async Task OnValidSubmit()
{
await OnSubmit.Invoke(Form);
await HideAsync();
}
private Task SubmitAsync() => HandleForm.SubmitAsync();
}

View File

@@ -1,10 +0,0 @@
@using MoonlightServers.Shared.Http.Requests.Admin.Nodes
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
</div>
@code
{
[Parameter] public UpdateNodeRequest Request { get; set; }
}

View File

@@ -1,150 +0,0 @@
@using MoonCore.Blazor.FlyonUi.Alerts
@using MoonCore.Blazor.FlyonUi.Common
@using MoonCore.Blazor.FlyonUi.Grid
@using MoonCore.Blazor.FlyonUi.Grid.Columns
@using MoonCore.Blazor.FlyonUi.Modals
@using MoonCore.Blazor.FlyonUi.Toasts
@using MoonCore.Common
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes
@using MoonCore.Helpers
@using MoonlightServers.Frontend.UI.Components.Nodes.Modals
@using MoonlightServers.Shared.Http.Requests.Admin.NodeAllocations
@using MoonlightServers.Shared.Http.Responses.Admin.NodeAllocations
@inject HttpApiClient ApiClient
@inject ModalService ModalService
@inject ToastService ToastService
@inject AlertService AlertService
<div class="grid grid-cols-1 md:grid-cols-3 md:gap-x-5">
<div class="col-span-1">
<div class="card">
<div class="card-header">
<span class="card-title">Actions</span>
</div>
<div class="card-body">
<div class="flex flex-col gap-y-3">
<button type="button" @onclick="AddAllocationAsync" class="btn btn-primary">Create</button>
<button type="button" @onclick="AddAllocationRangeAsync" class="btn btn-accent">Create multiple
</button>
<button type="button" @onclick="DeleteAllAllocationsAsync" class="btn btn-error">Delete all</button>
</div>
</div>
</div>
</div>
<div class="col-span-1 md:col-span-2 -mb-3">
<DataGrid @ref="Grid"
TGridItem="NodeAllocationResponse"
ItemSource="ItemSource">
<PropertyColumn Field="x => x.IpAddress" Title="IP Address"/>
<PropertyColumn Field="x => x.Port"/>
<TemplateColumn>
<td>
<div class="flex justify-end items-center">
<a @onclick="() => UpdateAllocationAsync(context)"
@onclick:preventDefault href="#"
class="text-primary mr-2 sm:mr-3">
<i class="icon-pencil text-base"></i>
</a>
<a @onclick="() => DeleteAllocationAsync(context)"
@onclick:preventDefault href="#"
class="text-error">
<i class="icon-trash text-base"></i>
</a>
</div>
</td>
</TemplateColumn>
</DataGrid>
</div>
</div>
@code
{
[Parameter] public NodeResponse Node { get; set; }
private DataGrid<NodeAllocationResponse> Grid;
private ItemSource<NodeAllocationResponse> ItemSource => ItemSourceFactory.From(LoadAsync);
private async Task<IEnumerable<NodeAllocationResponse>> LoadAsync(int startIndex, int count)
{
var query = $"?startIndex={startIndex}&count={count}";
return await ApiClient.GetJson<CountedData<NodeAllocationResponse>>(
$"api/admin/servers/nodes/{Node.Id}/allocations{query}"
);
}
private async Task AddAllocationRangeAsync()
{
Func<CreateNodeAllocationRangeRequest, Task> onSubmit = async request =>
{
await ApiClient.Post($"api/admin/servers/nodes/{Node.Id}/allocations/range", request);
await ToastService.SuccessAsync("Successfully created allocations");
await Grid.RefreshAsync();
};
await ModalService.LaunchAsync<CreateMultipleAllocationModal>(parameters => { parameters.Add("OnSubmit", onSubmit); });
}
private async Task AddAllocationAsync()
{
Func<CreateNodeAllocationRequest, Task> onSubmit = async request =>
{
await ApiClient.Post($"api/admin/servers/nodes/{Node.Id}/allocations", request);
await ToastService.SuccessAsync("Successfully created allocation");
await Grid.RefreshAsync();
};
await ModalService.LaunchAsync<CreateAllocationModal>(parameters => { parameters.Add("OnSubmit", onSubmit); });
}
private async Task UpdateAllocationAsync(NodeAllocationResponse allocation)
{
Func<UpdateNodeAllocationRequest, Task> onSubmit = async request =>
{
await ApiClient.Patch($"api/admin/servers/nodes/{Node.Id}/allocations/{allocation.Id}", request);
await ToastService.SuccessAsync("Successfully updated allocation");
await Grid.RefreshAsync();
};
await ModalService.LaunchAsync<UpdateAllocationModal>(parameters =>
{
parameters.Add("OnSubmit", onSubmit);
parameters.Add("Allocation", allocation);
});
}
private async Task DeleteAllocationAsync(NodeAllocationResponse allocation)
{
await AlertService.ConfirmDangerAsync(
"Delete allocation",
"Do you really want to delete the selected allocation? This cannot be undone",
async () =>
{
await ApiClient.Delete($"api/admin/servers/nodes/{Node.Id}/allocations/{allocation.Id}");
await ToastService.SuccessAsync("Successfully deleted allocation");
await Grid.RefreshAsync();
}
);
}
private async Task DeleteAllAllocationsAsync()
{
await AlertService.ConfirmDangerAsync(
"Delete all allocations",
"Do you really want to delete all allocations? This cannot be undone",
async () =>
{
await ApiClient.Delete($"api/admin/servers/nodes/{Node.Id}/allocations/all");
await ToastService.SuccessAsync("Successfully deleted allocations");
await Grid.RefreshAsync();
}
);
}
}

View File

@@ -1,32 +0,0 @@
@using MoonlightServers.Shared.Http.Requests.Admin.Nodes
<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-base-content">Name</label>
<div class="mt-2">
<input @bind="Request.Name" type="text" autocomplete="off" class="input w-full">
</div>
</div>
<div class="sm:col-span-2">
<label class="block text-sm font-medium leading-6 text-base-content">Fqdn</label>
<div class="mt-2">
<input @bind="Request.Fqdn" type="text" autocomplete="off" class="input w-full">
</div>
</div>
<div class="sm:col-span-2">
<label class="block text-sm font-medium leading-6 text-base-content">Http Port</label>
<div class="mt-2">
<input @bind="Request.HttpPort" type="number" autocomplete="off" class="input w-full">
</div>
</div>
<div class="sm:col-span-2"><label class="block text-sm font-medium leading-6 text-base-content">Ftp Port</label>
<div class="mt-2">
<input @bind="Request.FtpPort" type="number" autocomplete="off" class="input w-full">
</div>
</div>
</div>
@code
{
[Parameter] public UpdateNodeRequest Request { get; set; }
}

View File

@@ -1,217 +0,0 @@
@using Microsoft.Extensions.Logging
@using MoonCore.Blazor.FlyonUi.Components
@using MoonCore.Blazor.FlyonUi.Toasts
@using MoonCore.Helpers
@using MoonlightServers.Frontend.Services
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes.Statistics
@inject NodeService NodeService
@inject ToastService ToastService
@inject ILogger<Overview> Logger
@implements IDisposable
<LazyLoader Load="LoadAsync">
<div class="mb-3 mt-5 text-xl font-semibold">
Overview
</div>
<div class="grid grid-cols-1 lg:grid-cols-3 gap-5">
<div class="col-span-1 card card-body">
<div class="flex justify-between">
<p class="text-xl font-semibold text-base-content">
@(Math.Round(Statistics.Cpu.Usage, 2))%
</p>
<i class="icon-cpu text-4xl text-primary"></i>
</div>
<div class="text-base text-base-content/90">
<span class="truncate">
CPU: @Statistics.Cpu.Model
</span>
</div>
</div>
<div class="col-span-1 card card-body">
<div class="flex justify-between">
<p class="text-xl font-semibold text-base-content">
@(Formatter.FormatSize(Statistics.Memory.Total - Statistics.Memory.Available))
/
@(Formatter.FormatSize(Statistics.Memory.Total))
</p>
<i class="icon-memory-stick text-4xl text-primary"></i>
</div>
<div class="text-base text-base-content/90">
Memory
</div>
</div>
<div class="col-span-1 card card-body">
<div class="flex justify-between">
<div class="text-xl font-semibold text-base-content">
@(Formatter.FormatSize(Statistics.Memory.SwapTotal - Statistics.Memory.SwapFree))
/
@(Formatter.FormatSize(Statistics.Memory.SwapTotal))
</div>
<i class="icon-shapes text-4xl text-primary"></i>
</div>
<div class="text-base text-base-content/90">
Swap
</div>
</div>
</div>
<div class="mb-3 mt-5 text-xl font-semibold">
CPU
</div>
<div class="card card-body grid grid-cols-1 lg:grid-cols-2 gap-y-2 gap-x-5">
@{
var i = 0;
}
@foreach (var usage in Statistics.Cpu.UsagePerCore)
{
var percentRounded = Math.Round(usage, 2);
<div class="flex flex-row items-center col-span-1">
<div class="text-sm text-base-content/90 me-1.5 grow-0 flex flex-col">
<span>#@(i)</span>
</div>
<div class="grow">
<div class="progress h-2" role="progressbar">
<div class="progress-bar transition-all duration-300 ease-in-out @(GetBackgroundColorByPercent(percentRounded))" style="width: @(usage)%"></div>
</div>
</div>
</div>
i++;
}
</div>
<div class="mb-3 mt-5 text-xl font-semibold">
Disks
</div>
<div class="grid grid-cols-1 lg:grid-cols-3 gap-5">
@foreach (var disk in Statistics.Disks)
{
var usedPercent = Math.Round((disk.DiskTotal - disk.DiskFree) / (double)disk.DiskTotal * 100, 2);
var iNodesPercent = Math.Round((disk.InodesTotal - disk.InodesFree) / (double)disk.InodesTotal * 100, 2);
<div class="col-span-1 card card-body">
<div class="flex items-center">
<div class="grow">
<div class="progress h-2" role="progressbar">
<div class="progress-bar transition-all duration-300 ease-in-out @(GetBackgroundColorByPercent(usedPercent))" style="width: @(usedPercent)%"></div>
</div>
</div>
</div>
<div class="text-sm text-base-content/90 mt-2.5 flex flex-col">
<div>
Device: <span class="font-semibold">@disk.Device</span> - Mounted at: <span class="font-semibold truncate">@disk.MountPath</span>
</div>
<div>
Used: <span class="font-semibold">@Formatter.FormatSize(disk.DiskTotal - disk.DiskFree)</span>
Total: <span class="font-semibold">@Formatter.FormatSize(disk.DiskTotal)</span>
</div>
<div>
INodes: <span class="font-semibold">@(iNodesPercent)%</span>
</div>
</div>
</div>
}
</div>
<div class="mb-3 mt-5 text-xl font-semibold">
Docker
</div>
<div class="grid grid-cols-1 lg:grid-cols-3 gap-5">
<div class="col-span-1 card card-body">
<div class="flex justify-between">
<p class="text-xl font-semibold text-base-content">
@Formatter.FormatSize(DockerStatistics.ImagesUsed) (@Formatter.FormatSize(DockerStatistics.ImagesReclaimable) unused)
</p>
<i class="icon-gallery-horizontal-end text-4xl text-primary"></i>
</div>
<div class="text-base text-base-content/90">
Images
</div>
</div>
<div class="col-span-1 card card-body">
<div class="flex justify-between">
<p class="text-xl font-semibold text-base-content">
@Formatter.FormatSize(DockerStatistics.ContainersUsed) ( @Formatter.FormatSize(DockerStatistics.ContainersReclaimable) unused)
</p>
<i class="icon-container text-4xl text-primary"></i>
</div>
<div class="text-base text-base-content/90">
Containers
</div>
</div>
<div class="col-span-1 card card-body">
<div class="flex justify-between">
<p class="text-xl font-semibold text-base-content">
@Formatter.FormatSize(DockerStatistics.BuildCacheUsed) (@Formatter.FormatSize(DockerStatistics.BuildCacheReclaimable) unused)
</p>
<i class="icon-hard-hat text-4xl text-primary"></i>
</div>
<div class="text-base text-base-content/90">
Build Cache
</div>
</div>
</div>
</LazyLoader>
@code
{
[Parameter] public NodeResponse Node { get; set; }
private StatisticsResponse Statistics;
private DockerStatisticsResponse DockerStatistics;
private Timer? UpdateTimer;
private async Task LoadAsync(LazyLoader _)
{
Statistics = await NodeService.GetStatisticsAsync(Node.Id);
DockerStatistics = await NodeService.GetDockerStatisticsAsync(Node.Id);
UpdateTimer = new Timer(HandleUpdateAsync, null, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(3));
}
private async void HandleUpdateAsync(object? _)
{
try
{
Statistics = await NodeService.GetStatisticsAsync(Node.Id);
DockerStatistics = await NodeService.GetDockerStatisticsAsync(Node.Id);
await InvokeAsync(StateHasChanged);
}
catch (Exception e)
{
Logger.LogWarning("An error occured while fetching status update: {e}", e);
await ToastService.ErrorAsync("Unable to fetch status update", e.Message);
}
}
private string GetBackgroundColorByPercent(double percent)
{
if (percent < 70)
return "bg-success";
else if (percent < 80)
return "bg-warning";
else
return "bg-error";
}
public void Dispose()
{
UpdateTimer?.Dispose();
}
}

View File

@@ -1,10 +0,0 @@
@using MoonlightServers.Shared.Http.Requests.Admin.Servers
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
</div>
@code
{
[Parameter] public CreateServerRequest Request { get; set; }
}

View File

@@ -1,42 +0,0 @@
@using MoonCore.Blazor.FlyonUi.Common
@using MoonlightServers.Shared.Http.Requests.Admin.Servers
@using MoonCore.Helpers
@using MoonlightServers.Shared.Http.Responses.Admin.NodeAllocations
@using MoonCore.Blazor.FlyonUi.Forms
@using MoonCore.Common
@using MoonlightServers.Frontend.UI.Views.Admin.All
@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-base-content">Allocations</label>
<div class="mt-2">
<InputMultipleItem TItem="NodeAllocationResponse"
DisplayField="@(x => $"{x.IpAddress}:{x.Port}")"
Value="Parent.Allocations"
ItemSource="ItemSource">
</InputMultipleItem>
</div>
</div>
</div>
@code
{
[Parameter] public CreateServerRequest Request { get; set; }
[Parameter] public Create Parent { get; set; }
private ItemSource<NodeAllocationResponse> ItemSource => ItemSourceFactory.From(LoadAsync);
private async Task<IEnumerable<NodeAllocationResponse>> LoadAsync(int startIndex, int count)
{
// Handle unselected node
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
if (Parent.Node == null)
return [];
return await ApiClient.GetJson<CountedData<NodeAllocationResponse>>(
$"api/admin/servers/nodes/{Parent.Node.Id}/allocations/free?startIndex={startIndex}&count={count}"
);
}
}

View File

@@ -1,116 +0,0 @@
@using MoonCore.Blazor.FlyonUi.Common
@using MoonlightServers.Shared.Http.Requests.Admin.Servers
@using MoonCore.Helpers
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes
@using MoonlightServers.Shared.Http.Responses.Admin.Stars
@using Moonlight.Shared.Http.Responses.Admin.Users
@using MoonCore.Blazor.FlyonUi.Forms
@using MoonCore.Common
@using MoonlightServers.Frontend.UI.Views.Admin.All
@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-base-content">Name</label>
<div class="mt-2">
<input @bind="Request.Name" type="text" autocomplete="off" class="input w-full">
</div>
</div>
<div class="sm:col-span-2">
<label class="block text-sm font-medium leading-6 text-base-content">Owner</label>
<div class="mt-2">
<InputItem TItem="UserResponse"
DisplayField="@(x => x.Username)"
ItemSource="UsersItemSource"
@bind-Value="Parent.Owner">
</InputItem>
</div>
</div>
<div class="sm:col-span-2">
<label class="block text-sm font-medium leading-6 text-base-content">Star</label>
<div class="mt-2">
<InputItem TItem="StarResponse"
DisplayField="@(x => x.Name)"
ItemSource="StarsItemSource"
@bind-Value="Parent.Star">
</InputItem>
</div>
</div>
<div class="sm:col-span-2">
<label class="block text-sm font-medium leading-6 text-base-content">Node</label>
<div class="mt-2">
<InputItem TItem="NodeResponse"
DisplayField="@(x => x.Name)"
ItemSource="NodesItemSource"
@bind-Value="Parent.Node">
</InputItem>
</div>
</div>
</div>
<div class="border-t border-base-content/20 pt-6 my-8">
<div class="mb-8">
<h2 class="text-base font-semibold leading-7 text-base-content">
Resources
</h2>
<p class="mt-1 text-sm leading-6 text-base-content/60">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-base-content">Cpu</label>
<div class="mt-2">
<input @bind="Request.Cpu" type="number" autocomplete="off" class="input w-full">
</div>
</div>
<div class="sm:col-span-2">
<label class="block text-sm font-medium leading-6 text-base-content">Memory</label>
<div class="mt-2">
<input @bind="Request.Memory" type="number" autocomplete="off" class="input w-full">
</div>
</div>
<div class="sm:col-span-2">
<label class="block text-sm font-medium leading-6 text-base-content">Disk</label>
<div class="mt-2">
<input @bind="Request.Disk" type="number" autocomplete="off" class="input w-full">
</div>
</div>
</div>
</div>
@code
{
[Parameter] public CreateServerRequest Request { get; set; }
[Parameter] public Create Parent { get; set; }
private ItemSource<StarResponse> StarsItemSource => ItemSourceFactory.From(LoadStarsAsync);
private ItemSource<NodeResponse> NodesItemSource => ItemSourceFactory.From(LoadNodesAsync);
private ItemSource<UserResponse> UsersItemSource => ItemSourceFactory.From(LoadUsersAsync);
private async Task<IEnumerable<StarResponse>> LoadStarsAsync(int startIndex, int count)
{
return await ApiClient.GetJson<CountedData<StarResponse>>(
$"api/admin/servers/stars?startIndex={startIndex}&count={count}"
);
}
private async Task<IEnumerable<NodeResponse>> LoadNodesAsync(int startIndex, int count)
{
return await ApiClient.GetJson<CountedData<NodeResponse>>(
$"api/admin/servers/nodes?startIndex={startIndex}&count={count}"
);
}
private async Task<IEnumerable<UserResponse>> LoadUsersAsync(int startIndex, int count)
{
return await ApiClient.GetJson<CountedData<UserResponse>>(
$"api/admin/users?startIndex={startIndex}&count={count}"
);
}
}

View File

@@ -1,89 +0,0 @@
@using MoonCore.Blazor.FlyonUi.Components
@using MoonCore.Common
@using MoonlightServers.Shared.Http.Requests.Admin.Servers
@using MoonCore.Helpers
@using MoonlightServers.Frontend.UI.Views.Admin.All
@using MoonlightServers.Shared.Http.Requests.Admin.ServerVariables
@using MoonlightServers.Shared.Http.Responses.Admin.StarVariables
@inject HttpApiClient ApiClient
<LazyLoader Load="LoadAsync">
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
@foreach (var variable in StarVariables)
{
// Load value of default
var requestVar = Request.Variables.FirstOrDefault(x => x.Key == variable.Key);
var value = requestVar != null
? requestVar.Value
: variable.DefaultValue;
<div class="sm:col-span-2">
<label class="block text-sm font-medium leading-6 text-base-content">
@variable.Name
</label>
<div class="mt-2">
<input type="text"
class="input placeholder-base-content/50 w-full"
value="@value"
placeholder="@variable.DefaultValue"
@onchange="@(args => UpdateValueAsync(variable, args))"/>
</div>
<p class="mt-1 text-sm leading-6 text-base-content/60">
@variable.Description
</p>
</div>
}
</div>
</LazyLoader>
@code
{
[Parameter] public CreateServerRequest Request { get; set; }
[Parameter] public Create Parent { get; set; }
private StarVariableResponse[] StarVariables;
private async Task LoadAsync(LazyLoader _)
{
if (Parent.Star == null)
{
StarVariables = [];
return;
}
StarVariables = await CountedData.AllAsync(async (index, count) =>
await ApiClient.GetJson<CountedData<StarVariableResponse>>(
$"api/admin/servers/stars/{Parent.Star.Id}/variables?startIndex={index}&count={count}"
)
);
}
private async Task UpdateValueAsync(StarVariableResponse starVariable, ChangeEventArgs args)
{
var value = args.Value?.ToString() ?? "";
// Remove variable from request when set to its default value
if (value == starVariable.DefaultValue && Request.Variables.Any(x => x.Key == starVariable.Key))
Request.Variables.RemoveAll(x => x.Key == starVariable.Key);
else
{
var serverVar = Request.Variables
.FirstOrDefault(x => x.Key == starVariable.Key);
if (serverVar == null)
{
serverVar = new CreateServerVariableRequest()
{
Key = starVariable.Key
};
Request.Variables.Add(serverVar);
}
serverVar.Value = value;
}
await InvokeAsync(StateHasChanged);
}
}

View File

@@ -1,76 +0,0 @@
@using MoonCore.Blazor.FlyonUi.Components
@using MoonlightServers.Shared.Enums
@using MoonlightServers.Shared.Http.Requests.Client.Servers.Shares
@using MoonlightServers.Shared.Http.Responses.Client.Servers
@inherits MoonCore.Blazor.FlyonUi.Modals.BaseModal
<div class="p-5">
<div class="flex items-center gap-4">
<div class="avatar avatar-placeholder max-sm:hidden">
<div class="border-base-content/20 rounded-box w-13 border-1">
<span class="icon-share-2 text-xl"></span>
</div>
</div>
<div class="space-y-1">
<h3 class="text-base-content text-2xl font-semibold">Create a new share</h3>
<p class="text-base-content/80">Grant access to this server to other users</p>
</div>
</div>
<div class="mt-5">
<HandleForm @ref="HandleForm" Model="Request" OnValidSubmit="OnValidSubmit">
<div class="mt-2">
<label class="label-text">Username</label>
<input class="input" @bind="Request.Username" type="text"/>
</div>
<div class="mt-5">
<PermissionEditor Server="Server" PermissionLevels="Permissions" />
</div>
</HandleForm>
</div>
<div class="mt-5 flex justify-end">
<button @onclick="HideAsync" type="button" class="btn btn-secondary me-2">
Cancel
</button>
<WButton OnClick="SubmitAsync">
Create
</WButton>
</div>
</div>
@code
{
[Parameter] public ServerDetailResponse Server { get; set; }
[Parameter] public string Username { get; set; }
[Parameter] public Func<CreateShareRequest, Task> OnSubmit { get; set; }
private HandleForm HandleForm;
private CreateShareRequest Request;
private Dictionary<string, ServerPermissionLevel> Permissions = new();
protected override void OnInitialized()
{
Request = new()
{
Username = Username
};
}
private async Task SetAsync(string name, ServerPermissionLevel level)
{
Permissions[name] = level;
await InvokeAsync(StateHasChanged);
}
private async Task SubmitAsync()
=> await HandleForm.SubmitAsync();
private async Task OnValidSubmit()
{
Request.Permissions = Permissions;
await OnSubmit.Invoke(Request);
await HideAsync();
}
}

View File

@@ -1,95 +0,0 @@
@using MoonlightServers.Frontend.Interfaces
@using MoonCore.Blazor.FlyonUi.Components
@using MoonlightServers.Frontend.Models
@using MoonlightServers.Shared.Enums
@using MoonlightServers.Shared.Http.Responses.Client.Servers
@inject IEnumerable<IServerPermissionProvider> PermissionProviders
<LazyLoader Load="LoadAsync">
<div class="grid grid-cols-1 lg:grid-cols-2 gap-y-3">
@foreach (var permission in AvailablePermissions)
{
var level = PermissionLevels.GetValueOrDefault(permission.Identifier, ServerPermissionLevel.None);
<div class="col-span-1 flex flex-row items-center justify-start text-base-content">
<i class="text-lg @permission.Icon me-4"></i>
<div class="flex flex-col">
<span>@permission.DisplayName</span>
<span class="text-base-content/60 text-sm">@permission.Description</span>
</div>
</div>
<div class="col-span-1 flex justify-start lg:justify-end mb-5 lg:mb-0">
<div class="join drop-shadow">
@if (level == ServerPermissionLevel.None)
{
<input class="join-item btn btn-soft" type="radio" name="share-@permission.Identifier"
aria-label="None"
checked="checked"/>
}
else
{
<input @onclick="() => SetAsync(permission.Identifier, ServerPermissionLevel.None)"
class="join-item btn btn-soft"
type="radio" name="share-@permission.Identifier" aria-label="None"/>
}
@if (level == ServerPermissionLevel.Read)
{
<input class="join-item btn btn-soft" type="radio" name="share-@permission.Identifier"
aria-label="Read"
checked="checked"/>
}
else
{
<input @onclick="() => SetAsync(permission.Identifier, ServerPermissionLevel.Read)"
class="join-item btn btn-soft"
type="radio" name="share-@permission.Identifier" aria-label="Read"/>
}
@if (level == ServerPermissionLevel.ReadWrite)
{
<input class="join-item btn btn-soft" type="radio" name="share-@permission.Identifier"
aria-label="Read & Write"
checked="checked"/>
}
else
{
<input @onclick="() => SetAsync(permission.Identifier, ServerPermissionLevel.ReadWrite)"
class="join-item btn btn-soft"
type="radio" name="share-@permission.Identifier" aria-label="Read & Write"/>
}
</div>
</div>
}
</div>
</LazyLoader>
@code
{
[Parameter] public ServerDetailResponse Server { get; set; }
[Parameter] public Dictionary<string, ServerPermissionLevel> PermissionLevels { get; set; }
private ServerPermission[] AvailablePermissions;
private async Task LoadAsync(LazyLoader _)
{
var permissions = new List<ServerPermission>();
foreach (var provider in PermissionProviders)
{
permissions.AddRange(
await provider.GetPermissionsAsync(Server)
);
}
AvailablePermissions = permissions.ToArray();
}
private async Task SetAsync(string name, ServerPermissionLevel level)
{
PermissionLevels[name] = level;
await InvokeAsync(StateHasChanged);
}
}

View File

@@ -1,189 +0,0 @@
@using Microsoft.Extensions.Logging
@using MoonCore.Helpers
@using MoonlightServers.Frontend.Services
@using MoonlightServers.Shared.Enums
@using MoonlightServers.Shared.Http.Responses.Client.Servers
@inject ServerService ServerService
@inject ILogger<ServerCard> Logger
@{
var gradient = "from-base-100/20";
var border = "border-base-content/80";
if (IsLoaded && !IsFailed)
{
gradient = Status.State switch
{
ServerState.Installing => "from-primary/20",
ServerState.Offline => "from-error/20",
ServerState.Starting => "from-warning/20",
ServerState.Stopping => "from-warning/20",
ServerState.Online => "from-success/20",
_ => "from-base-100"
};
border = Status.State switch
{
ServerState.Installing => "border-primary",
ServerState.Offline => "border-error",
ServerState.Starting => "border-warning",
ServerState.Stopping => "border-warning",
ServerState.Online => "border-success",
_ => "border-base-content/80"
};
}
}
<a href="/servers/@Server.Id"
class="w-full bg-gradient-to-r @gradient to-base-100/75 to-25% px-5 py-3.5 rounded-xl border-l-8 @border">
<div class="grid grid-cols-6">
<div class="flex items-center col-span-6 sm:col-span-2 2xl:col-span-1">
<div class="bg-base-content/10 bg-opacity-45 py-1 px-2 rounded-lg flex items-center">
<i class="icon-server me-3 align-middle"></i>
<div class="text-lg align-middle">
@Server.Name
</div>
</div>
</div>
<div class="hidden sm:flex items-center justify-end gap-x-3 sm:col-span-4 2xl:col-span-3">
@if (
IsLoaded &&
!IsFailed &&
Status.State is ServerState.Starting or ServerState.Stopping or ServerState.Online
)
{
<div class="bg-base-200/75 py-1 px-2 rounded-lg flex flex-row">
<div>
<i class="icon-cpu"></i>
</div>
<div class="ms-3">@(Stats.CpuUsage)%</div>
</div>
<div class="bg-base-200/75 py-1 px-2 rounded-lg flex flex-row">
<div>
<i class="icon-memory-stick"></i>
</div>
<div class="ms-3">@(Formatter.FormatSize(Stats.MemoryUsage)) / @(Formatter.FormatSize(ByteConverter.FromMegaBytes(Server.Memory).Bytes))</div>
</div>
<div class="bg-base-200/75 py-1 px-2 rounded-lg flex flex-row">
<div>
<i class="icon-hard-drive"></i>
</div>
<div class="ms-3">53 GB / 100GB</div>
</div>
}
else
{
if (!IsLoaded)
{
<div class="bg-base-200/75 py-1 px-2 rounded-lg flex flex-row text-gray-700">
<div>
<i class="icon-loader"></i>
</div>
<div class="ms-3">Loading</div>
</div>
}
else if (IsFailed)
{
<div class="bg-base-200/75 py-1 px-2 rounded-lg flex flex-row text-error">
<div>
<i class="icon-cable"></i>
</div>
<div class="ms-3">Unreachable</div>
</div>
}
else if (IsLoaded && !IsFailed && Status.State is ServerState.Offline)
{
<div class="bg-base-200/75 py-1 px-2 rounded-lg flex flex-row text-error">
<div>
<i class="icon-power-off"></i>
</div>
<div class="ms-3">Offline</div>
</div>
}
else if (IsLoaded && !IsFailed && Status.State is ServerState.Installing)
{
<div class="bg-base-200/75 py-1 px-2 rounded-lg flex flex-row text-primary">
<div>
<i class="icon-hammer"></i>
</div>
<div class="ms-3">Installing</div>
</div>
}
}
</div>
<div class="hidden 2xl:flex items-center justify-end gap-x-3 2xl:col-span-2">
@if (Server.Share != null)
{
<div class="bg-base-200/75 py-1 px-2 rounded-lg flex flex-row col-span-2">
<div>
<i class="icon-share-2"></i>
</div>
<div class="ms-3">Shared by <span class="text-primary">@Server.Share.SharedBy</span></div>
</div>
}
else
{
<div class="bg-base-200/75 py-1 px-2 rounded-lg flex flex-row">
<div>
<i class="icon-sparkles"></i>
</div>
<div class="ms-3">@Server.StarName</div>
</div>
<div class="bg-base-200/75 py-1 px-2 rounded-lg flex flex-row">
<div>
<i class="icon-database"></i>
</div>
<div class="ms-3">@Server.NodeName</div>
</div>
}
</div>
</div>
</a>
@code
{
[Parameter] public ServerDetailResponse Server { get; set; }
private ServerStatusResponse Status;
private ServerStatsResponse Stats;
private bool IsFailed = false;
private bool IsLoaded = false;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender)
return;
try
{
Status = await ServerService.GetStatusAsync(Server.Id);
Stats = await ServerService.GetStatsAsync(Server.Id);
}
catch (Exception e)
{
IsFailed = true;
Logger.LogWarning("Unable to fetch status from server {id}: {e}", Server.Id, e);
}
IsLoaded = true;
await InvokeAsync(StateHasChanged);
}
}

View File

@@ -1,13 +0,0 @@
@using Microsoft.AspNetCore.SignalR.Client
@using MoonlightServers.Frontend.UI.Views.Client
@using MoonlightServers.Shared.Enums
@using MoonlightServers.Shared.Http.Responses.Client.Servers
@code
{
[Parameter] public ServerDetailResponse Server { get; set; }
[Parameter] public ServerState State { get; set; }
[Parameter] public string InitialConsoleMessage { get; set; }
[Parameter] public HubConnection? HubConnection { get; set; }
[Parameter] public Manage Parent { get; set; }
}

View File

@@ -1,39 +0,0 @@
@using Microsoft.AspNetCore.SignalR.Client
@using MoonlightServers.Frontend.Services
@inherits BaseServerTab
@inject ServerService ServerService
<div class="h-44">
<XtermConsole @ref="XtermConsole"
OnAfterInitialized="OnAfterConsoleInitialized"
CommandHistory="Parent.CommandHistory"
OnCommand="OnCommand"/>
</div>
@code
{
private XtermConsole? XtermConsole;
protected override Task OnInitializedAsync()
{
// We are already connected to the hub at this point
HubConnection.On<string>("ConsoleOutput", async content =>
{
if (XtermConsole != null)
await XtermConsole.WriteAsync(content);
});
return Task.CompletedTask;
}
private async Task OnAfterConsoleInitialized()
{
await XtermConsole!.WriteAsync(InitialConsoleMessage);
}
private async Task OnCommand(string command)
=> await ServerService.RunCommandAsync(Server.Id, command + "\n");
}

View File

@@ -1,22 +0,0 @@
@using MoonlightServers.Frontend.Services
@using MoonCore.Blazor.FlyonUi.Files.Manager
@using MoonlightServers.Frontend.Helpers
@inherits BaseServerTab
@inject ServerFileSystemService FileSystemService
<FileManager FsAccess="FsAccess" />
@code
{
private IFsAccess FsAccess;
protected override void OnInitialized()
{
FsAccess = new ServerFsAccess(
Server.Id,
FileSystemService
);
}
}

View File

@@ -1,40 +0,0 @@
@using MoonCore.Blazor.FlyonUi.Alerts
@using MoonCore.Blazor.FlyonUi.Components
@using MoonlightServers.Frontend.Services
@using MoonlightServers.Shared.Enums
@inherits BaseServerTab
@inject ServerService ServerService
@inject AlertService AlertService
<div class="grid grid-cols-1 md:col-span-2 lg:grid-cols-3">
<div class="col-span-1 card card-body">
@if (State != ServerState.Offline)
{
<button class="btn btn-primary" disabled="disabled">
<i class="align-middle icon-hammer me-1"></i>
<span class="align-middle">Reinstall</span>
</button>
}
else
{
<WButton CssClasses="btn btn-primary" OnClick="ReinstallAsync">
<i class="align-middle icon-hammer"></i>
<span class="align-middle">Reinstall</span>
</WButton>
}
</div>
</div>
@code
{
private async Task ReinstallAsync(WButton _)
{
await AlertService.ConfirmDangerAsync(
"Server installation",
"Do you really want to reinstall the server? This can potentially lead to loss of data",
() => ServerService.InstallAsync(Server.Id)
);
}
}

View File

@@ -1,123 +0,0 @@
@using MoonCore.Blazor.FlyonUi.Alerts
@using MoonCore.Blazor.FlyonUi.Components
@using MoonCore.Blazor.FlyonUi.Modals
@using MoonCore.Blazor.FlyonUi.Toasts
@using MoonCore.Common
@using MoonlightServers.Frontend.Services
@using MoonlightServers.Shared.Http.Requests.Client.Servers.Shares
@using MoonlightServers.Shared.Http.Responses.Client.Servers.Shares
@inherits BaseServerTab
@inject ServerShareService ShareService
@inject ModalService ModalService
@inject ToastService ToastService
@inject AlertService AlertService
<div class="flex flex-row mb-5">
<input @bind="UsernameInput" class="input grow placeholder-base-content/50 me-1.5" autocomplete="none" placeholder="Enter a username"/>
<button @onclick="OpenCreateModalAsync" class="btn btn-primary">
<i class="icon-send me-1"></i>
<span>Invite</span>
</button>
</div>
<LazyLoader @ref="LazyLoader" Load="LoadAsync">
@if (Shares.Length == 0)
{
<IconAlert Title="No shares found" Color="text-primary" Icon="icon-search">
Enter a username and press invite to share this server to another user
</IconAlert>
}
else
{
<div class="grid grid-col-1 gap-y-3">
@foreach (var share in Shares)
{
<div class="col-span-1 card card-body py-3 flex flex-row items-center justify-between">
<div class="flex justify-start font-semibold">
<i class="icon-user-round me-2"></i>
<span>@share.Username</span>
</div>
<div class="flex justify-end">
<WButton OnClick="_ => OpenUpdateModalAsync(share)" CssClasses="btn btn-primary me-1.5">
<i class="icon-settings-2 me-1"></i>
<span>Edit</span>
</WButton>
<WButton OnClick="_ => DeleteAsync(share)" CssClasses="btn btn-error">
<i class="icon-trash-2 me-1"></i>
<span>Delete</span>
</WButton>
</div>
</div>
}
</div>
}
</LazyLoader>
@code
{
private ServerShareResponse[] Shares;
private string UsernameInput = "";
private LazyLoader LazyLoader;
private async Task LoadAsync(LazyLoader _)
{
Shares = await CountedData.AllAsync<ServerShareResponse>(async (startIndex, count)
=> await ShareService.GetAsync(Server.Id, startIndex, count)
);
}
private async Task OpenCreateModalAsync()
{
await ModalService.LaunchAsync<CreateShareModal>(parameters =>
{
parameters["Username"] = UsernameInput;
parameters["Server"] = Server;
parameters["OnSubmit"] = SubmitCreateAsync;
}, size: "max-w-2xl");
}
private async Task SubmitCreateAsync(CreateShareRequest request)
{
await ShareService.CreateAsync(Server.Id, request);
await ToastService.SuccessAsync("Share successfully created");
await LazyLoader.ReloadAsync();
}
private async Task OpenUpdateModalAsync(ServerShareResponse share)
{
await ModalService.LaunchAsync<UpdateShareModal>(parameters =>
{
parameters["Share"] = share;
parameters["Server"] = Server;
parameters["OnSubmit"] = (UpdateShareRequest request) => SubmitUpdateAsync(share.Id, request);
}, size: "max-w-2xl");
}
private async Task SubmitUpdateAsync(int shareId, UpdateShareRequest request)
{
await ShareService.UpdateAsync(Server.Id, shareId, request);
await ToastService.SuccessAsync("Share successfully updated");
await LazyLoader.ReloadAsync();
}
private async Task DeleteAsync(ServerShareResponse share)
{
await AlertService.ConfirmDangerAsync(
"Share deletion",
$"Do you really want to delete the share for the user '{share.Username}'? This cannot be undone",
async () =>
{
await ShareService.DeleteAsync(Server.Id, share.Id);
await ToastService.SuccessAsync("Successfully deleted share");
await LazyLoader.ReloadAsync();
}
);
}
}

View File

@@ -1,65 +0,0 @@
@using MoonCore.Blazor.FlyonUi.Components
@using MoonCore.Blazor.FlyonUi.Toasts
@using MoonCore.Common
@using MoonlightServers.Frontend.Services
@using MoonlightServers.Shared.Http.Responses.Client.Servers.Variables
@inherits BaseServerTab
@inject ServerService ServerService
@inject ToastService ToastService
<LazyLoader @ref="LazyLoader" Load="LoadAsync">
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
@foreach (var variable in Variables)
{
<div class="sm:col-span-2 card card-sm">
<div class="card-header pb-1">
<h5 class="text-base font-semibold">
@variable.Name
</h5>
</div>
<div class="card-body">
<p class="mb-2.5 text-sm leading-6 text-base-content/60">
@variable.Description
</p>
<div class="mt-auto">
<input @onchange="e => UpdateVariableAsync(variable, e)"
value="@variable.Value"
type="text"
class="input w-full">
</div>
</div>
</div>
}
</div>
</LazyLoader>
@code
{
private ServerVariableDetailResponse[] Variables;
private LazyLoader LazyLoader;
private async Task LoadAsync(LazyLoader _)
{
Variables = await CountedData.AllAsync<ServerVariableDetailResponse>(async (startIndex, count)
=> await ServerService.GetVariablesAsync(Server.Id, startIndex, count)
);
}
private async Task UpdateVariableAsync(ServerVariableDetailResponse variable, ChangeEventArgs args)
{
var value = args.Value?.ToString() ?? "";
await ServerService.UpdateVariableAsync(Server.Id, new()
{
Key = variable.Key,
Value = value
});
// Fetch the current data to make sure the user sees the latest data
await LazyLoader.ReloadAsync();
await ToastService.SuccessAsync("Successfully updated variable");
}
}

View File

@@ -1,125 +0,0 @@
@using MoonlightServers.Shared.Http.Responses.Client.Servers
@{
var gradient = Status switch
{
4 => "from-primary/20",
3 => "from-danger/20",
2 => "from-warning/20",
1 => "from-success/20",
_ => "from-gray-600/20"
};
var border = Status switch
{
4 => "border-primary",
3 => "border-danger",
2 => "border-warning",
1 => "border-success",
_ => "border-gray-600"
};
}
<a href="/servers/@Server.Id" class="w-full bg-gradient-to-r @gradient to-gray-750/65 to-25% px-5 py-3.5 rounded-xl border-l-8 @border">
<div class="grid grid-cols-6">
<div class="flex items-center col-span-6 sm:col-span-2 2xl:col-span-1">
<div class="bg-gray-900 bg-opacity-45 py-1 px-2 rounded-lg flex items-center">
<i class="icon-server me-3 align-middle"></i>
<div class="text-lg align-middle">
@Server.Name
</div>
</div>
</div>
<div class="hidden sm:flex items-center justify-end gap-x-3 sm:col-span-4 2xl:col-span-3">
@if (Status >= 1 && Status <= 2)
{
<div class="bg-gray-900 bg-opacity-45 py-1 px-2 rounded-lg flex flex-row">
<div>
<i class="icon-cpu"></i>
</div>
<div class="ms-3">56,8%</div>
</div>
<div class="bg-gray-900 bg-opacity-45 py-1 px-2 rounded-lg flex flex-row">
<div>
<i class="icon-memory-stick"></i>
</div>
<div class="ms-3">4,2 GB / 8 GB</div>
</div>
<div class="bg-gray-900 bg-opacity-45 py-1 px-2 rounded-lg flex flex-row">
<div>
<i class="icon-hard-drive"></i>
</div>
<div class="ms-3">53 GB / 100GB</div>
</div>
}
else
{
if (Status == 0)
{
<div class="bg-gray-900 bg-opacity-45 py-1 px-2 rounded-lg flex flex-row text-gray-700">
<div>
<i class="icon-loader"></i>
</div>
<div class="ms-3">Loading</div>
</div>
}
else if (Status == 3)
{
<div class="bg-gray-900 bg-opacity-45 py-1 px-2 rounded-lg flex flex-row text-error">
<div>
<i class="icon-power-off"></i>
</div>
<div class="ms-3">Offline</div>
</div>
}
else if (Status == 4)
{
<div class="bg-gray-900 bg-opacity-45 py-1 px-2 rounded-lg flex flex-row text-primary">
<div>
<i class="icon-hammer"></i>
</div>
<div class="ms-3">Installing</div>
</div>
}
}
</div>
<div class="hidden 2xl:flex items-center justify-end gap-x-3 2xl:col-span-2">
<div class="bg-gray-900 bg-opacity-45 py-1 px-2 rounded-lg flex flex-row">
<div>
<i class="icon-sparkles"></i>
</div>
<div class="ms-3">@Server.StarName</div>
</div>
<div class="bg-gray-900 bg-opacity-45 py-1 px-2 rounded-lg flex flex-row">
<div>
<i class="icon-database"></i>
</div>
<div class="ms-3">@Server.NodeName</div>
</div>
</div>
</div>
</a>
@code
{
[Parameter]
public ServerDetailResponse Server { get; set; }
[Parameter]
public int Status { get; set; }
}

View File

@@ -1,9 +0,0 @@
@using MoonlightServers.Shared.Http.Requests.Admin.Servers
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
</div>
@code
{
[Parameter] public UpdateServerRequest Request { get; set; }
}

View File

@@ -1,39 +0,0 @@
@using MoonCore.Blazor.FlyonUi.Common
@using MoonlightServers.Shared.Http.Requests.Admin.Servers
@using MoonCore.Helpers
@using MoonlightServers.Shared.Http.Responses.Admin.NodeAllocations
@using MoonlightServers.Shared.Http.Responses.Admin.Servers
@using MoonCore.Blazor.FlyonUi.Forms
@using MoonCore.Common
@using MoonlightServers.Frontend.UI.Views.Admin.All
@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-base-content">Allocations</label>
<div class="mt-2">
<InputMultipleItem TItem="NodeAllocationResponse"
Value="Parent.Allocations"
DisplayField="@(x => $"{x.IpAddress}:{x.Port}")"
ItemSource="ItemSource">
</InputMultipleItem>
</div>
</div>
</div>
@code
{
[Parameter] public UpdateServerRequest Request { get; set; }
[Parameter] public ServerResponse Server { get; set; }
[Parameter] public Update Parent { get; set; }
private ItemSource<NodeAllocationResponse> ItemSource => ItemSourceFactory.From(LoadAsync);
private async Task<IEnumerable<NodeAllocationResponse>> LoadAsync(int startIndex, int count)
{
return await ApiClient.GetJson<CountedData<NodeAllocationResponse>>(
$"api/admin/servers/nodes/{Server.NodeId}/allocations/free?startIndex={startIndex}&count={count}&serverId={Server.Id}"
);
}
}

View File

@@ -1,75 +0,0 @@
@using MoonCore.Blazor.FlyonUi.Common
@using MoonlightServers.Shared.Http.Requests.Admin.Servers
@using MoonCore.Helpers
@using Moonlight.Shared.Http.Responses.Admin.Users
@using MoonCore.Blazor.FlyonUi.Forms
@using MoonCore.Common
@using MoonlightServers.Frontend.UI.Views.Admin.All
@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-base-content">Name</label>
<div class="mt-2">
<input @bind="Request.Name" type="text" autocomplete="off" class="input w-full">
</div>
</div>
<div class="sm:col-span-2">
<label class="block text-sm font-medium leading-6 text-base-content">Owner</label>
<div class="mt-2">
<InputItem TItem="UserResponse"
DisplayField="@(x => x.Username)"
@bind-Value="Parent.Owner"
ItemSource="UserItemSource">
</InputItem>
</div>
</div>
</div>
<div class="border-t border-base-content/10 pt-6 my-8">
<div class="mb-8"><h2 class="text-base font-semibold leading-7 text-base-content">
Resources
</h2>
<p class="mt-1 text-sm leading-6 text-base-content/60">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-base-content">Cpu</label>
<div class="mt-2">
<input @bind="Request.Cpu" type="number" autocomplete="off" class="input w-full">
</div>
</div>
<div class="sm:col-span-2">
<label class="block text-sm font-medium leading-6 text-base-content">Memory</label>
<div class="mt-2">
<input @bind="Request.Memory" type="number" autocomplete="off" class="input w-full">
</div>
</div>
<div class="sm:col-span-2">
<label class="block text-sm font-medium leading-6 text-base-content">Disk</label>
<div class="mt-2">
<input @bind="Request.Disk" type="number" autocomplete="off" class="input w-full">
</div>
</div>
</div>
</div>
@code
{
[Parameter] public UpdateServerRequest Request { get; set; }
[Parameter] public Update Parent { get; set; }
private ItemSource<UserResponse> UserItemSource => ItemSourceFactory.From(LoadAsync);
private async Task<IEnumerable<UserResponse>> LoadAsync(int startIndex, int count)
{
return await ApiClient.GetJson<CountedData<UserResponse>>(
$"api/admin/users?startIndex={startIndex}&count={count}"
);
}
}

View File

@@ -1,93 +0,0 @@
@using MoonCore.Blazor.FlyonUi.Components
@using MoonCore.Common
@using MoonlightServers.Shared.Http.Requests.Admin.Servers
@using MoonCore.Helpers
@using MoonlightServers.Shared.Http.Requests.Admin.ServerVariables
@using MoonlightServers.Shared.Http.Responses.Admin.Servers
@using MoonlightServers.Shared.Http.Responses.Admin.ServerVariables
@using MoonlightServers.Shared.Http.Responses.Admin.StarVariables
@inject HttpApiClient ApiClient
<LazyLoader Load="LoadAsync">
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
@foreach (var variable in ServerVariables)
{
var reqVariable = Request.Variables.FirstOrDefault(x => x.Key == variable.Key);
var starVariable = StarVariables.FirstOrDefault(x => x.Key == variable.Key);
// Ignore all variables which aren't defined in the star
if (starVariable == null)
continue;
var value = reqVariable != null
? reqVariable.Value
: variable.Value;
<div class="sm:col-span-2">
<label class="block text-sm font-medium leading-6 text-base-content">
@starVariable.Name
</label>
<div class="mt-2">
<input type="text" class="input w-full" value="@value"
@onchange="@(args => UpdateValueAsync(variable, args))"/>
</div>
<p class="mt-1 text-sm leading-6 text-base-content/60">
@starVariable.Description
</p>
</div>
}
</div>
</LazyLoader>
@code
{
[Parameter] public UpdateServerRequest Request { get; set; }
[Parameter] public ServerResponse Server { get; set; }
private StarVariableResponse[] StarVariables;
private ServerVariableResponse[] ServerVariables;
private async Task LoadAsync(LazyLoader _)
{
StarVariables = await CountedData.AllAsync<StarVariableResponse>(async (startIndex, count) =>
await ApiClient.GetJson<CountedData<StarVariableResponse>>(
$"api/admin/servers/stars/{Server.StarId}/variables?startIndex={startIndex}&count={count}"
)
);
ServerVariables = await CountedData.AllAsync<ServerVariableResponse>(async (startIndex, count) =>
await ApiClient.GetJson<CountedData<ServerVariableResponse>>(
$"api/admin/servers/{Server.Id}/variables?startIndex={startIndex}&count={count}"
)
);
}
private async Task UpdateValueAsync(ServerVariableResponse serverVariable, ChangeEventArgs args)
{
var value = args.Value?.ToString() ?? "";
// Remove variable from request when set to its default value
if (value == serverVariable.Value && Request.Variables.Any(x => x.Key == serverVariable.Key))
Request.Variables.RemoveAll(x => x.Key == serverVariable.Key);
else
{
var serverVar = Request.Variables
.FirstOrDefault(x => x.Key == serverVariable.Key);
if (serverVar == null)
{
serverVar = new UpdateServerVariableRequest()
{
Key = serverVariable.Key
};
Request.Variables.Add(serverVar);
}
serverVar.Value = value;
}
await InvokeAsync(StateHasChanged);
}
}

View File

@@ -1,70 +0,0 @@
@using MoonCore.Blazor.FlyonUi.Components
@using MoonlightServers.Shared.Enums
@using MoonlightServers.Shared.Http.Requests.Client.Servers.Shares
@using MoonlightServers.Shared.Http.Responses.Client.Servers
@using MoonlightServers.Shared.Http.Responses.Client.Servers.Shares
@inherits MoonCore.Blazor.FlyonUi.Modals.BaseModal
<div class="p-5">
<div class="flex items-center gap-4">
<div class="avatar avatar-placeholder max-sm:hidden">
<div class="border-base-content/20 rounded-box w-13 border-1">
<span class="icon-share-2 text-xl"></span>
</div>
</div>
<div class="space-y-1">
<h3 class="text-base-content text-2xl font-semibold">Update share for @Share.Username</h3>
<p class="text-base-content/80">Grant access to this server to other users</p>
</div>
</div>
<div class="mt-5">
<HandleForm @ref="HandleForm" Model="Request" OnValidSubmit="OnValidSubmit">
<PermissionEditor Server="Server" PermissionLevels="Permissions" />
</HandleForm>
</div>
<div class="mt-5 flex justify-end">
<button @onclick="HideAsync" type="button" class="btn btn-secondary me-2">
Cancel
</button>
<WButton OnClick="SubmitAsync">
Create
</WButton>
</div>
</div>
@code
{
[Parameter] public ServerDetailResponse Server { get; set; }
[Parameter] public ServerShareResponse Share { get; set; }
[Parameter] public Func<UpdateShareRequest, Task> OnSubmit { get; set; }
private HandleForm HandleForm;
private UpdateShareRequest Request;
private Dictionary<string, ServerPermissionLevel> Permissions = new();
protected override void OnInitialized()
{
Request = new();
Permissions = Share.Permissions;
}
private async Task SetAsync(string name, ServerPermissionLevel level)
{
Permissions[name] = level;
await InvokeAsync(StateHasChanged);
}
private async Task SubmitAsync()
=> await HandleForm.SubmitAsync();
private async Task OnValidSubmit()
{
Request.Permissions = Permissions;
await OnSubmit.Invoke(Request);
await HideAsync();
}
}

View File

@@ -1,68 +0,0 @@
@using MoonCore.Blazor.FlyonUi.Components
@using MoonlightServers.Frontend.UI.Components.Forms
@using MoonlightServers.Shared.Http.Requests.Admin.StarDockerImages
@inherits MoonCore.Blazor.FlyonUi.Modals.BaseModal
<div class="p-5">
<div class="flex items-center gap-4">
<div class="avatar avatar-placeholder max-sm:hidden">
<div class="border-base-content/20 rounded-box w-13 border-1">
<span class="icon-container text-xl"></span>
</div>
</div>
<div class="space-y-1">
<h3 class="text-base-content text-2xl font-semibold">Add a new docker image</h3>
<p class="text-base-content/80">Add a new docker image to the star</p>
</div>
</div>
<div class="mt-5">
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
<div class="mt-2">
<label class="label-text">Display Name</label>
<input class="input" @bind="Form.DisplayName" type="text"/>
</div>
<div class="mt-2">
<label class="label-text">Identifier</label>
<input class="input" @bind="Form.Identifier" type="text"/>
</div>
<div class="mt-2">
<label class="label-text">Automatic pulling</label>
<Switch @bind-Value="Form.AutoPulling"/>
</div>
</HandleForm>
</div>
<div class="mt-5 flex justify-end">
<button @onclick="HideAsync" type="button" class="btn btn-secondary me-2">
Cancel
</button>
<WButton OnClick="SubmitAsync">
Create
</WButton>
</div>
</div>
@code
{
[Parameter] public Func<CreateStarDockerImageRequest, Task> OnSubmit { get; set; }
private CreateStarDockerImageRequest Form;
private HandleForm HandleForm;
protected override void OnInitialized()
{
// Set default values
Form = new()
{
AutoPulling = true
};
}
private async Task OnValidSubmit()
{
await OnSubmit.Invoke(Form);
await HideAsync();
}
private Task SubmitAsync() => HandleForm.SubmitAsync();
}

View File

@@ -1,86 +0,0 @@
@using MoonCore.Blazor.FlyonUi.Components
@using MoonlightServers.Shared.Enums
@using MoonlightServers.Shared.Models
@inherits MoonCore.Blazor.FlyonUi.Modals.BaseModal
<div class="p-5">
<div class="flex items-center gap-4">
<div class="avatar avatar-placeholder max-sm:hidden">
<div class="border-base-content/20 rounded-box w-13 border-1">
<span class="icon-braces text-xl"></span>
</div>
</div>
<div class="space-y-1">
<h3 class="text-base-content text-2xl font-semibold">Add a parse configuration</h3>
<p class="text-base-content/80">Add a new parse configuration to the star</p>
</div>
</div>
<div class="mt-5">
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
<div class="mt-2">
<label class="label-text">File</label>
<input class="input" @bind="Form.File" type="text"/>
</div>
<div class="mt-2">
<label class="label-text">Parser</label>
<select @bind="Form.Parser" class="select w-full">
@foreach (var val in Enum.GetValues<FileParsers>())
{
<option value="@val">@val</option>
}
</select>
</div>
<div class="mt-2">
<button type="button" @onclick="AddEntryAsync" class="btn btn-primary w-full">Add entry</button>
</div>
@foreach (var entry in Form.Entries)
{
<div class="flex flex-row mt-2">
<input @bind="entry.Key" placeholder="Key" class="input placeholder-base-content/50 grow rounded-r-none"/>
<input @bind="entry.Value" placeholder="Value" class="input placeholder-base-content/50 grow rounded-none"/>
<button type="button" @onclick="() => RemoveEntryAsync(entry)" class="btn btn-error grow-0 rounded-l-none">
<i class="icon-x"></i>
</button>
</div>
}
</HandleForm>
</div>
<div class="mt-5 flex justify-end">
<button @onclick="HideAsync" type="button" class="btn btn-secondary me-2">
Cancel
</button>
<WButton OnClick="SubmitAsync">
Create
</WButton>
</div>
</div>
@code
{
[Parameter] public Func<ParseConfiguration, Task> OnSubmit { get; set; }
private ParseConfiguration Form = new();
private HandleForm HandleForm;
private async Task OnValidSubmit()
{
await OnSubmit.Invoke(Form);
await HideAsync();
}
private Task SubmitAsync() => HandleForm.SubmitAsync();
private async Task AddEntryAsync()
{
Form.Entries.Add(new());
await InvokeAsync(StateHasChanged);
}
private async Task RemoveEntryAsync(ParseConfiguration.ParseConfigurationEntry entry)
{
Form.Entries.Remove(entry);
await InvokeAsync(StateHasChanged);
}
}

View File

@@ -1,94 +0,0 @@
@using MoonCore.Blazor.FlyonUi.Components
@using MoonlightServers.Shared.Enums
@using MoonlightServers.Shared.Http.Requests.Admin.StarVariables
@using MoonlightServers.Frontend.UI.Components.Forms
@inherits MoonCore.Blazor.FlyonUi.Modals.BaseModal
<div class="p-5">
<div class="flex items-center gap-4">
<div class="avatar avatar-placeholder max-sm:hidden">
<div class="border-base-content/20 rounded-box w-13 border-1">
<span class="icon-variable text-xl"></span>
</div>
</div>
<div class="space-y-1">
<h3 class="text-base-content text-2xl font-semibold">Add a new variable</h3>
<p class="text-base-content/80">Add a new variable to the star</p>
</div>
</div>
<div class="mt-5">
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
<div class="grid grid-cols-2 gap-2">
<div class="col-span-1">
<label class="label-text">Name</label>
<input @bind="Form.Name" type="text" class="input w-full"/>
</div>
<div class="col-span-1">
<label class="label-text">Description</label>
<input @bind="Form.Description" type="text" class="input w-full"/>
</div>
<div class="col-span-1">
<label class="label-text">Key</label>
<input @bind="Form.Key" type="text" class="input w-full"/>
</div>
<div class="col-span-1">
<label class="label-text">Default Value</label>
<input @bind="Form.DefaultValue" type="text" class="input w-full"/>
</div>
<div class="col-span-1">
<label class="label-text">Allow Viewing</label>
<Switch @bind-Value="Form.AllowViewing"/>
</div>
<div class="col-span-1">
<label class="label-text">Allow Editing</label>
<Switch @bind-Value="Form.AllowEditing"/>
</div>
<div class="col-span-1">
<label class="label-text">Type</label>
<select @bind="Form.Type" class="select w-full">
@foreach (var val in Enum.GetValues<StarVariableType>())
{
<option value="@val">@val</option>
}
</select>
</div>
<div class="col-span-1">
<label class="label-text">Filter</label>
<input @bind="Form.Filter" type="text" class="input w-full"/>
</div>
</div>
</HandleForm>
</div>
<div class="mt-5 flex justify-end">
<button @onclick="HideAsync" type="button" class="btn btn-secondary me-2">
Cancel
</button>
<WButton OnClick="SubmitAsync">
Create
</WButton>
</div>
</div>
@code
{
[Parameter] public Func<CreateStarVariableRequest, Task> OnSubmit { get; set; }
private CreateStarVariableRequest Form = new();
private HandleForm HandleForm;
private async Task OnValidSubmit()
{
await OnSubmit.Invoke(Form);
await HideAsync();
}
private Task SubmitAsync() => HandleForm.SubmitAsync();
}

View File

@@ -1,71 +0,0 @@
@using MoonCore.Blazor.FlyonUi.Components
@using MoonlightServers.Frontend.UI.Components.Forms
@using MoonlightServers.Shared.Http.Requests.Admin.StarDockerImages
@using MoonlightServers.Shared.Http.Responses.Admin.StarDockerImages
@inherits MoonCore.Blazor.FlyonUi.Modals.BaseModal
<div class="p-5">
<div class="flex items-center gap-4">
<div class="avatar avatar-placeholder max-sm:hidden">
<div class="border-base-content/20 rounded-box w-13 border-1">
<span class="icon-container text-xl"></span>
</div>
</div>
<div class="space-y-1">
<h3 class="text-base-content text-2xl font-semibold">Update docker image</h3>
<p class="text-base-content/80">Update docker image properties</p>
</div>
</div>
<div class="mt-5">
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
<div class="mt-2">
<label class="label-text">Display Name</label>
<input class="input" @bind="Form.DisplayName" type="text"/>
</div>
<div class="mt-2">
<label class="label-text">Identifier</label>
<input class="input" @bind="Form.Identifier" type="text"/>
</div>
<div class="mt-2">
<label class="label-text">Automatic pulling</label>
<Switch @bind-Value="Form.AutoPulling"/>
</div>
</HandleForm>
</div>
<div class="mt-5 flex justify-end">
<button @onclick="HideAsync" type="button" class="btn btn-secondary me-2">
Cancel
</button>
<WButton OnClick="SubmitAsync">
Update
</WButton>
</div>
</div>
@code
{
[Parameter] public Func<UpdateStarDockerImageRequest, Task> OnSubmit { get; set; }
[Parameter] public StarDockerImageResponse DockerImage { get; set; }
private UpdateStarDockerImageRequest Form;
private HandleForm HandleForm;
protected override void OnInitialized()
{
Form = new UpdateStarDockerImageRequest()
{
AutoPulling = DockerImage.AutoPulling,
DisplayName = DockerImage.DisplayName,
Identifier = DockerImage.Identifier
};
}
private async Task OnValidSubmit()
{
await OnSubmit.Invoke(Form);
await HideAsync();
}
private Task SubmitAsync() => HandleForm.SubmitAsync();
}

View File

@@ -1,93 +0,0 @@
@using MoonCore.Blazor.FlyonUi.Components
@using MoonlightServers.Shared.Enums
@using MoonlightServers.Shared.Models
@inherits MoonCore.Blazor.FlyonUi.Modals.BaseModal
<div class="p-5">
<div class="flex items-center gap-4">
<div class="avatar avatar-placeholder max-sm:hidden">
<div class="border-base-content/20 rounded-box w-13 border-1">
<span class="icon-braces text-xl"></span>
</div>
</div>
<div class="space-y-1">
<h3 class="text-base-content text-2xl font-semibold">Update parse configuration</h3>
<p class="text-base-content/80">Update parse configuration properties</p>
</div>
</div>
<div class="mt-5">
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
<div class="mt-2">
<label class="label-text">File</label>
<input class="input" @bind="Form.File" type="text"/>
</div>
<div class="mt-2">
<label class="label-text">Parser</label>
<select @bind="Form.Parser" class="select w-full">
@foreach (var val in Enum.GetValues<FileParsers>())
{
<option value="@val">@val</option>
}
</select>
</div>
<div class="mt-2">
<button type="button" @onclick="AddEntryAsync" class="btn btn-primary w-full">Add entry</button>
</div>
@foreach (var entry in Form.Entries)
{
<div class="flex flex-row mt-2">
<input @bind="entry.Key" placeholder="Key" class="input placeholder-base-content/50 grow rounded-r-none"/>
<input @bind="entry.Value" placeholder="Value" class="input placeholder-base-content/50 grow rounded-none"/>
<button type="button" @onclick="() => RemoveEntryAsync(entry)" class="btn btn-error grow-0 rounded-l-none">
<i class="icon-x"></i>
</button>
</div>
}
</HandleForm>
</div>
<div class="mt-5 flex justify-end">
<button @onclick="HideAsync" type="button" class="btn btn-secondary me-2">
Cancel
</button>
<WButton OnClick="SubmitAsync">
Update
</WButton>
</div>
</div>
@code
{
[Parameter] public Func<ParseConfiguration, Task> OnSubmit { get; set; }
[Parameter] public ParseConfiguration Configuration { get; set; }
private ParseConfiguration Form;
private HandleForm HandleForm;
protected override void OnInitialized()
{
// Manual mapping :(
Form = Configuration;
}
private async Task OnValidSubmit()
{
await OnSubmit.Invoke(Form);
await HideAsync();
}
private Task SubmitAsync() => HandleForm.SubmitAsync();
private async Task AddEntryAsync()
{
Form.Entries.Add(new());
await InvokeAsync(StateHasChanged);
}
private async Task RemoveEntryAsync(ParseConfiguration.ParseConfigurationEntry entry)
{
Form.Entries.Remove(entry);
await InvokeAsync(StateHasChanged);
}
}

View File

@@ -1,111 +0,0 @@
@using MoonCore.Blazor.FlyonUi.Components
@using MoonlightServers.Shared.Enums
@using MoonlightServers.Shared.Http.Requests.Admin.StarVariables
@using MoonlightServers.Frontend.UI.Components.Forms
@using MoonlightServers.Shared.Http.Responses.Admin.StarVariables
@inherits MoonCore.Blazor.FlyonUi.Modals.BaseModal
<div class="p-5">
<div class="flex items-center gap-4">
<div class="avatar avatar-placeholder max-sm:hidden">
<div class="border-base-content/20 rounded-box w-13 border-1">
<span class="icon-variable text-xl"></span>
</div>
</div>
<div class="space-y-1">
<h3 class="text-base-content text-2xl font-semibold">Update variable</h3>
<p class="text-base-content/80">Update variable properties</p>
</div>
</div>
<div class="mt-5">
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
<div class="grid grid-cols-2 gap-2">
<div class="col-span-1">
<label class="label-text">Name</label>
<input @bind="Form.Name" type="text" class="input w-full"/>
</div>
<div class="col-span-1">
<label class="label-text">Description</label>
<input @bind="Form.Description" type="text" class="input w-full"/>
</div>
<div class="col-span-1">
<label class="label-text">Key</label>
<input @bind="Form.Key" type="text" class="input w-full"/>
</div>
<div class="col-span-1">
<label class="label-text">Default Value</label>
<input @bind="Form.DefaultValue" type="text" class="input w-full"/>
</div>
<div class="col-span-1">
<label class="label-text">Allow Viewing</label>
<Switch @bind-Value="Form.AllowViewing"/>
</div>
<div class="col-span-1">
<label class="label-text">Allow Editing</label>
<Switch @bind-Value="Form.AllowEditing"/>
</div>
<div class="col-span-1">
<label class="label-text">Type</label>
<select @bind="Form.Type" class="select w-full">
@foreach (var val in Enum.GetValues<StarVariableType>())
{
<option value="@val">@val</option>
}
</select>
</div>
<div class="col-span-1">
<label class="label-text">Filter</label>
<input @bind="Form.Filter" type="text" class="input w-full"/>
</div>
</div>
</HandleForm>
</div>
<div class="mt-5 flex justify-end">
<button @onclick="HideAsync" type="button" class="btn btn-secondary me-2">
Cancel
</button>
<WButton OnClick="SubmitAsync">
Update
</WButton>
</div>
</div>
@code
{
[Parameter] public Func<UpdateStarVariableRequest, Task> OnSubmit { get; set; }
[Parameter] public StarVariableResponse Variable { get; set; }
private UpdateStarVariableRequest Form;
private HandleForm HandleForm;
protected override void OnInitialized()
{
Form = new()
{
Name = Variable.Name,
AllowEditing = Variable.AllowEditing,
AllowViewing = Variable.AllowViewing,
DefaultValue = Variable.DefaultValue,
Description = Variable.Description,
Filter = Variable.Filter,
Key = Variable.Key,
Type = Variable.Type
};
}
private async Task OnValidSubmit()
{
await OnSubmit.Invoke(Form);
await HideAsync();
}
private Task SubmitAsync() => HandleForm.SubmitAsync();
}

View File

@@ -1,109 +0,0 @@
@using MoonCore.Blazor.FlyonUi.Alerts
@using MoonCore.Blazor.FlyonUi.Components
@using MoonCore.Blazor.FlyonUi.Modals
@using MoonCore.Blazor.FlyonUi.Toasts
@using MoonCore.Common
@using MoonCore.Helpers
@using MoonlightServers.Frontend.UI.Components.Stars.Modals
@using MoonlightServers.Shared.Http.Requests.Admin.StarDockerImages
@using MoonlightServers.Shared.Http.Responses.Admin.StarDockerImages
@using MoonlightServers.Shared.Http.Responses.Admin.Stars
@inject HttpApiClient ApiClient
@inject ModalService ModalService
@inject ToastService ToastService
@inject AlertService AlertService
<LazyLoader @ref="LazyLoader" Load="LoadAsync">
<div class="flex justify-end">
<button type="button" @onclick="AddDockerImageAsync" class="btn btn-primary">Add docker image</button>
</div>
<div class="grid sm:grid-cols-2 xl:grid-cols-3 gap-4 mt-5">
@foreach (var dockerImage in DockerImages)
{
<div class="col-span-1 card card-body p-2.5">
<div class="flex items-center justify-between">
<div class="ml-3">
<i class="icon-container text-xl align-middle mr-2"></i>
<span class="align-middle text-lg">@dockerImage.DisplayName</span>
</div>
<div class="gap-x-2">
<button type="button" @onclick="() => UpdateDockerImageAsync(dockerImage)"
class="btn btn-primary">
<i class="icon-settings text-base"></i>
</button>
<button type="button" @onclick="() => DeleteDockerImageAsync(dockerImage)"
class="btn btn-error">
<i class="icon-trash text-base"></i>
</button>
</div>
</div>
</div>
}
</div>
</LazyLoader>
@code
{
[Parameter] public StarResponse Star { get; set; }
private StarDockerImageResponse[] DockerImages;
private LazyLoader LazyLoader;
private async Task LoadAsync(LazyLoader _)
{
DockerImages = await CountedData.AllAsync<StarDockerImageResponse>(async (startIndex, count) =>
await ApiClient.GetJson<CountedData<StarDockerImageResponse>>(
$"api/admin/servers/stars/{Star.Id}/dockerImages?startIndex={startIndex}&count={count}"
)
);
}
private async Task AddDockerImageAsync()
{
Func<CreateStarDockerImageRequest, Task> onSubmit = async request =>
{
await ApiClient.Post($"api/admin/servers/stars/{Star.Id}/dockerImages", request);
await ToastService.SuccessAsync("Successfully created docker image");
await LazyLoader.ReloadAsync();
};
await ModalService.LaunchAsync<CreateDockerImageModal>(parameters => { parameters.Add("OnSubmit", onSubmit); });
}
private async Task UpdateDockerImageAsync(StarDockerImageResponse dockerImage)
{
Func<UpdateStarDockerImageRequest, Task> onSubmit = async request =>
{
await ApiClient.Patch($"api/admin/servers/stars/{Star.Id}/dockerImages/{dockerImage.Id}", request);
await ToastService.SuccessAsync("Successfully updated docker image");
await LazyLoader.ReloadAsync();
};
await ModalService.LaunchAsync<UpdateDockerImageModal>(parameters =>
{
parameters.Add("OnSubmit", onSubmit);
parameters.Add("DockerImage", dockerImage);
});
}
private async Task DeleteDockerImageAsync(StarDockerImageResponse dockerImage)
{
await AlertService.ConfirmDangerAsync(
"Delete docker image",
"Do you really want to delete the selected docker image? This cannot be undone",
async () =>
{
await ApiClient.Delete($"api/admin/servers/stars/{Star.Id}/dockerImages/{dockerImage.Id}");
await ToastService.SuccessAsync("Successfully deleted docker image");
await LazyLoader.ReloadAsync();
}
);
}
}

View File

@@ -1,41 +0,0 @@
@using MoonlightServers.Shared.Http.Requests.Admin.Stars
<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-base-content">Name</label>
<div class="mt-2">
<input @bind="Request.Name" type="text" autocomplete="off" class="input w-full">
</div>
</div>
<div class="sm:col-span-2">
<label class="block text-sm font-medium leading-6 text-base-content">Version</label>
<div class="mt-2">
<input @bind="Request.Version" type="text" autocomplete="off" class="input w-full">
</div>
</div>
<div class="sm:col-span-2">
<label class="block text-sm font-medium leading-6 text-base-content">Author</label>
<div class="mt-2">
<input @bind="Request.Author" type="text" autocomplete="off" class="input w-full">
</div>
</div>
<div class="sm:col-span-2">
<label class="block text-sm font-medium leading-6 text-base-content">Donate Url</label>
<div class="mt-2">
<input @bind="Request.DonateUrl" type="text" autocomplete="off" class="input w-full">
</div>
</div>
<div class="sm:col-span-2">
<label class="block text-sm font-medium leading-6 text-base-content">Update Url</label>
<div class="mt-2">
<input @bind="Request.UpdateUrl" type="text" autocomplete="off" class="input w-full">
</div>
</div>
</div>
</div>
@code
{
[Parameter] public UpdateStarRequest Request { get; set; }
}

View File

@@ -1,42 +0,0 @@
@using MoonCore.Blazor.FlyonUi.Ace
@using MoonlightServers.Shared.Http.Requests.Admin.Stars
<div>
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
<div class="sm:col-span-3">
<label class="block text-sm font-medium leading-6 text-base-content">Docker Image</label>
<div class="mt-2">
<input @bind="Request.InstallDockerImage" type="text" autocomplete="off" class="input w-full">
</div>
</div>
<div class="sm:col-span-3">
<label class="block text-sm font-medium leading-6 text-base-content">Shell</label>
<div class="mt-2">
<input @bind="Request.InstallShell" type="text" autocomplete="off" class="input w-full">
</div>
</div>
<div class="sm:col-span-6">
<label class="block text-sm font-medium leading-6 text-base-content">Script</label>
<div class="mt-2" @onfocusout="OnFocusOut">
<CodeEditor @ref="CodeEditor" InitialContent="@Request.InstallScript" OnConfigure="OnConfigure" />
</div>
</div>
</div>
</div>
@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.GetValueAsync();
}
}

View File

@@ -1,69 +0,0 @@
@using MoonCore.Blazor.FlyonUi.Components
@using MoonCore.Common
@using MoonCore.Helpers
@using MoonlightServers.Shared.Http.Requests.Admin.Stars
@using MoonlightServers.Shared.Http.Responses.Admin.StarDockerImages
@using MoonlightServers.Shared.Http.Responses.Admin.Stars
@using MoonlightServers.Frontend.UI.Components.Forms
@inject HttpApiClient ApiClient
<LazyLoader Load="LoadAsync">
<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-base-content">Allow docker image change</label>
<div class="mt-2">
<Switch @bind-Value="Request.AllowDockerImageChange" />
</div>
</div>
<div class="sm:col-span-2">
<label class="block text-sm font-medium leading-6 text-base-content">Default docker image</label>
<div class="mt-2">
<select @bind="Request.DefaultDockerImage" class="select w-full">
@foreach (var dockerImage in DockerImages)
{
var index = DockerImages.IndexOf(dockerImage);
if (Request.DefaultDockerImage == index)
{
<option selected="selected"
value="@index">
@dockerImage.DisplayName
</option>
}
else
{
<option value="@index">
@dockerImage.DisplayName
</option>
}
}
</select>
</div>
</div>
</div>
</div>
</LazyLoader>
@code
{
[Parameter] public UpdateStarRequest Request { get; set; }
[Parameter] public StarResponse Star { get; set; }
private List<StarDockerImageResponse> DockerImages;
private async Task LoadAsync(LazyLoader _)
{
var pagedVariables = await ApiClient.GetJson<CountedData<StarDockerImageResponse>>(
$"api/admin/servers/stars/{Star.Id}/dockerImages?startIndex=0&count=100"
);
// TODO: Fix this
DockerImages = pagedVariables
.Items
.OrderBy(x => x.Id) // Make sure its in the correct order every time
.ToList();
}
}

View File

@@ -1,134 +0,0 @@
@using System.Text.Json
@using Microsoft.Extensions.Logging
@using MoonCore.Blazor.FlyonUi.Alerts
@using MoonCore.Blazor.FlyonUi.Modals
@using MoonCore.Blazor.FlyonUi.Toasts
@using MoonlightServers.Frontend.UI.Components.Stars.Modals
@using MoonlightServers.Shared.Http.Requests.Admin.Stars
@using MoonlightServers.Shared.Models
@inject ILogger<ParseConfig> Logger
@inject ModalService ModalService
@inject AlertService AlertService
@inject ToastService ToastService
<div class="flex justify-end mb-5">
<button type="button" @onclick="AddConfigAsync" class="btn btn-primary">Add parse configuration</button>
</div>
@if (HasParseError)
{
}
else
{
<div class="grid sm:grid-cols-2 xl:grid-cols-3 gap-4">
@foreach (var configuration in Configurations)
{
<div class="col-span-1 card card-body p-2.5">
<div class="flex items-center justify-between">
<div class="ml-3">
<i class="icon-file-cog text-xl align-middle mr-2"></i>
<span class="align-middle text-lg">@configuration.File</span>
</div>
<div class="gap-x-2">
<button type="button" @onclick="() => UpdateConfigAsync(configuration)" class="btn btn-primary">
<i class="icon-settings text-base"></i>
</button>
<button type="button" @onclick="() => DeleteConfigAsync(configuration)" class="btn btn-error">
<i class="icon-trash text-base"></i>
</button>
</div>
</div>
</div>
}
</div>
}
@code
{
[Parameter] public UpdateStarRequest Request { get; set; }
private List<ParseConfiguration> Configurations;
private bool HasParseError = false;
protected override Task OnInitializedAsync()
{
ReadFromJson();
return Task.CompletedTask;
}
private async Task AddConfigAsync()
{
Func<ParseConfiguration, Task> onSubmit = async configuration =>
{
Configurations.Add(configuration);
SaveChanges();
await InvokeAsync(StateHasChanged);
await ToastService.SuccessAsync("Successfully created parse configuration");
};
await ModalService.LaunchAsync<CreateParseConfigModal>(parameters =>
{
parameters.Add("OnSubmit", onSubmit);
}, "max-w-xl");
}
private async Task UpdateConfigAsync(ParseConfiguration configuration)
{
Func<ParseConfiguration, Task> onSubmit = async _ =>
{
SaveChanges();
await InvokeAsync(StateHasChanged);
await ToastService.SuccessAsync("Successfully updated parse configuration");
};
await ModalService.LaunchAsync<UpdateParseConfigModal>(parameters =>
{
parameters.Add("OnSubmit", onSubmit);
parameters.Add("Configuration", configuration);
}, "max-w-xl");
}
private async Task DeleteConfigAsync(ParseConfiguration configuration)
{
await AlertService.ConfirmDangerAsync(
"Parse configuration deletion",
"Do you really want to delete the selected parse configuration",
async () =>
{
Configurations.Remove(configuration);
SaveChanges();
await InvokeAsync(StateHasChanged);
await ToastService.SuccessAsync("Successfully deleted parse configuration");
}
);
}
private void SaveChanges()
{
Request.ParseConfiguration = JsonSerializer.Serialize(Configurations);
ReadFromJson();
}
private void ReadFromJson()
{
try
{
Configurations = JsonSerializer.Deserialize<List<ParseConfiguration>>(Request.ParseConfiguration)
?? throw new ArgumentNullException();
HasParseError = false;
}
catch (Exception e)
{
Logger.LogWarning("An error occured while reading parse configuration: {e}", e);
HasParseError = true;
}
}
}

View File

@@ -1,28 +0,0 @@
@using MoonlightServers.Shared.Http.Requests.Admin.Stars
<div>
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
<div class="sm:col-span-4">
<label class="block text-sm font-medium leading-6 text-base-content">Startup Command</label>
<div class="mt-2">
<input @bind="Request.StartupCommand" type="text" autocomplete="off" class="input w-full">
</div>
</div>
<div class="sm:col-span-2">
<label class="block text-sm font-medium leading-6 text-base-content">Stop Command</label>
<div class="mt-2">
<input @bind="Request.StopCommand" type="text" autocomplete="off" class="input w-full">
</div>
</div>
<div class="sm:col-span-2">
<label class="block text-sm font-medium leading-6 text-base-content">Online Detection</label>
<div class="mt-2">
<input @bind="Request.OnlineDetection" type="text" autocomplete="off" class="input w-full">
</div>
</div>
</div>
</div>
@code
{
[Parameter] public UpdateStarRequest Request { get; set; }
}

View File

@@ -1,107 +0,0 @@
@using MoonCore.Blazor.FlyonUi.Alerts
@using MoonCore.Blazor.FlyonUi.Components
@using MoonCore.Blazor.FlyonUi.Modals
@using MoonCore.Blazor.FlyonUi.Toasts
@using MoonCore.Common
@using MoonCore.Helpers
@using MoonlightServers.Frontend.UI.Components.Stars.Modals
@using MoonlightServers.Shared.Http.Requests.Admin.StarVariables
@using MoonlightServers.Shared.Http.Responses.Admin.Stars
@using MoonlightServers.Shared.Http.Responses.Admin.StarVariables
@inject HttpApiClient ApiClient
@inject ModalService ModalService
@inject AlertService AlertService
@inject ToastService ToastService
<div class="flex justify-end mb-5">
<button type="button" @onclick="AddVariableAsync" class="btn btn-primary">Add variable</button>
</div>
<LazyLoader @ref="LazyLoader" Load="LoadAsync">
<div class="grid sm:grid-cols-2 xl:grid-cols-3 gap-4">
@foreach (var variable in CurrentVariables)
{
<div class="col-span-1 card card-body p-2.5">
<div class="flex items-center justify-between">
<div class="ml-3">
<i class="icon-variable text-xl align-middle mr-2"></i>
<span class="align-middle text-lg">@variable.Name</span>
</div>
<div class="gap-x-2">
<button type="button" @onclick="() => UpdateVariableAsync(variable)" class="btn btn-primary">
<i class="icon-settings text-base"></i>
</button>
<button type="button" @onclick="() => DeleteVariableAsync(variable)" class="btn btn-error">
<i class="icon-trash text-base"></i>
</button>
</div>
</div>
</div>
}
</div>
</LazyLoader>
@code
{
[Parameter] public StarResponse Star { get; set; }
private StarVariableResponse[] CurrentVariables;
private LazyLoader LazyLoader;
private async Task LoadAsync(LazyLoader arg)
{
CurrentVariables = await CountedData.AllAsync<StarVariableResponse>(async (startIndex, count) =>
await ApiClient.GetJson<CountedData<StarVariableResponse>>(
$"api/admin/servers/stars/{Star.Id}/variables?startIndex={startIndex}&count={count}"
)
);
}
private async Task AddVariableAsync()
{
Func<CreateStarVariableRequest, Task> onSubmit = async request =>
{
await ApiClient.Post($"api/admin/servers/stars/{Star.Id}/variables", request);
await ToastService.SuccessAsync("Successfully created variable");
await LazyLoader.ReloadAsync();
};
await ModalService.LaunchAsync<CreateVariableModal>(parameters => { parameters.Add("OnSubmit", onSubmit); }, "max-w-xl");
}
private async Task UpdateVariableAsync(StarVariableResponse variable)
{
Func<UpdateStarVariableRequest, Task> onSubmit = async request =>
{
await ApiClient.Patch($"api/admin/servers/stars/{Star.Id}/variables/{variable.Id}", request);
await ToastService.SuccessAsync("Successfully updated variable");
await LazyLoader.ReloadAsync();
};
await ModalService.LaunchAsync<UpdateVariableModal>(parameters =>
{
parameters.Add("OnSubmit", onSubmit);
parameters.Add("Variable", variable);
}, "max-w-xl");
}
private async Task DeleteVariableAsync(StarVariableResponse variable)
{
await AlertService.ConfirmDangerAsync(
"Delete variable",
"Do you really want to delete the selected variable? This cannot be undone",
async () =>
{
await ApiClient.Delete($"api/admin/servers/stars/{Star.Id}/variables/{variable.Id}");
await ToastService.SuccessAsync("Successfully deleted variable");
await LazyLoader.ReloadAsync();
}
);
}
}

View File

@@ -1,237 +0,0 @@
@using Microsoft.Extensions.Logging
@using MoonCore.Blazor.FlyonUi.Modals
@using MoonCore.Helpers
@using XtermBlazor
@using MoonCore.Blazor.FlyonUi.Components
@inject IJSRuntime JsRuntime
@inject ModalService ModalService
@inject ILogger<XtermConsole> Logger
@implements IAsyncDisposable
<div class="bg-black rounded-lg p-2 relative">
@if (IsInitialized)
{
<Xterm @ref="Terminal"
Addons="Addons"
Options="Options"
Class="h-full w-full"
OnFirstRender="HandleFirstRenderAsync"/>
}
<div class="flex flex-row w-full mt-1.5">
<input @bind="CommandInput" @onkeyup="HandleKeyAsync" type="text" placeholder="Type here..." class="input grow"/>
<WButton OnClick="_ => SubmitCommandAsync()" CssClasses="btn btn-square btn-primary grow-0 ms-1.5">
<i class="icon-send-horizontal text-lg"></i>
</WButton>
</div>
<div class="absolute top-4 right-4">
<div class="flex flex-col gap-y-1.5">
@if (IsPaused)
{
<button @onclick="TogglePauseAsync" class="btn btn-primary btn-square">
<i class="icon-play text-lg"></i>
</button>
}
else
{
<button @onclick="TogglePauseAsync" class="btn btn-secondary btn-square">
<i class="icon-pause text-lg"></i>
</button>
}
<button @onclick="OpenFullscreenAsync" class="btn btn-secondary btn-square">
<i class="icon-maximize text-lg"></i>
</button>
</div>
</div>
</div>
@code
{
[Parameter] public Func<Task>? OnAfterInitialized { get; set; }
[Parameter] public Func<Task>? OnFirstRender { get; set; }
[Parameter] public bool ShowActions { get; set; } = true;
[Parameter] public bool ShowInput { get; set; } = false;
[Parameter] public int MaxOutputCacheSize { get; set; } = 250;
[Parameter] public Func<string, Task>? OnCommand { get; set; }
[Parameter] public IList<string> CommandHistory { get; set; } = new ConcurrentList<string>();
public event Func<string, Task>? OnWrite;
private Xterm Terminal;
public HashSet<string> Addons { get; } = ["addon-fit"];
public TerminalOptions Options { get; } = new()
{
CursorBlink = false,
CursorStyle = CursorStyle.Bar,
CursorWidth = 1,
FontFamily = "Space Mono, monospace",
DisableStdin = true,
CursorInactiveStyle = CursorInactiveStyle.None,
Theme =
{
Background = "#000000"
},
};
public ConcurrentList<string> OutputCache { get; private set; } = new();
public ConcurrentList<string> WriteQueue { get; private set; } = new();
private int CommandIndex = -1;
private bool IsReadyToWrite = false;
private bool IsPaused = false;
private bool IsInitialized = false;
private string CommandInput = "";
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender)
return;
try
{
await JsRuntime.InvokeVoidAsync("moonlightServers.loadAddons");
}
catch (Exception e)
{
Logger.LogError("An error occured while initializing addons: {e}", e);
}
IsInitialized = true;
await InvokeAsync(StateHasChanged);
if (OnAfterInitialized != null)
await OnAfterInitialized.Invoke();
}
private async Task HandleFirstRenderAsync()
{
try
{
await Terminal.Addon("addon-fit").InvokeVoidAsync("fit");
}
catch (Exception e)
{
Logger.LogError("An error occured while calling addons: {e}", e);
}
IsReadyToWrite = true;
// Write queued content since initialisation started
var queueContent = string.Concat(WriteQueue);
WriteQueue.Clear();
await Terminal.Write(queueContent);
if (OnFirstRender != null)
await OnFirstRender.Invoke();
}
public async Task WriteAsync(string content)
{
// We cache messages here as there is the chance that the console isn't ready for input while receiving write tasks
if (IsReadyToWrite && !IsPaused)
await HandleWriteAsync(content);
else
WriteQueue.Add(content);
}
private async Task HandleWriteAsync(string content)
{
// Update output cache and prune it if required
if (OutputCache.Count > MaxOutputCacheSize)
{
for (var i = 0; i < 50; i++)
OutputCache.RemoveAt(i);
}
OutputCache.Add(content);
// Trigger events
if (OnWrite != null)
await OnWrite.Invoke(content);
// Write in own terminal
await Terminal.Write(content);
}
private async Task OpenFullscreenAsync()
{
await ModalService.LaunchAsync<FullScreenModal>(parameters => { parameters["Parent"] = this; }, size: "max-w-none");
}
private async Task TogglePauseAsync()
{
IsPaused = !IsPaused;
await InvokeAsync(StateHasChanged);
if (IsPaused)
return;
var queueContent = string.Concat(WriteQueue);
WriteQueue.Clear();
await HandleWriteAsync(queueContent);
}
private async Task SubmitCommandAsync()
{
CommandHistory.Add(CommandInput);
if (OnCommand != null)
await OnCommand.Invoke(CommandInput);
CommandIndex = -1;
CommandInput = "";
await InvokeAsync(StateHasChanged);
}
private async Task HandleKeyAsync(KeyboardEventArgs keyboard)
{
switch (keyboard.Code)
{
case "Enter":
await SubmitCommandAsync();
break;
case "ArrowUp" or "ArrowDown":
{
var highestIndex = CommandHistory.Count - 1;
if (CommandIndex == -1)
CommandIndex = highestIndex;
else
{
if (keyboard.Code is "ArrowUp")
CommandIndex++;
else if (keyboard.Code is "ArrowDown")
CommandIndex--;
}
if (CommandIndex > highestIndex)
CommandIndex = highestIndex;
if (CommandIndex < 0)
CommandIndex = 0;
if (CommandIndex <= highestIndex || CommandHistory.Count > 0)
CommandInput = CommandHistory[CommandIndex];
await InvokeAsync(StateHasChanged);
break;
}
}
}
public async ValueTask DisposeAsync()
{
await Terminal.DisposeAsync();
}
}

View File

@@ -1,79 +0,0 @@
@page "/admin/servers/all/create"
@using MoonCore.Blazor.FlyonUi.Components
@using MoonCore.Blazor.FlyonUi.Toasts
@using MoonCore.Helpers
@using Moonlight.Shared.Http.Responses.Admin.Users
@using MoonlightServers.Shared.Http.Requests.Admin.Servers
@using MoonlightServers.Frontend.UI.Components.Servers.CreatePartials
@using MoonlightServers.Shared.Http.Responses.Admin.NodeAllocations
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes
@using MoonlightServers.Shared.Http.Responses.Admin.Stars
@inject HttpApiClient ApiClient
@inject NavigationManager Navigation
@inject ToastService ToastService
@attribute [Authorize(Policy = "permissions:admin.servers.create")]
<PageHeader Title="Create Server">
<a href="/admin/servers/all" class="btn btn-secondary">
<i class="icon-chevron-left"></i>
Back
</a>
<WButton OnClick="Form.SubmitAsync" CssClasses="btn btn-primary">
<i class="icon-check"></i>
Create
</WButton>
</PageHeader>
<div class="mt-5">
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
<Tabs>
<Tab Name="General">
<General Request="Request" Parent="this" />
</Tab>
<Tab Name="Allocations">
<Allocations Request="Request" Parent="this" />
</Tab>
<Tab Name="Variables">
<Variables Request="Request" Parent="this" />
</Tab>
<Tab Name="Advanced">
<Advanced Request="Request" />
</Tab>
</Tabs>
</HandleForm>
</div>
@code
{
private HandleForm Form;
private CreateServerRequest Request;
public List<NodeAllocationResponse> Allocations = new();
public UserResponse? Owner;
public StarResponse? Star;
public NodeResponse? Node;
protected override void OnInitialized()
{
Request = new();
}
private async Task OnSubmit()
{
Request.AllocationIds = Allocations
.Select(x => x.Id)
.ToArray();
Request.StarId = Star?.Id ?? -1;
Request.NodeId = Node?.Id ?? -1;
Request.OwnerId = Owner?.Id ?? -1;
await ApiClient.Post("api/admin/servers", Request);
await ToastService.SuccessAsync("Successfully created Server");
Navigation.NavigateTo("/admin/servers/all");
}
}

View File

@@ -1,162 +0,0 @@
@page "/admin/servers/all"
@using MoonCore.Blazor.FlyonUi.Alerts
@using MoonCore.Blazor.FlyonUi.Common
@using MoonCore.Blazor.FlyonUi.Toasts
@using MoonCore.Helpers
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes
@using MoonlightServers.Shared.Http.Responses.Admin.Servers
@using MoonlightServers.Shared.Http.Responses.Admin.Stars
@using MoonCore.Blazor.FlyonUi.Components
@using MoonCore.Blazor.FlyonUi.Grid
@using MoonCore.Blazor.FlyonUi.Grid.Columns
@using MoonCore.Common
@using Moonlight.Shared.Http.Responses.Admin.Users
@inject HttpApiClient ApiClient
@inject AlertService AlertService
@inject ToastService ToastService
@attribute [Authorize(Policy = "permissions:admin.servers.get")]
<div class="mb-3">
<NavTabs Index="1" Names="@UiConstants.AdminNavNames" Links="@UiConstants.AdminNavLinks"/>
</div>
<div class="mb-5">
<PageHeader Title="Servers">
<a href="/admin/servers/all/create" class="btn btn-primary">
Create
</a>
</PageHeader>
</div>
<DataGrid @ref="Grid"
TGridItem="ServerResponse"
ItemSource="ItemSource">
<PropertyColumn Field="x => x.Id"/>
<TemplateColumn Title="Name">
<td>
<a class="text-primary" href="/admin/servers/all/update/@context.Id">
@context.Name
</a>
</td>
</TemplateColumn>
<TemplateColumn Title="Owner">
<td>
@{
var owner = Users.GetValueOrDefault(context.OwnerId);
}
<span>
@(owner?.Username ?? "N/A")
</span>
</td>
</TemplateColumn>
<TemplateColumn Title="Node">
<td>
@{
var node = Nodes.GetValueOrDefault(context.NodeId);
}
<span>
@(node?.Name ?? "N/A")
</span>
</td>
</TemplateColumn>
<TemplateColumn Title="Star">
<td>
@{
var star = Stars.GetValueOrDefault(context.StarId);
}
<span>
@(star?.Name ?? "N/A")
</span>
</td>
</TemplateColumn>
<TemplateColumn Title="Actions">
<td>
<div class="flex justify-end">
<a href="/admin/servers/all/update/@(context.Id)" class="text-primary mr-2 sm:mr-3">
<i class="icon-pencil text-base"></i>
</a>
<a href="#" @onclick="() => DeleteAsync(context)" @onclick:preventDefault
class="text-error">
<i class="icon-trash text-base"></i>
</a>
</div>
</td>
</TemplateColumn>
</DataGrid>
@code
{
private DataGrid<ServerResponse> Grid;
private Dictionary<int, StarResponse> Stars = new();
private Dictionary<int, NodeResponse> Nodes = new();
private Dictionary<int, UserResponse> Users = new();
private ItemSource<ServerResponse> ItemSource => ItemSourceFactory.From(LoadAsync);
private async Task<IEnumerable<ServerResponse>> LoadAsync(int startIndex, int count)
{
var query = $"?startIndex={startIndex}&count={count}";
var countedData = await ApiClient.GetJson<CountedData<ServerResponse>>($"api/admin/servers{query}");
// Fetch relations
var nodesToFetch = countedData.Items
.Where(x => !Nodes.ContainsKey(x.Id))
.Select(x => x.Id)
.Distinct();
foreach (var id in nodesToFetch)
{
var node = await ApiClient.GetJson<NodeResponse>($"api/admin/servers/nodes/{id}");
Nodes[node.Id] = node;
}
var starsToFetch = countedData.Items
.Where(x => !Stars.ContainsKey(x.Id))
.Select(x => x.Id)
.Distinct();
foreach (var id in starsToFetch)
{
var star = await ApiClient.GetJson<StarResponse>($"api/admin/servers/stars/{id}");
Stars[star.Id] = star;
}
var usersToFetch = countedData.Items
.Where(x => !Users.ContainsKey(x.Id))
.Select(x => x.Id)
.Distinct();
foreach (var id in usersToFetch)
{
var user = await ApiClient.GetJson<UserResponse>($"api/admin/users/{id}");
Users[user.Id] = user;
}
return countedData;
}
private async Task DeleteAsync(ServerResponse response)
{
await AlertService.ConfirmDangerAsync(
"Server deletion",
$"Do you really want to delete the server '{response.Name}'",
async () =>
{
await ApiClient.Delete($"api/admin/servers/{response.Id}");
await ToastService.SuccessAsync("Successfully deleted server");
await Grid.RefreshAsync();
}
);
}
}

View File

@@ -1,101 +0,0 @@
@page "/admin/servers/all/update/{Id:int}"
@using MoonCore.Blazor.FlyonUi.Components
@using MoonCore.Blazor.FlyonUi.Toasts
@using MoonCore.Helpers
@using Moonlight.Shared.Http.Responses.Admin.Users
@using MoonlightServers.Shared.Http.Requests.Admin.Servers
@using MoonlightServers.Shared.Http.Responses.Admin.Servers
@using MoonlightServers.Frontend.UI.Components.Servers.UpdatePartials
@using MoonlightServers.Shared.Http.Responses.Admin.NodeAllocations
@inject HttpApiClient ApiClient
@inject NavigationManager Navigation
@inject ToastService ToastService
@attribute [Authorize(Policy = "permissions:admin.servers.update")]
<LazyLoader Load="LoadAsync">
<PageHeader Title="Update Server">
<a href="/admin/servers/all" class="btn btn-secondary">
<i class="icon-chevron-left"></i>
Back
</a>
<WButton OnClick="Form.SubmitAsync" CssClasses="btn btn-primary">
<i class="icon-check"></i>
Update
</WButton>
</PageHeader>
<div class="mt-5">
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
<Tabs>
<Tab Name="General">
<General Request="Request" Parent="this"/>
</Tab>
<Tab Name="Allocations">
<Allocations Request="Request" Server="Server" Parent="this"/>
</Tab>
<Tab Name="Variables">
<Variables Request="Request" Server="Server"/>
</Tab>
<Tab Name="Advanced">
<Advanced Request="Request"/>
</Tab>
</Tabs>
</HandleForm>
</div>
</LazyLoader>
@code
{
[Parameter] public int Id { get; set; }
private HandleForm Form;
private UpdateServerRequest Request;
private ServerResponse Server;
public List<NodeAllocationResponse> Allocations = new();
public UserResponse Owner;
private async Task LoadAsync(LazyLoader _)
{
Server = await ApiClient.GetJson<ServerResponse>($"api/admin/servers/{Id}");
Request = new()
{
Name = Server.Name,
AllocationIds = Server.AllocationIds,
OwnerId = Server.OwnerId,
Cpu = Server.Cpu,
Disk = Server.Disk,
DockerImageIndex = Server.DockerImageIndex,
Memory = Server.Memory,
StartupOverride = Server.StartupOverride
};
foreach (var allocationId in Server.AllocationIds)
{
var allocation = await ApiClient.GetJson<NodeAllocationResponse>(
$"api/admin/servers/nodes/{Server.NodeId}/allocations/{allocationId}"
);
Allocations.Add(allocation);
}
Owner = await ApiClient.GetJson<UserResponse>(
$"api/admin/users/{Server.OwnerId}"
);
}
private async Task OnSubmit()
{
Request.AllocationIds = Allocations.Select(x => x.Id).ToArray();
Request.OwnerId = Owner.Id;
await ApiClient.Patch($"api/admin/servers/{Id}", Request);
await ToastService.SuccessAsync("Successfully updated server");
Navigation.NavigateTo("/admin/servers/all");
}
}

View File

@@ -1,8 +0,0 @@
@page "/admin/servers"
@using MoonCore.Blazor.FlyonUi.Components
@attribute [Authorize(Policy = "permissions:admin.servers.overview")]
<NavTabs Index="0" Names="@UiConstants.AdminNavNames" Links="@UiConstants.AdminNavLinks"/>

View File

@@ -1,77 +0,0 @@
@page "/admin/servers/nodes/create"
@using MoonCore.Blazor.FlyonUi.Components
@using MoonCore.Blazor.FlyonUi.Toasts
@using MoonCore.Helpers
@using MoonlightServers.Shared.Http.Requests.Admin.Nodes
@inject HttpApiClient ApiClient
@inject NavigationManager Navigation
@inject ToastService ToastService
@attribute [Authorize(Policy = "permissions:admin.servers.nodes.create")]
<PageHeader Title="Create Node">
<a href="/admin/servers/nodes" class="btn btn-secondary">
<i class="icon-chevron-left"></i>
Back
</a>
<WButton OnClick="Form.SubmitAsync" CssClasses="btn btn-primary">
<i class="icon-check"></i>
Create
</WButton>
</PageHeader>
<div class="mt-5">
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
<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-base-content">Name</label>
<div class="mt-2">
<input @bind="Request.Name" type="text" autocomplete="off" class="input w-full">
</div>
</div>
<div class="sm:col-span-2">
<label class="block text-sm font-medium leading-6 text-base-content">Fqdn</label>
<div class="mt-2">
<input @bind="Request.Fqdn" type="text" autocomplete="off" class="input w-full">
</div>
</div>
<div class="sm:col-span-2">
<label class="block text-sm font-medium leading-6 text-base-content">HttpPort</label>
<div class="mt-2">
<input @bind="Request.HttpPort" type="number" autocomplete="off" class="input w-full">
</div>
</div>
<div class="sm:col-span-2">
<label class="block text-sm font-medium leading-6 text-base-content">FtpPort</label>
<div class="mt-2">
<input @bind="Request.FtpPort" type="number" autocomplete="off" class="input w-full">
</div>
</div>
</div>
</HandleForm>
</div>
@*
TODO: EnableTransparentMode, EnableDynamicFirewall
*@
@code
{
private HandleForm Form;
private CreateNodeRequest Request;
protected override void OnInitialized()
{
Request = new();
}
private async Task OnSubmit()
{
await ApiClient.Post("api/admin/servers/nodes", Request);
await ToastService.SuccessAsync("Successfully created node");
Navigation.NavigateTo("/admin/servers/nodes");
}
}

View File

@@ -1,245 +0,0 @@
@page "/admin/servers/nodes"
@using Microsoft.Extensions.Logging
@using MoonCore.Blazor.FlyonUi.Alerts
@using MoonCore.Blazor.FlyonUi.Common
@using MoonCore.Blazor.FlyonUi.Toasts
@using MoonCore.Helpers
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes
@using MoonlightServers.Frontend.Services
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes.Statistics
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes.Sys
@using MoonCore.Blazor.FlyonUi.Components
@using MoonCore.Blazor.FlyonUi.Grid
@using MoonCore.Blazor.FlyonUi.Grid.Columns
@using MoonCore.Common
@inject HttpApiClient ApiClient
@inject NodeService NodeService
@inject AlertService AlertService
@inject ToastService ToastService
@inject ILogger<Index> Logger
@attribute [Authorize(Policy = "permissions:admin.servers.nodes.get")]
<div class="mb-3">
<NavTabs Index="2" Names="@UiConstants.AdminNavNames" Links="@UiConstants.AdminNavLinks"/>
</div>
<div class="mb-5">
<PageHeader Title="Nodes">
<a href="/admin/servers/nodes/create" class="btn btn-primary">
Create
</a>
</PageHeader>
</div>
<DataGrid @ref="Grid"
TGridItem="NodeResponse"
ItemSource="ItemSource">
<PropertyColumn Field="x => x.Id"/>
<TemplateColumn Title="Name">
<td>
<a class="text-primary" href="/admin/servers/nodes/update/@(context.Id)">
@context.Name
</a>
</td>
</TemplateColumn>
<PropertyColumn Field="x => x.Fqdn"/>
<TemplateColumn Title="Status">
<td>
@{
var isFetched = StatusResponses.TryGetValue(context.Id, out var data);
}
@if (isFetched)
{
if (data == null)
{
<div class="text-error flex items-center">
<i class="icon-server-off text-base me-1"></i>
<span>
API Error
</span>
</div>
}
else
{
if (data.RoundtripSuccess)
{
<div class="text-success flex items-center">
<i class="icon-check text-base me-1"></i>
<span>Online (@(data.Version))</span>
</div>
}
else
{
<div class="text-error flex items-center">
<i class="icon-server-off text-base me-1"></i>
<span class="me-2">
Error
</span>
<a @onclick="() => ShowErrorDetailsAsync(context.Id)" @onclick:preventDefault
href="#" class="ms-1 text-base-content/40">Details</a>
</div>
}
}
}
else
{
<div class="text-gray-500">
<i class="icon-loader text-base me-1 align-middle"></i>
<span class="align-middle">Loading</span>
</div>
}
</td>
</TemplateColumn>
<TemplateColumn Title="Utilization">
<td>
@{
var isFetched = Statistics.TryGetValue(context.Id, out var data);
}
@if (isFetched)
{
if (data == null)
{
<div class="flex items-center text-error">
<i class="icon-server-off text-base me-1"></i>
<span>
API Error
</span>
</div>
}
else
{
<div class="flex flex-row">
<div class="flex items-center">
<i class="text-primary text-base me-2 icon-cpu"></i>
<span>@(Math.Round(data.Cpu.Usage))%</span>
</div>
<div class="flex items-center ms-5">
<i class="text-primary text-base me-2 icon-memory-stick"></i>
<span>
@(Math.Round((data.Memory.Total - data.Memory.Free - data.Memory.Cached) / (double)data.Memory.Total * 100))%
</span>
</div>
</div>
}
}
else
{
<div class="flex items-center text-gray-500">
<i class="icon-loader text-base me-1"></i>
<span>Loading</span>
</div>
}
</td>
</TemplateColumn>
<TemplateColumn Title="Actions">
<td>
<div class="flex justify-end">
<a href="/admin/servers/nodes/update/@(context.Id)" class="text-primary mr-2 sm:mr-3">
<i class="icon-pencil text-base"></i>
</a>
<a href="#" @onclick="() => DeleteAsync(context)" @onclick:preventDefault
class="text-error">
<i class="icon-trash text-base"></i>
</a>
</div>
</td>
</TemplateColumn>
</DataGrid>
@code
{
private DataGrid<NodeResponse> Grid;
private Dictionary<int, NodeSystemStatusResponse?> StatusResponses = new();
private Dictionary<int, StatisticsResponse?> Statistics = new();
private ItemSource<NodeResponse> ItemSource => ItemSourceFactory.From(LoadAsync);
private async Task<IEnumerable<NodeResponse>> LoadAsync(int startIndex, int count)
{
var query = $"?startIndex={startIndex}&count={count}";
var countedData = await ApiClient.GetJson<CountedData<NodeResponse>>($"api/admin/servers/nodes{query}");
Statistics.Clear();
StatusResponses.Clear();
Task.Run(async () =>
{
foreach (var item in countedData.Items)
{
try
{
Statistics[item.Id] = await NodeService.GetStatisticsAsync(item.Id);
}
catch (Exception e)
{
Logger.LogWarning(
"An error occured while fetching statistics for node {nodeId}: {e}",
item.Id,
e
);
Statistics[item.Id] = null;
}
await InvokeAsync(StateHasChanged);
try
{
StatusResponses[item.Id] = await NodeService.GetSystemStatusAsync(item.Id);
}
catch (Exception e)
{
Logger.LogWarning(
"An error occured while fetching status for node {nodeId}: {e}",
item.Id,
e
);
StatusResponses[item.Id] = null;
}
await InvokeAsync(StateHasChanged);
}
});
return countedData;
}
private async Task DeleteAsync(NodeResponse response)
{
await AlertService.ConfirmDangerAsync(
"Node deletion",
$"Do you really want to delete the node '{response.Name}'",
async () =>
{
await ApiClient.Delete($"api/admin/servers/nodes/{response.Id}");
await ToastService.SuccessAsync("Successfully deleted node");
await Grid.RefreshAsync();
}
);
}
private async Task ShowErrorDetailsAsync(int id)
{
var data = StatusResponses.GetValueOrDefault(id);
if (data == null)
return;
var message = $"Failed after {Math.Round(data.RoundtripTime.TotalSeconds, 2)} seconds: " +
(data.RoundtripRemoteFailure ? "(Failed at node)" : "(Failed at api server)") +
$" {data.RoundtripError}";
await AlertService.ErrorAsync("Node error details", message);
}
}

View File

@@ -1,81 +0,0 @@
@page "/admin/servers/nodes/update/{Id:int}"
@using MoonCore.Blazor.FlyonUi.Components
@using MoonCore.Blazor.FlyonUi.Toasts
@using MoonCore.Helpers
@using MoonlightServers.Shared.Http.Requests.Admin.Nodes
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes
@using MoonlightServers.Frontend.UI.Components.Nodes.UpdatePartials
@inject HttpApiClient ApiClient
@inject NavigationManager Navigation
@inject ToastService ToastService
@attribute [Authorize(Policy = "permissions:admin.servers.nodes.update")]
<LazyLoader Load="LoadAsync">
<PageHeader Title="@Node.Name">
<a href="/admin/servers/nodes" class="btn btn-secondary">
<i class="icon-chevron-left"></i>
Back
</a>
<WButton OnClick="Form.SubmitAsync" CssClasses="btn btn-primary">
<i class="icon-check"></i>
Update
</WButton>
</PageHeader>
<div class="mt-5">
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
<Tabs>
<Tab Name="Overview">
<Overview Node="Node" />
</Tab>
<Tab Name="Settings">
<General Request="Request"/>
</Tab>
<Tab Name="Allocations">
<Allocations Node="Node"/>
</Tab>
<Tab Name="Advanced Settings">
<Advanced Request="Request"/>
</Tab>
</Tabs>
</HandleForm>
</div>
</LazyLoader>
@code
{
[Parameter] public int Id { get; set; }
private HandleForm Form;
private UpdateNodeRequest Request;
private NodeResponse Node;
private async Task LoadAsync(LazyLoader _)
{
Node = await ApiClient.GetJson<NodeResponse>($"api/admin/servers/nodes/{Id}");
Request = new UpdateNodeRequest()
{
Name = Node.Name,
Fqdn = Node.Fqdn,
FtpPort = Node.FtpPort,
HttpPort = Node.HttpPort
};
}
private async Task OnSubmit()
{
await ApiClient.Patch($"api/admin/servers/nodes/{Id}", Request);
await ToastService.SuccessAsync("Successfully updated Node");
Navigation.NavigateTo("/admin/servers/nodes");
}
}

View File

@@ -1,67 +0,0 @@
@page "/admin/servers/stars/create"
@using Microsoft.AspNetCore.Components.Authorization
@using MoonCore.Blazor.FlyonUi.Components
@using MoonCore.Blazor.FlyonUi.Toasts
@using MoonCore.Helpers
@using MoonlightServers.Shared.Http.Requests.Admin.Stars
@inject HttpApiClient ApiClient
@inject NavigationManager Navigation
@inject ToastService ToastService
@attribute [Authorize(Policy = "permissions:admin.servers.stars.create")]
<PageHeader Title="Create Star">
<a href="/admin/servers/stars" class="btn btn-secondary">
<i class="icon-chevron-left"></i>
Back
</a>
<WButton OnClick="Form.SubmitAsync" CssClasses="btn btn-primary">
<i class="icon-check"></i>
Create
</WButton>
</PageHeader>
<div class="mt-5">
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
<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-base-content">Name</label>
<div class="mt-2">
<input @bind="Request.Name" type="text" autocomplete="off" class="input w-full">
</div>
</div>
<div class="sm:col-span-2">
<label class="block text-sm font-medium leading-6 text-base-content">Author</label>
<div class="mt-2">
<input @bind="Request.Author" type="text" autocomplete="off" class="input w-full">
</div>
</div>
</div>
</HandleForm>
</div>
@code
{
[CascadingParameter] public Task<AuthenticationState> AuthState { get; set; }
private HandleForm Form;
private CreateStarRequest Request;
protected override async Task OnInitializedAsync()
{
Request = new();
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.SuccessAsync("Successfully created star");
Navigation.NavigateTo("/admin/servers/stars");
}
}

View File

@@ -1,166 +0,0 @@
@page "/admin/servers/stars"
@using MoonCore.Blazor.FlyonUi.Alerts
@using MoonCore.Blazor.FlyonUi.Common
@using MoonCore.Blazor.FlyonUi.Helpers
@using MoonCore.Blazor.FlyonUi.Toasts
@using MoonCore.Helpers
@using MoonlightServers.Shared.Http.Responses.Admin.Stars
@using MoonCore.Exceptions
@using MoonCore.Blazor.FlyonUi.Components
@using MoonCore.Blazor.FlyonUi.Grid
@using MoonCore.Blazor.FlyonUi.Grid.Columns
@using MoonCore.Common
@inject HttpApiClient ApiClient
@inject DownloadService DownloadService
@inject ToastService ToastService
@inject AlertService AlertService
@attribute [Authorize(Policy = "permissions:admin.servers.stars.get")]
<div class="mb-3">
<NavTabs Index="3" Names="@UiConstants.AdminNavNames" Links="@UiConstants.AdminNavLinks"/>
</div>
<div class="mb-5">
<PageHeader Title="Stars">
<InputFile id="import-file" hidden="" multiple OnChange="OnImportFiles"/>
<label for="import-file" class="btn btn-accent cursor-pointer">
<i class="icon-file-up"></i>
Import
</label>
<a href="/admin/servers/nodes/create" class="btn btn-primary">
Create
</a>
</PageHeader>
</div>
<DataGrid @ref="Grid"
TGridItem="StarResponse"
ItemSource="ItemSource">
<PropertyColumn Field="x => x.Id" />
<TemplateColumn Title="Name">
<td>
<a class="text-primary" href="/admin/servers/stars/update/@(context.Id)">
@context.Name
</a>
</td>
</TemplateColumn>
<PropertyColumn Field="x => x.Version" />
<PropertyColumn Field="x => x.Author" />
<TemplateColumn>
<td>
<div class="flex justify-end">
@if (!string.IsNullOrEmpty(context.DonateUrl))
{
<a href="@context.DonateUrl" target="_blank" class="text-accent 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-accent mr-3">
<i class="icon-refresh-cw align-middle"></i>
<span class="align-middle">Update</span>
</a>
}
<a href="#" @onclick="() => ExportAsync(context)" @onclick:preventDefault class="text-success 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 mr-2 sm:mr-3">
<i class="icon-pencil text-base"></i>
</a>
<a href="#" @onclick="() => DeleteAsync(context)" @onclick:preventDefault
class="text-error">
<i class="icon-trash text-base"></i>
</a>
</div>
</td>
</TemplateColumn>
</DataGrid>
@code
{
private DataGrid<StarResponse> Grid;
private ItemSource<StarResponse> ItemSource => ItemSourceFactory.From(LoadAsync);
private async Task<IEnumerable<StarResponse>> LoadAsync(int startIndex, int count)
{
var query = $"?startIndex={startIndex}&count={count}";
return await ApiClient.GetJson<CountedData<StarResponse>>($"api/admin/servers/stars{query}");
}
private async Task DeleteAsync(StarResponse response)
{
await AlertService.ConfirmDangerAsync(
"Star deletion",
$"Do you really want to delete the star '{response.Name}'",
async () =>
{
await ApiClient.Delete($"api/admin/servers/stars/{response.Id}");
await ToastService.SuccessAsync("Successfully deleted star");
await Grid.RefreshAsync();
}
);
}
private async Task ExportAsync(StarResponse star)
{
var json = await ApiClient.GetString($"api/admin/servers/stars/{star.Id}/export");
var formattedFileName = star.Name.Replace(" ", "_") + ".json";
await DownloadService.DownloadAsync(formattedFileName, json);
await ToastService.SuccessAsync($"Successfully exported '{star.Name}'");
}
private async Task OnImportFiles(InputFileChangeEventArgs eventArgs)
{
IBrowserFile[] files;
if(eventArgs.FileCount == 0)
return;
if (eventArgs.FileCount > 1)
files = eventArgs.GetMultipleFiles().ToArray();
else
files = [eventArgs.File];
foreach (var file in files)
{
try
{
if (!file.Name.EndsWith(".json"))
{
await ToastService.ErrorAsync($"Failed to import '{file.Name}': Only json files are supported");
continue;
}
await using var stream = file.OpenReadStream();
var content = new MultipartFormDataContent();
content.Add(new StreamContent(stream), "file", file.Name);
var star = await ApiClient.PostJson<StarResponse>("api/admin/servers/stars/import", content);
await ToastService.SuccessAsync($"Successfully imported '{star.Name}'");
}
catch (HttpApiException e)
{
await ToastService.ErrorAsync($"Failed to import '{file.Name}': {e.Title}");
}
}
await Grid.RefreshAsync();
}
}

View File

@@ -1,103 +0,0 @@
@page "/admin/servers/stars/update/{Id:int}"
@using MoonCore.Blazor.FlyonUi.Components
@using MoonCore.Blazor.FlyonUi.Toasts
@using MoonCore.Helpers
@using MoonlightServers.Shared.Http.Requests.Admin.Stars
@using MoonlightServers.Shared.Http.Responses.Admin.Stars
@using MoonlightServers.Frontend.UI.Components.Stars.UpdatePartials
@inject HttpApiClient ApiClient
@inject NavigationManager Navigation
@inject ToastService ToastService
@attribute [Authorize(Policy = "permissions:admin.servers.stars.update")]
<LazyLoader Load="LoadAsync">
<PageHeader Title="Update Star">
<a href="/admin/servers/stars" class="btn btn-secondary">
<i class="icon-chevron-left"></i>
Back
</a>
<WButton OnClick="Form.SubmitAsync" CssClasses="btn btn-primary">
<i class="icon-check"></i>
Update
</WButton>
</PageHeader>
<div class="mt-5">
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
<Tabs>
<Tab Name="General">
<General Request="Request" />
</Tab>
<Tab Name="Start, Stop & Status">
<StartStopStatus Request="Request" />
</Tab>
<Tab Name="Parse Configuration">
<ParseConfig Request="Request" />
</Tab>
<Tab Name="Installation">
<Installation Request="Request" />
</Tab>
<Tab Name="Variables">
<Variables Star="Detail" />
</Tab>
<Tab Name="Docker Images">
<DockerImage Star="Detail" />
</Tab>
<Tab Name="Miscellaneous">
<Misc Star="Detail" Request="Request" />
</Tab>
</Tabs>
</HandleForm>
</div>
</LazyLoader>
@code
{
[Parameter] public int Id { get; set; }
private HandleForm Form;
private UpdateStarRequest Request;
private StarResponse Detail;
private async Task LoadAsync(LazyLoader _)
{
Detail = await ApiClient.GetJson<StarResponse>($"api/admin/servers/stars/{Id}");
Request = new()
{
Name = Detail.Name,
AllowDockerImageChange = Detail.AllowDockerImageChange,
Author = Detail.Author,
DefaultDockerImage = Detail.DefaultDockerImage,
DonateUrl = Detail.DonateUrl,
InstallDockerImage = Detail.InstallDockerImage,
InstallScript = Detail.InstallScript,
InstallShell = Detail.InstallShell,
OnlineDetection = Detail.OnlineDetection,
ParseConfiguration = Detail.ParseConfiguration,
RequiredAllocations = Detail.RequiredAllocations,
StartupCommand = Detail.StartupCommand,
StopCommand = Detail.StopCommand,
UpdateUrl = Detail.UpdateUrl,
Version = Detail.Version
};
}
private async Task OnSubmit()
{
await ApiClient.Patch($"api/admin/servers/stars/{Id}", Request);
await ToastService.SuccessAsync("Successfully updated Star");
Navigation.NavigateTo("/admin/servers/stars");
}
}

View File

@@ -1,88 +0,0 @@
@page "/servers"
@using MoonCore.Blazor.FlyonUi.Components
@using MoonCore.Common
@using MoonlightServers.Frontend.UI.Components.Servers
@using MoonlightServers.Frontend.Services
@using MoonlightServers.Shared.Http.Responses.Client.Servers
@inject ServerService ServerService
<Tabs>
<Tab Name="Your servers">
<LazyLoader Load="LoadOwnServersAsync">
@if (OwnServers.Length == 0)
{
<IconAlert Title="No servers found" Color="text-primary" Icon="icon-search">
There are no servers linked to your account
</IconAlert>
}
else
{
<div class="flex flex-col gap-y-5">
@* Folder design idea
<div class="w-full bg-gray-800 px-5 py-3.5 rounded-xl">
<div class="flex items-center">
<div class="bg-gray-900 bg-opacity-45 py-1 px-2 rounded-lg flex items-center">
<i class="icon-folder-open me-3 align-middle"></i>
<div class="text-lg align-middle">
My Cool Folder
</div>
</div>
</div>
<div class="mt-5 flex flex-col gap-y-3">
@foreach (var server in Servers)
{
<ServerCard Server="server" />
}
</div>
</div>
*@
@foreach (var server in OwnServers)
{
<ServerCard Server="server"/>
}
</div>
}
</LazyLoader>
</Tab>
<Tab Name="Shared servers">
<LazyLoader Load="LoadSharedServersAsync">
@if (SharedServers.Length == 0)
{
<IconAlert Title="No shared servers found" Color="text-primary" Icon="icon-share-2">
There are no shared servers linked to your account
</IconAlert>
}
else
{
<div class="flex flex-col gap-y-5">
@foreach (var server in SharedServers)
{
<ServerCard Server="server"/>
}
</div>
}
</LazyLoader>
</Tab>
</Tabs>
@code
{
private ServerDetailResponse[] OwnServers;
private ServerDetailResponse[] SharedServers;
private async Task LoadOwnServersAsync(LazyLoader lazyLoader)
{
OwnServers = await CountedData.AllAsync<ServerDetailResponse>(async (startIndex, count) =>
await ServerService.GetServersAsync(startIndex, count)
);
}
private async Task LoadSharedServersAsync(LazyLoader lazyLoader)
{
SharedServers = await CountedData.AllAsync<ServerDetailResponse>(async (startIndex, count) =>
await ServerService.GetSharedServersAsync(startIndex, count)
);
}
}

View File

@@ -1,347 +0,0 @@
@page "/servers/{ServerId:int}"
@page "/servers/{ServerId:int}/{TabPath:alpha}"
@using Microsoft.AspNetCore.SignalR.Client
@using MoonCore.Blazor.FlyonUi.Components
@using MoonCore.Exceptions
@using MoonCore.Helpers
@using MoonlightServers.Frontend.Interfaces
@using MoonlightServers.Frontend.Models
@using MoonlightServers.Frontend.Services
@using MoonlightServers.Shared.Enums
@using MoonlightServers.Shared.Http.Responses.Client.Servers
@inject ServerService ServerService
@inject NavigationManager Navigation
@inject IEnumerable<IServerTabProvider> TabProviders
@implements IAsyncDisposable
<LazyLoader Load="LoadAsync">
@if (NotFound)
{
<IconAlert Title="Server not found" Icon="icon-search" Color="text-primary">
The requested server could not be found
</IconAlert>
}
else
{
<div class="card card-body justify-between py-2.5 px-5 flex-row">
<div class="flex flex-row items-center">
@{
var statusClass = State switch
{
ServerState.Installing => "status-primary",
ServerState.Offline => "status-error",
ServerState.Starting => "status-warning",
ServerState.Stopping => "status-warning",
ServerState.Online => "status-success",
_ => "status-secondary"
};
}
<div class="inline-grid *:[grid-area:1/1] me-3">
@if (State != ServerState.Offline)
{
<div class="status status-xl @statusClass animate-ping"></div>
}
<div class="status status-xl @statusClass"></div>
</div>
<div class="flex flex-col">
<div class="hidden sm:flex text-lg font-semibold">@Server.Name</div>
<div class="hidden text-sm text-base-content/60 md:flex gap-x-3">
<span>
<i class="icon-sparkles me-0.5 align-middle"></i>
<span class="align-middle">@Server.StarName</span>
</span>
<span>
<i class="icon-database me-0.5 align-middle"></i>
<span class="align-middle">@Server.NodeName</span>
</span>
</div>
</div>
</div>
<div class="flex flex-row items-center">
<div class="flex gap-x-1.5">
@if (HasPermissionTo("power", ServerPermissionLevel.ReadWrite))
{
@if (State == ServerState.Offline)
{
<WButton CssClasses="btn btn-success" OnClick="_ => StartAsync()">
<i class="icon-play align-middle"></i>
<span class="align-middle">Start</span>
</WButton>
}
else
{
<button type="button" class="btn btn-success" disabled="disabled">
<i class="icon-play align-middle"></i>
<span class="align-middle">Start</span>
</button>
}
@if (State == ServerState.Online)
{
<button type="button" class="btn btn-primary">
<i class="icon-rotate-ccw align-middle"></i>
<span class="align-middle">Restart</span>
</button>
}
else
{
<button type="button" class="btn btn-primary" disabled="disabled">
<i class="icon-rotate-ccw align-middle"></i>
<span class="align-middle">Restart</span>
</button>
}
@if (State == ServerState.Starting || State == ServerState.Online || State == ServerState.Stopping)
{
if (State == ServerState.Stopping)
{
<WButton CssClasses="btn btn-error" OnClick="_ => KillAsync()">
<i class="icon-bomb align-middle"></i>
<span class="align-middle">Kill</span>
</WButton>
}
else
{
<WButton CssClasses="btn btn-error" OnClick="_ => StopAsync()">
<i class="icon-squircle align-middle"></i>
<span class="align-middle">Stop</span>
</WButton>
}
}
else
{
<button type="button" class="btn btn-error" disabled="disabled">
<i class="icon-squircle align-middle"></i>
<span class="align-middle">Stop</span>
</button>
}
}
else
{
<button type="button" class="btn btn-success" disabled="disabled">
<i class="icon-play align-middle"></i>
<span class="align-middle">Start</span>
</button>
<button type="button" class="btn btn-primary" disabled="disabled">
<i class="icon-rotate-ccw align-middle"></i>
<span class="align-middle">Restart</span>
</button>
<button type="button" class="btn btn-error" disabled="disabled">
<i class="icon-squircle align-middle"></i>
<span class="align-middle">Stop</span>
</button>
}
</div>
</div>
</div>
<div class="mt-3">
<nav class="tabs space-x-2 overflow-x-auto" aria-label="Tabs" role="tablist" aria-orientation="horizontal">
@foreach (var tab in Tabs)
{
<a href="/servers/@(ServerId)/@(tab.Path)"
class="btn btn-text active-tab:bg-primary active-tab:text-primary-content hover:text-primary hover:bg-primary/20 bg-base-150 text-sm py-0.5 px-3 rounded-xl @(tab == CurrentTab ? "active" : "")"
data-tab="na"
role="tab"
@onclick:preventDefault
@onclick="() => SwitchTabAsync(tab)">
@tab.Name
</a>
}
</nav>
<div class="mt-5">
@if (CurrentTab == null)
{
<IconAlert Title="No tabs found" Color="text-primary" Icon="icon-app-window">
Seems like you are missing access to all tabs or no tabs for this server could be found
</IconAlert>
}
else
{
var rf = ComponentHelper.FromType(CurrentTab!.ComponentType, parameters =>
{
parameters.Add("Server", Server);
parameters.Add("State", State);
parameters.Add("InitialConsoleMessage", InitialConsoleMessage);
parameters.Add("HubConnection", HubConnection!);
parameters.Add("Parent", this);
});
@rf
}
</div>
</div>
}
</LazyLoader>
@code
{
[Parameter] public int ServerId { get; set; }
[Parameter] public string? TabPath { get; set; }
private ServerTab[] Tabs;
private ServerTab? CurrentTab;
private ServerDetailResponse Server;
private bool NotFound = false;
private ServerState State;
private string InitialConsoleMessage = "";
private HubConnection? HubConnection;
public ConcurrentList<string> CommandHistory = new();
private async Task LoadAsync(LazyLoader _)
{
try
{
// Load meta data
Server = await ServerService.GetServerAsync(ServerId);
// Load server tabs
var tmpTabs = new List<ServerTab>();
foreach (var serverTabProvider in TabProviders)
tmpTabs.AddRange(await serverTabProvider.GetTabsAsync(Server));
// If we are accessing a shared server, we need to handle permissions
if (Server.Share != null)
{
// This removes all tabs where the user doesn't have the required permissions
tmpTabs.RemoveAll(tab =>
{
if (string.IsNullOrEmpty(tab.PermissionId) || tab.PermissionLevel == ServerPermissionLevel.None)
return false;
// If permission is required but not set, we don't have access to it
if (!Server.Share.Permissions.TryGetValue(tab.PermissionId, out var level))
return true;
// False if the acquired level is higher or equal than the required permission level for the tab so it won't get removed
return level < tab.PermissionLevel;
});
}
Tabs = tmpTabs.OrderBy(x => x.Priority).ToArray();
// Find current tab
if (!string.IsNullOrEmpty(TabPath))
{
CurrentTab = Tabs.FirstOrDefault(x => TabPath.Equals(x.Path, StringComparison.InvariantCultureIgnoreCase)
);
}
if (CurrentTab == null)
CurrentTab = Tabs.FirstOrDefault();
// Load initial status for first render
var status = await ServerService.GetStatusAsync(ServerId);
State = status.State;
if (!HasPermissionTo("console", ServerPermissionLevel.Read))
return; // Exit early if we don't have permissions to load the console
// Load initial messages
var initialLogs = await ServerService.GetLogsAsync(ServerId);
InitialConsoleMessage = "";
foreach (var message in initialLogs.Messages)
InitialConsoleMessage += message;
// Load websocket meta
var websocketDetails = await ServerService.GetWebSocketAsync(ServerId);
// Build signal r
HubConnection = new HubConnectionBuilder()
.WithUrl(websocketDetails.Target, options =>
{
options.AccessTokenProvider = async () =>
{
var details = await ServerService.GetWebSocketAsync(ServerId);
return details.AccessToken;
};
})
.WithAutomaticReconnect()
.Build();
// Define handlers
HubConnection.On<string>("StateChanged", async stateStr =>
{
if (!Enum.TryParse(stateStr, out ServerState receivedState))
return;
State = receivedState;
await InvokeAsync(StateHasChanged);
});
HubConnection.On<string>("ConsoleOutput", async content =>
{
// Update initial message
InitialConsoleMessage += content;
await InvokeAsync(StateHasChanged);
});
// Connect
await HubConnection.StartAsync();
}
catch (HttpApiException e)
{
if (e.Status == 404)
NotFound = true;
else
throw;
}
}
private bool HasPermissionTo(string id, ServerPermissionLevel level)
{
// All non shares have permissions
if (Server.Share == null)
return true;
if (!Server.Share.Permissions.TryGetValue(id, out var acquiredLevel))
return false;
return acquiredLevel >= level;
}
private async Task SwitchTabAsync(ServerTab tab)
{
CurrentTab = tab;
Navigation.NavigateTo($"/servers/{ServerId}/{tab.Path}");
await InvokeAsync(StateHasChanged);
}
private async Task StartAsync()
=> await ServerService.StartAsync(ServerId);
private async Task StopAsync()
=> await ServerService.StopAsync(ServerId);
private async Task KillAsync()
=> await ServerService.KillAsync(ServerId);
public async ValueTask DisposeAsync()
{
if (HubConnection != null)
{
if (HubConnection.State == HubConnectionState.Connected)
await HubConnection.StopAsync();
await HubConnection.DisposeAsync();
}
}
}

View File

@@ -0,0 +1,43 @@
@page "/demo"
@using LucideBlazor
@using MoonlightServers.Frontend.UI.Components
@using ShadcnBlazor.Buttons
@using ShadcnBlazor.Cards
@using ShadcnBlazor.Extras.Dialogs
@inject DialogService DialogService
<div class="grid grid-cols-1 lg:grid-cols-2 gap-5">
<Card ClassName="col-span-1">
<CardHeader>
<CardTitle>Demo</CardTitle>
<CardDescription>A cool demo page</CardDescription>
</CardHeader>
<CardContent>
You successfully used the plugin template to create your moonlight plugin :)
</CardContent>
<CardFooter>
<Button>
<Slot>
<a @attributes="context" href="https://moonlightpa.nl/dev">
<ExternalLinkIcon/>
Visit documentation
</a>
</Slot>
</Button>
</CardFooter>
</Card>
<Card>
<CardContent>
<Button @onclick="LaunchFormAsync" Variant="ButtonVariant.Outline">
Open Form
</Button>
</CardContent>
</Card>
</div>
@code
{
private async Task LaunchFormAsync()
=> await DialogService.LaunchAsync<FormDialog>();
}

View File

@@ -1,6 +1,6 @@
@using System.Net.Http
@using Microsoft.AspNetCore.Authorization
@using System.Net.Http
@using System.Net.Http.Json
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@using Microsoft.AspNetCore.Components.Web.Virtualization

View File

@@ -1,7 +0,0 @@
namespace MoonlightServers.Frontend;
public static class UiConstants
{
public static readonly string[] AdminNavNames = ["Overview", "Servers", "Nodes", "Stars", "Manager"];
public static readonly string[] AdminNavLinks = ["/admin/servers", "/admin/servers/all", "/admin/servers/nodes", "/admin/servers/stars", "/admin/servers/manager"];
}

View File

@@ -1 +0,0 @@
.xterm{cursor:text;position:relative;user-select:none;-ms-user-select:none;-webkit-user-select:none}.xterm.focus,.xterm:focus{outline:none}.xterm .xterm-helpers{position:absolute;top:0;z-index:5}.xterm .xterm-helper-textarea{border:0;height:0;left:-9999em;margin:0;opacity:0;overflow:hidden;padding:0;position:absolute;resize:none;top:0;white-space:nowrap;width:0;z-index:-5}.xterm .composition-view{background:#000;color:#fff;display:none;position:absolute;white-space:nowrap;z-index:1}.xterm .composition-view.active{display:block}.xterm .xterm-viewport{background-color:#000;bottom:0;cursor:default;left:0;overflow-y:scroll;position:absolute;right:0;top:0}.xterm .xterm-screen{position:relative}.xterm .xterm-screen canvas{left:0;position:absolute;top:0}.xterm .xterm-scroll-area{visibility:hidden}.xterm-char-measure-element{display:inline-block;left:-9999em;line-height:normal;position:absolute;top:0;visibility:hidden}.xterm.enable-mouse-events{cursor:default}.xterm .xterm-cursor-pointer,.xterm.xterm-cursor-pointer{cursor:pointer}.xterm.column-select.focus{cursor:crosshair}.xterm .xterm-accessibility:not(.debug),.xterm .xterm-message{bottom:0;color:transparent;left:0;pointer-events:none;position:absolute;right:0;top:0;z-index:10}.xterm .xterm-accessibility-tree:not(.debug) ::selection{color:transparent}.xterm .xterm-accessibility-tree{user-select:text;white-space:pre}.xterm .live-region{height:1px;left:-9999px;overflow:hidden;position:absolute;width:1px}.xterm-dim{opacity:1!important}.xterm-underline-1{text-decoration:underline}.xterm-underline-2{text-decoration:double underline}.xterm-underline-3{text-decoration:wavy underline}.xterm-underline-4{text-decoration:dotted underline}.xterm-underline-5{text-decoration:dashed underline}.xterm-overline{text-decoration:overline}.xterm-overline.xterm-underline-1{text-decoration:overline underline}.xterm-overline.xterm-underline-2{text-decoration:overline double underline}.xterm-overline.xterm-underline-3{text-decoration:overline wavy underline}.xterm-overline.xterm-underline-4{text-decoration:overline dotted underline}.xterm-overline.xterm-underline-5{text-decoration:overline dashed underline}.xterm-strikethrough{text-decoration:line-through}.xterm-screen .xterm-decoration-container .xterm-decoration{position:absolute;z-index:6}.xterm-screen .xterm-decoration-container .xterm-decoration.xterm-decoration-top-layer{z-index:7}.xterm-decoration-overview-ruler{pointer-events:none;position:absolute;right:0;top:0;z-index:8}.xterm-decoration-top{position:relative;z-index:2}

File diff suppressed because one or more lines are too long

View File

@@ -1,2 +0,0 @@
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.FitAddon=t():e.FitAddon=t()}(self,(()=>(()=>{"use strict";var e={};return(()=>{var t=e;Object.defineProperty(t,"__esModule",{value:!0}),t.FitAddon=void 0,t.FitAddon=class{activate(e){this._terminal=e}dispose(){}fit(){const e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;const t=this._terminal._core;this._terminal.rows===e.rows&&this._terminal.cols===e.cols||(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}proposeDimensions(){if(!this._terminal)return;if(!this._terminal.element||!this._terminal.element.parentElement)return;const e=this._terminal._core,t=e._renderService.dimensions;if(0===t.css.cell.width||0===t.css.cell.height)return;const r=0===this._terminal.options.scrollback?0:e.viewport.scrollBarWidth,i=window.getComputedStyle(this._terminal.element.parentElement),o=parseInt(i.getPropertyValue("height")),s=Math.max(0,parseInt(i.getPropertyValue("width"))),n=window.getComputedStyle(this._terminal.element),l=o-(parseInt(n.getPropertyValue("padding-top"))+parseInt(n.getPropertyValue("padding-bottom"))),a=s-(parseInt(n.getPropertyValue("padding-right"))+parseInt(n.getPropertyValue("padding-left")))-r;return{cols:Math.max(2,Math.floor(a/t.css.cell.width)),rows:Math.max(1,Math.floor(l/t.css.cell.height))}}}})(),e})()));
//# sourceMappingURL=addon-fit.js.map

View File

@@ -1,11 +0,0 @@
window.moonlightServers = {
loadAddons: function () {
if(window.moonlightServers.consoleAddonsLoaded)
return;
window.moonlightServers.consoleAddonsLoaded = true;
XtermBlazor.registerAddons({"addon-fit": new FitAddon.FitAddon()});
}
}
window.moonlightServers.consoleAddonsLoaded = false;