Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add [module:PublicationsByPlatform] #1952

Merged
merged 1 commit into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
YoshiRulz marked this conversation as resolved.
Show resolved Hide resolved
@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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this local function necessary here? It seems to be called only once, and it makes the entire method more difficult to parse and understand, because I have to keep going up and down to see what things are affected where.

Copy link
Collaborator Author

@YoshiRulz YoshiRulz Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's that or goto, since C# doesn't have multi-break.

edit: I considered having the method return a List<...>? and then conditionally appending to rows in the outer loop; do you think that would be better?

{
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();
}
}
Loading