QOL updates for profile meta

implement filterable meta for issue #158
update translations and use humanizer lib with datetime/timespan for issue #80
This commit is contained in:
RaidMax
2020-08-17 21:21:11 -05:00
parent 1ef2ba5344
commit 778e339a61
78 changed files with 1800 additions and 775 deletions

View File

@ -1,17 +1,17 @@
@model SharedLibraryCore.Dtos.PlayerInfo
@using SharedLibraryCore.Database.Models
@using SharedLibraryCore.Interfaces
@using SharedLibraryCore
@model SharedLibraryCore.Dtos.PlayerInfo
@{
string match = System.Text.RegularExpressions.Regex.Match(Model.Name.ToUpper(), "[A-Z]").Value;
string shortCode = match == string.Empty ? "?" : match;
var loc = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex;
string gravatarUrl = Model.Meta.FirstOrDefault(m => m.Key == "GravatarEmail")?.Value;
bool isTempBanned = Model.ActivePenaltyType == "TempBan";
bool isFlagged = Model.LevelInt == (int)SharedLibraryCore.Database.Models.EFClient.Permission.Flagged;
bool isPermBanned = Model.LevelInt == (int)SharedLibraryCore.Database.Models.EFClient.Permission.Banned;
var informationMeta = Model.Meta
.Where(_meta => _meta.Type == SharedLibraryCore.Dtos.ProfileMeta.MetaType.Information)
.OrderBy(_meta => _meta.Order)
.GroupBy(_meta => _meta.Column)
.OrderBy(_grouping => _grouping.Key);
bool isTempBanned = Model.ActivePenalty?.Type == EFPenalty.PenaltyType.TempBan;
string translationKey = $"WEBFRONT_PROFILE_{Model.ActivePenalty?.Type.ToString().ToUpper()}_INFO";
var ignoredMetaTypes = new[] { MetaType.Information, MetaType.Other, MetaType.QuickMessage };
}
<div id="profile_wrapper" class="pb-3 row d-flex flex-column flex-lg-row">
@ -23,7 +23,7 @@
}
</div>
<!-- Name/Level Column -->
<div class="d-block d-lg-inline-flex flex-column flex-fill text-center text-lg-left pb-3 pb-lg-0 pt-3 pt-lg-0 pl-3 pr-3">
<div class="w-75 d-block d-lg-inline-flex flex-column flex-fill text-center text-lg-left pb-3 pb-lg-0 pt-3 pt-lg-0 pl-3 pr-3 ml-auto mr-auto" style="overflow-wrap: anywhere">
<div class="mt-n2 flex-fill d-block d-lg-inline-flex">
<div id="profile_name" class="client-name h1 mb-0"><color-code value="@Model.Name" allow="@ViewBag.EnableColorCodes"></color-code></div>
@if (ViewBag.Authorized)
@ -31,6 +31,7 @@
<div id="profile_aliases_btn" class="oi oi-caret-bottom h3 ml-0 ml-lg-2 mb-0 pt-lg-2 mt-lg-1"></div>
}
</div>
@if (ViewBag.Authorized)
{
<div id="profile_aliases" class="text-muted pt-0 pt-lg-2 pb-2">
@ -49,9 +50,34 @@
}
</div>
}
<div id="profile_level" class="font-weight-bold h4 mb-0 level-color-@Model.LevelInt @(isTempBanned ? "penalties-color-tempban" : "")">
@Model.Level @(isTempBanned ? $"({loc["WEBFRONT_PROFILE_TEMPBAN"]})" : "")
</div>
@if (Model.ActivePenalty != null)
{
<div class="font-weight-bold h4 mb-0 penalties-color-@Model.ActivePenalty.Type.ToString().ToLower()">
@foreach (var result in Utilities.SplitTranslationTokens(translationKey))
{
switch (result.MatchValue)
{
case "reason":
<span class="text-white font-weight-lighter">@(ViewBag.Authorized ? !string.IsNullOrEmpty(Model.ActivePenalty.AutomatedOffense) && Model.ActivePenalty.Type != EFPenalty.PenaltyType.Warning ? Utilities.FormatExt(ViewBag.Localization["WEBFRONT_PROFILE_ANTICHEAT_DETECTION"], Model.ActivePenalty.AutomatedOffense) : Model.ActivePenalty.Offense : Model.ActivePenalty.Offense)</span>
break;
case "time":
<span class="text-white font-weight-lighter">
@Utilities.HumanizeForCurrentCulture(Model.ActivePenalty.Expires.Value - DateTime.UtcNow)
</span>
break;
default:
<span>@result.MatchValue</span>
break;
}
}
</div>
}
else
{
<div id="profile_level" class="font-weight-bold h4 mb-0 level-color-@Model.LevelInt">
@Model.Level
</div>
}
</div>
@if (ViewBag.Authorized)
{
@ -89,23 +115,32 @@
</div>
<div id="profile_info" class="row d-block d-lg-flex flex-row border-bottom border-top pt-2 pb-2">
@foreach (var metaColumn in informationMeta)
{
<div class="text-center text-lg-left mr-0 mr-lg-4">
@foreach (var meta in metaColumn)
<partial name="Meta/_Information.cshtml" model="@Model.Meta" />
</div>
<div class="row border-bottom">
<div class="text-center bg-dark p-2 pl-3 pr-4 text-muted col-12 col-md-auto" id="filter_meta_container_button">
<span class="oi oi-sort-ascending"></span>
<a>Filter Meta</a>
</div>
<div class="d-none d-md-flex flex-fill" id="filter_meta_container">
@foreach (MetaType type in Enum.GetValues(typeof(MetaType)))
{
if (!ignoredMetaTypes.Contains(type))
{
<div class="profile-meta-entry" title="@(string.IsNullOrEmpty(meta.Extra) ? meta.Key : meta.Extra)">
<span class="profile-meta-value text-primary"><color-code value="@meta.Value" allow="@ViewBag.EnableColorCodes"></color-code></span>
<span class="profile-meta-title text-muted"> @meta.Key</span>
</div>
<a asp-action="ProfileAsync" asp-controller="Client"
class="nav-link p-2 pl-3 pr-3 text-center col-12 col-md-auto text-md-left @(Model.MetaFilterType.HasValue && Model.MetaFilterType.Value.ToString() == type.ToString() ? "btn-primary text-white" : "text-muted")"
asp-route-id="@Model.ClientId"
asp-route-metaFilterType="@type"
data-meta-type="@type">@type.ToTranslatedName()</a>
}
</div>
}
}
</div>
</div>
<div class="row d-md-flex pt-2">
<div id="profile_events" class="text-muted text-left ml-sm-0">
@await Component.InvokeAsync("ProfileMetaList", new { clientId = Model.ClientId, count = 30, offset = 0 })
<div id="profile_events" class="text-muted text-left pl-4 pr-4 pl-md-0 pr-md-0">
@await Component.InvokeAsync("ProfileMetaList", new { clientId = Model.ClientId, count = 30, offset = 0, startAt = DateTime.UtcNow, metaType = Model.MetaFilterType })
</div>
</div>
@ -122,5 +157,5 @@
<script type="text/javascript" src="~/js/loader.js"></script>
<script type="text/javascript" src="~/js/profile.js"></script>
</environment>
<script>initLoader('/Client/Meta/@Model.ClientId', '#profile_events', 30);</script>
<script>initLoader('/Client/Meta/@Model.ClientId', '#profile_events', 30, 30, [{ 'name': 'metaFilterType', 'value': '@Model.MetaFilterType' }]);</script>
}

