mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-01 01:38:39 +00:00
Redesign the admin panel a little bit
This commit is contained in:
parent
ef1e472ab0
commit
ef84bf1d50
6 changed files with 116 additions and 63 deletions
|
@ -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<IActionResult> 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");
|
||||
}
|
||||
}
|
22
ProjectLighthouse/Maintenance/Commands/TestWebhookCommand.cs
Normal file
22
ProjectLighthouse/Maintenance/Commands/TestWebhookCommand.cs
Normal file
|
@ -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;
|
||||
}
|
|
@ -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";
|
||||
}
|
||||
|
||||
<a href="/admin/users">
|
||||
<div class="ui blue button">
|
||||
View Users
|
||||
</div>
|
||||
</a>
|
||||
@if (ServerSettings.Instance.DiscordWebhookEnabled)
|
||||
@if (!this.Request.IsMobile())
|
||||
{
|
||||
<a href="/admin/testWebhook">
|
||||
<div class="ui blue button">
|
||||
Test Discord Webhook
|
||||
</div>
|
||||
</a>
|
||||
<div class="ui center aligned grid">
|
||||
@foreach (AdminPanelStatistic statistic in Model.Statistics)
|
||||
{
|
||||
@await Html.PartialAsync("Partials/AdminPanelStatisticPartial", statistic)
|
||||
}
|
||||
</div>
|
||||
<br>
|
||||
}
|
||||
else
|
||||
{
|
||||
@foreach (AdminPanelStatistic statistic in Model.Statistics)
|
||||
{
|
||||
@await Html.PartialAsync("Partials/AdminPanelStatisticPartial", statistic)
|
||||
<br>
|
||||
}
|
||||
}
|
||||
|
||||
<h2>Commands</h2>
|
||||
<div class="ui grid">
|
||||
@foreach (ICommand command in MaintenanceHelper.Commands)
|
||||
{
|
||||
<div class="four wide column">
|
||||
<div class="ui blue segment">
|
||||
<h3>@command.Name()</h3>
|
||||
<form>
|
||||
<div class="ui input" style="width: 100%;">
|
||||
<input type="text" name="args" placeholder="@command.Arguments()">
|
||||
</div><br><br>
|
||||
<input type="text" name="command" style="display: none;" value="@command.FirstAlias">
|
||||
<button type="submit" class="ui green button" style="width: 100%;">
|
||||
<i class="play icon"></i>
|
||||
Execute
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@foreach (ICommand command in MaintenanceHelper.Commands)
|
||||
{
|
||||
<div class="ui blue segment">
|
||||
<h3>@command.Name()</h3>
|
||||
<form>
|
||||
@if (command.RequiredArgs() > 0)
|
||||
{
|
||||
<div class="ui input" style="width: @(Model.Request.IsMobile() ? 100 : 30)%;">
|
||||
<input type="text" name="args" placeholder="@command.Arguments()">
|
||||
</div>
|
||||
<br>
|
||||
<br>
|
||||
}
|
||||
<input type="text" name="command" style="display: none;" value="@command.FirstAlias">
|
||||
<button type="submit" class="ui green button">
|
||||
<i class="play icon"></i>
|
||||
Execute
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
}
|
||||
<h2>Maintenance Jobs</h2>
|
||||
<p>
|
||||
<b>Warning: Interrupting Lighthouse during maintenance may leave the database in an unclean state.</b>
|
||||
</p>
|
||||
|
||||
<div class="ui grid">
|
||||
@foreach (IMaintenanceJob job in MaintenanceHelper.MaintenanceJobs)
|
||||
{
|
||||
<div class="four wide column">
|
||||
<div class="ui red segment">
|
||||
<h3>@job.Name()</h3>
|
||||
<p>@job.Description()</p>
|
||||
<form>
|
||||
<input type="text" name="maintenanceJob" style="display: none;" value="@job.GetType().Name">
|
||||
<button type="submit" class="ui green button" style="width: 100%;">
|
||||
<i class="play icon"></i>
|
||||
Execute
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@foreach (IMaintenanceJob job in MaintenanceHelper.MaintenanceJobs)
|
||||
{
|
||||
<div class="ui red segment">
|
||||
<h3>@job.Name()</h3>
|
||||
<p>@job.Description()</p>
|
||||
<form>
|
||||
<input type="text" name="maintenanceJob" style="display: none;" value="@job.GetType().Name">
|
||||
<button type="submit" class="ui green button">
|
||||
<i class="play icon"></i>
|
||||
Run Job
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
}
|
|
@ -15,12 +15,18 @@ public class AdminPanelPage : BaseLayout
|
|||
public AdminPanelPage(Database database) : base(database)
|
||||
{}
|
||||
|
||||
public List<AdminPanelStatistic> Statistics = new();
|
||||
|
||||
public async Task<IActionResult> 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 ??= "";
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
@model LBPUnion.ProjectLighthouse.Types.AdminPanelStatistic
|
||||
|
||||
<div class="three wide column">
|
||||
<div class="ui center aligned blue segment">
|
||||
@if (Model.ViewAllEndpoint != null)
|
||||
{
|
||||
<h2>
|
||||
<a href="/admin/@Model.ViewAllEndpoint">@Model.StatisticNamePlural</a>
|
||||
</h2>
|
||||
}
|
||||
else
|
||||
{
|
||||
<h2>@Model.StatisticNamePlural</h2>
|
||||
}
|
||||
<h3>@Model.Count</h3>
|
||||
</div>
|
||||
</div>
|
18
ProjectLighthouse/Types/AdminPanelStatistic.cs
Normal file
18
ProjectLighthouse/Types/AdminPanelStatistic.cs
Normal file
|
@ -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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue