fix some issues with chat search feature

This commit is contained in:
RaidMax 2023-08-27 12:28:00 -05:00
parent 648eec25f2
commit 69691f75f4
6 changed files with 9 additions and 118 deletions

View File

@ -13,7 +13,6 @@ namespace IW4MAdmin.Plugins.Stats
{ {
private const int ZScoreRange = 3; private const int ZScoreRange = 3;
private const int RankIconDivisions = 24; private const int RankIconDivisions = 24;
private const int MaxMessages = 100;
public class LogParams public class LogParams
{ {
@ -127,70 +126,5 @@ namespace IW4MAdmin.Plugins.Stats
return 0; return 0;
} }
/// <summary>
/// todo: lets abstract this out to a generic buildable query
/// this is just a dirty PoC
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
public static ChatSearchQuery ParseSearchInfo(this string query, int count, int offset)
{
string[] filters = query.Split('|');
var searchRequest = new ChatSearchQuery
{
Filter = query,
Count = count,
Offset = offset
};
// sanity checks
searchRequest.Count = Math.Min(searchRequest.Count, MaxMessages);
searchRequest.Count = Math.Max(searchRequest.Count, 0);
searchRequest.Offset = Math.Max(searchRequest.Offset, 0);
if (filters.Length > 1)
{
if (filters[0].ToLower() != "chat")
{
throw new ArgumentException("Query is not compatible with chat");
}
foreach (string filter in filters.Skip(1))
{
string[] args = filter.Split(' ');
if (args.Length > 1)
{
string recombinedArgs = string.Join(' ', args.Skip(1));
switch (args[0].ToLower())
{
case "before":
searchRequest.SentBefore = DateTime.Parse(recombinedArgs);
break;
case "after":
searchRequest.SentAfter = DateTime.Parse(recombinedArgs);
break;
case "server":
searchRequest.ServerId = args[1];
break;
case "client":
searchRequest.ClientId = int.Parse(args[1]);
break;
case "contains":
searchRequest.MessageContains = string.Join(' ', args.Skip(1));
break;
case "sort":
searchRequest.Direction = Enum.Parse<SortDirection>(args[1], ignoreCase: true);
break;
}
}
}
return searchRequest;
}
throw new ArgumentException("No filters specified for chat search");
}
} }
} }

View File

@ -50,8 +50,8 @@ namespace SharedLibraryCore
public static char[] DirectorySeparatorChars = { '\\', '/' }; public static char[] DirectorySeparatorChars = { '\\', '/' };
public static char CommandPrefix { get; set; } = '!'; public static char CommandPrefix { get; set; } = '!';
public static string ToStandardFormat(this DateTime? time) => time?.ToString("yyyy-MM-dd H:mm:ss UTC"); public static string ToStandardFormat(this DateTime? time) => time?.ToString("yyyy-MM-dd HH:mm:ss UTC");
public static string ToStandardFormat(this DateTime time) => time.ToString("yyyy-MM-dd H:mm:ss UTC"); public static string ToStandardFormat(this DateTime time) => time.ToString("yyyy-MM-dd HH:mm:ss UTC");
public static EFClient IW4MAdminClient(Server server = null) public static EFClient IW4MAdminClient(Server server = null)
{ {

View File

@ -137,29 +137,9 @@ namespace IW4MAdmin.Plugins.Web.StatsWeb.Controllers
} }
[HttpGet("Message/FindNext")] [HttpGet("Message/FindNext")]
public async Task<IActionResult> FindNextMessages([FromQuery] string query, [FromQuery] int count, public async Task<IActionResult> FindNextMessages(ChatResourceRequest query)
[FromQuery] int offset)
{ {
ChatSearchQuery searchRequest; var result = await _chatResourceQueryHelper.QueryResource(query);
try
{
searchRequest = query.ParseSearchInfo(count, offset);
}
catch (ArgumentException e)
{
_logger.LogWarning(e, "Could not parse chat message search query {query}", query);
throw;
}
catch (FormatException e)
{
_logger.LogWarning(e, "Could not parse chat message search query filter format {query}", query);
throw;
}
var result = await _chatResourceQueryHelper.QueryResource(searchRequest);
return PartialView("~/Views/Client/Message/_Item.cshtml", result.Results); return PartialView("~/Views/Client/Message/_Item.cshtml", result.Results);
} }