View File

@ -0,0 +1,53 @@
@using SharedLibraryCore.Dtos.Meta.Responses
@model AdministeredPenaltyResponse
@{
string localizationKey = $"WEBFRONT_CLIENT_META_PENALIZED_{Model.PenaltyType.ToString().ToUpper()}_V2";
}
<div class="d-inline">
@foreach (var match in Utilities.SplitTranslationTokens(localizationKey))
{
if (match.IsInterpolation)
{
if (match.MatchValue == "action")
{
<span class="penalties-color-@Model.PenaltyType.ToString().ToLower()">@match.TranslationValue</span>
}
else if (match.MatchValue == "offender")
{
<span class="text-highlight">
<a class="link-inverse" href="@Model.OffenderClientId">
<color-code value="@Model.OffenderName" allow="@ViewBag.EnableColorCodes"></color-code>
</a>
</span>
}
else if (match.MatchValue == "reason")
{
<span class="text-white">
@if (ViewBag.Authorized && !string.IsNullOrEmpty(Model.AutomatedOffense) && Model.PenaltyType != SharedLibraryCore.Database.Models.EFPenalty.PenaltyType.Warning)
{
<span>@Utilities.FormatExt(ViewBag.Localization["WEBFRONT_PROFILE_ANTICHEAT_DETECTION"], Model.AutomatedOffense)</span>
<span class="oi oi-list-rich align-top text-primary automated-penalty-info-detailed" data-penalty-id="@Model.PenaltyId" style="margin-top: 0.125rem;" title="@ViewBag.Localization["WEBFRONT_CLIENT_META_AC_METRIC"]"></span>
}
else
{
<color-code value="@Model.Offense" allow="@ViewBag.EnableColorCodes"></color-code>
}
</span>
}
else if (match.MatchValue == "time")
{
<span class="text-white">@Model.LengthText</span>
}
}
else
{
<span>@match.MatchValue</span>
}
}
</div>

