finish initial rework of profile page with meta pagination

This commit is contained in:
RaidMax 2019-03-29 21:56:56 -05:00
parent 7b8126d57e
commit 8521df85f5
16 changed files with 227 additions and 140 deletions

View File

@ -6,7 +6,7 @@
<RuntimeFrameworkVersion>2.2.2</RuntimeFrameworkVersion>
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
<PackageId>RaidMax.IW4MAdmin.Application</PackageId>
<Version>2.2.5.8</Version>
<Version>2.2.5.9</Version>
<Authors>RaidMax</Authors>
<Company>Forever None</Company>
<Product>IW4MAdmin</Product>
@ -31,7 +31,7 @@
<PropertyGroup>
<ServerGarbageCollection>true</ServerGarbageCollection>
<TieredCompilation>true</TieredCompilation>
<AssemblyVersion>2.2.5.8</AssemblyVersion>
<AssemblyVersion>2.2.5.9</AssemblyVersion>
<FileVersion>2.2.5.8</FileVersion>
</PropertyGroup>

View File

@ -12,6 +12,7 @@ using SharedLibraryCore.Events;
using SharedLibraryCore.Exceptions;
using SharedLibraryCore.Helpers;
using SharedLibraryCore.Interfaces;
using SharedLibraryCore.Objects;
using SharedLibraryCore.Services;
using System;
using System.Collections.Generic;
@ -388,7 +389,7 @@ namespace IW4MAdmin.Application
#endregion
#region META
async Task<List<ProfileMeta>> getProfileMeta(int clientId, int offset, int count)
async Task<List<ProfileMeta>> getProfileMeta(int clientId, int offset, int count, DateTime? startAt)
{
var metaList = new List<ProfileMeta>();
@ -400,6 +401,8 @@ namespace IW4MAdmin.Application
var lastMapMeta = await _metaService.GetPersistentMeta("LastMapPlayed", new EFClient() { ClientId = clientId });
if (lastMapMeta != null)
{
metaList.Add(new ProfileMeta()
{
Id = lastMapMeta.MetaId,
@ -408,9 +411,12 @@ namespace IW4MAdmin.Application
Show = true,
Type = ProfileMeta.MetaType.Information
});
}
var lastServerMeta = await _metaService.GetPersistentMeta("LastServerPlayed", new EFClient() { ClientId = clientId });
if (lastServerMeta != null)
{
metaList.Add(new ProfileMeta()
{
Id = lastServerMeta.MetaId,
@ -419,6 +425,7 @@ namespace IW4MAdmin.Application
Show = true,
Type = ProfileMeta.MetaType.Information
});
}
var client = await GetClientService().Get(clientId);
@ -450,6 +457,7 @@ namespace IW4MAdmin.Application
});
metaList.Add(new ProfileMeta()
{
Id = client.ClientId,
Key = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_CONNECTIONS"],
@ -458,10 +466,51 @@ namespace IW4MAdmin.Application
Type = ProfileMeta.MetaType.Information
});
metaList.Add(new ProfileMeta()
{
Key = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_MASKED"],
Value = client.Masked ? Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_TRUE"] : Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_FALSE"],
Sensitive = true,
Type = ProfileMeta.MetaType.Information
});
return metaList;
};
}
async Task<List<ProfileMeta>> getPenaltyMeta(int clientId, int offset, int count, DateTime? startAt)
{
if (count <= 1)
{
return new List<ProfileMeta>();
}
var penalties = await GetPenaltyService().GetAllClientPenaltiesAsync(clientId, count, offset, startAt);
return penalties.Select(_penalty => new ProfileMeta()
{
Id = _penalty.PenaltyId,
Type = _penalty.PunisherId == clientId ? ProfileMeta.MetaType.Penalized : ProfileMeta.MetaType.ReceivedPenalty,
Value = new PenaltyInfo
{
Id = _penalty.PenaltyId,
OffenderName = _penalty.Offender.Name,
OffenderId = _penalty.OffenderId,
PunisherName = _penalty.Punisher.Name,
PunisherId = _penalty.PunisherId,
Offense = _penalty.Offense,
PenaltyType = _penalty.Type.ToString(),
TimeRemaining = _penalty.Expires.HasValue ? (DateTime.Now > _penalty.Expires ? "" : _penalty.Expires.ToString()) : DateTime.MaxValue.ToString(),
AutomatedOffense = _penalty.AutomatedOffense,
Expired = _penalty.Expires.HasValue && _penalty.Expires <= DateTime.UtcNow
},
When = _penalty.When,
Sensitive = _penalty.Type == Penalty.PenaltyType.Flag
})
.ToList();
}
MetaService.AddRuntimeMeta(getProfileMeta);
MetaService.AddRuntimeMeta(getPenaltyMeta);
#endregion
#region INIT

