mirror of
https://github.com/aliasvault/aliasvault.git
synced 2026-05-16 12:29:01 -04:00
Add general log source context to term filter (#705)
This commit is contained in:
committed by
Leendert de Borst
parent
d1924f4044
commit
c7360ee23c
@@ -153,24 +153,8 @@ else
|
||||
await using var dbContext = await DbContextFactory.CreateDbContextAsync();
|
||||
var query = dbContext.Logs.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(SearchTerm))
|
||||
{
|
||||
// Reset page number back to 1 if the search term has changed.
|
||||
if (SearchTerm != _lastSearchTerm)
|
||||
{
|
||||
CurrentPage = 1;
|
||||
}
|
||||
_lastSearchTerm = SearchTerm;
|
||||
|
||||
query = query.Where(x => EF.Functions.Like(x.Application.ToLower(), "%" + SearchTerm.ToLower() + "%") ||
|
||||
EF.Functions.Like(x.Message.ToLower(), "%" + SearchTerm.ToLower() + "%") ||
|
||||
EF.Functions.Like(x.Level.ToLower(), "%" + SearchTerm.ToLower() + "%"));
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(SelectedServiceName))
|
||||
{
|
||||
query = query.Where(x => x.Application == SelectedServiceName);
|
||||
}
|
||||
query = ApplySearchTermFilter(query);
|
||||
query = ApplyServiceNameFilter(query);
|
||||
|
||||
// Apply sort.
|
||||
switch (SortColumn)
|
||||
@@ -212,6 +196,44 @@ else
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies a search term filter to the query.
|
||||
/// </summary>
|
||||
/// <param name="query">The query to apply the filter to.</param>
|
||||
private IQueryable<Log> ApplySearchTermFilter(IQueryable<Log> query)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(SearchTerm))
|
||||
{
|
||||
// Reset page number back to 1 if the search term has changed.
|
||||
if (SearchTerm != _lastSearchTerm)
|
||||
{
|
||||
CurrentPage = 1;
|
||||
}
|
||||
_lastSearchTerm = SearchTerm;
|
||||
|
||||
query = query.Where(x => EF.Functions.Like(x.Application.ToLower(), "%" + SearchTerm.ToLower() + "%") ||
|
||||
EF.Functions.Like(x.Message.ToLower(), "%" + SearchTerm.ToLower() + "%") ||
|
||||
EF.Functions.Like(x.Level.ToLower(), "%" + SearchTerm.ToLower() + "%") ||
|
||||
EF.Functions.Like(x.SourceContext.ToLower(), "%" + SearchTerm.ToLower() + "%"));
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies a service name filter to the query.
|
||||
/// </summary>
|
||||
/// <param name="query">The query to apply the filter to.</param>
|
||||
private IQueryable<Log> ApplyServiceNameFilter(IQueryable<Log> query)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(SelectedServiceName))
|
||||
{
|
||||
query = query.Where(x => x.Application == SelectedServiceName);
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
private async Task DeleteLogsWithConfirmation()
|
||||
{
|
||||
if (await ConfirmModalService.ShowConfirmation("Confirm Delete", "Are you sure you want to delete all logs? This action cannot be undone."))
|
||||
|
||||
@@ -82,12 +82,6 @@ else
|
||||
/// </summary>
|
||||
private string _lastSearchTerm = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The page number before the search term was changed.
|
||||
/// This is used to reset the page number back to the previous page when the search term is removed.
|
||||
/// </summary>
|
||||
private int _currentPageBeforeSearch = 1;
|
||||
|
||||
private string SearchTerm
|
||||
{
|
||||
get => _searchTerm;
|
||||
@@ -136,7 +130,6 @@ else
|
||||
// Reset page number back to 1 if the search term has changed.
|
||||
if (SearchTerm != _lastSearchTerm && CurrentPage != 1)
|
||||
{
|
||||
_currentPageBeforeSearch = CurrentPage;
|
||||
CurrentPage = 1;
|
||||
}
|
||||
_lastSearchTerm = SearchTerm;
|
||||
|
||||
Reference in New Issue
Block a user