Add basic mod panel

This commit is contained in:
jvyden 2022-06-10 18:38:11 -04:00
parent 1037a6eddb
commit 693f0a3855
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
9 changed files with 84 additions and 22 deletions

View file

@ -8,7 +8,7 @@ using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Servers.Website.Controllers.Admin; namespace LBPUnion.ProjectLighthouse.Servers.Website.Controllers.Admin;
[ApiController] [ApiController]
[Route("admin/report/{id:int}")] [Route("/modPanel/report/{id:int}")]
public class AdminReportController : ControllerBase public class AdminReportController : ControllerBase
{ {
private readonly Database database; private readonly Database database;
@ -73,6 +73,6 @@ public class AdminReportController : ControllerBase
await this.database.SaveChangesAsync(); await this.database.SaveChangesAsync();
return this.Redirect("~/admin/reports/0"); return this.Redirect("~/modPanel/reports/0");
} }
} }

View file

@ -41,6 +41,11 @@ else
} }
} }
<a class="ui blue button" href="/modPanel">
<i class="user shield icon"></i>
<span>View Mod Panel</span>
</a>
<h2>Commands</h2> <h2>Commands</h2>
@foreach (ICommand command in MaintenanceHelper.Commands) @foreach (ICommand command in MaintenanceHelper.Commands)
{ {

View file

@ -27,10 +27,9 @@ public class AdminPanelPage : BaseLayout
if (user == null) return this.Redirect("~/login"); if (user == null) return this.Redirect("~/login");
if (!user.IsAdmin) return this.NotFound(); if (!user.IsAdmin) return this.NotFound();
this.Statistics.Add(new AdminPanelStatistic("Users", await StatisticsHelper.UserCount(), "users")); this.Statistics.Add(new AdminPanelStatistic("Users", await StatisticsHelper.UserCount(), "/admin/users"));
this.Statistics.Add(new AdminPanelStatistic("Slots", await StatisticsHelper.SlotCount())); this.Statistics.Add(new AdminPanelStatistic("Slots", await StatisticsHelper.SlotCount()));
this.Statistics.Add(new AdminPanelStatistic("Photos", await StatisticsHelper.PhotoCount())); this.Statistics.Add(new AdminPanelStatistic("Photos", await StatisticsHelper.PhotoCount()));
this.Statistics.Add(new AdminPanelStatistic("Reports", await StatisticsHelper.ReportCount(), "reports/0"));
if (!string.IsNullOrEmpty(command)) if (!string.IsNullOrEmpty(command))
{ {

View file

@ -0,0 +1,28 @@
@page "/modPanel"
@using LBPUnion.ProjectLighthouse.Administration
@using LBPUnion.ProjectLighthouse.Extensions
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.Admin.ModPanelPage
@{
Layout = "Layouts/BaseLayout";
Model.Title = "Moderator Panel";
}
@if (!this.Request.IsMobile())
{
<div class="ui 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>
}
}

View file

@ -0,0 +1,26 @@
using LBPUnion.ProjectLighthouse.Administration;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.PlayerData.Profiles;
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
using Microsoft.AspNetCore.Mvc;
namespace LBPUnion.ProjectLighthouse.Servers.Website.Pages.Admin;
public class ModPanelPage : BaseLayout
{
public ModPanelPage(Database database) : base(database)
{}
public List<AdminPanelStatistic> Statistics = new();
public async Task<IActionResult> OnGet()
{
User? user = this.Database.UserFromWebRequest(this.Request);
if (user == null) return this.Redirect("~/login");
if (!user.IsModerator) return this.NotFound();
this.Statistics.Add(new AdminPanelStatistic("Reports", await StatisticsHelper.ReportCount(), "/modPanel/reports/0"));
return this.Page();
}
}

View file

@ -21,6 +21,10 @@
{ {
Model.NavigationItemsRight.Add(new PageNavigationItem("Admin Panel", "/admin", "cogs")); Model.NavigationItemsRight.Add(new PageNavigationItem("Admin Panel", "/admin", "cogs"));
} }
else if(Model.User.IsModerator)
{
Model.NavigationItemsRight.Add(new PageNavigationItem("Mod Panel", "/modPanel", "user shield"));
}
Model.NavigationItemsRight.Add(new PageNavigationItem("Log out", "/logout", "user alternate slash")); // should always be last Model.NavigationItemsRight.Add(new PageNavigationItem("Log out", "/logout", "user alternate slash")); // should always be last
} }

View file

@ -5,7 +5,7 @@
@if (Model.ViewAllEndpoint != null) @if (Model.ViewAllEndpoint != null)
{ {
<h2> <h2>
<a href="/admin/@Model.ViewAllEndpoint">@Model.StatisticNamePlural</a> <a href="@Model.ViewAllEndpoint">@Model.StatisticNamePlural</a>
</h2> </h2>
} }
else else

View file

@ -1,4 +1,4 @@
@page "/admin/reports/{pageNumber:int}" @page "/modPanel/reports/{pageNumber:int}"
@using LBPUnion.ProjectLighthouse.Administration.Reports @using LBPUnion.ProjectLighthouse.Administration.Reports
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.ReportsPage @model LBPUnion.ProjectLighthouse.Servers.Website.Pages.ReportsPage
@ -7,9 +7,9 @@
Model.Title = "Reports"; Model.Title = "Reports";
} }
<p>There are @Model.ReportCount total reports!</p> <p>There are @Model.ReportCount total reports.</p>
<form action="/admin/reports/0"> <form action="/modPanel/reports/0">
<div class="ui icon input"> <div class="ui icon input">
<input type="text" name="name" placeholder="Search reports..." value="@Model.SearchValue"> <input type="text" name="name" placeholder="Search reports..." value="@Model.SearchValue">
<i class="search icon"></i> <i class="search icon"></i>
@ -69,11 +69,11 @@
</div> </div>
<br> <br>
<a class="ui green small button" href="/admin/report/@report.ReportId/dismiss"> <a class="ui green small button" href="/modPanel/report/@report.ReportId/dismiss">
<i class="checkmark icon"></i> <i class="checkmark icon"></i>
<span>Dismiss</span> <span>Dismiss</span>
</a> </a>
<a class="ui red small button" href="/admin/report/@report.ReportId/remove"> <a class="ui red small button" href="/modPanel/report/@report.ReportId/remove">
<i class="trash icon"></i> <i class="trash icon"></i>
<span>Remove all related assets</span> <span>Remove all related assets</span>
</a> </a>
@ -239,10 +239,10 @@
@if (Model.PageNumber != 0) @if (Model.PageNumber != 0)
{ {
<a href="/admin/reports/@(Model.PageNumber - 1)@(Model.SearchValue.Length == 0 ? "" : "?name=" + Model.SearchValue)">Previous Page</a> <a href="/modPanel/reports/@(Model.PageNumber - 1)@(Model.SearchValue.Length == 0 ? "" : "?name=" + Model.SearchValue)">Previous Page</a>
} }
@(Model.PageNumber + 1) / @(Model.PageAmount) @(Model.PageNumber + 1) / @(Model.PageAmount)
@if (Model.PageNumber < Model.PageAmount - 1) @if (Model.PageNumber < Model.PageAmount - 1)
{ {
<a href="/admin/reports/@(Model.PageNumber + 1)@(Model.SearchValue.Length == 0 ? "" : "?name=" + Model.SearchValue)">Next Page</a> <a href="/modPanel/reports/@(Model.PageNumber + 1)@(Model.SearchValue.Length == 0 ? "" : "?name=" + Model.SearchValue)">Next Page</a>
} }

