From 2ae437dd61ca14ca6166c0d255a65aa80a81ccac Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Wed, 31 Jul 2024 00:12:58 +1000 Subject: [PATCH] Add `[module:PublicationsByPlatform]` --- 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(); + } +}