Migrate filesystems chart to Blazor.Bootstrap.

This commit is contained in:
2025-05-20 21:55:22 +01:00
parent d012a074a7
commit 6c5daf2c5a
3 changed files with 32 additions and 22 deletions

View File

@@ -1,6 +1,6 @@
@using Aaru.Server.Database
@using Aaru.Server.Database.Models
@using Blazorise.Charts
@using BlazorBootstrap
@using Blazorise.DataGrid
@rendermode InteractiveServer
@@ -10,7 +10,8 @@
<p class="text-center" style="color: deeppink;">All filesystems found...</p>
</h1>
<PieChart @ref="_filesystemsChart" style="padding: 40px" TItem="long"/>
<DataGrid Data="@FilesystemsList" FixedHeader FixedHeaderDataGridMaxHeight="300px" PageSize="int.MaxValue" TItem="Filesystem">
<DataGrid Data="@FilesystemsList" FixedHeader FixedHeaderDataGridMaxHeight="300px" PageSize="int.MaxValue"
TItem="Filesystem">
<DataGridColumn Caption="Filesystem name" Field="@nameof(Filesystem.Name)"/>
<DataGridNumericColumn Caption="Times found" Field="@nameof(Filesystem.Count)"/>
</DataGrid>

View File

@@ -1,5 +1,5 @@
using Aaru.Server.Database.Models;
using Blazorise.Charts;
using BlazorBootstrap;
using Microsoft.EntityFrameworkCore;
using DbContext = Aaru.Server.Database.DbContext;
@@ -7,9 +7,9 @@ namespace Aaru.Server.Components.Pages.Statistics;
public partial class Filesystems
{
PieChart<long>? _filesystemsChart;
List<long> _filesystemsCounts = [];
string[] _filesystemsLabels = [];
PieChart _filesystemsChart;
List<double?> _filesystemsCounts = [];
List<string> _filesystemsLabels = [];
bool _isAlreadyInitialized;
List<Filesystem> FilesystemsList { get; set; } = [];
@@ -34,31 +34,40 @@ public partial class Filesystems
_filesystemsLabels = await ctx.Filesystems.OrderByDescending(static o => o.Count)
.Take(10)
.Select(static v => v.Name)
.ToArrayAsync();
.ToListAsync();
_filesystemsCounts = await ctx.Filesystems.OrderByDescending(static o => o.Count)
.Take(10)
.Select(static x => x.Count)
.Select(static x => (double?)x.Count)
.ToListAsync();
if(_filesystemsLabels.Length >= 10)
if(_filesystemsLabels.Count >= 10)
{
_filesystemsLabels[9] = "Other";
_filesystemsCounts[9] = ctx.Filesystems.Sum(static o => o.Count) - _filesystemsCounts.Take(9).Sum();
}
#pragma warning disable CS8604 // Possible null reference argument.
await Common.HandleRedrawAsync(_filesystemsChart, _filesystemsLabels, GetFilesystemsChartDataset);
#pragma warning restore CS8604 // Possible null reference argument.
}
PieChartOptions pieChartOptions = new()
{
Responsive = true
};
PieChartDataset<long> GetFilesystemsChartDataset() => new()
{
Label = $"Top {_filesystemsLabels.Length} filesystems found",
Data = _filesystemsCounts,
BackgroundColor = Common.BackgroundColors,
BorderColor = Common.BorderColors,
BorderWidth = 1
};
pieChartOptions.Plugins.Title.Text = $"Top {_filesystemsLabels.Count} filesystems found";
pieChartOptions.Plugins.Title.Display = true;
var chartData = new ChartData
{
Labels = _filesystemsLabels,
Datasets =
[
new PieChartDataset
{
Data = _filesystemsCounts
}
]
};
await _filesystemsChart.InitializeAsync(chartData, pieChartOptions);
}
}

View File

@@ -39,7 +39,7 @@
<Partitions/>
</TabPanel>
<TabPanel Name="filesystems">
<!-- <Filesystems/>-->
<Filesystems/>
</TabPanel>
<TabPanel Name="virtualMedias">
<VirtualMedias/>