Skip to content

Commit

Permalink
Add a diagnostics page that lists all system wiki pages needed by the…
Browse files Browse the repository at this point in the history
… site code and flag any that do not exist
  • Loading branch information
adelikat committed Jul 8, 2023
1 parent 48e8072 commit 17ebbd6
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
9 changes: 8 additions & 1 deletion TASVideos/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc.Rendering;
using System.Reflection;
using Microsoft.AspNetCore.Mvc.Rendering;

namespace TASVideos;

Expand Down Expand Up @@ -45,4 +46,10 @@ public static class SystemWiki
public const string WelcomeText = "System/WelcomeText";
public const string WikiEditHelp = "System/WikiEditHelp";
public const string WikiEditNote = "System/WikiEditNote";

public static readonly HashSet<string> Pages = typeof(SystemWiki)
.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)
.Where(fi => fi.IsLiteral && !fi.IsInitOnly)
.Select(fi => fi.GetRawConstantValue()?.ToString() ?? "")
.ToHashSet(StringComparer.InvariantCultureIgnoreCase);
}
1 change: 1 addition & 0 deletions TASVideos/Pages/Diagnostics/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<li><a asp-page="Logging">Logging</a></li>
<li><a asp-page="SendTweet">Send a Tweet</a></li>
<li><a asp-page="SendEmail">Send an Email</a></li>
<li><a asp-page="SystemPages">System Wiki Pages</a></li>
</ul>

<table class="table table-bordered table-striped">
Expand Down
29 changes: 29 additions & 0 deletions TASVideos/Pages/Diagnostics/SystemPages.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@page
@{ ViewData.SetTitle("System Wiki Pages Used By the Site Code"); }
@model SystemPagesModel
<ul>
<li><a asp-page="Index">Diagnostics</a></li>
</ul>
<label class="float-end">Total: @Model.SystemPages.Count</label>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Page Name</th>
<th>Exists</th>
</tr>
</thead>
<tbody>
@foreach (var p in Model.SystemPages.OrderBy(p => p.Exists).ThenBy(p => p.Name))
{
<tr>
<td>
<wiki-link page-name="@p.Name"></wiki-link>
<td>
<td>
<i condition="p.Exists" class="text-success fa fa-check"></i>
<i condition="!p.Exists" class="text-danger fa fa-exclamation"></i>
</td>
</tr>
}
</tbody>
</table>
30 changes: 30 additions & 0 deletions TASVideos/Pages/Diagnostics/SystemPages.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Microsoft.AspNetCore.Mvc;
using TASVideos.Core.Services.Wiki;
using TASVideos.Data.Entity;

namespace TASVideos.Pages.Diagnostics;

[RequirePermission(PermissionTo.SeeDiagnostics)]
public class SystemPagesModel : BasePageModel
{
private readonly IWikiPages _wikiPages;

public SystemPagesModel(IWikiPages wikiPages)
{
_wikiPages = wikiPages;
}

public record SystemPage(string Name, bool Exists);
public List<SystemPage> SystemPages { get; set; } = new List<SystemPage>();

public async Task<IActionResult> OnGet()
{
foreach (var page in SystemWiki.Pages)
{
var exists = await _wikiPages.Exists(page);
SystemPages.Add(new SystemPage(page, exists));
}

return Page();
}
}

0 comments on commit 17ebbd6

Please sign in to comment.