add chat to advanced search

This commit is contained in:
RaidMax 2023-08-26 22:56:37 -05:00
parent 08edbf9bd4
commit 80774853b6
10 changed files with 288 additions and 146 deletions

View File

@ -25,11 +25,24 @@ namespace Stats.Dtos
/// </summary>
public DateTime? SentAfter { get; set; }
/// <summary>
/// The time associated with SentAfter date
/// </summary>
public string SentAfterTime { get; set; } = "00:00";
public DateTime? SentAfterDateTime => SentAfter?.Add(TimeSpan.Parse(SentAfterTime));
/// <summary>
/// only look for messages sent before this date0
/// </summary>
public DateTime SentBefore { get; set; } = DateTime.UtcNow;
public DateTime SentBefore { get; set; } = DateTime.UtcNow.Date;
public string SentBeforeTime { get; set; } = DateTime.UtcNow.ToString("HH:mm");
public DateTime? SentBeforeDateTime => SentBefore.Add(TimeSpan.Parse(SentBeforeTime));
public bool IsExactMatch { get; set; }
/// <summary>
/// indicates if the chat is on the meta page
/// </summary>

View File

@ -53,11 +53,11 @@ namespace Stats.Helpers
}
var iqMessages = context.Set<EFClientMessage>()
.Where(message => message.TimeSent < query.SentBefore);
.Where(message => message.TimeSent < query.SentBeforeDateTime);
if (query.SentAfter is not null)
if (query.SentAfterDateTime is not null)
{
iqMessages = iqMessages.Where(message => message.TimeSent >= query.SentAfter);
iqMessages = iqMessages.Where(message => message.TimeSent >= query.SentAfterDateTime);
}
if (query.ClientId is not null)
@ -72,7 +72,10 @@ namespace Stats.Helpers
if (!string.IsNullOrEmpty(query.MessageContains))
{
iqMessages = iqMessages.Where(message => EF.Functions.Like(message.Message.ToLower(), $"%{query.MessageContains.ToLower()}%"));
iqMessages = query.IsExactMatch
? iqMessages.Where(message => message.Message.ToLower() == query.MessageContains.ToLower())
: iqMessages.Where(message =>
EF.Functions.Like(message.Message.ToLower(), $"%{query.MessageContains.ToLower()}%"));
}
var iqResponse = iqMessages

View File

@ -179,6 +179,7 @@ namespace SharedLibraryCore
server.Reports.Count(report => DateTime.UtcNow - report.ReportedOn <= TimeSpan.FromHours(24)));
ViewBag.PermissionsSet = PermissionsSet;
ViewBag.Alerts = AlertManager.RetrieveAlerts(Client);
ViewBag.Manager = Manager;
base.OnActionExecuting(context);
}

View File

@ -17,6 +17,7 @@ using Microsoft.Extensions.Logging;
using ILogger = Microsoft.Extensions.Logging.ILogger;
using Data.Abstractions;
using Stats.Config;
using WebfrontCore.QueryHelpers.Models;
namespace IW4MAdmin.Plugins.Web.StatsWeb.Controllers
{
@ -121,7 +122,7 @@ namespace IW4MAdmin.Plugins.Web.StatsWeb.Controllers
}
[HttpGet("Message/Find")]
public async Task<IActionResult> FindMessage([FromQuery] string query)
public async Task<IActionResult> FindMessage([FromQuery] ChatResourceRequest query)
{
ViewBag.Localization = _translationLookup;
ViewBag.EnableColorCodes = _manager.GetApplicationSettings().Configuration().EnableColorCodes;
@ -130,26 +131,8 @@ namespace IW4MAdmin.Plugins.Web.StatsWeb.Controllers
ViewBag.Title = _translationLookup["WEBFRONT_STATS_MESSAGES_TITLE"];
ViewBag.Error = null;
ViewBag.IsFluid = true;
ChatSearchQuery searchRequest = null;
try
{
searchRequest = query.ParseSearchInfo(int.MaxValue, 0);
}
catch (ArgumentException e)
{
_logger.LogWarning(e, "Could not parse chat message search query {query}", query);
ViewBag.Error = e;
}
catch (FormatException e)
{
_logger.LogWarning(e, "Could not parse chat message search query filter format {query}", query);
ViewBag.Error = e;
}
var result = searchRequest != null ? await _chatResourceQueryHelper.QueryResource(searchRequest) : null;
var result = query != null ? await _chatResourceQueryHelper.QueryResource(query) : null;
return View("~/Views/Client/Message/Find.cshtml", result);
}