View File

@ -124,7 +124,7 @@ namespace IW4MAdmin.Plugins.Stats
"/Stats/TopPlayersAsync");
// meta data info
async Task<List<ProfileMeta>> getStats(int clientId, int offset, int count)
async Task<List<ProfileMeta>> getStats(int clientId, int offset, int count, DateTime? startAt)
{
if (count > 1)
{
@ -186,7 +186,7 @@ namespace IW4MAdmin.Plugins.Stats
};
}
async Task<List<ProfileMeta>> getAnticheatInfo(int clientId, int offset, int count)
async Task<List<ProfileMeta>> getAnticheatInfo(int clientId, int offset, int count, DateTime? startAt)
{
if (count > 1)
{
@ -280,7 +280,7 @@ namespace IW4MAdmin.Plugins.Stats
};
}
async Task<List<ProfileMeta>> getMessages(int clientId, int offset, int count)
async Task<List<ProfileMeta>> getMessages(int clientId, int offset, int count, DateTime? startAt)
{
if (count <= 1)
{
@ -291,7 +291,8 @@ namespace IW4MAdmin.Plugins.Stats
new ProfileMeta()
{
Key = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_PROFILE_MESSAGES"],
Value = await ctx.Set<EFClientMessage>().CountAsync(),
Value = await ctx.Set<EFClientMessage>()
.CountAsync(_message => _message.ClientId == clientId),
Type = ProfileMeta.MetaType.Information
}
};
@ -301,7 +302,9 @@ namespace IW4MAdmin.Plugins.Stats
List<ProfileMeta> messageMeta;
using (var ctx = new DatabaseContext(disableTracking: true))
{
var messages = ctx.Set<EFClientMessage>().Where(m => m.ClientId == clientId)
var messages = ctx.Set<EFClientMessage>()
.Where(m => m.ClientId == clientId)
.Where(_message => _message.TimeSent < startAt)
.OrderByDescending(_message => _message.TimeSent)
.Skip(offset)
.Take(count);

View File

@ -18,10 +18,6 @@ namespace SharedLibraryCore.Dtos
public List<string> IPs { get; set; }
public bool HasActivePenalty { get; set; }
public string ActivePenaltyType { get; set; }
//public int ConnectionCount { get; set; }
//public string LastSeen { get; set; }
//public string FirstSeen { get; set; }
//public string TimePlayed { get; set; }
public bool Authenticated { get; set; }
public List<ProfileMeta> Meta { get; set; }
public bool Online { get; set; }

View File

@ -13,7 +13,9 @@ namespace SharedLibraryCore.Dtos
Other,
Information,
AliasUpdate,
ChatMessage
ChatMessage,
Penalized,
ReceivedPenalty,
}
public DateTime When { get; set; }

View File

@ -11,7 +11,7 @@ namespace SharedLibraryCore.Services
{
public class MetaService
{
private static List<Func<int, int, int, Task<List<ProfileMeta>>>> _metaActions = new List<Func<int, int, int, Task<List<ProfileMeta>>>>();
private static List<Func<int, int, int, DateTime?, Task<List<ProfileMeta>>>> _metaActions = new List<Func<int, int, int, DateTime?, Task<List<ProfileMeta>>>>();
/// <summary>
/// adds or updates meta key and value to the database
@ -71,7 +71,7 @@ namespace SharedLibraryCore.Services
/// aads a meta task to the runtime meta list
/// </summary>
/// <param name="metaAction"></param>
public static void AddRuntimeMeta(Func<int, int, int, Task<List<ProfileMeta>>> metaAction)
public static void AddRuntimeMeta(Func<int, int, int, DateTime?, Task<List<ProfileMeta>>> metaAction)
{
_metaActions.Add(metaAction);
}
@ -83,16 +83,24 @@ namespace SharedLibraryCore.Services
/// <param name="count">number of meta items to retrieve</param>
/// <param name="offset">offset from the first item</param>
/// <returns></returns>
public static async Task<List<ProfileMeta>> GetRuntimeMeta(int clientId, int offset = 0, int count = int.MaxValue)
public static async Task<List<ProfileMeta>> GetRuntimeMeta(int clientId, int offset = 0, int count = int.MaxValue, DateTime? startAt = null)
{
var meta = new List<ProfileMeta>();
foreach (var action in _metaActions)
{
meta.AddRange(await action(clientId, offset, count));
var metaItems = await action(clientId, offset, count, startAt);
meta.AddRange(metaItems);
}
if (count == 1)
{
return meta;
}
return meta.OrderByDescending(_meta => _meta.When)
.Take(count)
.ToList();
}
}
}

View File

@ -159,6 +159,24 @@ namespace SharedLibraryCore.Services
}
}
public async Task<IList<EFPenalty>> GetAllClientPenaltiesAsync(int clientId, int count, int offset, DateTime? startAt)
{
using (var ctx = new DatabaseContext(true))
{
var iqPenalties = ctx.Penalties.AsNoTracking()
.Include(_penalty => _penalty.Offender.CurrentAlias)
.Include(_penalty => _penalty.Punisher.CurrentAlias)
.Where(_penalty => _penalty.Active)
.Where(_penalty => _penalty.OffenderId == clientId || _penalty.PunisherId == clientId)
.Where(_penalty => _penalty.When < startAt)
.OrderByDescending(_penalty => _penalty.When)
.Skip(offset)
.Take(count);
return await iqPenalties.ToListAsync();
}
}
/// <summary>
/// Get a read-only copy of client penalties
/// </summary>

