User manager search persistence
This commit is contained in:
		@ -2,17 +2,20 @@
 | 
			
		||||
@inherits ModuleBase
 | 
			
		||||
@inject IUserRoleService UserRoleService
 | 
			
		||||
@inject IUserService UserService
 | 
			
		||||
@inject ISettingService SettingService
 | 
			
		||||
 | 
			
		||||
@if (userroles == null)
 | 
			
		||||
{
 | 
			
		||||
    <p><em>Loading...</em></p>
 | 
			
		||||
    <p>
 | 
			
		||||
        <em>Loading...</em>
 | 
			
		||||
    </p>
 | 
			
		||||
}
 | 
			
		||||
else
 | 
			
		||||
{
 | 
			
		||||
    <ActionLink Action="Add" Text="Add User"/>
 | 
			
		||||
 | 
			
		||||
    <div class="d-flex p-1">
 | 
			
		||||
            <input class="form-control mr-4" @bind="@search"/><button class="btn btn-outline-primary ml-1" @onclick="OnSearch">Search</button>
 | 
			
		||||
        <input class="form-control mr-4" @bind="@_search"/><button class="btn btn-outline-primary ml-1" @onclick="OnSearch">Search</button>
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
    <Pager Items="@userroles">
 | 
			
		||||
@ -23,9 +26,15 @@ else
 | 
			
		||||
            <th>Name</th>
 | 
			
		||||
        </Header>
 | 
			
		||||
        <Row>
 | 
			
		||||
            <td><ActionLink Action="Edit" Parameters="@($"id=" + context.UserId.ToString())" /></td>
 | 
			
		||||
            <td><ActionDialog Header="Delete User" Message="@("Are You Sure You Wish To Delete " + context.User.DisplayName + "?")" Action="Delete" Security="SecurityAccessLevel.Admin" Class="btn btn-danger" OnClick="@(async () => await DeleteUser(context))" /></td>
 | 
			
		||||
            <td><ActionLink Action="Roles" Parameters="@($"id=" + context.UserId.ToString())" /></td>
 | 
			
		||||
            <td>
 | 
			
		||||
                <ActionLink Action="Edit" Parameters="@($"id=" + context.UserId.ToString())"/>
 | 
			
		||||
            </td>
 | 
			
		||||
            <td>
 | 
			
		||||
                <ActionDialog Header="Delete User" Message="@("Are You Sure You Wish To Delete " + context.User.DisplayName + "?")" Action="Delete" Security="SecurityAccessLevel.Admin" Class="btn btn-danger" OnClick="@(async () => await DeleteUser(context))"/>
 | 
			
		||||
            </td>
 | 
			
		||||
            <td>
 | 
			
		||||
                <ActionLink Action="Roles" Parameters="@($"id=" + context.UserId.ToString())"/>
 | 
			
		||||
            </td>
 | 
			
		||||
            <td>@context.User.DisplayName</td>
 | 
			
		||||
        </Row>
 | 
			
		||||
    </Pager>
 | 
			
		||||
@ -34,19 +43,24 @@ else
 | 
			
		||||
@code {
 | 
			
		||||
    private List<UserRole> allroles;
 | 
			
		||||
    private List<UserRole> userroles;
 | 
			
		||||
    private string search;
 | 
			
		||||
    private string _search;
 | 
			
		||||
 | 
			
		||||
    public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin;
 | 
			
		||||
 | 
			
		||||
    protected override async Task OnInitializedAsync()
 | 
			
		||||
    {
 | 
			
		||||
        allroles = await UserRoleService.GetUserRolesAsync(PageState.Site.SiteId);
 | 
			
		||||
        userroles = allroles.Where(item => item.Role.Name == Constants.RegisteredRole).ToList();
 | 
			
		||||
        await LoadSettingsAsync();
 | 
			
		||||
        userroles = Search(_search);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void OnSearch()
 | 
			
		||||
    private List<UserRole> Search(string search)
 | 
			
		||||
    {
 | 
			
		||||
        userroles = allroles
 | 
			
		||||
        if (string.IsNullOrEmpty(_search))
 | 
			
		||||
        {
 | 
			
		||||
            return allroles.Where(item => item.Role.Name == Constants.RegisteredRole).ToList();
 | 
			
		||||
        }
 | 
			
		||||
        return allroles
 | 
			
		||||
            .Where(item => item.Role.Name == Constants.RegisteredRole &&
 | 
			
		||||
                           (
 | 
			
		||||
                               item.User.Username.Contains(search, StringComparison.OrdinalIgnoreCase) ||
 | 
			
		||||
@ -57,6 +71,11 @@ else
 | 
			
		||||
            .ToList();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private async Task OnSearch()
 | 
			
		||||
    {
 | 
			
		||||
        userroles = Search(_search);
 | 
			
		||||
        await UpdateSettingsAsync();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private async Task DeleteUser(UserRole UserRole)
 | 
			
		||||
    {
 | 
			
		||||
@ -76,4 +95,20 @@ else
 | 
			
		||||
            AddModuleMessage(ex.Message, MessageType.Error);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private string settingSearch = "AU-search";
 | 
			
		||||
 | 
			
		||||
    private async Task LoadSettingsAsync()
 | 
			
		||||
    {
 | 
			
		||||
        Dictionary<string, string> settings = await SettingService.GetUserSettingsAsync(PageState.User.UserId);
 | 
			
		||||
        _search = SettingService.GetSetting(settings, settingSearch, "");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private async Task UpdateSettingsAsync()
 | 
			
		||||
    {
 | 
			
		||||
        Dictionary<string, string> settings = await SettingService.GetUserSettingsAsync(PageState.User.UserId);
 | 
			
		||||
        SettingService.SetSetting(settings, settingSearch, _search);
 | 
			
		||||
        await SettingService.UpdateUserSettingsAsync(settings, PageState.User.UserId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user