mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-31 22:56:18 +00:00
Properly organize mod panel related pages
This commit is contained in:
parent
e962c2dee4
commit
5b1342c29d
10 changed files with 10 additions and 13 deletions
|
@ -1,53 +0,0 @@
|
|||
@page "/moderation"
|
||||
@using System.Diagnostics
|
||||
@using LBPUnion.ProjectLighthouse.Administration
|
||||
@using LBPUnion.ProjectLighthouse.Extensions
|
||||
@using LBPUnion.ProjectLighthouse.Localization.StringLists
|
||||
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.Admin.ModPanelPage
|
||||
|
||||
@{
|
||||
Layout = "Layouts/BaseLayout";
|
||||
Model.Title = Model.Translate(ModPanelStrings.ModPanelTitle);
|
||||
|
||||
if (Model.User == null) throw new ArgumentNullException($"{nameof(Model)}.{nameof(User)}");
|
||||
|
||||
// Technically, this should never happen but I'm going to handle it anyways.
|
||||
if (!Model.User.IsModerator)
|
||||
{
|
||||
if(Debugger.IsAttached) Debugger.Break();
|
||||
throw new Exception("Tried to render mod panel with user whose not mod somehow???");
|
||||
}
|
||||
}
|
||||
|
||||
<p>@Model.Translate(ModPanelStrings.Greeting, Model.User.Username)</p>
|
||||
|
||||
@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>
|
||||
}
|
||||
}
|
||||
|
||||
<h2>Actions</h2>
|
||||
|
||||
<a href="/moderation/bannedUsers" class="ui red button">
|
||||
<i class="users icon"></i>
|
||||
<span>View banned users</span>
|
||||
</a><br/><br/>
|
||||
|
||||
<a href="/moderation/hiddenSlots" class="ui yellow button">
|
||||
<i class="certificate icon"></i>
|
||||
<span>View hidden levels</span>
|
||||
</a>
|
|
@ -1,37 +0,0 @@
|
|||
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(
|
||||
statisticNamePlural: "Reports",
|
||||
count: await StatisticsHelper.ReportCount(),
|
||||
viewAllEndpoint: "/moderation/reports/0")
|
||||
);
|
||||
|
||||
this.Statistics.Add(new AdminPanelStatistic(
|
||||
statisticNamePlural: "Cases",
|
||||
count: await StatisticsHelper.DismissedCaseCount(),
|
||||
viewAllEndpoint: "/moderation/cases/0",
|
||||
secondStatistic: await StatisticsHelper.CaseCount())
|
||||
);
|
||||
|
||||
return this.Page();
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
@page "/moderation/newCase"
|
||||
@using LBPUnion.ProjectLighthouse.Administration
|
||||
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.Admin.NewCasePage
|
||||
|
||||
@{
|
||||
Layout = "Layouts/BaseLayout";
|
||||
Model.Title = $"New {Model.Type.ToString()} Case";
|
||||
}
|
||||
|
||||
<form method="post">
|
||||
@Html.AntiForgeryToken()
|
||||
|
||||
<input type="hidden" name="type" value="@((int)Model.Type)"/>
|
||||
<input type="hidden" name="affectedId" value="@Model.AffectedId"/>
|
||||
|
||||
<div class="ui left labeled input">
|
||||
<label for="reason" class="ui blue label">Reason: </label>
|
||||
<input type="text" name="reason" id="reason"/>
|
||||
</div><br/><br/>
|
||||
|
||||
<div class="ui left labeled input">
|
||||
<label for="mod-notes" class="ui blue label">Mod Notes: </label>
|
||||
<input type="text" name="modNotes" id="mod-notes"/>
|
||||
</div><br/><br/>
|
||||
|
||||
<div class="ui left labeled input">
|
||||
<label for="expires" class="ui blue label">Expires: </label>
|
||||
<input type="datetime-local" name="expires" id="expires"/>
|
||||
</div><br/><br/>
|
||||
|
||||
<br/><input type="submit" value="Create case" class="ui red button"/>
|
||||
</form>
|
|
@ -1,62 +0,0 @@
|
|||
using LBPUnion.ProjectLighthouse.Administration;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
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 NewCasePage : BaseLayout
|
||||
{
|
||||
public NewCasePage(Database database) : base(database)
|
||||
{}
|
||||
|
||||
public CaseType Type { get; set; }
|
||||
public int AffectedId { get; set; }
|
||||
|
||||
public IActionResult OnGet([FromQuery] CaseType? type, [FromQuery] int? affectedId)
|
||||
{
|
||||
User? user = this.Database.UserFromWebRequest(this.Request);
|
||||
if (user == null || !user.IsModerator) return this.Redirect("/login");
|
||||
|
||||
if (type == null) return this.BadRequest();
|
||||
if (affectedId == null) return this.BadRequest();
|
||||
|
||||
this.Type = (CaseType)type;
|
||||
this.AffectedId = (int)affectedId;
|
||||
|
||||
return this.Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPost(CaseType? type, string? reason, string? modNotes, DateTime expires, int? affectedId)
|
||||
{
|
||||
User? user = this.Database.UserFromWebRequest(this.Request);
|
||||
if (user == null || !user.IsModerator) return this.Redirect("/login");
|
||||
|
||||
if (type == null) return this.BadRequest();
|
||||
if (affectedId == null) return this.BadRequest();
|
||||
|
||||
reason ??= string.Empty;
|
||||
modNotes ??= string.Empty;
|
||||
|
||||
// this is fucking ugly
|
||||
// if id is invalid then return bad request
|
||||
if (!(await ((CaseType)type).IsIdValid((int)affectedId, this.Database))) return this.BadRequest();
|
||||
|
||||
ModerationCase @case = new()
|
||||
{
|
||||
Type = (CaseType)type,
|
||||
Reason = reason,
|
||||
ModeratorNotes = modNotes,
|
||||
ExpiresAt = expires,
|
||||
CreatedAt = DateTime.Now,
|
||||
CreatorId = user.UserId,
|
||||
AffectedId = (int)affectedId,
|
||||
};
|
||||
|
||||
this.Database.Cases.Add(@case);
|
||||
await this.Database.SaveChangesAsync();
|
||||
|
||||
return this.Redirect("/moderation/cases/0");
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
@page "/moderation/reports/{pageNumber:int}"
|
||||
@using LBPUnion.ProjectLighthouse.Administration.Reports
|
||||
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.Admin.ReportsPage
|
||||
|
||||
@{
|
||||
Layout = "Layouts/BaseLayout";
|
||||
Model.Title = "Reports";
|
||||
}
|
||||
|
||||
<p>There are @Model.ReportCount total reports.</p>
|
||||
|
||||
<form action="/moderation/reports/0">
|
||||
<div class="ui icon input">
|
||||
<input type="text" autocomplete="off" name="name" placeholder="Search reports..." value="@Model.SearchValue">
|
||||
<i class="search icon"></i>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="ui divider"></div>
|
||||
|
||||
<script>
|
||||
let subjects = [];
|
||||
let bounds = [];
|
||||
let canvases = [];
|
||||
let ctx = [];
|
||||
let images = [];
|
||||
</script>
|
||||
|
||||
@foreach (GriefReport report in Model.Reports)
|
||||
{
|
||||
@await Html.PartialAsync("Partials/ReportPartial", report)
|
||||
}
|
||||
|
||||
@await Html.PartialAsync("Partials/RenderReportBoundsPartial")
|
||||
|
||||
@if (Model.PageNumber != 0)
|
||||
{
|
||||
<a href="/moderation/reports/@(Model.PageNumber - 1)@(Model.SearchValue.Length == 0 ? "" : "?name=" + Model.SearchValue)">Previous Page</a>
|
||||
}
|
||||
@(Model.PageNumber + 1) / @(Model.PageAmount)
|
||||
@if (Model.PageNumber < Model.PageAmount - 1)
|
||||
{
|
||||
<a href="/moderation/reports/@(Model.PageNumber + 1)@(Model.SearchValue.Length == 0 ? "" : "?name=" + Model.SearchValue)">Next Page</a>
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
#nullable enable
|
||||
using System.Text.Json;
|
||||
using LBPUnion.ProjectLighthouse.Administration.Reports;
|
||||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.PlayerData.Profiles;
|
||||
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.Website.Pages.Admin;
|
||||
|
||||
public class ReportsPage : BaseLayout
|
||||
{
|
||||
public int PageAmount;
|
||||
|
||||
public int PageNumber;
|
||||
|
||||
public int ReportCount;
|
||||
|
||||
public List<GriefReport> Reports = new();
|
||||
|
||||
public string SearchValue = "";
|
||||
|
||||
public ReportsPage(Database database) : base(database)
|
||||
{}
|
||||
|
||||
public async Task<IActionResult> OnGet([FromRoute] int pageNumber, [FromQuery] string? name)
|
||||
{
|
||||
User? user = this.Database.UserFromWebRequest(this.Request);
|
||||
if (user == null) return this.Redirect("~/login");
|
||||
if (!user.IsModerator) return this.NotFound();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(name)) name = "";
|
||||
|
||||
this.SearchValue = name.Replace(" ", string.Empty);
|
||||
|
||||
this.ReportCount = await this.Database.Reports.Include(r => r.ReportingPlayer).CountAsync(r => r.ReportingPlayer.Username.Contains(this.SearchValue));
|
||||
|
||||
this.PageNumber = pageNumber;
|
||||
this.PageAmount = Math.Max(1, (int)Math.Ceiling((double)this.ReportCount / ServerStatics.PageSize));
|
||||
|
||||
if (this.PageNumber < 0 || this.PageNumber >= this.PageAmount)
|
||||
return this.Redirect($"/moderation/reports/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}");
|
||||
|
||||
this.Reports = await this.Database.Reports.Include(r => r.ReportingPlayer)
|
||||
.Where(r => r.ReportingPlayer.Username.Contains(this.SearchValue))
|
||||
.OrderByDescending(r => r.Timestamp)
|
||||
.Skip(pageNumber * ServerStatics.PageSize)
|
||||
.Take(ServerStatics.PageSize)
|
||||
.ToListAsync();
|
||||
|
||||
foreach (GriefReport r in this.Reports)
|
||||
{
|
||||
r.XmlPlayers = (ReportPlayer[])JsonSerializer.Deserialize(r.Players, typeof(ReportPlayer[]))!;
|
||||
|
||||
r.XmlBounds = new Marqee()
|
||||
{
|
||||
Rect = (Rectangle)JsonSerializer.Deserialize(r.Bounds, typeof(Rectangle))!,
|
||||
};
|
||||
}
|
||||
|
||||
return this.Page();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue