mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
Add device statistics page with delete functionality for device stats
This commit is contained in:
@@ -26,6 +26,9 @@
|
|||||||
<NavLink class="nav-link" href="/admin/devices">
|
<NavLink class="nav-link" href="/admin/devices">
|
||||||
Device reports
|
Device reports
|
||||||
</NavLink>
|
</NavLink>
|
||||||
|
<NavLink class="nav-link" href="/admin/device-stats">
|
||||||
|
Device statistics
|
||||||
|
</NavLink>
|
||||||
<NavLink class="nav-link" href="/admin/filesystems">
|
<NavLink class="nav-link" href="/admin/filesystems">
|
||||||
Filesystems
|
Filesystems
|
||||||
</NavLink>
|
</NavLink>
|
||||||
|
|||||||
95
Aaru.Server/Components/Admin/Pages/DeviceStats/View.razor
Normal file
95
Aaru.Server/Components/Admin/Pages/DeviceStats/View.razor
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
@page "/admin/device-stats"
|
||||||
|
@attribute [Authorize]
|
||||||
|
@layout AdminLayout
|
||||||
|
@rendermode InteractiveServer
|
||||||
|
|
||||||
|
@inject Microsoft.EntityFrameworkCore.IDbContextFactory<DbContext> DbContextFactory
|
||||||
|
|
||||||
|
<PageTitle>Device statistics</PageTitle>
|
||||||
|
|
||||||
|
@if(!_initialized)
|
||||||
|
{
|
||||||
|
<div class="stats-section">
|
||||||
|
<h1 style="color: red; align-content: center; padding: 2rem">Loading...</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
<section class="stats-section">
|
||||||
|
<h4>Device statistics</h4>
|
||||||
|
<table class="table table-dark table-striped table-bordered mt-4 mb-4">
|
||||||
|
<thead class="thead-dark">
|
||||||
|
<tr>
|
||||||
|
<th class="fw-bold bg-secondary text-light">
|
||||||
|
@DisplayNameHelper.GetDisplayName(typeof(DeviceStat), nameof(DeviceStat.Manufacturer))
|
||||||
|
</th>
|
||||||
|
<th class="fw-bold bg-secondary text-light">
|
||||||
|
@DisplayNameHelper.GetDisplayName(typeof(DeviceStat), nameof(DeviceStat.Model))
|
||||||
|
</th>
|
||||||
|
<th class="fw-bold bg-secondary text-light">
|
||||||
|
@DisplayNameHelper.GetDisplayName(typeof(DeviceStat), nameof(DeviceStat.Revision))
|
||||||
|
</th>
|
||||||
|
<th class="fw-bold bg-secondary text-light">
|
||||||
|
@DisplayNameHelper.GetDisplayName(typeof(DeviceStat), nameof(DeviceStat.Bus))
|
||||||
|
</th>
|
||||||
|
<th class="fw-bold bg-secondary text-light">
|
||||||
|
Has report?
|
||||||
|
</th>
|
||||||
|
<th class="fw-bold bg-secondary text-light">
|
||||||
|
Actions
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach(DeviceStat item in _items)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
@item.Manufacturer
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@item.Model
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@item.Revision
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@item.Bus
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@if(item.Report is null)
|
||||||
|
{
|
||||||
|
@("No")
|
||||||
|
|
||||||
|
<a href="/admin/devices/find/@item.Id?bus=@item.Bus&manufacturer=@item.Manufacturer&model=@item.Model&revision=@item.Revision"
|
||||||
|
target="_blank">(Find)</a>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<a href="/admin/devices/@item.Report.Id" target="_blank">Yes</a>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a class="btn btn-secondary btn-sm" href="/admin/device-stats/edit/@item.Id">
|
||||||
|
<i class="bi bi-pencil"></i> Edit
|
||||||
|
</a>
|
||||||
|
<button class="btn btn-danger btn-sm" @onclick="async () => await ShowDeleteModal(item.Id)">
|
||||||
|
<i class="bi bi-trash"></i> Delete
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<BlazorBootstrap.Modal @ref="_deleteModal" Title="Delete Version" Size="ModalSize.Small">
|
||||||
|
<BodyTemplate>
|
||||||
|
<div class="text-danger">Are you sure you want to delete this device statistic?</div>
|
||||||
|
</BodyTemplate>
|
||||||
|
<FooterTemplate>
|
||||||
|
<button class="btn btn-secondary" @onclick="HideDeleteModal">Cancel</button>
|
||||||
|
<button class="btn btn-danger" @onclick="ConfirmDelete">Delete</button>
|
||||||
|
</FooterTemplate>
|
||||||
|
</BlazorBootstrap.Modal>
|
||||||
75
Aaru.Server/Components/Admin/Pages/DeviceStats/View.razor.cs
Normal file
75
Aaru.Server/Components/Admin/Pages/DeviceStats/View.razor.cs
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
using Aaru.Server.Database.Models;
|
||||||
|
using BlazorBootstrap;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using DbContext = Aaru.Server.Database.DbContext;
|
||||||
|
|
||||||
|
namespace Aaru.Server.Components.Admin.Pages.DeviceStats;
|
||||||
|
|
||||||
|
public partial class View
|
||||||
|
{
|
||||||
|
private int _deleteId;
|
||||||
|
private Modal? _deleteModal;
|
||||||
|
bool _initialized;
|
||||||
|
List<DeviceStat> _items;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
await base.OnInitializedAsync();
|
||||||
|
|
||||||
|
StateHasChanged();
|
||||||
|
|
||||||
|
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
|
||||||
|
|
||||||
|
_items = await ctx.DeviceStats.OrderBy(static d => d.Manufacturer)
|
||||||
|
.ThenBy(static d => d.Model)
|
||||||
|
.ThenBy(static d => d.Bus)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
_initialized = true;
|
||||||
|
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ShowDeleteModal(int id)
|
||||||
|
{
|
||||||
|
_deleteId = id;
|
||||||
|
if(_deleteModal != null) await _deleteModal.ShowAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task HideDeleteModal()
|
||||||
|
{
|
||||||
|
if(_deleteModal != null) await _deleteModal.HideAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ConfirmDelete()
|
||||||
|
{
|
||||||
|
await DeleteAsync(_deleteId);
|
||||||
|
await HideDeleteModal();
|
||||||
|
await RefreshItemsAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task DeleteAsync(int id)
|
||||||
|
{
|
||||||
|
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
|
||||||
|
DeviceStat? stat = await ctx.DeviceStats.FindAsync(id);
|
||||||
|
|
||||||
|
if(stat is not null)
|
||||||
|
{
|
||||||
|
ctx.DeviceStats.Remove(stat);
|
||||||
|
await ctx.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task RefreshItemsAsync()
|
||||||
|
{
|
||||||
|
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
|
||||||
|
|
||||||
|
_items = await ctx.DeviceStats.OrderBy(static d => d.Manufacturer)
|
||||||
|
.ThenBy(static d => d.Model)
|
||||||
|
.ThenBy(static d => d.Bus)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user