Cleaned up diagnose system. Fixed smaller inconsistencies

This commit is contained in:
2025-05-17 19:38:36 +02:00
parent f87e4a0800
commit 255bfba9e3
7 changed files with 153 additions and 114 deletions

View File

@@ -2,8 +2,8 @@
@using MoonCore.Attributes
@using MoonCore.Helpers
@using Moonlight.Shared.Http.Requests.Admin.Sys
@using Moonlight.Shared.Http.Responses.Admin.Sys
@using Moonlight.Shared.Misc
@attribute [RequirePermission("admin.system.diagnose")]
@@ -11,7 +11,7 @@
@inject DownloadService DownloadService
<div class="mb-5">
<NavTabs Index="5" Names="UiConstants.AdminNavNames" Links="UiConstants.AdminNavLinks" />
<NavTabs Index="5" Names="UiConstants.AdminNavNames" Links="UiConstants.AdminNavLinks"/>
</div>
<div class="grid grid-cols-2">
@@ -22,27 +22,43 @@
<div class="card-body">
<p>
If you're experiencing issues or need help via our Discord, you're in the right place here!
By pressing the button below, Moonlight will run all available diagnostic checks and package the results into a
By pressing the button below, Moonlight will run all available diagnostic checks and package the results
into a
downloadable zip file.
The report includes useful information about your system, plugins, and environment, making it easier to identify problems or share with support.
The report includes useful information about your system, plugins, and environment, making it easier to
identify problems or share with support.
</p>
<WButton OnClick="GenerateDiagnose" CssClasses="btn btn-primary my-5">Generate diagnose</WButton>
<div>
<a class="text-primary cursor-pointer" @onclick:preventDefault @onclick="ToggleDropDown">Advanced <i class="icon-chevron-@(DropdownOpen ? "up" : "down")"></i></a>
<div class="text-sm">
<a class="text-primary cursor-pointer flex items-center" @onclick:preventDefault
@onclick="ToggleDropDown">
<span class="me-1.5">Advanced</span>
@if (DropdownOpen)
{
<i class="icon-chevron-up"></i>
}
else
{
<i class="icon-chevron-down"></i>
}
</a>
<div class="@(DropdownOpen ? "" : "hidden")">
<LazyLoader Load="Load">
<div class="mb-2 pb-2 pt-4 border-b border-white/5 flex items-center gap-3">
<input class="rounded" @bind="SelectAll" type="checkbox" id="selectall_checkbox"/>
<div class="mb-2 py-2 border-b border-gray-700 flex items-center gap-3">
<input id="selectall_checkbox" @bind="SelectAll" type="checkbox" class="form-checkbox">
<label for="selectall_checkbox">Select all</label>
</div>
@foreach (var item in AvailableProviders)
{
<div class="mt-1 flex gap-3 items-center">
<input class="rounded" type="checkbox" id="@(item.Key.Type + "_checkbox")" @bind="@AvailableProviders[item.Key]" />
<label for="@(item.Key.Type + "_checkbox")">@Formatter.ConvertCamelCaseToSpaces(item.Key.Name)</label>
<input class="form-checkbox" type="checkbox" id="@(item.Key.Type + "_checkbox")"
@bind="@AvailableProviders[item.Key]"/>
<label
for="@(item.Key.Type + "_checkbox")">@Formatter.ConvertCamelCaseToSpaces(item.Key.Name)</label>
</div>
}
</LazyLoader>
@@ -54,54 +70,51 @@
@code
{
private async Task GenerateDiagnose(WButton _)
{
string[] payload = [];
if (!SelectAll)
{
// filter the providers which have been selected if not all providers have been selected
payload = AvailableProviders
.Where(x => x.Value)
.Select(x => x.Key)
.Select(x => x.Type)
.ToArray();
}
var stream = await ApiClient.PostStream("api/admin/system/diagnose", payload);
await DownloadService.DownloadStream("diagnose.zip", stream);
}
private bool DropdownOpen = false;
private bool AllSelected = true;
private Dictionary<DiagnoseProvideResponse, bool> AvailableProviders;
private async Task ToggleDropDown()
{
DropdownOpen = !DropdownOpen;
await InvokeAsync(StateHasChanged);
}
private async Task Load(LazyLoader arg)
{
AvailableProviders = (await ApiClient.GetJson<DiagnoseProvideResponse[]>("api/admin/system/diagnose/available"))
.ToDictionary(x => x, _ => true);
}
private bool SelectAll
{
get => AvailableProviders.Values.All(v => v);
set
{
// flip every entry to the new value
var keys = AvailableProviders.Keys.ToList();
foreach (var k in keys)
{
foreach (var k in AvailableProviders.Keys)
AvailableProviders[k] = value;
}
}
}
private async Task Load(LazyLoader arg)
{
var providers = await ApiClient.GetJson<DiagnoseProvideResponse[]>(
"api/admin/system/diagnose/providers"
);
AvailableProviders = providers
.ToDictionary(x => x, _ => true);
}
private async Task GenerateDiagnose(WButton _)
{
var request = new GenerateDiagnoseRequest();
if (!SelectAll)
{
// filter the providers which have been selected if not all providers have been selected
request.Providers = AvailableProviders
.Where(x => x.Value)
.Select(x => x.Key.Type)
.ToArray();
}
var stream = await ApiClient.PostStream("api/admin/system/diagnose", request);
await DownloadService.DownloadStream("diagnose.zip", stream);
}
private async Task ToggleDropDown()
{
DropdownOpen = !DropdownOpen;
await InvokeAsync(StateHasChanged);
}
}