update recently clients to show last 24 hours

fix color codes on profile meta data
This commit is contained in:
RaidMax 2019-10-02 17:59:10 -05:00
parent 524589717b
commit ede5c9de51
2 changed files with 47 additions and 20 deletions

View File

@ -10,7 +10,6 @@ using static SharedLibraryCore.Database.Models.EFClient;
namespace SharedLibraryCore.Services
{
public class ClientService : Interfaces.IEntityService<EFClient>
{
public async Task<EFClient> Create(EFClient entity)
@ -579,19 +578,20 @@ namespace SharedLibraryCore.Services
/// <returns></returns>
public async Task<IList<PlayerInfo>> GetRecentClients()
{
var startOfPeriod = DateTime.UtcNow.AddHours(-24);
using (var context = new DatabaseContext(true))
{
var iqClients = context.Clients
.Where(_client => _client.CurrentAlias.IPAddress != null)
.Where(_client => _client.LastConnection >= startOfPeriod)
.Select(_client => new PlayerInfo()
{
ClientId = _client.ClientId,
Name = _client.CurrentAlias.Name,
IPAddress = _client.CurrentAlias.IPAddress.ConvertIPtoString(),
LastConnection = _client.FirstConnection
})
.OrderByDescending(_client => _client.ClientId)
.Take(10);
});
#if DEBUG
var sql = iqClients.ToSql();
#endif

View File

@ -4,7 +4,7 @@
var timeSinceLastEvent = DateTime.MinValue;
string formatPenalty(SharedLibraryCore.Dtos.ProfileMeta meta)
dynamic formatPenaltyInfo(SharedLibraryCore.Dtos.ProfileMeta meta)
{
var penalty = meta.Value as SharedLibraryCore.Dtos.PenaltyInfo;
@ -15,21 +15,15 @@
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\}");
localizationMessage = localizationMessage.Replace(penaltyType, $"<span class='penalties-color-{penalty.PenaltyTypeText.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='{(ViewBag.Authorized ? "automated-penalty-info-detailed" : "")} text-white' data-penalty-id='{penalty.Id}'>{penalty.Offense} {(ViewBag.Authorized ? penalty.AdditionalPenaltyInformation : "")}</span>")
.Replace("{", "")
.Replace("}", "") :
string.Format(localizationMessage,
$"<span class='text-highlight'><a class='link-inverse' href='{penalty.PunisherId}'>{penalty.PunisherName}</a></span>",
$"<span class='{(ViewBag.Authorized ? "automated-penalty-info-detailed" : "")} text-white' data-penalty-id='{penalty.Id}'>{penalty.Offense} {(ViewBag.Authorized ? penalty.AdditionalPenaltyInformation : "")}</span>",
penalty.Offense)
.Replace("{", "")
.Replace("}", "");
return new
{
Type = meta.Type,
Match = secondMatch,
Penalty = penalty,
PenaltyType = penaltyType
};
}
}
@ -61,7 +55,40 @@
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"><color-code value="@Html.Raw(formatPenalty(meta))" allow="@ViewBag.EnableColorCodes"></color-code></div>
<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;
}
}