This commit is contained in:
Leendert de Borst
2024-10-07 20:50:20 +02:00
parent 14845e77e0
commit 62d2249f40
7 changed files with 87 additions and 67 deletions

View File

@@ -22,7 +22,7 @@ else
<div class="overflow-x-auto px-4">
<Paginator CurrentPage="CurrentPage" PageSize="PageSize" TotalRecords="TotalRecords" OnPageChanged="HandlePageChanged" />
<SortableTable TItem="Log" Columns="@_tableColumns" SortColumn="@SortColumn" SortDirection="@SortDirection" OnSortChanged="HandleSortChanged">
<SortableTable Columns="@_tableColumns" SortColumn="@SortColumn" SortDirection="@SortDirection" OnSortChanged="HandleSortChanged">
@foreach (var email in EmailList)
{
<tr class="bg-white border-b hover:bg-gray-50">

View File

@@ -41,7 +41,7 @@ else
</div>
</div>
<SortableTable TItem="Log" Columns="@_tableColumns" SortColumn="@SortColumn" SortDirection="@SortDirection" OnSortChanged="HandleSortChanged">
<SortableTable Columns="@_tableColumns" SortColumn="@SortColumn" SortDirection="@SortDirection" OnSortChanged="HandleSortChanged">
@foreach (var log in LogList)
{
<tr class="bg-white border-b hover:bg-gray-50">
@@ -173,6 +173,23 @@ else
}
}
query = ApplySort(query);
TotalRecords = await query.CountAsync();
LogList = await query
.Skip((CurrentPage - 1) * PageSize)
.Take(PageSize)
.ToListAsync();
IsLoading = false;
StateHasChanged();
}
/// <summary>
/// Apply sort to the query.
/// </summary>
private IQueryable<AuthLog> ApplySort(IQueryable<AuthLog> query)
{
// Apply sort.
switch (SortColumn)
{
@@ -208,14 +225,7 @@ else
break;
}
TotalRecords = await query.CountAsync();
LogList = await query
.Skip((CurrentPage - 1) * PageSize)
.Take(PageSize)
.ToListAsync();
IsLoading = false;
StateHasChanged();
return query;
}
private async Task DeleteLogsWithConfirmation()

View File