View File

@ -0,0 +1,9 @@
using Stats.Dtos;
namespace WebfrontCore.QueryHelpers.Models;
public class ChatResourceRequest : ChatSearchQuery
{
public bool HasData => !string.IsNullOrEmpty(MessageContains) || !string.IsNullOrEmpty(ServerId) ||
ClientId is not null || SentAfterDateTime is not null;
}

View File

@ -16,4 +16,7 @@ public class ClientResourceRequest : ClientPaginationRequest
public EFClient.Permission? ClientLevel { get; set; }
public Reference.Game? GameName { get; set; }
public bool IncludeGeolocationData { get; set; } = true;
public bool HasData => !string.IsNullOrEmpty(ClientName) || !string.IsNullOrEmpty(ClientIp) ||
!string.IsNullOrEmpty(ClientGuid) || ClientLevel is not null || GameName is not null;
}

View File

@ -0,0 +1,86 @@
@using WebfrontCore.QueryHelpers.Models
@using SharedLibraryCore.Interfaces
@using System.Globalization
@using Microsoft.AspNetCore.Mvc.TagHelpers
@model string
@{
var existingChatFilter = ViewBag.Query as ChatResourceRequest;
var manager = ViewBag.Manager as IManager;
}
<div id="chatSearchWrapper@(Model)" data-has-data="@(existingChatFilter?.HasData ?? false)" >
<div class="form-group">
<label for="messageContains@(Model)">@ViewBag.Localization["WEBFRONT_ACTION_LABEL_MESSAGE"]</label>
<div class="d-flex">
<input type="text" class="form-control" name="messageContains" id="messageContains@(Model)}"
placeholder="Contains" value="@existingChatFilter?.MessageContains"/>
<div class="custom-control ml-10 align-self-center">
<div class="custom-switch">
@if (existingChatFilter?.IsExactMatch ?? false)
{
<input type="checkbox" id="isExactMatch@(Model)" name="isExactMatch" value="true"
checked="checked">
}
else
{
<input type="checkbox" id="isExactMatch@(Model)" name="isExactMatch" value="true">
}
<label for="isExactMatch@(Model)">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_LABEL_EXACT"]</label>
</div>
</div>
</div>
</div>
<div class="form-group">
<label for="serverId@(Model)" class="w-quarter">@ViewBag.Localization["WEBFRONT_BAN_MGMT_FORM_ID"]</label>
<label for="clientId@(Model)" class="">@ViewBag.Localization["WEBFRONT_CONTEXT_MENU_GLOBAL_SERVER"]</label>
<div class="d-flex">
<input type="text" class="form-control w-quarter" name="clientId" id="clientId@(Model)}"
placeholder="Id" value="@existingChatFilter?.ClientId"/>
<select class="form-control w-three-quarter ml-10" id="serverId@(Model)" name="serverId">
<option value="">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_SELECT_PERMISSIONS_ANY"]</option>
@foreach (var server in manager!.GetServers())
{
<option value="@server.Id" selected="@(server.Id == existingChatFilter?.ServerId)">
[@server.GameName.ToString()] @server.ServerName
</option>
}
</select>
</div>
</div>
<div class="form-group">
<label for="sentAfter@(Model)">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_LABEL_SENT_AFTER"]</label>
@{
var afterDate = existingChatFilter?.SentAfterDateTime ?? DateTime.UtcNow.AddHours(-1);
}
<div class="d-flex">
<input type="text" class="form-control date-picker-input w-half" name="sentAfter"
id="sentAfter@(Model)" data-date="@afterDate.ToString("s", CultureInfo.InvariantCulture)"
value="@afterDate.ToString("s", CultureInfo.InvariantCulture)"/>
<input type="time" class="form-control w-half ml-10" name="sentAfterTime"
id="sentAfterTime@(Model)"
value="@afterDate.ToString("HH:mm")"/>
</div>
</div>
<div class="form-group">
<label for="sentAfter@(Model)">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_LABEL_SENT_BEFORE"]</label>
@{
var beforeDate = existingChatFilter?.SentBeforeDateTime ?? DateTime.UtcNow;
}
<div class="d-flex">
<input type="text" class="form-control date-picker-input w-half" name="sentBefore"
id="sentBefore@(Model)" data-date="@beforeDate.ToString("s", CultureInfo.InvariantCulture)"
value="@beforeDate.ToString("s", CultureInfo.InvariantCulture)"/>
<input type="time" class="form-control w-half ml-10" name="sentBeforeTime"
id="sentBeforeTime@(Model)"
value="@beforeDate.ToString("HH:mm")"/>
</div>
</div>
<input type="submit" class="btn btn-primary" value="@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_BUTTON_SUBMIT"]"/>
</div>

