Services: Extract GenerateToolTipData() from GenerateToolTip()
All checks were successful
Test / Run tests (push) Successful in 1m35s

This commit is contained in:
2024-09-22 20:40:53 +02:00
parent dcec6f03fe
commit 7791d02979
5 changed files with 99 additions and 69 deletions

View File

@ -162,20 +162,13 @@ namespace Elwig.Services {
AddToolTipCell(grid, max == null ? "" : $"{max:N0} kg", row, 4, 1, bold, true);
}
public static async Task<(string, Grid)> GenerateToolTip(IQueryable<AreaCom> areaComs, int maxKgPerHa) {
var grid = new Grid();
grid.ColumnDefinitions.Add(new() { Width = new(10) });
grid.ColumnDefinitions.Add(new() { Width = new(60) });
grid.ColumnDefinitions.Add(new() { Width = new(80) });
grid.ColumnDefinitions.Add(new() { Width = new(80) });
grid.ColumnDefinitions.Add(new() { Width = new(80) });
AddToolTipCell(grid, "Lieferpflicht", 0, 3, 1, false, false, true);
AddToolTipCell(grid, "Lieferrecht", 0, 4, 1, false, false, true);
public static async Task<(string, (string?, string?, int, int?, int?)[])> GenerateToolTipData(IQueryable<AreaCom> areaComs, int maxKgPerHa) {
var grid = new List<(string?, string?, int, int?, int?)>();
var text = "-";
var area = await areaComs.SumAsync(p => p.Area);
text = $"{area:N0} m²";
AddToolTipRow(grid, 1, "Geb. Fläche", null, area, null, null);
grid.Add(("Geb. Fläche", null, area, null, null));
if (await areaComs.AnyAsync()) {
var attrGroups = await areaComs
@ -221,24 +214,38 @@ namespace Elwig.Services {
.ThenBy(g => g.SortId)
.ToListAsync();
int rowNum = 2;
if (noAttr.Count > 0) {
rowNum++;
AddToolTipRow(grid, rowNum++, null, null, noAttr.Sum(g => g.Area), noAttr.Sum(g => g.Min), noAttr.Sum(g => g.Max));
grid.Add((null, null, noAttr.Sum(g => g.Area), noAttr.Sum(g => g.Min), noAttr.Sum(g => g.Max)));
foreach (var g in noAttr) {
AddToolTipRow(grid, rowNum++, null, g.SortId, g.Area, g.Min, g.Max);
grid.Add((null, g.SortId, g.Area, g.Min, g.Max));
}
}
foreach (var attrG in attrGroups) {
rowNum++;
AddToolTipRow(grid, rowNum++, attrG.Attr, null, attrG.Area, attrG.Min, attrG.Max);
grid.Add((attrG.Attr, null, attrG.Area, attrG.Min, attrG.Max));
foreach (var g in groups.Where(g => g.Attr == attrG.Attr).OrderByDescending(g => g.Area).ThenBy(g => g.SortId)) {
AddToolTipRow(grid, rowNum++, null, g.SortId, g.Area, g.Min, g.Max);
grid.Add((null, g.SortId, g.Area, g.Min, g.Max));
}
}
}
return (text, grid);
return (text, grid.ToArray());
}
public static Grid GenerateToolTip((string?, string?, int, int?, int?)[] data) {
var grid = new Grid();
grid.ColumnDefinitions.Add(new() { Width = new(10) });
grid.ColumnDefinitions.Add(new() { Width = new(60) });
grid.ColumnDefinitions.Add(new() { Width = new(80) });
grid.ColumnDefinitions.Add(new() { Width = new(80) });
grid.ColumnDefinitions.Add(new() { Width = new(80) });
AddToolTipCell(grid, "Lieferpflicht", 0, 3, 1, false, false, true);
AddToolTipCell(grid, "Lieferrecht", 0, 4, 1, false, false, true);
int rowNum = 1;
foreach (var row in data) {
AddToolTipRow(grid, rowNum++, row.Item1, row.Item2, row.Item3, row.Item4, row.Item5);
if (rowNum == 2) rowNum++;
}
return grid;
}
}
}