View File

@ -0,0 +1,43 @@
@model IEnumerable<SharedLibraryCore.Dtos.Meta.Responses.InformationResponse>
@{
var informationMeta = Model
.Where(_meta => _meta.Type == SharedLibraryCore.Interfaces.MetaType.Information)
.OrderBy(_meta => _meta.Order)
.GroupBy(_meta => _meta.Column)
.OrderBy(_grouping => _grouping.Key);
}
@foreach (var metaColumn in informationMeta)
{
<div class="text-center text-lg-left mr-0 mr-lg-4">
@foreach (var meta in metaColumn)
{
<div class="profile-meta-entry" title="@meta.ToolTipText">
@{var results = Utilities.SplitTranslationTokens(meta.Key);}
@if (results.Any(_result => _result.IsInterpolation))
{
foreach (var result in results)
{
if (result.IsInterpolation)
{
<span class="profile-meta-value text-primary"><color-code value="@meta.Value" allow="@ViewBag.EnableColorCodes"></color-code></span>
}
else
{
<span class="profile-meta-title text-muted">@result.MatchValue</span>
}
}
}
else
{
<span class="profile-meta-value text-primary"><color-code value="@meta.Value" allow="@ViewBag.EnableColorCodes"></color-code></span>
<span class="profile-meta-title text-muted"> @meta.Key</span>
}
</div>
}
</div>
}

View File

@ -0,0 +1,9 @@
@using SharedLibraryCore.Dtos.Meta.Responses;
@model MessageResponse
<span class="client-message" data-serverid="@Model.ServerId" data-when="@Model.When.ToFileTimeUtc()">
<span class="oi oi-chevron-right text-white-50 align-middle client-message-prefix" title="@ViewBag.Localization["WEBFRONT_PROFILE_MESSAGE_CONTEXT"]" style="font-size: 0.75rem; margin-top: -0.256rem"></span>
<span class="text-muted">
<color-code value="@Model.Message" allow="@ViewBag.EnableColorCodes"></color-code>
</span>
</span>

View File

@ -0,0 +1,74 @@
@using SharedLibraryCore.Dtos.Meta.Responses
@using SharedLibraryCore
@model ReceivedPenaltyResponse
@{
string localizationKey = $"WEBFRONT_CLIENT_META_WAS_PENALIZED_{Model.PenaltyType.ToString().ToUpper()}_V2";
}
<div class="d-inline">
@foreach (var match in Utilities.SplitTranslationTokens(localizationKey))
{
if (match.IsInterpolation)
{
if (match.MatchValue == "action")
{
<span class="penalties-color-@Model.PenaltyType.ToString().ToLower()">@match.TranslationValue</span>
}
else if (match.MatchValue == "punisher")
{
<span class="text-highlight">
<a class="link-inverse" href="@Model.PunisherClientId">
<color-code value="@Model.PunisherName" allow="@ViewBag.EnableColorCodes"></color-code>
</a>
</span>
}
else if (match.MatchValue == "reason")
{
<span class="text-white">
@if (ViewBag.Authorized && !string.IsNullOrEmpty(Model.AutomatedOffense) && Model.PenaltyType != SharedLibraryCore.Database.Models.EFPenalty.PenaltyType.Warning)
{
<span>@Utilities.FormatExt(ViewBag.Localization["WEBFRONT_PROFILE_ANTICHEAT_DETECTION"], Model.AutomatedOffense)</span>
<span class="oi oi-list-rich align-top text-primary automated-penalty-info-detailed" data-penalty-id="@Model.PenaltyId" style="margin-top: 0.125rem;" title="@ViewBag.Localization["WEBFRONT_CLIENT_META_AC_METRIC"]"></span>
}
else
{
<color-code value="@Model.Offense" allow="@ViewBag.EnableColorCodes"></color-code>
}
</span>
}
else if (match.MatchValue == "time")
{
<span class="text-white">@Model.LengthText</span>
}
}
else
{
<span>@match.MatchValue</span>
}
}
@if (Model.ClientId != Model.OffenderClientId)
{
<span>&mdash;</span>
@foreach (var helperResult in Utilities.SplitTranslationTokens("WEBFRONT_PROFILE_LINKED_ACCOUNT"))
{
if (!helperResult.IsInterpolation)
{
<span>@helperResult.MatchValue</span>
}
else
{
<a class="link-inverse" href="@Model.OffenderClientId">
<color-code value="@Model.OffenderName" allow="@ViewBag.EnableColorCodes"></color-code>
</a>
}
}
}
</div>

