mirror of
https://github.com/aliasvault/aliasvault.git
synced 2026-05-19 13:57:18 -04:00
Refactor (#220)
This commit is contained in:
@@ -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">
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
// <auto-generated />
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user