From 54bc520f8ca12a40368f48c91c653bfd046d7e0b Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 28 Sep 2024 09:43:41 -0500 Subject: [PATCH] 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 --- .../WikiModules/PublicationsByPlatform.cshtml | 4 +- .../PublicationsByPlatform.cshtml.cs | 55 ++++++++++--------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/TASVideos/WikiModules/PublicationsByPlatform.cshtml b/TASVideos/WikiModules/PublicationsByPlatform.cshtml index c07c42e0d..9c9da4879 100644 --- a/TASVideos/WikiModules/PublicationsByPlatform.cshtml +++ b/TASVideos/WikiModules/PublicationsByPlatform.cshtml @@ -1,5 +1,5 @@ @model PublicationsByPlatform - + @foreach (var platform in Model.Platforms.OrderBy(res => res.DisplayName)) { @@ -11,4 +11,4 @@ } } -
+ diff --git a/TASVideos/WikiModules/PublicationsByPlatform.cshtml.cs b/TASVideos/WikiModules/PublicationsByPlatform.cshtml.cs index 406bf4ce8..0daa794d7 100644 --- a/TASVideos/WikiModules/PublicationsByPlatform.cshtml.cs +++ b/TASVideos/WikiModules/PublicationsByPlatform.cshtml.cs @@ -13,38 +13,39 @@ public async Task InvokeAsync(IList groupings) { var extant = (await platforms.GetAll()).ToList(); List> rows = []; - void ProcessGroup(string groupStr) + rows.AddRange(groupings + .Select(groupStr => ProcessGroup(extant, groupStr)) + .OfType>()); + + 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? ProcessGroup(List extant, string groupStr) + { + List row = []; + foreach (var idStr in groupStr.Split('-')) { - List 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; } }