181 lines
6.9 KiB
Plaintext
181 lines
6.9 KiB
Plaintext
@page "/logs"
|
|
@using Microsoft.EntityFrameworkCore
|
|
@using TrafagSalesExporter.Data
|
|
@inject IDbContextFactory<AppDbContext> DbFactory
|
|
@inject ISnackbar Snackbar
|
|
@inject IDialogService DialogService
|
|
@inject TrafagSalesExporter.Services.IUiTextService UiText
|
|
|
|
<PageTitle>@T("Logs", "Logs")</PageTitle>
|
|
|
|
<MudText Typo="Typo.h4" Class="mb-4">@T("Export Logs", "Export Logs")</MudText>
|
|
|
|
<MudPaper Class="pa-4 mb-4" Elevation="1">
|
|
<MudStack Row AlignItems="AlignItems.Center" Spacing="3">
|
|
<MudSelect @bind-Value="_filterLand" Label="@T("Land", "Country")" Clearable Dense Style="max-width:200px;">
|
|
@foreach (var land in _availableLands)
|
|
{
|
|
<MudSelectItem Value="@land">@land</MudSelectItem>
|
|
}
|
|
</MudSelect>
|
|
<MudSelect @bind-Value="_filterStatus" Label="@T("Status", "Status")" Clearable Dense Style="max-width:150px;">
|
|
<MudSelectItem Value="@("OK")">OK</MudSelectItem>
|
|
<MudSelectItem Value="@("Error")">Error</MudSelectItem>
|
|
</MudSelect>
|
|
<MudDatePicker @bind-Date="_filterDate" Label="@T("Datum", "Date")" Clearable Dense Style="max-width:200px;" />
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="ApplyFilter"
|
|
StartIcon="@Icons.Material.Filled.FilterAlt">
|
|
@T("Filtern", "Filter")
|
|
</MudButton>
|
|
<MudSpacer />
|
|
<MudButton Variant="Variant.Outlined" Color="Color.Error" OnClick="DeleteOldLogs"
|
|
StartIcon="@Icons.Material.Filled.DeleteSweep">
|
|
@T("Alte Logs loeschen", "Delete old logs")
|
|
</MudButton>
|
|
</MudStack>
|
|
</MudPaper>
|
|
|
|
<MudTable Items="_logs" Dense Hover Striped Loading="_loading">
|
|
<HeaderContent>
|
|
<MudTh>@T("Zeitpunkt", "Timestamp")</MudTh>
|
|
<MudTh>@T("Land", "Country")</MudTh>
|
|
<MudTh>TSC</MudTh>
|
|
<MudTh>@T("Status", "Status")</MudTh>
|
|
<MudTh>@T("Zeilen", "Rows")</MudTh>
|
|
<MudTh>@T("Dauer", "Duration")</MudTh>
|
|
<MudTh>@T("Dateiname", "File name")</MudTh>
|
|
<MudTh>@T("Fehler", "Error")</MudTh>
|
|
</HeaderContent>
|
|
<RowTemplate>
|
|
<MudTd>@context.Timestamp.ToString("dd.MM.yyyy HH:mm:ss")</MudTd>
|
|
<MudTd>@context.Land</MudTd>
|
|
<MudTd>@context.TSC</MudTd>
|
|
<MudTd>
|
|
@if (context.Status == "OK")
|
|
{
|
|
<MudChip T="string" Size="Size.Small" Color="Color.Success">OK</MudChip>
|
|
}
|
|
else
|
|
{
|
|
<MudChip T="string" Size="Size.Small" Color="Color.Error">Error</MudChip>
|
|
}
|
|
</MudTd>
|
|
<MudTd>@context.RowCount.ToString("N0")</MudTd>
|
|
<MudTd>@($"{context.DurationSeconds:F1}s")</MudTd>
|
|
<MudTd>@context.FileName</MudTd>
|
|
<MudTd>
|
|
@if (!string.IsNullOrEmpty(context.ErrorMessage))
|
|
{
|
|
<MudTooltip Text="@context.ErrorMessage">
|
|
<MudText Typo="Typo.caption" Color="Color.Error" Style="max-width:300px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; display:block;">
|
|
@context.ErrorMessage
|
|
</MudText>
|
|
</MudTooltip>
|
|
}
|
|
</MudTd>
|
|
</RowTemplate>
|
|
</MudTable>
|
|
|
|
<MudText Typo="Typo.h5" Class="mt-6 mb-2">@T("Technische Logs", "Technical logs")</MudText>
|
|
|
|
<MudTable Items="_appLogs" Dense Hover Striped Loading="_loading">
|
|
<HeaderContent>
|
|
<MudTh>@T("Zeitpunkt", "Timestamp")</MudTh>
|
|
<MudTh>Level</MudTh>
|
|
<MudTh>@T("Kategorie", "Category")</MudTh>
|
|
<MudTh>@T("Land", "Country")</MudTh>
|
|
<MudTh>@T("Meldung", "Message")</MudTh>
|
|
<MudTh>Details</MudTh>
|
|
</HeaderContent>
|
|
<RowTemplate>
|
|
<MudTd>@context.Timestamp.ToString("dd.MM.yyyy HH:mm:ss")</MudTd>
|
|
<MudTd>@context.Level</MudTd>
|
|
<MudTd>@context.Category</MudTd>
|
|
<MudTd>@(string.IsNullOrWhiteSpace(context.Land) ? "-" : context.Land)</MudTd>
|
|
<MudTd>@context.Message</MudTd>
|
|
<MudTd>
|
|
@if (!string.IsNullOrWhiteSpace(context.Details))
|
|
{
|
|
<MudTooltip Text="@context.Details">
|
|
<MudText Typo="Typo.caption" Style="max-width:420px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; display:block;">
|
|
@context.Details
|
|
</MudText>
|
|
</MudTooltip>
|
|
}
|
|
</MudTd>
|
|
</RowTemplate>
|
|
</MudTable>
|
|
|
|
@code {
|
|
private List<ExportLog> _logs = new();
|
|
private List<AppEventLog> _appLogs = new();
|
|
private List<string> _availableLands = new();
|
|
private string? _filterLand;
|
|
private string? _filterStatus;
|
|
private DateTime? _filterDate;
|
|
private bool _loading = true;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
using var db = await DbFactory.CreateDbContextAsync();
|
|
_availableLands = await db.ExportLogs.Select(l => l.Land).Distinct().OrderBy(l => l).ToListAsync();
|
|
await LoadLogsAsync();
|
|
}
|
|
|
|
private async Task LoadLogsAsync()
|
|
{
|
|
_loading = true;
|
|
using var db = await DbFactory.CreateDbContextAsync();
|
|
IQueryable<ExportLog> query = db.ExportLogs.OrderByDescending(l => l.Timestamp);
|
|
|
|
if (!string.IsNullOrEmpty(_filterLand))
|
|
query = query.Where(l => l.Land == _filterLand);
|
|
|
|
if (!string.IsNullOrEmpty(_filterStatus))
|
|
query = query.Where(l => l.Status == _filterStatus);
|
|
|
|
if (_filterDate.HasValue)
|
|
query = query.Where(l => l.Timestamp.Date == _filterDate.Value.Date);
|
|
|
|
_logs = await query.Take(500).ToListAsync();
|
|
|
|
IQueryable<AppEventLog> appLogQuery = db.AppEventLogs.OrderByDescending(l => l.Timestamp);
|
|
|
|
if (!string.IsNullOrEmpty(_filterLand))
|
|
appLogQuery = appLogQuery.Where(l => l.Land == _filterLand);
|
|
|
|
if (_filterDate.HasValue)
|
|
appLogQuery = appLogQuery.Where(l => l.Timestamp.Date == _filterDate.Value.Date);
|
|
|
|
_appLogs = await appLogQuery.Take(500).ToListAsync();
|
|
_loading = false;
|
|
}
|
|
|
|
private async Task ApplyFilter()
|
|
{
|
|
await LoadLogsAsync();
|
|
}
|
|
|
|
private async Task DeleteOldLogs()
|
|
{
|
|
var result = await DialogService.ShowMessageBox(
|
|
T("Alte Logs loeschen", "Delete old logs"),
|
|
T("Logs aelter als 90 Tage loeschen?", "Delete logs older than 90 days?"),
|
|
yesText: T("Loeschen", "Delete"), cancelText: T("Abbrechen", "Cancel"));
|
|
|
|
if (result != true) return;
|
|
|
|
using var db = await DbFactory.CreateDbContextAsync();
|
|
var cutoff = DateTime.Now.AddDays(-90);
|
|
var oldLogs = await db.ExportLogs.Where(l => l.Timestamp < cutoff).ToListAsync();
|
|
db.ExportLogs.RemoveRange(oldLogs);
|
|
var count = await db.SaveChangesAsync();
|
|
await LoadLogsAsync();
|
|
Snackbar.Add(string.Format(T("{0} alte Logs geloescht", "{0} old logs deleted"), oldLogs.Count), Severity.Info);
|
|
}
|
|
}
|
|
|
|
@code {
|
|
private string T(string german, string english) => UiText.Text(german, english);
|
|
}
|