View file

@ -10,36 +10,36 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\ProjectLighthouse\ProjectLighthouse.csproj"/> <ProjectReference Include="..\ProjectLighthouse\ProjectLighthouse.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Remove="gitVersion.txt"/> <None Remove="gitVersion.txt" />
<EmbeddedResource Include="gitVersion.txt"> <EmbeddedResource Include="gitVersion.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource> </EmbeddedResource>
<None Remove="gitBranch.txt"/> <None Remove="gitBranch.txt" />
<EmbeddedResource Include="gitBranch.txt"> <EmbeddedResource Include="gitBranch.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource> </EmbeddedResource>
<None Remove="gitRemotes.txt"/> <None Remove="gitRemotes.txt" />
<EmbeddedResource Include="gitRemotes.txt"> <EmbeddedResource Include="gitRemotes.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource> </EmbeddedResource>
<None Remove="gitUnpushed.txt"/> <None Remove="gitUnpushed.txt" />
<EmbeddedResource Include="gitUnpushed.txt"> <EmbeddedResource Include="gitUnpushed.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.5"/> <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.5" />
</ItemGroup> </ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent"> <Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="git describe --long --always --dirty --exclude=\* --abbrev=8 &gt; &quot;$(ProjectDir)/gitVersion.txt&quot;"/> <Exec Command="git describe --long --always --dirty --exclude=\* --abbrev=8 &gt; &quot;$(ProjectDir)/gitVersion.txt&quot;" />
<Exec Command="git branch --show-current &gt; &quot;$(ProjectDir)/gitBranch.txt&quot;"/> <Exec Command="git branch --show-current &gt; &quot;$(ProjectDir)/gitBranch.txt&quot;" />
<Exec Command="git remote -v &gt; &quot;$(ProjectDir)/gitRemotes.txt&quot;"/> <Exec Command="git remote -v &gt; &quot;$(ProjectDir)/gitRemotes.txt&quot;" />
<Exec Command="git log --branches --not --remotes --oneline &gt; &quot;$(ProjectDir)/gitUnpushed.txt&quot;"/> <Exec Command="git log --branches --not --remotes --oneline &gt; &quot;$(ProjectDir)/gitUnpushed.txt&quot;" />
</Target> </Target>
</Project> </Project>