mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-15 17:51:28 +00:00
Redesign case creation page (#854)
* Redesign case creation page * Fix user id placeholder text * Handle empty moderation history * Mod history dropdown nitpick * Fix styling issue with dropdown ui fluid dropdown inherits from ui form * Potentially fix NRE * Un-require reason/mod notes * Display username in moderation history view * Order mod history by creation time descending * Nitpick no moderation history string * Handle AffectedUser null check within controller * Fix styling issues * Move moderation history segment above create case button segment * Link back to affected user * Move expiration field in with the other entries * Grammatical consistency nitpick in history dropdown * Handle empty case reasons in mod history * This is the last nitpick, I swear! * I lied. Variable naming consistency :trollface: * Consolidate setPermanent function into button onclick * Use HTML details and Fomantic list instead of dropdown * Fix padding issue with details list * Format history and user/id nicely * Styling fixes and nitpicks of list items/links * Apply suggestions from code review * Clarification with code review suggestion
This commit is contained in:
parent
24225d5ef5
commit
027173b9c7
3 changed files with 103 additions and 21 deletions
|
@ -1,4 +1,5 @@
|
|||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
using LBPUnion.ProjectLighthouse.Types.Moderation.Cases;
|
||||
using LBPUnion.ProjectLighthouse.Types.Users;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.Website.Extensions;
|
||||
|
@ -7,6 +8,21 @@ public static class FormattingExtensions
|
|||
{
|
||||
public static string GetLevelLockIcon(this SlotEntity slot) => slot.InitiallyLocked ? "ui icon lock" : "";
|
||||
|
||||
public static string GetCaseTypeIcon(this CaseType caseType)
|
||||
{
|
||||
return caseType switch
|
||||
{
|
||||
CaseType.UserBan => "ui icon ban",
|
||||
CaseType.UserRestriction => "ui icon user alternate slash",
|
||||
CaseType.UserSilence => "ui icon volume off",
|
||||
CaseType.UserDisableComments => "ui icon comment slash",
|
||||
CaseType.LevelHide => "ui icon eye slash",
|
||||
CaseType.LevelLock => "ui icon lock",
|
||||
CaseType.LevelDisableComments => "ui icon comment slash",
|
||||
_ => "ui icon question",
|
||||
};
|
||||
}
|
||||
|
||||
public static string ToHtmlColor(this PermissionLevel permissionLevel)
|
||||
{
|
||||
return permissionLevel switch
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
@page "/moderation/newCase"
|
||||
@using LBPUnion.ProjectLighthouse.Localization.StringLists
|
||||
@using LBPUnion.ProjectLighthouse.Servers.Website.Extensions
|
||||
@using LBPUnion.ProjectLighthouse.Types.Entities.Moderation
|
||||
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.Moderation.NewCasePage
|
||||
|
||||
@{
|
||||
Layout = "Layouts/BaseLayout";
|
||||
Model.Title = $"New {Model.Type.ToString()} Case";
|
||||
Model.Title = "New Moderation Case";
|
||||
|
||||
string timeZone = (string?)ViewData["TimeZone"] ?? TimeZoneInfo.Local.Id;
|
||||
TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(timeZone);
|
||||
}
|
||||
|
||||
<form method="post">
|
||||
<form method="post" class="ui form center aligned">
|
||||
@Html.AntiForgeryToken()
|
||||
|
||||
@if (!string.IsNullOrWhiteSpace(Model.Error))
|
||||
|
@ -18,20 +23,68 @@
|
|||
<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 yellow segment">
|
||||
<div>
|
||||
<b>Case Type:</b> @Model.Type.ToString()
|
||||
</div>
|
||||
<div>
|
||||
<b>Affected User:</b> <a href="/user/@Model.AffectedId">@Model.AffectedUser!.Username (id: @Model.AffectedId)</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<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 yellow segment">
|
||||
<div class="field">
|
||||
<label style="text-align: left" for="reason">Reason</label>
|
||||
<textarea name="reason" id="reason" spellcheck="true" rows="1"></textarea>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label style="text-align: left" for="mod-notes">Mod Notes</label>
|
||||
<textarea name="modNotes" id="mod-notes" spellcheck="true" rows="1"></textarea>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label style="text-align: left" for="expires">Expiration</label>
|
||||
<input type="datetime-local" name="expires" id="expires" required/>
|
||||
</div>
|
||||
<button type="button" class="ui yellow button" onclick="document.getElementById('expires').value = '9999-12-31T23:59';">
|
||||
Set Expiration to Permanent
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<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/>
|
||||
<div class="ui blue segment">
|
||||
<details style="transition: max-height 0.25s ease-in-out;">
|
||||
<summary>Moderation history for user <a href="/user/@Model.AffectedId">@Model.AffectedUser!.Username</a></summary>
|
||||
<div class="ui list" style="padding-left: 1vh;">
|
||||
@if (Model.AffectedHistory.Count != 0)
|
||||
{
|
||||
@foreach (ModerationCaseEntity moderationCase in Model.AffectedHistory)
|
||||
{
|
||||
<div class="item">
|
||||
<i class="@moderationCase.Type.GetCaseTypeIcon()"></i>
|
||||
<div class="content">
|
||||
<b>@moderationCase.Type.ToString()</b> by <a href="/user/@moderationCase.CreatorId">@moderationCase.CreatorUsername</a>
|
||||
on <b>@TimeZoneInfo.ConvertTime(moderationCase.CreatedAt, timeZoneInfo).ToString("M/d/yyyy @ h:mm tt")</b>
|
||||
with reason <b>@(!string.IsNullOrWhiteSpace(moderationCase.Reason) ? moderationCase.Reason : "No reason provided")</b>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="item">
|
||||
<i class="ui icon check"></i>
|
||||
<div class="content">
|
||||
No moderation history found for user <a href="/user/@Model.AffectedId">@Model.AffectedUser!.Username</a>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
|
||||
<br/><input type="submit" value="Create case" class="ui red button"/>
|
||||
<div class="ui red segment">
|
||||
<div style="margin-bottom: 1em;">
|
||||
<i class="ui icon warning"></i><i>Remember to dismiss your case after expiration otherwise it will remain in effect!</i>
|
||||
</div>
|
||||
<button type="submit" class="ui red button">Create Case</button>
|
||||
</div>
|
||||
</form>
|
|
@ -12,14 +12,17 @@ namespace LBPUnion.ProjectLighthouse.Servers.Website.Pages.Moderation;
|
|||
public class NewCasePage : BaseLayout
|
||||
{
|
||||
public NewCasePage(DatabaseContext database) : base(database)
|
||||
{}
|
||||
{ }
|
||||
|
||||
public CaseType Type { get; set; }
|
||||
|
||||
public int AffectedId { get; set; }
|
||||
public UserEntity? AffectedUser { get; set; }
|
||||
public List<ModerationCaseEntity> AffectedHistory { get; set; } = new();
|
||||
|
||||
public string? Error { get; private set; }
|
||||
|
||||
public IActionResult OnGet([FromQuery] CaseType? type, [FromQuery] int? affectedId)
|
||||
public async Task<IActionResult> OnGet([FromQuery] CaseType? type, [FromQuery] int? affectedId)
|
||||
{
|
||||
UserEntity? user = this.Database.UserFromWebRequest(this.Request);
|
||||
if (user == null || !user.IsModerator) return this.Redirect("/login");
|
||||
|
@ -28,8 +31,16 @@ public class NewCasePage : BaseLayout
|
|||
if (affectedId == null) return this.BadRequest();
|
||||
|
||||
this.Type = type.Value;
|
||||
|
||||
this.AffectedId = affectedId.Value;
|
||||
|
||||
this.AffectedUser = await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == this.AffectedId);
|
||||
if (this.AffectedUser == null) return this.BadRequest();
|
||||
|
||||
this.AffectedHistory = await this.Database.Cases.Where(c => c.AffectedId == this.AffectedId)
|
||||
.OrderByDescending(c => c.CreatedAt)
|
||||
.ToListAsync();
|
||||
|
||||
return this.Page();
|
||||
}
|
||||
|
||||
|
@ -43,14 +54,16 @@ public class NewCasePage : BaseLayout
|
|||
|
||||
reason ??= string.Empty;
|
||||
modNotes ??= string.Empty;
|
||||
|
||||
|
||||
// if id is invalid then return bad request
|
||||
if (!await type.Value.IsIdValid((int)affectedId, this.Database)) return this.BadRequest();
|
||||
|
||||
UserEntity? affectedUserEntity =
|
||||
UserEntity? affectedUser =
|
||||
await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == affectedId.Value);
|
||||
|
||||
if (affectedUserEntity?.IsModerator ?? false)
|
||||
if (affectedUser == null) return this.NotFound();
|
||||
|
||||
if (affectedUser.IsModerator)
|
||||
{
|
||||
this.Error = this.Translate(ErrorStrings.ActionNoPermission);
|
||||
return this.Page();
|
||||
|
@ -70,7 +83,7 @@ public class NewCasePage : BaseLayout
|
|||
|
||||
this.Database.Cases.Add(@case);
|
||||
await this.Database.SaveChangesAsync();
|
||||
|
||||
|
||||
return this.Redirect("/moderation/cases/0");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue