mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
Migrate filesystems chart to Blazor.Bootstrap.
This commit is contained in:
@@ -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>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@
|
||||
<Partitions/>
|
||||
</TabPanel>
|
||||
<TabPanel Name="filesystems">
|
||||
<!-- <Filesystems/>-->
|
||||
<Filesystems/>
|
||||
</TabPanel>
|
||||
<TabPanel Name="virtualMedias">
|
||||
<VirtualMedias/>
|
||||
|
||||
Reference in New Issue
Block a user