Skip to content

Commit

Permalink
Add [module:PublicationsByPlatform]
Browse files Browse the repository at this point in the history
  • Loading branch information
YoshiRulz committed Sep 23, 2024
1 parent 6ab3853 commit 2ae437d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions TASVideos.WikiEngine/ModuleNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
14 changes: 14 additions & 0 deletions TASVideos/WikiModules/PublicationsByPlatform.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@model PublicationsByPlatform
<table>
@foreach (var platform in Model.Platforms.OrderBy(res => res.DisplayName))
{
<tr>
<td>@platform.DisplayName</td>
<td><a href="/[email protected]">All Publications</a></td>
@foreach (var pubClass in Model.PubClasses.OrderBy(t => t.Id))
{
<td><a href="/[email protected]@pubClass.Link">@pubClass.Name</a></td>
}
</tr>
}
</table>
50 changes: 50 additions & 0 deletions TASVideos/WikiModules/PublicationsByPlatform.cshtml.cs
Original file line number Diff line number Diff line change
@@ -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<PublicationClass> PubClasses { get; set; } = null!;

public async Task<IViewComponentResult> InvokeAsync(IList<string> groupings)
{
var extant = (await platforms.GetAll()).ToList();
List<IReadOnlyList<SystemsResponse>> rows = [];
void ProcessGroup(string groupStr)
{
List<SystemsResponse> 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();
}
}

0 comments on commit 2ae437d

Please sign in to comment.