From ef84bf1d500be29073c43606deaafcabbd169ed2 Mon Sep 17 00:00:00 2001 From: jvyden Date: Mon, 24 Jan 2022 13:40:39 -0500 Subject: [PATCH] Redesign the admin panel a little bit --- .../Website/Admin/AdminPanelController.cs | 13 --- .../Commands/TestWebhookCommand.cs | 22 ++++ .../Pages/Admin/AdminPanelPage.cshtml | 103 +++++++++--------- .../Pages/Admin/AdminPanelPage.cshtml.cs | 6 + .../AdminPanelStatisticPartial.cshtml | 17 +++ .../Types/AdminPanelStatistic.cs | 18 +++ 6 files changed, 116 insertions(+), 63 deletions(-) create mode 100644 ProjectLighthouse/Maintenance/Commands/TestWebhookCommand.cs create mode 100644 ProjectLighthouse/Pages/Partials/AdminPanelStatisticPartial.cshtml create mode 100644 ProjectLighthouse/Types/AdminPanelStatistic.cs diff --git a/ProjectLighthouse/Controllers/Website/Admin/AdminPanelController.cs b/ProjectLighthouse/Controllers/Website/Admin/AdminPanelController.cs index c7e0e31a..d736fd44 100644 --- a/ProjectLighthouse/Controllers/Website/Admin/AdminPanelController.cs +++ b/ProjectLighthouse/Controllers/Website/Admin/AdminPanelController.cs @@ -1,7 +1,4 @@ #nullable enable -using System.Threading.Tasks; -using LBPUnion.ProjectLighthouse.Helpers; -using LBPUnion.ProjectLighthouse.Types; using Microsoft.AspNetCore.Mvc; namespace LBPUnion.ProjectLighthouse.Controllers.Website.Admin; @@ -16,14 +13,4 @@ public class AdminPanelController : ControllerBase { this.database = database; } - - [HttpGet("testWebhook")] - public async Task TestWebhook() - { - User? user = this.database.UserFromWebRequest(this.Request); - if (user == null || !user.IsAdmin) return this.NotFound(); - - await WebhookHelper.SendWebhook("Testing 123", "Someone is testing the Discord webhook from the admin panel."); - return this.Redirect("/admin"); - } } \ No newline at end of file diff --git a/ProjectLighthouse/Maintenance/Commands/TestWebhookCommand.cs b/ProjectLighthouse/Maintenance/Commands/TestWebhookCommand.cs new file mode 100644 index 00000000..93ed05b5 --- /dev/null +++ b/ProjectLighthouse/Maintenance/Commands/TestWebhookCommand.cs @@ -0,0 +1,22 @@ +using System.Threading.Tasks; +using JetBrains.Annotations; +using LBPUnion.ProjectLighthouse.Helpers; + +namespace LBPUnion.ProjectLighthouse.Maintenance.Commands; + +[UsedImplicitly] +public class TestWebhookCommand : ICommand +{ + public async Task Run(string[] args) + { + await WebhookHelper.SendWebhook("Testing 123", "Someone is testing the Discord webhook from the admin panel."); + } + public string Name() => "Test Discord Webhook"; + public string[] Aliases() + => new[] + { + "testWebhook", "testDiscordWebhook", + }; + public string Arguments() => ""; + public int RequiredArgs() => 0; +} \ No newline at end of file diff --git a/ProjectLighthouse/Pages/Admin/AdminPanelPage.cshtml b/ProjectLighthouse/Pages/Admin/AdminPanelPage.cshtml index cb28e826..97228b43 100644 --- a/ProjectLighthouse/Pages/Admin/AdminPanelPage.cshtml +++ b/ProjectLighthouse/Pages/Admin/AdminPanelPage.cshtml @@ -1,7 +1,8 @@ @page "/admin" @using LBPUnion.ProjectLighthouse.Helpers +@using LBPUnion.ProjectLighthouse.Helpers.Extensions @using LBPUnion.ProjectLighthouse.Maintenance -@using LBPUnion.ProjectLighthouse.Types.Settings +@using LBPUnion.ProjectLighthouse.Types @model LBPUnion.ProjectLighthouse.Pages.Admin.AdminPanelPage @{ @@ -9,61 +10,63 @@ Model.Title = "Admin Panel"; } - -
- View Users -
-
-@if (ServerSettings.Instance.DiscordWebhookEnabled) +@if (!this.Request.IsMobile()) { - -
- Test Discord Webhook -
-
+
+ @foreach (AdminPanelStatistic statistic in Model.Statistics) + { + @await Html.PartialAsync("Partials/AdminPanelStatisticPartial", statistic) + } +
+
+} +else +{ + @foreach (AdminPanelStatistic statistic in Model.Statistics) + { + @await Html.PartialAsync("Partials/AdminPanelStatisticPartial", statistic) +
+ } }

