211 lines
7.6 KiB
Plaintext
211 lines
7.6 KiB
Plaintext
@page "/"
|
|
@page "/system/health"
|
|
@using System.Reflection
|
|
@using ErsatzTV.Application.Health
|
|
@using ErsatzTV.Core.Health
|
|
@using ErsatzTV.Core.Interfaces.GitHub
|
|
@using Microsoft.Extensions.Caching.Memory
|
|
@implements IDisposable
|
|
@inject IGitHubApiClient GitHubApiClient
|
|
@inject IMemoryCache MemoryCache
|
|
@inject IMediator Mediator
|
|
@inject SystemStartup SystemStartup;
|
|
|
|
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="pt-8">
|
|
@if (!SystemStartup.IsDatabaseReady)
|
|
{
|
|
<MudCard>
|
|
<MudCardHeader>
|
|
<CardHeaderContent>
|
|
<MudText Typo="Typo.h4">Database is initializing</MudText>
|
|
</CardHeaderContent>
|
|
</MudCardHeader>
|
|
<MudCardContent>
|
|
<MudText>Please wait, this may take a few minutes.</MudText>
|
|
<MudText>This page will automatically refresh when the database is ready.</MudText>
|
|
</MudCardContent>
|
|
<MudCardActions>
|
|
<MudProgressCircular Color="Color.Primary" Size="Size.Medium" Indeterminate="true"/>
|
|
</MudCardActions>
|
|
</MudCard>
|
|
}
|
|
else if (!SystemStartup.IsSearchIndexReady)
|
|
{
|
|
<MudCard>
|
|
<MudCardHeader>
|
|
<CardHeaderContent>
|
|
<MudText Typo="Typo.h4">Search Index is initializing</MudText>
|
|
</CardHeaderContent>
|
|
</MudCardHeader>
|
|
<MudCardContent>
|
|
<MudText>Please wait, this may take a few minutes.</MudText>
|
|
<MudText>This page will automatically refresh when the search index is ready.</MudText>
|
|
</MudCardContent>
|
|
<MudCardActions>
|
|
<MudProgressCircular Color="Color.Primary" Size="Size.Medium" Indeterminate="true"/>
|
|
</MudCardActions>
|
|
</MudCard>
|
|
}
|
|
else
|
|
{
|
|
<MudTable Hover="true"
|
|
Dense="true"
|
|
ServerData="@(new Func<TableState, CancellationToken, Task<TableData<HealthCheckResult>>>(ServerReload))"
|
|
@ref="_table">
|
|
<ToolBarContent>
|
|
<MudText Typo="Typo.h6">Health Checks</MudText>
|
|
</ToolBarContent>
|
|
<HeaderContent>
|
|
<MudTh>Check</MudTh>
|
|
<MudTh>Message</MudTh>
|
|
</HeaderContent>
|
|
<RowTemplate>
|
|
<MudTd DataLabel="Check">
|
|
<div style="align-items: center; display: flex; flex-direction: row;">
|
|
@if (context.Status == HealthCheckStatus.Fail)
|
|
{
|
|
<MudIcon Color="@Color.Error" Icon="@Icons.Material.Filled.Error"/>
|
|
}
|
|
else if (context.Status == HealthCheckStatus.Warning)
|
|
{
|
|
<MudIcon Color="@Color.Warning" Icon="@Icons.Material.Filled.Warning"/>
|
|
}
|
|
else if (context.Status == HealthCheckStatus.Info)
|
|
{
|
|
<MudIcon Color="@Color.Info" Icon="@Icons.Material.Filled.Info"/>
|
|
}
|
|
else
|
|
{
|
|
<MudIcon Color="@Color.Success" Icon="@Icons.Material.Filled.Check"/>
|
|
}
|
|
<div class="ml-2">@context.Title</div>
|
|
</div>
|
|
</MudTd>
|
|
<MudTd DataLabel="Message">
|
|
@if (context.Link.IsSome)
|
|
{
|
|
foreach (string link in context.Link)
|
|
{
|
|
<MudLink Href="@link">
|
|
@context.Message
|
|
</MudLink>
|
|
}
|
|
}
|
|
else
|
|
{
|
|
<MudText>
|
|
@context.Message
|
|
</MudText>
|
|
}
|
|
</MudTd>
|
|
</RowTemplate>
|
|
</MudTable>
|
|
<MudCard Class="mt-6" Style="max-height: 600px; overflow: auto">
|
|
<MudCardContent Class="release-notes mud-typography mud-typography-body1">
|
|
<MarkdownView Content="@_releaseNotes"/>
|
|
</MudCardContent>
|
|
</MudCard>
|
|
<MudText Class="mt-6">Full changelog is available on <MudLink Href="https://github.com/ErsatzTV/ErsatzTV/blob/main/CHANGELOG.md">GitHub</MudLink></MudText>
|
|
}
|
|
</MudContainer>
|
|
|
|
@code {
|
|
private readonly CancellationTokenSource _cts = new();
|
|
|
|
private string _releaseNotes;
|
|
private MudTable<HealthCheckResult> _table;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
SystemStartup.OnDatabaseReady += OnStartupProgress;
|
|
SystemStartup.OnSearchIndexReady += OnStartupProgress;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
SystemStartup.OnDatabaseReady -= OnStartupProgress;
|
|
SystemStartup.OnSearchIndexReady -= OnStartupProgress;
|
|
|
|
_cts.Cancel();
|
|
_cts.Dispose();
|
|
}
|
|
|
|
private async void OnStartupProgress(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// do nothing
|
|
}
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
try
|
|
{
|
|
if (MemoryCache.TryGetValue("Index.ReleaseNotesHtml", out string releaseNotesHtml))
|
|
{
|
|
_releaseNotes = releaseNotesHtml;
|
|
}
|
|
else
|
|
{
|
|
var assembly = Assembly.GetEntryAssembly();
|
|
if (assembly != null)
|
|
{
|
|
string version = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
|
|
if (version != null)
|
|
{
|
|
Either<BaseError, string> maybeNotes;
|
|
|
|
if (version != "develop")
|
|
{
|
|
string gitHubVersion = version.Split("-").Head();
|
|
if (!gitHubVersion.StartsWith("v"))
|
|
{
|
|
gitHubVersion = $"v{gitHubVersion}";
|
|
}
|
|
|
|
maybeNotes = await GitHubApiClient.GetReleaseNotes(gitHubVersion, _cts.Token);
|
|
foreach (string notes in maybeNotes.RightToSeq())
|
|
{
|
|
_releaseNotes = notes;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
maybeNotes = await GitHubApiClient.GetLatestReleaseNotes(_cts.Token);
|
|
foreach (string notes in maybeNotes.RightToSeq())
|
|
{
|
|
_releaseNotes = notes;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (_releaseNotes != null)
|
|
{
|
|
MemoryCache.Set("Index.ReleaseNotesHtml", _releaseNotes);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// ignore
|
|
}
|
|
}
|
|
|
|
private async Task<TableData<HealthCheckResult>> ServerReload(TableState state, CancellationToken cancellationToken)
|
|
{
|
|
List<HealthCheckResult> healthCheckResults = await Mediator.Send(new GetAllHealthCheckResults(), _cts.Token);
|
|
|
|
return new TableData<HealthCheckResult>
|
|
{
|
|
TotalItems = healthCheckResults.Count,
|
|
Items = healthCheckResults
|
|
};
|
|
}
|
|
|
|
} |