@@ -40,7 +40,7 @@ else
</div>
</div>
<SortableTable TItem="Log" Columns="@_tableColumns" SortColumn="@SortColumn" SortDirection="@SortDirection" OnSortChanged="HandleSortChanged">
<SortableTable Columns="@_tableColumns" SortColumn="@SortColumn" SortDirection="@SortDirection" OnSortChanged="HandleSortChanged">
@foreach (var log in LogList)
{
<tr class="bg-white border-b hover:bg-gray-50">

View File

@@ -26,7 +26,7 @@ else
<input type="text" @bind-value="SearchTerm" @bind-value:event="oninput" id="search" placeholder="Search users..." class="w-full px-4 py-2 border rounded text-sm text-gray-700 focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<SortableTable TItem="Log" Columns="@_tableColumns" SortColumn="@SortColumn" SortDirection="@SortDirection" OnSortChanged="HandleSortChanged">
<SortableTable Columns="@_tableColumns" SortColumn="@SortColumn" SortDirection="@SortDirection" OnSortChanged="HandleSortChanged">
@foreach (var user in UserList)
{
<tr class="bg-white border-b hover:bg-gray-50">
@@ -117,57 +117,9 @@ else
}
// Apply sort.
switch (SortColumn)
{
case "Id":
query = SortDirection == SortDirection.Ascending
? query.OrderBy(x => x.Id)
: query.OrderByDescending(x => x.Id);
break;
case "CreatedAt":
query = SortDirection == SortDirection.Ascending
? query.OrderBy(x => x.CreatedAt)
: query.OrderByDescending(x => x.CreatedAt);
break;
case "UserName":
query = SortDirection == SortDirection.Ascending
? query.OrderBy(x => x.UserName)
: query.OrderByDescending(x => x.UserName);
break;
case "VaultCount":
query = SortDirection == SortDirection.Ascending
? query.OrderBy(x => x.Vaults.Count())
: query.OrderByDescending(x => x.Vaults.Count());
break;
case "EmailClaimCount":
query = SortDirection == SortDirection.Ascending
? query.OrderBy(x => x.EmailClaims.Count())
: query.OrderByDescending(x => x.EmailClaims.Count());
break;
case "VaultStorageInKb":
query = SortDirection == SortDirection.Ascending
? query.OrderBy(x => x.Vaults.Sum(v => v.FileSize))
: query.OrderByDescending(x => x.Vaults.Sum(v => v.FileSize));
break;
case "TwoFactorEnabled":
query = SortDirection == SortDirection.Ascending
? query.OrderBy(x => x.TwoFactorEnabled)
: query.OrderByDescending(x => x.TwoFactorEnabled);
break;
case "LastVaultUpdate":
query = SortDirection == SortDirection.Ascending
? query.OrderBy(x => x.Vaults.Max(v => v.CreatedAt))
: query.OrderByDescending(x => x.Vaults.Max(v => v.CreatedAt));
break;
default:
query = SortDirection == SortDirection.Ascending
? query.OrderBy(x => x.Id)
: query.OrderByDescending(x => x.Id);
break;
}
query = ApplySort(query);
TotalRecords = await query.CountAsync();
var users = await query
.Skip((CurrentPage - 1) * PageSize)
.Take(PageSize)
@@ -204,4 +156,63 @@ else
IsLoading = false;
StateHasChanged();
}
/// <summary>
/// Apply sort to the query.
/// </summary>
private IQueryable<AliasVaultUser> ApplySort(IQueryable<AliasVaultUser> query)
{
// Apply sort.
switch (SortColumn)
{
case "Id":
query = SortDirection == SortDirection.Ascending
? query.OrderBy(x => x.Id)
: query.OrderByDescending(x => x.Id);
break;
case "CreatedAt":
query = SortDirection == SortDirection.Ascending
? query.OrderBy(x => x.CreatedAt)
: query.OrderByDescending(x => x.CreatedAt);
break;
case "UserName":
query = SortDirection == SortDirection.Ascending
? query.OrderBy(x => x.UserName)
: query.OrderByDescending(x => x.UserName);
break;
case "VaultCount":
query = SortDirection == SortDirection.Ascending
? query.OrderBy(x => x.Vaults.Count)
: query.OrderByDescending(x => x.Vaults.Count);
break;
case "EmailClaimCount":
query = SortDirection == SortDirection.Ascending
? query.OrderBy(x => x.EmailClaims.Count)
: query.OrderByDescending(x => x.EmailClaims.Count);
break;
case "VaultStorageInKb":
query = SortDirection == SortDirection.Ascending
? query.OrderBy(x => x.Vaults.Sum(v => v.FileSize))
: query.OrderByDescending(x => x.Vaults.Sum(v => v.FileSize));
break;
case "TwoFactorEnabled":
query = SortDirection == SortDirection.Ascending
? query.OrderBy(x => x.TwoFactorEnabled)
: query.OrderByDescending(x => x.TwoFactorEnabled);
break;
case "LastVaultUpdate":
query = SortDirection == SortDirection.Ascending
? query.OrderBy(x => x.Vaults.Max(v => v.CreatedAt))
: query.OrderByDescending(x => x.Vaults.Max(v => v.CreatedAt));
break;
default:
query = SortDirection == SortDirection.Ascending
? query.OrderBy(x => x.Id)
: query.OrderByDescending(x => x.Id);
break;
}
return query;
}
}

View File

@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore.Migrations;
// <auto-generated />
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable

View File

@@ -1,6 +1,4 @@
@typeparam TItem
<table class="w-full text-sm text-left text-gray-500 shadow rounded border">
<table class="w-full text-sm text-left text-gray-500 shadow rounded border">
<thead class="text-xs text-gray-700 uppercase bg-gray-50">
<tr>
@foreach (var column in Columns)

View File

@@ -253,8 +253,8 @@ public class ClientPlaywrightTest : PlaywrightTest
await Page.ClickAsync("text=" + credentialName);
// Wait for the credential details page to load.
await WaitForUrlAsync("credentials/**", "Delete credentials entry");
await Page.ClickAsync("text=Delete credentials entry");
await WaitForUrlAsync("credentials/**", "Delete");
await Page.ClickAsync("text=Delete");
// Wait for the delete credential page to load.
await WaitForUrlAsync("credentials/**/delete", "You can delete a credentials entry below");