View File

@ -0,0 +1,116 @@
@using WebfrontCore.QueryHelpers.Models
@using System.Globalization
@using Data.Models
@using Data.Models.Client
@using Microsoft.AspNetCore.Mvc.TagHelpers
@using SharedLibraryCore.Dtos
@model string
@{
var existingClientFilter = ViewBag.ClientResourceRequest as ClientResourceRequest;
}
<div id="clientSearchWrapper@(Model)" data-has-data="@(existingClientFilter?.HasData ?? false)" >
<div class="form-group">
<label for="clientName@(Model)">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_LABEL_NAME"]</label>
<div class="d-flex">
<input type="text" class="form-control" name="clientName" id="clientName@(Model)"
placeholder="Unknown Soldier" value="@existingClientFilter?.ClientName"/>
<div class="custom-control ml-10 align-self-center">
<div class="custom-switch">
@if (existingClientFilter?.IsExactClientName ?? false)
{
<input type="checkbox" id="isExactClientName@(Model)" name="isExactClientName" value="true"
checked="checked">
}
else
{
<input type="checkbox" id="isExactClientName@(Model)" name="isExactClientName" value="true">
}
<label for="isExactClientName@(Model)">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_LABEL_EXACT"]</label>
</div>
</div>
</div>
</div>
<div class="form-group">
<label for="clientIP@(Model)">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_LABEL_IP"]</label>
<div class="d-flex">
<input type="text" class="form-control" name="clientIP" id="clientIP@(Model)" placeholder="1.1.1.1"
value="@existingClientFilter?.ClientIp">
<div class="custom-control ml-10 align-self-center">
<div class="custom-switch">
@if (existingClientFilter?.IsExactClientIp ?? false)
{
<input type="checkbox" id="isExactClientIP@(Model)" name="isExactClientIP" value="true"
checked="checked">
}
else
{
<input type="checkbox" id="isExactClientIP@(Model)" name="isExactClientIP" value="true">
}
<label for="isExactClientIP@(Model)">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_LABEL_EXACT"]</label>
</div>
</div>
</div>
</div>
<div class="form-group">
<label for="clientGuid@(Model)">GUID <span class="text-primary">&bull;</span> XUID <span class="text-primary">&bull;</span> NetworkID</label>
<input type="text" class="form-control" name="clientGuid" id="clientGuid@(Model)"
placeholder="110000100000001" value="@existingClientFilter?.ClientGuid"/>
</div>
<div class="form-group">
<label for="clientLevel@(Model)" class="w-half">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_LABEL_PERMISSION"]</label>
<label for="clientGameName@(Model)">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_LABEL_GAME"]</label>
<div class="d-flex">
<select class="form-control w-half" id="clientLevel@(Model)" name="clientLevel">
<option value="">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_SELECT_PERMISSIONS_ANY"]</option>
@foreach (EFClient.Permission permission in Enum.GetValues(typeof(EFClient.Permission)))
{
<option value="@((int)permission)" selected="@(permission == existingClientFilter?.ClientLevel)">
@permission.ToLocalizedLevelName()
</option>
}
</select>
<select class="form-control w-half ml-10" id="clientGameName@(Model)" name="gameName">
<option value="">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_SELECT_PERMISSIONS_ANY"]</option>
@foreach (Reference.Game game in Enum.GetValues(typeof(Reference.Game)))
{
<option value="@((int)game)" selected="@(game == existingClientFilter?.GameName)">
@ViewBag.Localization["GAME_" + game]
</option>
}
</select>
</div>
</div>
<div class="form-group">
<label for="clientConnected@(Model)">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_LABEL_CONNECTED_SINCE"]</label>
<div class="d-flex">
@{ var presetDate = (existingClientFilter?.ClientConnected ?? DateTime.UtcNow.AddYears(-1)).ToString("s", CultureInfo.InvariantCulture); }
<input type="text" class="form-control date-picker-input w-half" name="clientConnected"
id="clientConnected@(Model)" data-date="@presetDate"
value="@presetDate"/>
<div class="custom-control ml-10 align-self-center">
<div class="custom-switch">
@if ((existingClientFilter?.Direction ?? SortDirection.Descending) is SortDirection.Descending)
{
<input type="checkbox" id="resultOrder@(Model)" name="direction"
value="@((int)SortDirection.Ascending)">
}
else
{
<input type="checkbox" id="resultOrder@(Model)" name="direction"
value="@((int)SortDirection.Ascending)" checked="checked">
}
<label for="resultOrder@(Model)">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_LABEL_OLDEST_FIRST"]</label>
</div>
</div>
</div>
</div>
<input type="submit" class="btn btn-primary" value="@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_BUTTON_SUBMIT"]"/>
</div>

