Skip to content

Commit

Permalink
PublicationsByPlatform module cleanup - use standard-table for consis…
Browse files Browse the repository at this point in the history
…tent table look, avoid static in LINQ for consistency, make ProcessRow a separate method, consolidate into a probably-too-clever LINQ statement
  • Loading branch information
adelikat committed Sep 28, 2024
1 parent dbc6836 commit 54bc520
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 29 deletions.
4 changes: 2 additions & 2 deletions TASVideos/WikiModules/PublicationsByPlatform.cshtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@model PublicationsByPlatform
<table>
<standard-table>
@foreach (var platform in Model.Platforms.OrderBy(res => res.DisplayName))
{
<tr>
Expand All @@ -11,4 +11,4 @@
}
</tr>
}
</table>
</standard-table>
55 changes: 28 additions & 27 deletions TASVideos/WikiModules/PublicationsByPlatform.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,39 @@ public async Task<IViewComponentResult> InvokeAsync(IList<string> groupings)
{
var extant = (await platforms.GetAll()).ToList();
List<IReadOnlyList<SystemsResponse>> rows = [];
void ProcessGroup(string groupStr)
rows.AddRange(groupings
.Select(groupStr => ProcessGroup(extant, groupStr))
.OfType<List<SystemsResponse>>());

Platforms = extant
.Select(sys => (sys.DisplayName, sys.Code))
.Concat(rows.Select(row => (
DisplayName: string.Join(" / ", row.Select(sys => sys.DisplayName)),
Code: string.Join("-", row.Select(sys => sys.Code))
)))
.OrderBy(tuple => tuple.DisplayName)
.ToArray();
PubClasses = await classes.GetAll();

return View();
}

private static List<SystemsResponse>? ProcessGroup(List<SystemsResponse> extant, string groupStr)
{
List<SystemsResponse> row = [];
foreach (var idStr in groupStr.Split('-'))
{
List<SystemsResponse> row = [];
foreach (var idStr in groupStr.Split('-'))
var found = extant.FirstOrDefault(sys => sys.Code.Equals(idStr, StringComparison.OrdinalIgnoreCase));
if (found is null)
{
var found = extant.FirstOrDefault(sys => sys.Code.Equals(idStr, StringComparison.OrdinalIgnoreCase));
if (found is null)
{
// ignore, TODO log?
return;
}

extant.Remove(found);
row.Add(found);
// ignore, TODO log?
return null;
}

rows.Add(row);
extant.Remove(found);
row.Add(found);
}

foreach (var groupStr in groupings)
{
ProcessGroup(groupStr);
}

Platforms = extant.Select(static sys => (sys.DisplayName, sys.Code))
.Concat(rows.Select(static row => (
DisplayName: string.Join(" / ", row.Select(static sys => sys.DisplayName)),
Code: string.Join("-", row.Select(static sys => sys.Code))
)))
.OrderBy(static tuple => tuple.DisplayName)
.ToArray();
PubClasses = await classes.GetAll();
return View();
return row;
}
}

0 comments on commit 54bc520

Please sign in to comment.