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
|
||||||
@using Aaru.Server.Database.Models
|
@using Aaru.Server.Database.Models
|
||||||
@using Blazorise.Charts
|
@using BlazorBootstrap
|
||||||
@using Blazorise.DataGrid
|
@using Blazorise.DataGrid
|
||||||
@rendermode InteractiveServer
|
@rendermode InteractiveServer
|
||||||
|
|
||||||
@@ -10,7 +10,8 @@
|
|||||||
<p class="text-center" style="color: deeppink;">All filesystems found...</p>
|
<p class="text-center" style="color: deeppink;">All filesystems found...</p>
|
||||||
</h1>
|
</h1>
|
||||||
<PieChart @ref="_filesystemsChart" style="padding: 40px" TItem="long"/>
|
<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)"/>
|
<DataGridColumn Caption="Filesystem name" Field="@nameof(Filesystem.Name)"/>
|
||||||
<DataGridNumericColumn Caption="Times found" Field="@nameof(Filesystem.Count)"/>
|
<DataGridNumericColumn Caption="Times found" Field="@nameof(Filesystem.Count)"/>
|
||||||
</DataGrid>
|
</DataGrid>
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
using Aaru.Server.Database.Models;
|
using Aaru.Server.Database.Models;
|
||||||
using Blazorise.Charts;
|
using BlazorBootstrap;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using DbContext = Aaru.Server.Database.DbContext;
|
using DbContext = Aaru.Server.Database.DbContext;
|
||||||
|
|
||||||
@@ -7,9 +7,9 @@ namespace Aaru.Server.Components.Pages.Statistics;
|
|||||||
|
|
||||||
public partial class Filesystems
|
public partial class Filesystems
|
||||||
{
|
{
|
||||||
PieChart<long>? _filesystemsChart;
|
PieChart _filesystemsChart;
|
||||||
List<long> _filesystemsCounts = [];
|
List<double?> _filesystemsCounts = [];
|
||||||
string[] _filesystemsLabels = [];
|
List<string> _filesystemsLabels = [];
|
||||||
bool _isAlreadyInitialized;
|
bool _isAlreadyInitialized;
|
||||||
List<Filesystem> FilesystemsList { get; set; } = [];
|
List<Filesystem> FilesystemsList { get; set; } = [];
|
||||||
|
|
||||||
@@ -34,31 +34,40 @@ public partial class Filesystems
|
|||||||
_filesystemsLabels = await ctx.Filesystems.OrderByDescending(static o => o.Count)
|
_filesystemsLabels = await ctx.Filesystems.OrderByDescending(static o => o.Count)
|
||||||
.Take(10)
|
.Take(10)
|
||||||
.Select(static v => v.Name)
|
.Select(static v => v.Name)
|
||||||
.ToArrayAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
_filesystemsCounts = await ctx.Filesystems.OrderByDescending(static o => o.Count)
|
_filesystemsCounts = await ctx.Filesystems.OrderByDescending(static o => o.Count)
|
||||||
.Take(10)
|
.Take(10)
|
||||||
.Select(static x => x.Count)
|
.Select(static x => (double?)x.Count)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
if(_filesystemsLabels.Length >= 10)
|
if(_filesystemsLabels.Count >= 10)
|
||||||
{
|
{
|
||||||
_filesystemsLabels[9] = "Other";
|
_filesystemsLabels[9] = "Other";
|
||||||
|
|
||||||
_filesystemsCounts[9] = ctx.Filesystems.Sum(static o => o.Count) - _filesystemsCounts.Take(9).Sum();
|
_filesystemsCounts[9] = ctx.Filesystems.Sum(static o => o.Count) - _filesystemsCounts.Take(9).Sum();
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma warning disable CS8604 // Possible null reference argument.
|
PieChartOptions pieChartOptions = new()
|
||||||
await Common.HandleRedrawAsync(_filesystemsChart, _filesystemsLabels, GetFilesystemsChartDataset);
|
{
|
||||||
#pragma warning restore CS8604 // Possible null reference argument.
|
Responsive = true
|
||||||
}
|
};
|
||||||
|
|
||||||
PieChartDataset<long> GetFilesystemsChartDataset() => new()
|
pieChartOptions.Plugins.Title.Text = $"Top {_filesystemsLabels.Count} filesystems found";
|
||||||
{
|
pieChartOptions.Plugins.Title.Display = true;
|
||||||
Label = $"Top {_filesystemsLabels.Length} filesystems found",
|
|
||||||
Data = _filesystemsCounts,
|
var chartData = new ChartData
|
||||||
BackgroundColor = Common.BackgroundColors,
|
{
|
||||||
BorderColor = Common.BorderColors,
|
Labels = _filesystemsLabels,
|
||||||
BorderWidth = 1
|
Datasets =
|
||||||
};
|
[
|
||||||
|
new PieChartDataset
|
||||||
|
{
|
||||||
|
Data = _filesystemsCounts
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
await _filesystemsChart.InitializeAsync(chartData, pieChartOptions);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
<Partitions/>
|
<Partitions/>
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
<TabPanel Name="filesystems">
|
<TabPanel Name="filesystems">
|
||||||
<!-- <Filesystems/>-->
|
<Filesystems/>
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
<TabPanel Name="virtualMedias">
|
<TabPanel Name="virtualMedias">
|
||||||
<VirtualMedias/>
|
<VirtualMedias/>
|
||||||
|
|||||||
Reference in New Issue
Block a user