Merge pull request #828 from Rhefew/feature/admin-account-search
feat(admin): add account & character search to accounts page (cherry picked from commit 75a435d7d3ac424f32a271c5275eac102881a80a)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
@page "/accounts"
|
||||
@page "/accounts"
|
||||
@using MUnique.OpenMU.DataModel
|
||||
@using MUnique.OpenMU.DataModel.Entities;
|
||||
@using MUnique.OpenMU.Persistence;
|
||||
@@ -21,6 +21,15 @@
|
||||
<th class="col-2">@typeof(Account).GetPropertyCaption(nameof(Account.EMail))</th>
|
||||
<th class="col-2">@Resources.Action</th>
|
||||
</TableHeader>
|
||||
<FilterHeader>
|
||||
<th colspan="3">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><span class="oi oi-magnifying-glass" aria-hidden="true"></span></span>
|
||||
<input type="search" class="form-control" placeholder="Search by Account or Character Name..." @bind="@this._accountService.SearchFilter"/>
|
||||
</div>
|
||||
</th>
|
||||
<th></th>
|
||||
</FilterHeader>
|
||||
<ItemTemplate Context="item">
|
||||
<td>@item.LoginName</td>
|
||||
<td>@item.State.GetEnumCaption()</td>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// <copyright file="AccountService.cs" company="MUnique">
|
||||
// <copyright file="AccountService.cs" company="MUnique">
|
||||
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
|
||||
// </copyright>
|
||||
|
||||
@@ -31,6 +31,25 @@ public class AccountService : IDataService<Account>, ISupportDataChangedNotifica
|
||||
this._modalService = modalService;
|
||||
}
|
||||
|
||||
private string _searchFilter = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the search filter query.
|
||||
/// </summary>
|
||||
public string SearchFilter
|
||||
{
|
||||
get => this._searchFilter;
|
||||
set
|
||||
{
|
||||
var newValue = value ?? string.Empty;
|
||||
if (this._searchFilter != newValue)
|
||||
{
|
||||
this._searchFilter = newValue;
|
||||
this.RaiseDataChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler? DataChanged;
|
||||
|
||||
@@ -45,7 +64,24 @@ public class AccountService : IDataService<Account>, ISupportDataChangedNotifica
|
||||
try
|
||||
{
|
||||
var playerContext = (IPlayerContext)await this._dataSource.GetContextAsync().ConfigureAwait(false);
|
||||
return (await playerContext.GetAccountsOrderedByLoginNameAsync(offset, count).ConfigureAwait(false)).ToList();
|
||||
var filter = this.SearchFilter.Trim();
|
||||
if (string.IsNullOrWhiteSpace(filter))
|
||||
{
|
||||
return (await playerContext.GetAccountsOrderedByLoginNameAsync(offset, count).ConfigureAwait(false)).ToList();
|
||||
}
|
||||
|
||||
var allAccounts = await playerContext.GetAsync<Account>().ConfigureAwait(false);
|
||||
var results = allAccounts.Where(account =>
|
||||
(account.LoginName != null && account.LoginName.Contains(filter, StringComparison.InvariantCultureIgnoreCase))
|
||||
|| account.Characters.Any(c => c.Name != null && c.Name.Contains(filter, StringComparison.InvariantCultureIgnoreCase))
|
||||
).ToList();
|
||||
|
||||
if (offset >= results.Count)
|
||||
{
|
||||
return results.Take(count).ToList();
|
||||
}
|
||||
|
||||
return results.Skip(offset).Take(count).ToList();
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user