Skip to content

Commit dbc6836

Browse files
authored
Add [module:PublicationsByPlatform] (#1952)
1 parent 6ab3853 commit dbc6836

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

TASVideos.WikiEngine/ModuleNames.cs

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public static class ModuleNames
3838
public const string PlayerPointsTable = "playerpointstable";
3939
public const string PublicationHistory = "publicationhistory";
4040
public const string PublicationPoints = "publicationpoints";
41+
public const string PublicationsByPlatform = "publicationsbyplatform";
4142
public const string Screenshots = "screenshots";
4243
public const string SupportedMovieTypes = "supportedmovietypes";
4344
public const string TabularMovieList = "tabularmovielist";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@model PublicationsByPlatform
2+
<table>
3+
@foreach (var platform in Model.Platforms.OrderBy(res => res.DisplayName))
4+
{
5+
<tr>
6+
<td>@platform.DisplayName</td>
7+
<td><a href="/[email protected]">All Publications</a></td>
8+
@foreach (var pubClass in Model.PubClasses.OrderBy(t => t.Id))
9+
{
10+
<td><a href="/[email protected]@pubClass.Link">@pubClass.Name</a></td>
11+
}
12+
</tr>
13+
}
14+
</table>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using TASVideos.WikiEngine;
2+
3+
namespace TASVideos.WikiModules;
4+
5+
[WikiModule(ModuleNames.PublicationsByPlatform)]
6+
public class PublicationsByPlatform(IGameSystemService platforms, IClassService classes) : WikiViewComponent
7+
{
8+
public IReadOnlyList<(string DisplayName, string Code)> Platforms { get; private set; } = null!;
9+
10+
public IReadOnlyCollection<PublicationClass> PubClasses { get; set; } = null!;
11+
12+
public async Task<IViewComponentResult> InvokeAsync(IList<string> groupings)
13+
{
14+
var extant = (await platforms.GetAll()).ToList();
15+
List<IReadOnlyList<SystemsResponse>> rows = [];
16+
void ProcessGroup(string groupStr)
17+
{
18+
List<SystemsResponse> row = [];
19+
foreach (var idStr in groupStr.Split('-'))
20+
{
21+
var found = extant.FirstOrDefault(sys => sys.Code.Equals(idStr, StringComparison.OrdinalIgnoreCase));
22+
if (found is null)
23+
{
24+
// ignore, TODO log?
25+
return;
26+
}
27+
28+
extant.Remove(found);
29+
row.Add(found);
30+
}
31+
32+
rows.Add(row);
33+
}
34+
35+
foreach (var groupStr in groupings)
36+
{
37+
ProcessGroup(groupStr);
38+
}
39+
40+
Platforms = extant.Select(static sys => (sys.DisplayName, sys.Code))
41+
.Concat(rows.Select(static row => (
42+
DisplayName: string.Join(" / ", row.Select(static sys => sys.DisplayName)),
43+
Code: string.Join("-", row.Select(static sys => sys.Code))
44+
)))
45+
.OrderBy(static tuple => tuple.DisplayName)
46+
.ToArray();
47+
PubClasses = await classes.GetAll();
48+
return View();
49+
}
50+
}

0 commit comments

Comments
 (0)