View File

@ -59,7 +59,7 @@ namespace WebfrontCore.Controllers
{
ClientId = -1,
Level = EFClient.Permission.User,
CurrentAlias = new EFAlias() { Name = "Web Console Guest" }
CurrentAlias = new EFAlias() { Name = "Webfront Guest" }
};
if (!HttpContext.Connection.RemoteIpAddress.GetAddressBytes().SequenceEqual(LocalHost))
@ -70,6 +70,7 @@ namespace WebfrontCore.Controllers
Client.NetworkId = User.Claims.First(_claim => _claim.Type == ClaimTypes.PrimarySid).Value.ConvertLong();
Client.Level = (EFClient.Permission)Enum.Parse(typeof(EFClient.Permission), User.Claims.First(c => c.Type == ClaimTypes.Role).Value);
Client.CurrentAlias = new EFAlias() { Name = User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value };
Authorized = Client.ClientId >= 0;
}
catch (InvalidOperationException)
@ -93,7 +94,6 @@ namespace WebfrontCore.Controllers
Authorized = true;
}
Authorized = Client.ClientId >= 0;
ViewBag.Authorized = Authorized;
ViewBag.Url = Manager.GetApplicationSettings().Configuration().WebfrontUrl;
ViewBag.User = Client;

View File

@ -15,6 +15,7 @@ namespace WebfrontCore.Controllers
public async Task<IActionResult> ProfileAsync(int id)
{
var client = await Manager.GetClientService().Get(id);
if (client == null)
{
return NotFound();
@ -22,10 +23,6 @@ namespace WebfrontCore.Controllers
var activePenalties = await Manager.GetPenaltyService().GetActivePenaltiesAsync(client.AliasLinkId, client.IPAddress);
#if DEBUG
Authorized = true;
#endif
var clientDto = new PlayerInfo()
{
Name = client.Name,
@ -55,42 +52,7 @@ namespace WebfrontCore.Controllers
LinkedAccounts = client.LinkedAccounts
};
var meta = await MetaService.GetRuntimeMeta(client.ClientId, 0, 1);
var penaltyMeta = await Manager.GetPenaltyService()
.ReadGetClientPenaltiesAsync(client.ClientId);
var administeredPenaltiesMeta = await Manager.GetPenaltyService()
.ReadGetClientPenaltiesAsync(client.ClientId, false);
if (Authorized && client.Level > EFClient.Permission.Trusted)
{
clientDto.Meta.Add(new ProfileMeta()
{
Key = Localization["WEBFRONT_CLIENT_META_MASKED"],
Value = client.Masked ? Localization["WEBFRONT_CLIENT_META_TRUE"] : Localization["WEBFRONT_CLIENT_META_FALSE"],
Sensitive = true,
When = DateTime.MinValue
});
}
//if (Authorized)
//{
// clientDto.Meta.AddRange(client.AliasLink.Children
// .GroupBy(a => a.Name)
// .Select(a => a.First())
// .Select(a => new ProfileMeta()
// {
// Value = $"{Localization["WEBFRONT_CLIENT_META_JOINED"]} {a.Name}",
// Sensitive = true,
// When = a.DateAdded,
// Type = ProfileMeta.MetaType.AliasUpdate
// }));
//}
if (Authorized)
{
penaltyMeta.ForEach(p => p.Value.Offense = p.Value.AutomatedOffense ?? p.Value.Offense);
administeredPenaltiesMeta.ForEach(p => p.Value.Offense = p.Value.AutomatedOffense ?? p.Value.Offense);
}
var meta = await MetaService.GetRuntimeMeta(client.ClientId, 0, 1, DateTime.UtcNow);
var currentPenalty = activePenalties.FirstOrDefault();
@ -105,19 +67,6 @@ namespace WebfrontCore.Controllers
}
clientDto.Meta.AddRange(Authorized ? meta : meta.Where(m => !m.Sensitive));
clientDto.Meta.AddRange(Authorized ? penaltyMeta : penaltyMeta.Where(m => !m.Sensitive));
clientDto.Meta.AddRange(Authorized ? administeredPenaltiesMeta : administeredPenaltiesMeta.Where(m => !m.Sensitive));
clientDto.Meta.AddRange(client.Meta.Select(m => new ProfileMeta()
{
When = m.Created,
Key = m.Key,
Value = m.Value,
Show = false,
}));
clientDto.Meta = clientDto.Meta
.OrderByDescending(m => m.When)
.ToList();
ViewBag.Title = clientDto.Name.Substring(clientDto.Name.Length - 1).ToLower()[0] == 's' ?
clientDto.Name + "'" :
@ -179,9 +128,9 @@ namespace WebfrontCore.Controllers
return View("Find/Index", clientsDto);
}
public async Task<IActionResult> Meta(int id, int count, int offset)
public async Task<IActionResult> Meta(int id, int count, int offset, DateTime? startAt)
{
var meta = await MetaService.GetRuntimeMeta(id, offset, count);
var meta = await MetaService.GetRuntimeMeta(id, startAt == null ? offset : 0, count, startAt ?? DateTime.UtcNow);
if (meta.Count == 0)
{

View File

@ -1,14 +1,15 @@
using Microsoft.AspNetCore.Mvc;
using SharedLibraryCore.Services;
using System;
using System.Threading.Tasks;
namespace WebfrontCore.ViewComponents
{
public class ProfileMetaListViewComponent : ViewComponent
{
public async Task<IViewComponentResult> InvokeAsync(int clientId, int count, int offset)
public async Task<IViewComponentResult> InvokeAsync(int clientId, int count, int offset, DateTime? startAt)
{
var meta = await MetaService.GetRuntimeMeta(clientId, offset, count);
var meta = await MetaService.GetRuntimeMeta(clientId, offset, count, startAt ?? DateTime.UtcNow);
return View("_List", meta);
}
}

View File

@ -79,7 +79,6 @@
</div>
<div id="profile_info" class="row d-block d-lg-flex flex-row border-bottom border-top pt-2 pb-2">
<div id="profile_meta_0" class="text-center text-lg-left mr-0 mr-lg-4">
@for (int i = 0; i < informationMeta.Count; i += 3)
{
@ -117,6 +116,10 @@
</div>
</div>
<div class="row">
<div class="oi oi-chevron-bottom text-center mt-2 btn btn-primary btn-block loader-load-more" title="Load more meta" data-action="unban" aria-hidden="true"></div>
</div>
@section targetid {
<input type="hidden" name="targetId" value="@Model.ClientId" />
}

View File

@ -1,20 +1,62 @@
@model List<SharedLibraryCore.Dtos.ProfileMeta>
@{Layout = null;}
@{
Layout = null;
string formatPenalty(SharedLibraryCore.Dtos.ProfileMeta meta)
{
var penalty = meta.Value as SharedLibraryCore.Dtos.PenaltyInfo;
string localizationKey = meta.Type == SharedLibraryCore.Dtos.ProfileMeta.MetaType.Penalized ?
$"WEBFRONT_CLIENT_META_PENALIZED_{penalty.PenaltyType.ToUpper()}" :
$"WEBFRONT_CLIENT_META_WAS_PENALIZED_{penalty.PenaltyType.ToUpper()}";
string localizationMessage = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex[localizationKey];
var regexMatch = System.Text.RegularExpressions.Regex.Match(localizationMessage, @"^{{([^{}]+)}}.+$");
string penaltyType = regexMatch.Groups[1].Value.ToString();
localizationMessage = localizationMessage.Replace(penaltyType, $"<span class='penalties-color-{penalty.PenaltyType.ToLower()}'>{penaltyType}</span>");
return meta.Type == SharedLibraryCore.Dtos.ProfileMeta.MetaType.Penalized ?
string.Format(localizationMessage,
$"<span class='text-highlight'><a class='link-inverse' href='{penalty.OffenderId}'>{penalty.OffenderName}</a></span>",
$"<span class='automated-penalty-info-detailed text-white' data-clientid='{penalty.OffenderId}'>{penalty.Offense}</span>")
.Replace("{", "")
.Replace("}", "") :
string.Format(localizationMessage,
$"<span class='text-highlight'><a class='link-inverse' href='{penalty.PunisherId}'>{penalty.PunisherName}</a></span>",
$"<span class='automated-penalty-info-detailed text-white' data-clientid='{penalty.OffenderId}'>{penalty.Offense}</span>",
penalty.Offense)
.Replace("{", "")
.Replace("}", "");
}
}
@if (Model.Count > 0)
{
<div class="p2 text-white profile-event-timestep">
<span class="text-primary">&mdash;</span>
<span>@SharedLibraryCore.Utilities.GetTimePassed(Model.FirstOrDefault()?.When ?? DateTime.Now, true)</span>
<span>@SharedLibraryCore.Utilities.GetTimePassed(Model.First().When, true)</span>
</div>
}
@foreach (var meta in Model)
@if (Model.Count == 0)
{
<div class="p2 text-muted profile-event-timestep">@SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_NONE"]</div>
}
@foreach (var meta in Model.OrderByDescending(_meta => _meta.When))
{
@switch (meta.Type)
{
case SharedLibraryCore.Dtos.ProfileMeta.MetaType.ChatMessage:
<div>
<div class="profile-meta-entry loader-data-time" data-time="@meta.When">
<span style="color:white;">></span>
<span class="client-message text-muted" data-serverid="@meta.Extra" data-when="@meta.When"> @meta.Value</span>
</div>
break;
case SharedLibraryCore.Dtos.ProfileMeta.MetaType.ReceivedPenalty:
case SharedLibraryCore.Dtos.ProfileMeta.MetaType.Penalized:
<div class="profile-meta-entry loader-data-time" data-time="@meta.When">@Html.Raw(formatPenalty(meta))</div>
break;
}
}

View File

@ -6375,6 +6375,9 @@ form *, select {
padding: 5px;
visibility: hidden; }
.loader-load-more {
border-radius: 0; }
.input-border-transition {
-webkit-transition: border 500ms ease-out;
-moz-transition: border 500ms ease-out;

View File

@ -163,6 +163,10 @@ form *, select {
visibility: hidden;
}
.loader-load-more {
border-radius: 0;
}
.input-border-transition {
-webkit-transition: border 500ms ease-out;
-moz-transition: border 500ms ease-out;

View File

@ -1,5 +1,6 @@
let loaderOffset = 10;
let loadCount = 10;
let startAt = null;
let isLoaderLoading = false;
let loadUri = '';
let loaderResponseId = '';
@ -19,13 +20,14 @@ function loadMoreItems() {
showLoader();
isLoaderLoading = true;
$.get(loadUri, { offset: loaderOffset, count : loadCount })
$.get(loadUri, { offset: loaderOffset, count: loadCount, startAt: startAt })
.done(function (response) {
$(loaderResponseId).append(response);
if (response.trim().length === 0) {
staleLoader();
}
$(document).trigger("loaderFinished", response);
startAt = $(response).filter('.loader-data-time').last().data('time');
hideLoader();
isLoaderLoading = false;
})
@ -64,6 +66,11 @@ if ($(loaderResponseId).length === 1) {
$window
.off('scroll', ScrollHandler)
.on('scroll', ScrollHandler);
$('.loader-load-more').click(function (e) {
if (!isLoaderLoading) {
loadMoreItems();
}
})
});
function ScrollHandler(e) {

View File

@ -13,6 +13,7 @@
/*
* load context of chat
*/
$(document).off('click', '.client-message');
$(document).on('click', '.client-message', function (e) {
showLoader();
const location = $(this);
@ -33,6 +34,7 @@
/*
* load info on ban/flag
*/
$(document).off('click', '.automated-penalty-info-detailed');
$(document).on('click', '.automated-penalty-info-detailed', function (e) {
showLoader();
const location = $(this).parent();