View File

@ -26,14 +26,14 @@ else
</tbody> </tbody>
</table> </table>
<div id="loaderLoad" class="mt-10 m-auto text-center d-none d-lg-block"> <div id="loaderLoad" class="mt-10 m-auto text-center">
<i class="loader-load-more oi oi-chevron-bottom"></i> <i class="loader-load-more oi oi-chevron-bottom"></i>
</div> </div>
@section scripts { @section scripts {
<script> <script>
$(document).ready(function () { $(document).ready(function () {
initLoader('/Message/FindNext?query=@ViewBag.Query', '#message_table_body', @Model.RetrievedResultCount, @ViewBag.QueryLimit); initLoader(`/Message/FindNext${window.location.search}`, '#message_table_body', @Model.RetrievedResultCount, 30);
}); });
</script> </script>
} }

View File

@ -44,7 +44,7 @@
@foreach (var server in manager!.GetServers()) @foreach (var server in manager!.GetServers())
{ {
<option value="@server.Id" selected="@(server.Id == existingChatFilter?.ServerId)"> <option value="@server.Id" selected="@(server.Id == existingChatFilter?.ServerId)">
[@server.GameName.ToString()] @server.ServerName [@server.GameName.ToString()] @server.ServerName.StripColors()
</option> </option>
} }
</select> </select>
@ -62,6 +62,7 @@
value="@afterDate.ToString("s", CultureInfo.InvariantCulture)"/> value="@afterDate.ToString("s", CultureInfo.InvariantCulture)"/>
<input type="time" class="form-control w-half ml-10" name="sentAfterTime" <input type="time" class="form-control w-half ml-10" name="sentAfterTime"
id="sentAfterTime@(Model)" id="sentAfterTime@(Model)"
style="color-scheme: dark;"
value="@afterDate.ToString("HH:mm")"/> value="@afterDate.ToString("HH:mm")"/>
</div> </div>
@ -78,6 +79,7 @@
value="@beforeDate.ToString("s", CultureInfo.InvariantCulture)"/> value="@beforeDate.ToString("s", CultureInfo.InvariantCulture)"/>
<input type="time" class="form-control w-half ml-10" name="sentBeforeTime" <input type="time" class="form-control w-half ml-10" name="sentBeforeTime"
id="sentBeforeTime@(Model)" id="sentBeforeTime@(Model)"
style="color-scheme: dark;"
value="@beforeDate.ToString("HH:mm")"/> value="@beforeDate.ToString("HH:mm")"/>
</div> </div>
</div> </div>

View File

@ -1,28 +1,4 @@
$(document).ready(function () { $(document).ready(function () {
$('.form-inline').submit(function (e) {
const id = $(e.currentTarget).find('input');
if ($(id).val().length < 3) {
e.preventDefault();
$(id)
.addClass('input-text-danger')
.delay(25)
.queue(function () {
$(this).addClass('input-border-transition').dequeue();
})
.delay(1000)
.queue(function () {
$(this).removeClass('input-text-danger').dequeue();
})
.delay(500)
.queue(function () {
$(this).removeClass('input-border-transition').dequeue();
});
} else if ($(id).val().startsWith("chat|")) {
e.preventDefault();
window.location = "/Message/Find?query=" + $(id).val();
}
});
$('.date-picker-input').each((index, selector) => { $('.date-picker-input').each((index, selector) => {
new Datepicker(selector, { new Datepicker(selector, {
buttonClass: 'btn', buttonClass: 'btn',
@ -33,7 +9,6 @@
}); });
}); });
const clientSearchWrapper = $('*[id^="clientSearchWrapper"]'); const clientSearchWrapper = $('*[id^="clientSearchWrapper"]');
const chatSearchWrapper = $('*[id^="chatSearchWrapper"]'); const chatSearchWrapper = $('*[id^="chatSearchWrapper"]');
const searchTypeSelector = $('#searchTypeSelectorParent select'); const searchTypeSelector = $('#searchTypeSelectorParent select');