Skip to content

Commit

Permalink
Display more note information
Browse files Browse the repository at this point in the history
Fixes #18
  • Loading branch information
PJB3005 committed Jan 12, 2024
1 parent dc38219 commit b47485d
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 22 deletions.
122 changes: 107 additions & 15 deletions SS14.Admin/Pages/Players/Info.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
@using Content.Server.Database
@using SS14.Admin.Helpers
@using SS14.Admin.Pages.Tables
@using System.Diagnostics
@using Content.Shared.Database
@model SS14.Admin.Pages.Players.Info

@{
Expand Down Expand Up @@ -92,44 +94,134 @@
</div>


<div class="container">
<div class="container-fluid">
<h2>Notes</h2>

<span class="small">Total: @Model.Notes.Length</span>
<span class="small">Total: @Model.Remarks.Length</span>
<table class="table table-striped mt-3">
<thead>
<tr>
<th>Type</th>
<th>Message</th>
<th>Round</th>
<th>Severity</th>
<th>Visible/Seen</th>
<th>Playtime (h:mm)</th>
<th>Expires (UTC)</th>
<th>Created</th>
<th>Edited</th>
</tr>
</thead>
<tbody>
@foreach (var note in Model.Notes)
@foreach (var remark in Model.Remarks)
{
<tr>
<td>
@note.Message
@switch (remark)
{
case AdminMessage:
<span class="text-success"><i class="fas fa-envelope"></i> Message</span>
break;
case AdminNote:
<span class="text-info"><i class="fas fa-clipboard"></i> Note</span>
break;
case AdminWatchlist:
<span class="text-warning"><i class="fas fa-eye"></i> Watchlist</span>

break;
default:
throw new UnreachableException();
}
</td>
<td>@remark.Message</td>
<td>@remark.RoundId</td>
<td>
@note.RoundId
@if (remark is AdminNote note)
{
switch (note.Severity)
{
case NoteSeverity.None:
<text><i class="fas fa-check-circle"></i> None</text>
break;
case NoteSeverity.Minor:
<span class="text-info"><i class="fas fa-minus-circle"></i> Minor</span>
break;
case NoteSeverity.Medium:
<span class="text-warning"><i class="fas fa-exclamation-circle"></i> Medium</span>
break;
case NoteSeverity.High:
<span class="text-danger"><i class="fas fa-exclamation-triangle"></i> High</span>
break;
default:
<text><i class="fas fa-question"></i> Unknown</text>
break;
}
}
else
{
<span class="text-secondary">N/A</span>
}
</td>
<td>
@note.CreatedAt.ToString("yyyy-MM-dd HH:mm:ss")<br/>
by @(note.CreatedBy?.LastSeenUserName ?? "unknown")
@switch (remark)
{
case AdminMessage adminMessage:
if (adminMessage.Seen)
{
<span class="text-success"><i class="fas fa-eye"></i> Seen</span>
}
else
{
<span class="text-secondary"><i class="fas fa-eye-slash"></i> Not seen</span>
}

break;
case AdminNote adminNote:
if (adminNote.Secret)
{
<span class="text-info"><i class="fas fa-eye-slash"></i> Secret</span>
}
else
{
<span class="text-success"><i class="fas fa-eye"></i> Visible</span>
}

break;
case AdminWatchlist:
<span class="text-secondary">N/A</span>
break;
default:
throw new UnreachableException();
}
</td>
<td>@((int)remark.PlaytimeAtNote.TotalHours):@remark.PlaytimeAtNote.Minutes.ToString("D2")</td>
<td>
@if (note.LastEditedAt != null && note.LastEditedBy != null)
@if (remark.ExpirationTime is { } expires)
{
<text>
@note.LastEditedAt.Value.ToString("yyyy-MM-dd HH:mm:ss")<br/>
by @note.LastEditedBy.LastSeenUserName
</text>
var utc = expires.ToUniversalTime();
var diff = utc - DateTime.UtcNow;
@expires.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss")<br/>
<text>(in @diff.Days days @diff.Hours:@diff.Minutes)</text>
}
else
{
<text>None</text>
<text>Permanent</text>
}

</td>
<td>
@remark.CreatedAt.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss")<br/>
<span class="text-secondary">by @(remark.CreatedBy?.LastSeenUserName ?? "unknown")</span>
</td>
<td>
@if (remark.LastEditedAt > remark.CreatedAt)
{
@remark.LastEditedAt.Value.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss")<br/>
<span class="text-secondary">by @(remark.LastEditedBy?.LastSeenUserName ?? "unknown")</span>
}
else
{
<span class="text-secondary">No</span>
}
</td>
</tr>
Expand All @@ -138,12 +230,12 @@
</table>
</div>

<div class="container">
<div class="container-fluid">
<h2>Bans</h2>
<partial name="Tables/BansTable" model="@(new BansTableModel(Model.GameSortState,Model.GameBanPagination, 0 ,false))"/>
</div>

<div class="container">
<div class="container-fluid">
<h2>Role Bans</h2>
<partial name="Tables/RoleBansTable" model="@(new RoleBansTableModel(Model.RoleSortState,Model.RoleBanPagination, 0, false))"/>
</div>
27 changes: 20 additions & 7 deletions SS14.Admin/Pages/Players/Info.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed class Info : PageModel

public bool Whitelisted { get; set; }
public Player Player { get; set; } = default!;
public AdminNote[] Notes { get; set; } = default!;
public IAdminRemarksCommon[] Remarks { get; set; } = default!;
public PlayTime[] PlayTimes { get; set; } = default!;
public Profile[] Profiles { get; set; } = default!;
public ISortState RoleSortState { get; private set; } = default!;
Expand Down Expand Up @@ -64,12 +64,13 @@ public async Task<IActionResult> OnGetAsync(

Player = player;

Notes = await _dbContext.AdminNotes
.Where(n => n.PlayerUserId == userId)
.Include(n => n.CreatedBy)
.Include(n => n.LastEditedBy)
.OrderByDescending(n => n.CreatedAt)
.ToArrayAsync();
var notes = await RemarksCommonQuery(_dbContext.AdminNotes);
var watchlist = await RemarksCommonQuery(_dbContext.AdminWatchlists);
var messages = await RemarksCommonQuery(_dbContext.AdminMessages);

Remarks = notes.Concat(watchlist).Concat(messages)
.OrderByDescending(p => p.CreatedAt)
.ToArray();

PlayTimes = await _dbContext.PlayTime
.Where(t => t.PlayerId == userId)
Expand All @@ -84,5 +85,17 @@ public async Task<IActionResult> OnGetAsync(
Whitelisted = await _dbContext.Whitelist.AnyAsync(p => p.UserId == userId);

return Page();

async Task<IAdminRemarksCommon[]> RemarksCommonQuery<T>(IQueryable<T> query) where T : class, IAdminRemarksCommon
{
return await query
.Where(n => n.PlayerUserId == userId)
.Where(n => n.ExpirationTime == null || n.ExpirationTime > DateTime.UtcNow)
.Where(n => !n.Deleted)
.Include(n => n.CreatedBy)
.Include(n => n.LastEditedBy)
.Cast<IAdminRemarksCommon>()
.ToArrayAsync();
}
}
}

0 comments on commit b47485d

Please sign in to comment.