Add debug info section to webpage

This commit is contained in:
jvyden 2021-12-23 20:57:49 -05:00
commit 2cdd094e00
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
4 changed files with 57 additions and 5 deletions

View file

@ -5,5 +5,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers
public static class TimestampHelper
{
public static long Timestamp => (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
public static long TimestampMillis => (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds;
}
}

View file

@ -1,4 +1,5 @@
@using LBPUnion.ProjectLighthouse.Helpers
@using LBPUnion.ProjectLighthouse.Helpers.Extensions
@using LBPUnion.ProjectLighthouse.Types
@using LBPUnion.ProjectLighthouse.Types.Settings
@model LBPUnion.ProjectLighthouse.Pages.Layouts.BaseLayout
@ -26,6 +27,9 @@
}
Model.NavigationItemsRight.Add(new PageNavigationItem("Log out", "/logout", "user alternate slash")); // should always be last
}
Model.IsMobile = Model.Request.IsMobile();
long timeStarted = TimestampHelper.TimestampMillis;
}
<!DOCTYPE html>
@ -151,6 +155,44 @@
}
</div>
</div>
@if (ServerStatics.IsDebug)
{
<div class="ui red attached inverted segment">
<div class="ui container">
<button type="button" class="ui inverted button collapsible">
<b>Show/Hide Debug Info</b>
</button>
<div style="display:none">
<p>Model.IsMobile: @Model.IsMobile</p>
<p>Model.Title: @Model.Title</p>
<p>Model.Description: @Model.Description</p>
<p>Render time: ~@(TimestampHelper.TimestampMillis - timeStarted)ms</p>
</div>
</div>
</div>
<script>
const collapsible = document.getElementsByClassName("collapsible");
for (let i = 0; i < collapsible.length; i++)
{
collapsible[i].addEventListener("click", function()
{
this.classList.toggle("active");
const content = this.nextElementSibling;
if (content.style.display === "block")
{
content.style.display = "none";
}
else
{
content.style.display = "block";
}
});
}
</script>
}
</footer>
</div>
</body>

View file

@ -7,6 +7,13 @@ namespace LBPUnion.ProjectLighthouse.Pages.Layouts
{
public class BaseLayout : PageModel
{
public BaseLayout(Database database)
{
this.Database = database;
}
public bool IsMobile;
public readonly Database Database;
public readonly List<PageNavigationItem> NavigationItems = new()
@ -25,11 +32,6 @@ namespace LBPUnion.ProjectLighthouse.Pages.Layouts
private User? user;
public BaseLayout(Database database)
{
this.Database = database;
}
public new User? User {
get {
if (this.user != null) return this.user;

View file

@ -27,5 +27,11 @@ namespace LBPUnion.ProjectLighthouse.Types.Settings
}
public static bool IsUnitTesting => AppDomain.CurrentDomain.GetAssemblies().Any(assembly => assembly.FullName.StartsWith("xunit"));
#if DEBUG
public static readonly bool IsDebug = true;
#else
public static readonly bool IsDebug = false;
#endif
}
}