Files
Moonlight/Moonlight/Shared/Views/Admin/Sys/AuditLog.razor
2023-03-06 02:21:23 +01:00

106 lines
3.6 KiB
Plaintext

@page "/admin/system/auditlog"
@using Moonlight.Shared.Components.Navigations
@using Moonlight.App.Repositories.LogEntries
@using Moonlight.App.Services
@using Moonlight.App.Database.Entities.LogsEntries
@using BlazorTable
@using Moonlight.App.Helpers
@using Moonlight.App.Models.Misc
@using Moonlight.Shared.Components.AuditLogEntrys
@inject AuditLogEntryRepository AuditLogEntryRepository
<OnlyAdmin>
<AdminSystemNavigation Index="1"/>
<div class="card">
<div class="card-header card-header-stretch">
<div class="card-title d-flex align-items-center">
<span class="me-3 lh-0">
<i class="bx bx-md bx-calendar"></i>
</span>
<h3 class="fw-bold m-0 text-gray-800">@(Formatter.FormatDateOnly(DateTime))</h3>
</div>
<div class="card-toolbar m-0">
<ul class="nav nav-tabs nav-line-tabs nav-stretch fs-6 border-0 fw-bold">
<li class="nav-item">
<button @onclick="Left" class="nav-link justify-content-center text-active-gray-800">
<i class="bx bx-md bx-left-arrow"></i>
</button>
</li>
<li class="nav-item">
<button @onclick="Right" class="nav-link justify-content-center text-active-gray-800">
<i class="bx bx-md bx-right-arrow"></i>
</button>
</li>
</ul>
</div>
</div>
<div class="card-body">
<LazyLoader @ref="LazyLoader" Load="Load">
@if (AuditLogEntries.Any())
{
<div class="timeline">
@foreach (var entry in AuditLogEntries)
{
switch (entry.Type)
{
case AuditLogType.Login:
<AuditLogEntryLogin Entry="entry"/>
break;
case AuditLogType.Register:
<AuditLogEntryRegister Entry="entry"/>
break;
case AuditLogType.ChangePassword:
<AuditLogEntryChangePassword Entry="entry"/>
break;
case AuditLogType.ChangePowerState:
<AuditLogEntryChangePowerState Entry="entry"/>
break;
}
}
</div>
}
else
{
<div class="alert alert-primary">
<TL>No records found for this day</TL>
</div>
}
</LazyLoader>
</div>
</div>
</OnlyAdmin>
@code
{
private AuditLogEntry[] AuditLogEntries;
private LazyLoader LazyLoader;
private DateTime DateTime = DateTime.Today;
private Task Load(LazyLoader arg)
{
AuditLogEntries = AuditLogEntryRepository
.Get()
.Where(x => x.CreatedAt.Date == DateTime.Date)
.OrderByDescending(x => x.Id)
.ToArray();
return Task.CompletedTask;
}
private async Task Left()
{
DateTime = DateTime.AddDays(1);
await LazyLoader.Reload();
}
private async Task Right()
{
DateTime = DateTime.AddDays(-1);
await LazyLoader.Reload();
}
}