Skip to content

Commit 54bc520

Browse files
committed
PublicationsByPlatform module cleanup - use standard-table for consistent table look, avoid static in LINQ for consistency, make ProcessRow a separate method, consolidate into a probably-too-clever LINQ statement
1 parent dbc6836 commit 54bc520

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

TASVideos/WikiModules/PublicationsByPlatform.cshtml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@model PublicationsByPlatform
2-
<table>
2+
<standard-table>
33
@foreach (var platform in Model.Platforms.OrderBy(res => res.DisplayName))
44
{
55
<tr>
@@ -11,4 +11,4 @@
1111
}
1212
</tr>
1313
}
14-
</table>
14+
</standard-table>

TASVideos/WikiModules/PublicationsByPlatform.cshtml.cs

+28-27
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,39 @@ public async Task<IViewComponentResult> InvokeAsync(IList<string> groupings)
1313
{
1414
var extant = (await platforms.GetAll()).ToList();
1515
List<IReadOnlyList<SystemsResponse>> rows = [];
16-
void ProcessGroup(string groupStr)
16+
rows.AddRange(groupings
17+
.Select(groupStr => ProcessGroup(extant, groupStr))
18+
.OfType<List<SystemsResponse>>());
19+
20+
Platforms = extant
21+
.Select(sys => (sys.DisplayName, sys.Code))
22+
.Concat(rows.Select(row => (
23+
DisplayName: string.Join(" / ", row.Select(sys => sys.DisplayName)),
24+
Code: string.Join("-", row.Select(sys => sys.Code))
25+
)))
26+
.OrderBy(tuple => tuple.DisplayName)
27+
.ToArray();
28+
PubClasses = await classes.GetAll();
29+
30+
return View();
31+
}
32+
33+
private static List<SystemsResponse>? ProcessGroup(List<SystemsResponse> extant, string groupStr)
34+
{
35+
List<SystemsResponse> row = [];
36+
foreach (var idStr in groupStr.Split('-'))
1737
{
18-
List<SystemsResponse> row = [];
19-
foreach (var idStr in groupStr.Split('-'))
38+
var found = extant.FirstOrDefault(sys => sys.Code.Equals(idStr, StringComparison.OrdinalIgnoreCase));
39+
if (found is null)
2040
{
21-
var found = extant.FirstOrDefault(sys => sys.Code.Equals(idStr, StringComparison.OrdinalIgnoreCase));
22-
if (found is null)
23-
{
24-
// ignore, TODO log?
25-
return;
26-
}
27-
28-
extant.Remove(found);
29-
row.Add(found);
41+
// ignore, TODO log?
42+
return null;
3043
}
3144

32-
rows.Add(row);
45+
extant.Remove(found);
46+
row.Add(found);
3347
}
3448

35-
foreach (var groupStr in groupings)
36-
{
37-
ProcessGroup(groupStr);
38-
}
39-
40-
Platforms = extant.Select(static sys => (sys.DisplayName, sys.Code))
41-
.Concat(rows.Select(static row => (
42-
DisplayName: string.Join(" / ", row.Select(static sys => sys.DisplayName)),
43-
Code: string.Join("-", row.Select(static sys => sys.Code))
44-
)))
45-
.OrderBy(static tuple => tuple.DisplayName)
46-
.ToArray();
47-
PubClasses = await classes.GetAll();
48-
return View();
49+
return row;
4950
}
5051
}

0 commit comments

Comments
 (0)