Cleaned up using in project. Improved prohect structure and refactored page names. Upgraded dependencies
This commit is contained in:
220
Moonlight.Frontend/Admin/Sys/ContainerHelper/Index.razor
Normal file
220
Moonlight.Frontend/Admin/Sys/ContainerHelper/Index.razor
Normal file
@@ -0,0 +1,220 @@
|
||||
@using LucideBlazor
|
||||
@using Moonlight.Shared.Admin.Sys.ContainerHelper
|
||||
@using Moonlight.Shared.Admin.Sys.Versions
|
||||
@using ShadcnBlazor.Buttons
|
||||
@using ShadcnBlazor.Cards
|
||||
@using ShadcnBlazor.Emptys
|
||||
@using ShadcnBlazor.Extras.AlertDialogs
|
||||
@using ShadcnBlazor.Extras.Common
|
||||
@using ShadcnBlazor.Extras.Dialogs
|
||||
@using ShadcnBlazor.Fields
|
||||
@using ShadcnBlazor.Selects
|
||||
@using ShadcnBlazor.Switches
|
||||
@inject HttpClient HttpClient
|
||||
@inject DialogService DialogService
|
||||
@inject AlertDialogService AlertDialogService
|
||||
|
||||
<div class="mt-5">
|
||||
<LazyLoader Load="LoadAsync">
|
||||
@if (StatusDto.IsEnabled)
|
||||
{
|
||||
if (StatusDto.IsReachable)
|
||||
{
|
||||
<div class="grid grid-cols-1 lg:grid-cols-2 gap-5">
|
||||
<Card ClassName="col-span-1">
|
||||
<CardHeader>
|
||||
<CardTitle>Version</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<FieldGroup>
|
||||
<FieldSet>
|
||||
<Field>
|
||||
<FieldLabel>Version / Branch</FieldLabel>
|
||||
<FieldContent>
|
||||
<Select DefaultValue="@SelectedVersion" @bind-Value="SelectedVersion">
|
||||
<SelectTrigger ClassName="w-64">
|
||||
<SelectValue/>
|
||||
</SelectTrigger>
|
||||
<SelectContent ClassName="w-64">
|
||||
@foreach (var version in Versions)
|
||||
{
|
||||
var displayName = version.Identifier;
|
||||
|
||||
if (version.IsDevelopment)
|
||||
displayName += " (dev)";
|
||||
|
||||
if (version.IsPreRelease)
|
||||
displayName += " (beta)";
|
||||
|
||||
<SelectItem Value="@version.Identifier">
|
||||
@displayName
|
||||
</SelectItem>
|
||||
}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</FieldContent>
|
||||
</Field>
|
||||
<Field>
|
||||
<FieldLabel>Bypass Build Cache</FieldLabel>
|
||||
<FieldContent>
|
||||
<Switch @bind-Value="NoBuildCache"/>
|
||||
</FieldContent>
|
||||
</Field>
|
||||
</FieldSet>
|
||||
<Field Orientation="FieldOrientation.Horizontal">
|
||||
<Button @onclick="AskApplyAsync">Apply</Button>
|
||||
</Field>
|
||||
</FieldGroup>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card ClassName="col-span-1">
|
||||
<CardHeader>
|
||||
<CardTitle>Plugins</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Empty>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia Variant="EmptyMediaVariant.Icon">
|
||||
<SearchIcon/>
|
||||
</EmptyMedia>
|
||||
<EmptyTitle>No Plugins found</EmptyTitle>
|
||||
<EmptyDescription>
|
||||
No plugins found in instance configuration
|
||||
</EmptyDescription>
|
||||
</EmptyHeader>
|
||||
</Empty>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<Empty>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia Variant="EmptyMediaVariant.Icon">
|
||||
<CircleAlertIcon ClassName="text-red-500"/>
|
||||
</EmptyMedia>
|
||||
<EmptyTitle>Container Helper unreachable</EmptyTitle>
|
||||
<EmptyDescription>
|
||||
The container helper is unreachable. No management actions are available
|
||||
</EmptyDescription>
|
||||
</EmptyHeader>
|
||||
</Empty>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<Empty>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia Variant="EmptyMediaVariant.Icon">
|
||||
<ToggleLeftIcon/>
|
||||
</EmptyMedia>
|
||||
<EmptyTitle>Container Helper is disabled</EmptyTitle>
|
||||
<EmptyDescription>
|
||||
The container helper is disabled on this instance.
|
||||
This might be due to running a multiple container moonlight setup
|
||||
</EmptyDescription>
|
||||
</EmptyHeader>
|
||||
</Empty>
|
||||
}
|
||||
</LazyLoader>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
private string SelectedVersion = "v2.1";
|
||||
private bool NoBuildCache;
|
||||
|
||||
private ContainerHelperStatusDto StatusDto;
|
||||
private VersionDto[] Versions;
|
||||
|
||||
private async Task LoadAsync(LazyLoader _)
|
||||
{
|
||||
StatusDto = (await HttpClient.GetFromJsonAsync<ContainerHelperStatusDto>("api/admin/ch/status"))!;
|
||||
|
||||
var currentVersion = await HttpClient.GetFromJsonAsync<VersionDto>("api/admin/versions/instance");
|
||||
|
||||
if (currentVersion != null)
|
||||
SelectedVersion = currentVersion.Identifier;
|
||||
|
||||
Versions = (await HttpClient.GetFromJsonAsync<VersionDto[]>("api/admin/versions"))!;
|
||||
}
|
||||
|
||||
private async Task ApplyAsync()
|
||||
{
|
||||
await DialogService.LaunchAsync<UpdateInstanceModal>(
|
||||
parameters =>
|
||||
{
|
||||
parameters[nameof(UpdateInstanceModal.Version)] = SelectedVersion;
|
||||
parameters[nameof(UpdateInstanceModal.NoBuildCache)] = NoBuildCache;
|
||||
},
|
||||
model =>
|
||||
{
|
||||
model.ShowCloseButton = false;
|
||||
model.ClassName = "sm:max-w-4xl!";
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private async Task AskApplyAsync()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(SelectedVersion))
|
||||
return;
|
||||
|
||||
var version = Versions.First(x => x.Identifier == SelectedVersion);
|
||||
|
||||
var shouldContinue = await ConfirmRiskyVersionAsync(
|
||||
"Moonlight Rebuild",
|
||||
"If you continue the moonlight instance will become unavailable during the rebuild process. This will impact users on this instance"
|
||||
);
|
||||
|
||||
if (!shouldContinue)
|
||||
return;
|
||||
|
||||
if (version.IsDevelopment)
|
||||
{
|
||||
shouldContinue = await ConfirmRiskyVersionAsync(
|
||||
"Development Version",
|
||||
"You are about to install development a version. This can break your instance. Continue at your own risk"
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (version.IsPreRelease)
|
||||
{
|
||||
shouldContinue = await ConfirmRiskyVersionAsync(
|
||||
"Beta / Pre-Release Version",
|
||||
"You are about to install a version marked as pre-release / beta. This can break your instance. Continue at your own risk"
|
||||
);
|
||||
}
|
||||
else
|
||||
shouldContinue = true;
|
||||
}
|
||||
|
||||
if (!shouldContinue)
|
||||
return;
|
||||
|
||||
await ApplyAsync();
|
||||
}
|
||||
|
||||
private async Task<bool> ConfirmRiskyVersionAsync(string title, string message)
|
||||
{
|
||||
var tcs = new TaskCompletionSource();
|
||||
var confirmed = false;
|
||||
|
||||
await AlertDialogService.ConfirmDangerAsync(
|
||||
title,
|
||||
message,
|
||||
() =>
|
||||
{
|
||||
confirmed = true;
|
||||
tcs.SetResult();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
);
|
||||
|
||||
await tcs.Task;
|
||||
|
||||
return confirmed;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user