Commands

-
- @foreach (ICommand command in MaintenanceHelper.Commands) - { -
-
-

@command.Name()

-
-
- -


- - -
-
-
- } -
+@foreach (ICommand command in MaintenanceHelper.Commands) +{ +
+

@command.Name()

+
+ @if (command.RequiredArgs() > 0) + { +
+ +
+
+
+ } + + +
+
+}

Maintenance Jobs

Warning: Interrupting Lighthouse during maintenance may leave the database in an unclean state.

-
- @foreach (IMaintenanceJob job in MaintenanceHelper.MaintenanceJobs) - { -
-
-

@job.Name()

-

@job.Description()

-
- - -
-
-
- } -
\ No newline at end of file +@foreach (IMaintenanceJob job in MaintenanceHelper.MaintenanceJobs) +{ +
+

@job.Name()

+

@job.Description()

+
+ + +
+
+} \ No newline at end of file diff --git a/ProjectLighthouse/Pages/Admin/AdminPanelPage.cshtml.cs b/ProjectLighthouse/Pages/Admin/AdminPanelPage.cshtml.cs index 4df3a805..92e5a5b0 100644 --- a/ProjectLighthouse/Pages/Admin/AdminPanelPage.cshtml.cs +++ b/ProjectLighthouse/Pages/Admin/AdminPanelPage.cshtml.cs @@ -15,12 +15,18 @@ public class AdminPanelPage : BaseLayout public AdminPanelPage(Database database) : base(database) {} + public List Statistics = new(); + public async Task OnGet([FromQuery] string? args, [FromQuery] string? command, [FromQuery] string? maintenanceJob) { User? user = this.Database.UserFromWebRequest(this.Request); if (user == null) return this.Redirect("~/login"); if (!user.IsAdmin) return this.NotFound(); + this.Statistics.Add(new AdminPanelStatistic("Users", await StatisticsHelper.UserCount(), "users")); + this.Statistics.Add(new AdminPanelStatistic("Slots", await StatisticsHelper.SlotCount())); + this.Statistics.Add(new AdminPanelStatistic("Photos", await StatisticsHelper.PhotoCount())); + if (!string.IsNullOrEmpty(command)) { args ??= ""; diff --git a/ProjectLighthouse/Pages/Partials/AdminPanelStatisticPartial.cshtml b/ProjectLighthouse/Pages/Partials/AdminPanelStatisticPartial.cshtml new file mode 100644 index 00000000..4acff434 --- /dev/null +++ b/ProjectLighthouse/Pages/Partials/AdminPanelStatisticPartial.cshtml @@ -0,0 +1,17 @@ +@model LBPUnion.ProjectLighthouse.Types.AdminPanelStatistic + +
+
+ @if (Model.ViewAllEndpoint != null) + { +

+ @Model.StatisticNamePlural +

+ } + else + { +

@Model.StatisticNamePlural

+ } +

@Model.Count

+
+
\ No newline at end of file diff --git a/ProjectLighthouse/Types/AdminPanelStatistic.cs b/ProjectLighthouse/Types/AdminPanelStatistic.cs new file mode 100644 index 00000000..eaa668a7 --- /dev/null +++ b/ProjectLighthouse/Types/AdminPanelStatistic.cs @@ -0,0 +1,18 @@ +#nullable enable + +namespace LBPUnion.ProjectLighthouse.Types; + +public struct AdminPanelStatistic +{ + public AdminPanelStatistic(string statisticNamePlural, int count, string? viewAllEndpoint = null) + { + this.StatisticNamePlural = statisticNamePlural; + this.Count = count; + this.ViewAllEndpoint = viewAllEndpoint; + } + + public readonly string StatisticNamePlural; + public readonly int Count; + + public readonly string? ViewAllEndpoint; +} \ No newline at end of file