View File

@ -0,0 +1,27 @@
@using SharedLibraryCore.Dtos.Meta.Responses
@using SharedLibraryCore
@model UpdatedAliasResponse
@foreach (var token in Utilities.SplitTranslationTokens("WEBFRONT_PROFILE_META_CONNECT_ALIAS"))
{
if (token.IsInterpolation)
{
switch (token.MatchValue)
{
case "action":
<span class="text-warning">@token.TranslationValue</span>
break;
case "alias":
<span class="text-white">
<color-code value="@Model.Name" allow="@ViewBag.EnableColorCodes"></color-code>
[@Model.IPAddress]
</span>
break;
}
}
else
{
<span class="text-muted">@token.MatchValue</span>
}
}

View File

@ -1,94 +1,66 @@
@model IEnumerable<SharedLibraryCore.Dtos.ProfileMeta>
@using SharedLibraryCore.Interfaces;
@model IEnumerable<IClientMeta>
@{
Layout = null;
var timeSinceLastEvent = DateTime.MinValue;
var lastHeaderEventDate = DateTime.UtcNow;
dynamic formatPenaltyInfo(SharedLibraryCore.Dtos.ProfileMeta meta)
TimeSpan timeSpanForEvent(DateTime When)
{
var penalty = meta.Value as SharedLibraryCore.Dtos.PenaltyInfo;
var timePassed = (DateTime.UtcNow - When);
var daysPassed = timePassed.TotalDays;
var minutesPassed = timePassed.TotalMinutes;
string localizationKey = meta.Type == SharedLibraryCore.Dtos.ProfileMeta.MetaType.Penalized ?
$"WEBFRONT_CLIENT_META_PENALIZED_{penalty.PenaltyTypeText.ToUpper()}" :
$"WEBFRONT_CLIENT_META_WAS_PENALIZED_{penalty.PenaltyTypeText.ToUpper()}";
string localizationMessage = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex[localizationKey];
var regexMatch = System.Text.RegularExpressions.Regex.Match(localizationMessage, @"^.*{{([^{}]+)}}.+$");
string penaltyType = regexMatch.Groups[1].Value.ToString();
var secondMatch = System.Text.RegularExpressions.Regex.Match(localizationMessage, @"\{\{.+\}\}(.+)\{0\}(.+)\{1\}");
return new
if (minutesPassed <= 60)
{
Type = meta.Type,
Match = secondMatch,
Penalty = penalty,
PenaltyType = penaltyType
};
return TimeSpan.FromMinutes(5);
}
if (minutesPassed > 60 && daysPassed <= 1)
{
return TimeSpan.FromHours(1);
}
if (daysPassed > 1 && daysPassed <= 7)
{
return TimeSpan.FromDays(1);
}
if (daysPassed > 7 && daysPassed <= 31)
{
return TimeSpan.FromDays(31);
}
if (daysPassed > 31 && daysPassed <= 365)
{
return TimeSpan.FromDays(31);
}
else
{
return TimeSpan.FromDays(365);
}
}
}
@if (Model.Count() == 0)
{
<div class="p2 text-muted profile-event-timestep">@SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_NONE"]</div>
<div class="p2 text-muted profile-event-timestep">@ViewBag.Localization["WEBFRONT_CLIENT_META_NONE"]</div>
}
@foreach (var meta in Model.OrderByDescending(_meta => _meta.When))
{
@if (Math.Abs((meta.When - timeSinceLastEvent).TotalDays) >= 1)
@if ((lastHeaderEventDate - meta.When) > timeSpanForEvent(lastHeaderEventDate))
{
<div class="p2 text-white profile-event-timestep">
<span class="text-primary">&mdash;</span>
<span>@SharedLibraryCore.Utilities.GetTimePassed(meta.When, true)</span>
<span>@meta.When.HumanizeForCurrentCulture()</span>
</div>
timeSinceLastEvent = meta.When;
lastHeaderEventDate = meta.When;
}
@switch (meta.Type)
{
case SharedLibraryCore.Dtos.ProfileMeta.MetaType.ChatMessage:
case SharedLibraryCore.Dtos.ProfileMeta.MetaType.QuickMessage:
<div class="profile-meta-entry loader-data-time" data-time="@meta.When">
<span style="color:white;">></span>
<span class="client-message text-muted @(meta.Type == SharedLibraryCore.Dtos.ProfileMeta.MetaType.QuickMessage ? "font-italic" : "")" data-serverid="@meta.Extra" data-when="@meta.When.ToFileTimeUtc()" title="@SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_PROFILE_MESSAGE_CONTEXT"]"> <color-code value="@meta.Value" allow="@ViewBag.EnableColorCodes"></color-code></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">
@{ var penaltyInfo = formatPenaltyInfo(meta); }
@if (meta.Type == SharedLibraryCore.Dtos.ProfileMeta.MetaType.Penalized)
{
<span class="penalties-color-@penaltyInfo.Penalty.PenaltyTypeText.ToLower()">@penaltyInfo.PenaltyType</span>
<span>@penaltyInfo.Match.Groups[1].ToString()</span> <!-- by -->
<span class="text-highlight">
<!-- punisher -->
<a class="link-inverse" href="@penaltyInfo.Penalty.OffenderId">
<color-code value="@penaltyInfo.Penalty.OffenderName" allow="@ViewBag.EnableColorCodes"></color-code>
</a>
</span>
<span>@penaltyInfo.Match.Groups[2].ToString()</span> <!-- for -->
<span class="@(ViewBag.Authorized ? "automated-penalty-info-detailed" : "")} text-white"
data-penalty-id="@penaltyInfo.Penalty.Id"><color-code value="@penaltyInfo.Penalty.Offense" allow="@ViewBag.EnableColorCodes"></color-code> @(ViewBag.Authorized ? penaltyInfo.Penalty.AdditionalPenaltyInformation : "")</span>
}
@if (meta.Type == SharedLibraryCore.Dtos.ProfileMeta.MetaType.ReceivedPenalty)
{
<span class="penalties-color-@penaltyInfo.Penalty.PenaltyTypeText.ToLower()">@penaltyInfo.PenaltyType</span> <!-- actioned -->
<span>@penaltyInfo.Match.Groups[1].ToString()</span> <!-- by -->
<span class="text-highlight">
<a class="link-inverse" href="@penaltyInfo.Penalty.PunisherId">
<color-code value="@penaltyInfo.Penalty.PunisherName" allow="@ViewBag.EnableColorCodes"></color-code>
</a> <!-- punisher -->
</span>
<span>@penaltyInfo.Match.Groups[2]</span>
<span class="@(ViewBag.Authorized ? "automated-penalty-info-detailed" : "") text-white"
data-penalty-id="@penaltyInfo.Penalty.Id">
<color-code value="@penaltyInfo.Penalty.Offense" allow="@ViewBag.EnableColorCodes"></color-code> @(ViewBag.Authorized ? penaltyInfo.Penalty.AdditionalPenaltyInformation : "")
</span>
}
</div>
break;
}
}
<div class="profile-meta-entry loader-data-time" data-time="@meta.When.ToFileTimeUtc()" title="@Utilities.FormatExt(ViewBag.Localization["WEBFRONT_PROFILE_META_DATE_OCCURRED"], meta.When.ToString())">
<partial name="~/Views/Client/Profile/Meta/_@(meta.GetType().Name).cshtml" model="meta" />
</div>
}

View File

@ -1,4 +1,5 @@
@using SharedLibraryCore
@using WebfrontCore
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, SharedLibraryCore
@addTagHelper *, SharedLibraryCore
@addTagHelper *, WebfrontCore