From dbc6836424c79ee9c2084938f11fa62e60ba0ba3 Mon Sep 17 00:00:00 2001 From: James Groom Date: Sun, 29 Sep 2024 00:27:44 +1000 Subject: [PATCH] Add `[module:PublicationsByPlatform]` (#1952) --- TASVideos.WikiEngine/ModuleNames.cs | 1 + .../WikiModules/PublicationsByPlatform.cshtml | 14 ++++++ .../PublicationsByPlatform.cshtml.cs | 50 +++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 TASVideos/WikiModules/PublicationsByPlatform.cshtml create mode 100644 TASVideos/WikiModules/PublicationsByPlatform.cshtml.cs diff --git a/TASVideos.WikiEngine/ModuleNames.cs b/TASVideos.WikiEngine/ModuleNames.cs index a6a45af9a..044985caf 100644 --- a/TASVideos.WikiEngine/ModuleNames.cs +++ b/TASVideos.WikiEngine/ModuleNames.cs @@ -38,6 +38,7 @@ public static class ModuleNames public const string PlayerPointsTable = "playerpointstable"; public const string PublicationHistory = "publicationhistory"; public const string PublicationPoints = "publicationpoints"; + public const string PublicationsByPlatform = "publicationsbyplatform"; public const string Screenshots = "screenshots"; public const string SupportedMovieTypes = "supportedmovietypes"; public const string TabularMovieList = "tabularmovielist"; diff --git a/TASVideos/WikiModules/PublicationsByPlatform.cshtml b/TASVideos/WikiModules/PublicationsByPlatform.cshtml new file mode 100644 index 000000000..c07c42e0d --- /dev/null +++ b/TASVideos/WikiModules/PublicationsByPlatform.cshtml @@ -0,0 +1,14 @@ +@model PublicationsByPlatform + + @foreach (var platform in Model.Platforms.OrderBy(res => res.DisplayName)) + { + + + + @foreach (var pubClass in Model.PubClasses.OrderBy(t => t.Id)) + { + + } + + } +
@platform.DisplayNameAll Publications@pubClass.Name
diff --git a/TASVideos/WikiModules/PublicationsByPlatform.cshtml.cs b/TASVideos/WikiModules/PublicationsByPlatform.cshtml.cs new file mode 100644 index 000000000..406bf4ce8 --- /dev/null +++ b/TASVideos/WikiModules/PublicationsByPlatform.cshtml.cs @@ -0,0 +1,50 @@ +using TASVideos.WikiEngine; + +namespace TASVideos.WikiModules; + +[WikiModule(ModuleNames.PublicationsByPlatform)] +public class PublicationsByPlatform(IGameSystemService platforms, IClassService classes) : WikiViewComponent +{ + public IReadOnlyList<(string DisplayName, string Code)> Platforms { get; private set; } = null!; + + public IReadOnlyCollection PubClasses { get; set; } = null!; + + public async Task InvokeAsync(IList groupings) + { + var extant = (await platforms.GetAll()).ToList(); + List> rows = []; + void ProcessGroup(string groupStr) + { + List row = []; + foreach (var idStr in groupStr.Split('-')) + { + 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); + } + + rows.Add(row); + } + + 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(); + } +}