Files
Moonlight/Moonlight/Shared/Views/Admin/Servers/Cleanup/Index.razor
2023-04-03 00:25:41 +02:00

200 lines
8.3 KiB
Plaintext

@page "/admin/servers/cleanup"
@using Moonlight.App.Services
@using Logging.Net
@using Moonlight.App.Models.Misc
@using Moonlight.App.Services.LogServices
@inject CleanupService CleanupService
@inject AuditLogService AuditLogService
@implements IDisposable
<PageTitle>
<TL>Cleanup</TL>
</PageTitle>
<IsAdmin>
<div class="row g-5 g-xl-10 mb-5 mb-xl-10">
<div class="col-xl-3">
<div class="card card-flush bgi-no-repeat bgi-size-contain bgi-position-x-end h-xl-100" style="background-color: #170049;">
<div class="card-header pt-5 mb-3">
<div class="d-flex flex-center rounded-circle h-80px w-80px" style="border: 1px rgba(255, 255, 255, 0.4);background-color: #7239EA">
<i class="text-white bx bxs-skull bx-lg"></i>
</div>
</div>
<div class="card-body d-flex align-items-end mb-3">
<div class="d-flex align-items-center">
<span class="fs-4hx text-white fw-bold me-6">@(CleanupService.ServersCleaned)</span>
<div class="fw-bold fs-6 text-white">
<span class="d-block">
<TL>Servers</TL>
</span>
<span>
<TL>stopped</TL>
</span>
</div>
</div>
</div>
</div>
</div>
<div class="col-xl-3">
<div class="card card-flush bgi-no-repeat bgi-size-contain bgi-position-x-end h-xl-100" style="background-color: #170049;">
<div class="card-header pt-5 mb-3">
<div class="d-flex flex-center rounded-circle h-80px w-80px" style="border: 1px rgba(255, 255, 255, 0.4);background-color: #7239EA">
<i class="text-white bx bx-transfer bx-lg"></i>
</div>
</div>
<div class="card-body d-flex align-items-end mb-3">
<div class="d-flex align-items-center">
<span class="fs-4hx text-white fw-bold me-6">@(CleanupService.CleanupsPerformed)</span>
<div class="fw-bold fs-6 text-white">
<span class="d-block">
<TL>Cleanups</TL>
</span>
<span>
<TL>executed</TL>
</span>
</div>
</div>
</div>
</div>
</div>
<div class="col-xl-3">
<div class="card card-flush bgi-no-repeat bgi-size-contain bgi-position-x-end h-xl-100" style="background-color: #170049;">
<div class="card-header pt-5 mb-3">
<div class="d-flex flex-center rounded-circle h-80px w-80px" style="border: 1px rgba(255, 255, 255, 0.4);background-color: #7239EA">
<i class="text-white bx bx-rocket bx-lg"></i>
</div>
</div>
<div class="card-body d-flex align-items-end mb-3">
<div class="d-flex align-items-center">
<span class="fs-4hx text-white fw-bold me-6">@(CleanupService.ServersRunning)</span>
<div class="fw-bold fs-6 text-white">
<span class="d-block">
<TL>Used clanup</TL>
</span>
<span>
<TL>Servers</TL>
</span>
</div>
</div>
</div>
</div>
</div>
<div class="col-xl-3">
<div class="card card-flush bgi-no-repeat bgi-size-contain bgi-position-x-end h-xl-100" style="background-color: #170049;">
<div class="card-body d-flex align-items-end mb-3">
<div class="d-flex align-items-center">
<div class="mb-3">
<label class="form-label"><TL>Status</TL>: @(CleanupService.Status)</label>
<div class="progress">
<div class="progress-bar progress-bar-striped progress-bar-animated bg-primary" role="progressbar" aria-valuenow="@(CleanupService.PercentProgress)" aria-valuemin="0" aria-valuemax="100" style="width: @(CleanupService.PercentProgress)%"></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-xl-3">
<div class="card card-flush bgi-no-repeat bgi-size-contain bgi-position-x-end">
<div class="card-body mb-3">
<div class="align-items-top">
<div class="fw-bold fs-6 text-white">
<div class="row mb-3">
@if (CleanupService.IsRunning)
{
<button class="btn btn-primary disabled" disabled="">
<TL>Start</TL>
</button>
}
else
{
<button @onclick="Trigger" class="btn btn-primary">
<TL>Start</TL>
</button>
}
</div>
<div class="row mb-3">
@if (CleanupService.Activated)
{
<button class="btn btn-success disabled" disabled="">
<TL>Enable</TL>
</button>
}
else
{
<button @onclick="Enable" class="btn btn-success">
<TL>Enable</TL>
</button>
}
</div>
<div class="row">
@if (CleanupService.Activated)
{
<button @onclick="Disabled" class="btn btn-danger">
<TL>Disable</TL>
</button>
}
else
{
<button class="btn btn-danger disabled" disabled="">
<TL>Disable</TL>
</button>
}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</IsAdmin>
<NonAdmin>
<UnauthorizedAlert></UnauthorizedAlert>
</NonAdmin>
@code
{
protected async override Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
CleanupService.OnUpdated += OnUpdated;
}
}
private void OnUpdated(object? sender, EventArgs e)
{
Logger.Debug(CleanupService.PercentProgress);
InvokeAsync(StateHasChanged);
}
public void Dispose()
{
CleanupService.OnUpdated -= OnUpdated;
}
private void Enable()
{
CleanupService.Activated = true;
AuditLogService.Log(AuditLogType.CleanupEnabled, "The automatic cleanup has been activated");
InvokeAsync(StateHasChanged);
}
private void Disabled()
{
CleanupService.Activated = false;
AuditLogService.Log(AuditLogType.CleanupDisabled, "The automatic cleanup has been disabled");
InvokeAsync(StateHasChanged);
}
private async void Trigger()
{
await CleanupService.TriggerPerform();
await AuditLogService.Log(AuditLogType.CleanupTriggered, "The automatic cleanup has been manually triggered");
await InvokeAsync(StateHasChanged);
}
}