View File

@ -1,126 +1,21 @@
@using Data.Models.Client
@using SharedLibraryCore.Dtos
@using WebfrontCore.QueryHelpers.Models
@using Data.Models
@using System.Globalization
@model string
@{
var existingClientFilter = ViewBag.ClientResourceRequest as ClientResourceRequest;
}
<h6 class="dropdown-header">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_TITLE"]</h6>
<div class="dropdown-divider"></div>
<div class="dropdown-content">
<div class="form-group" id="searchTypeSelectorParent">
<label for="searchType@(Model)">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_LABEL_FOR"]</label>
<br/>
<select class="form-control" id="searchType@(Model)" name="searchType">
<option value="client">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_SELECT_TYPE_PLAYERS"]</option>
<option value="chat">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_SELECT_TYPE_CHAT"]</option>
</select>
</div>
<form asp-controller="Client" asp-action="AdvancedFind" method="get" id="advancedSearchDropdownContent@(Model)" onsubmit="showLoader()">
<div class="form-group">
<label for="searchType@(Model)">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_LABEL_FOR"]</label>
<br/>
<select class="form-control" id="searchType@(Model)" name="searchType" disabled="disabled">
<option value="client">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_SELECT_TYPE_PLAYERS"]</option>
</select>
</div>
<div class="form-group">
<label for="clientName@(Model)">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_LABEL_NAME"]</label>
<div class="d-flex">
<input type="text" class="form-control" name="clientName" id="clientName@(Model)"
placeholder="Unknown Soldier" value="@existingClientFilter?.ClientName"/>
<div class="custom-control ml-10 align-self-center">
<div class="custom-switch">
@if (existingClientFilter?.IsExactClientName ?? false)
{
<input type="checkbox" id="isExactClientName@(Model)" name="isExactClientName" value="true"
checked="checked">
}
else
{
<input type="checkbox" id="isExactClientName@(Model)" name="isExactClientName" value="true">
}
<label for="isExactClientName@(Model)">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_LABEL_EXACT"]</label>
</div>
</div>
</div>
</div>
<div class="form-group">
<label for="clientIP@(Model)">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_LABEL_IP"]</label>
<div class="d-flex">
<input type="text" class="form-control" name="clientIP" id="clientIP@(Model)" placeholder="1.1.1.1"
value="@existingClientFilter?.ClientIp">
<div class="custom-control ml-10 align-self-center">
<div class="custom-switch">
@if (existingClientFilter?.IsExactClientIp ?? false)
{
<input type="checkbox" id="isExactClientIP@(Model)" name="isExactClientIP" value="true"
checked="checked">
}
else
{
<input type="checkbox" id="isExactClientIP@(Model)" name="isExactClientIP" value="true">
}
<label for="isExactClientIP@(Model)">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_LABEL_EXACT"]</label>
</div>
</div>
</div>
</div>
<div class="form-group">
<label for="clientGuid@(Model)">GUID <span class="text-primary">&bull;</span> XUID <span class="text-primary">&bull;</span> NetworkID</label>
<input type="text" class="form-control" name="clientGuid" id="clientGuid@(Model)"
placeholder="110000100000001" value="@existingClientFilter?.ClientGuid"/>
</div>
<div class="form-group">
<label for="clientLevel@(Model)" class="w-half">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_LABEL_PERMISSION"]</label>
<label for="clientGameName@(Model)">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_LABEL_GAME"]</label>
<div class="d-flex">
<select class="form-control w-half" id="clientLevel@(Model)" name="clientLevel">
<option value="">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_SELECT_PERMISSIONS_ANY"]</option>
@foreach (EFClient.Permission permission in Enum.GetValues(typeof(EFClient.Permission)))
{
<option value="@((int)permission)" selected="@(permission == existingClientFilter?.ClientLevel)">
@permission.ToLocalizedLevelName()
</option>
}
</select>
<select class="form-control w-half ml-10" id="clientGameName@(Model)" name="gameName">
<option value="">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_SELECT_PERMISSIONS_ANY"]</option>
@foreach (Reference.Game game in Enum.GetValues(typeof(Reference.Game)))
{
<option value="@((int)game)" selected="@(game == existingClientFilter?.GameName)">
@ViewBag.Localization["GAME_" + game]
</option>
}
</select>
</div>
</div>
<div class="form-group">
<label for="clientConnected@(Model)">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_LABEL_CONNECTED_SINCE"]</label>
<div class="d-flex">
@{ var presetDate = (existingClientFilter?.ClientConnected ?? DateTime.UtcNow.AddYears(-1)).ToString("s", CultureInfo.InvariantCulture); }
<input type="text" class="form-control date-picker-input w-half" name="clientConnected"
id="clientConnected@(Model)" data-date="@presetDate"
value="@presetDate"/>
<div class="custom-control ml-10 align-self-center">
<div class="custom-switch">
@if ((existingClientFilter?.Direction ?? SortDirection.Descending) is SortDirection.Descending)
{
<input type="checkbox" id="resultOrder@(Model)" name="direction"
value="@((int)SortDirection.Ascending)">
}
else
{
<input type="checkbox" id="resultOrder@(Model)" name="direction"
value="@((int)SortDirection.Ascending)" checked="checked">
}
<label for="resultOrder@(Model)">@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_LABEL_OLDEST_FIRST"]</label>
</div>
</div>
</div>
</div>
<input type="submit" class="btn btn-primary" value="@ViewBag.Localization["WEBFRONT_ADVANCED_SEARCH_BUTTON_SUBMIT"]"/>
<partial name="Search/_ClientSearch.cshtml" model="@Model"/>
</form>
<form asp-controller="Stats" asp-action="FindMessage" method="get" onsubmit="showLoader()">
<partial name="Search/_ChatSearch.cshtml" model="@Model"/>
</form>
</div>

View File

@ -31,5 +31,38 @@
prevArrow: '<',
orientation: 'auto top'
});
})
});
const clientSearchWrapper = $('*[id^="clientSearchWrapper"]');
const chatSearchWrapper = $('*[id^="chatSearchWrapper"]');
const searchTypeSelector = $('#searchTypeSelectorParent select');
let isClients = false;
searchTypeSelector.on('change', function () {
if (isClients) {
clientSearchWrapper.removeClass('d-none');
chatSearchWrapper.addClass('d-none');
} else {
chatSearchWrapper.removeClass('d-none');
clientSearchWrapper.addClass('d-none');
}
isClients = !isClients;
});
const isDefault = clientSearchWrapper.data('has-data') !== 'True' && chatSearchWrapper.data('has-data') !== 'True';
if (isDefault) {
isClients = false;
searchTypeSelector.val('client').change();
} else {
if (clientSearchWrapper.data('has-data') === 'True') {
isClients = false;
searchTypeSelector.val('client').change();
}
if (chatSearchWrapper.data('has-data') === 'True') {
isClients = true;
searchTypeSelector.val('chat').change();
}
}
});