Skip to content

Commit

Permalink
Merge pull request #29 from Lan2Play/feature/OrganizationDataSampleUsage
Browse files Browse the repository at this point in the history
Client side OrganizationData Usage
  • Loading branch information
MD-V authored Apr 29, 2022
2 parents 6c5e04c + 26eac97 commit a61ff57
Show file tree
Hide file tree
Showing 34 changed files with 1,507 additions and 250 deletions.
7 changes: 2 additions & 5 deletions NetEvent/Client/Pages/Administration/AdminMenu.razor.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components;
using MudBlazor.ThemeManager;

namespace NetEvent.Client.Pages.Administration
{
public partial class AdminMenu
{
[Inject]
public HttpClient HttpClient { get; set; }

private ThemeManagerTheme _themeManager = new ThemeManagerTheme();

}
}
}
2 changes: 1 addition & 1 deletion NetEvent/Client/Pages/Administration/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<MudIcon Icon="@Icons.Outlined.Group" Size="Size.Large">Users</MudIcon>
<MudText Typo="Typo.h6"><strong>@Users?.Count</strong> Users</MudText>
</MudStack>
</MudButton>
</MudButton>
</MudStack>
</MudItem>
<MudItem xs="12" sm="6" md="4">
Expand Down
15 changes: 9 additions & 6 deletions NetEvent/Client/Pages/Administration/Index.razor.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components;
using NetEvent.Client.Services;
using NetEvent.Shared.Dto;

namespace NetEvent.Client.Pages.Administration
{
public partial class Index
{

[Inject]
public HttpClient HttpClient { get; set; }
private IUserService UserService { get; set; } = default!;

public List<CurrentUserDto>? Users { get; private set; }
public List<UserDto>? Users { get; private set; }


protected override async Task OnInitializedAsync()
{
Users = await Utils.Get<List<CurrentUserDto>>(HttpClient, "api/users");
using var cancellationTokenSource = new CancellationTokenSource();

Users = await UserService.GetUsersAsync(cancellationTokenSource.Token).ConfigureAwait(false);
}

}
}
}
8 changes: 3 additions & 5 deletions NetEvent/Client/Pages/Administration/Settings.razor.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components;

namespace NetEvent.Client.Pages.Administration
{
public partial class Settings
{
[Inject]
public HttpClient HttpClient { get; set; }


protected override async Task OnInitializedAsync()
{
}

}
}
}
38 changes: 35 additions & 3 deletions NetEvent/Client/Pages/Administration/Users.razor
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
ReadOnly="false"
EditMode="DataGridEditMode.Form"
EditTrigger="DataGridEditTrigger.Manual"
CommittedItemChanges="@CommittedUserChanges"
CommittedItemChanges="@CommittedUserChangesAsync"
QuickFilter="@_usersQuickFilter"
Hideable="true">
<ToolBarContent>
<MudText Typo="Typo.h6">Periodic Elements</MudText>
<MudText Typo="Typo.h6">Users</MudText>
<MudSpacer />
<MudTextField @bind-Value="_usersSearchString" Placeholder="Search" Adornment="Adornment.Start" Immediate="true"
<MudTextField @bind-Value="_UsersSearchString" Placeholder="Search" Adornment="Adornment.Start" Immediate="true"
AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium" Class="mt-0"></MudTextField>
</ToolBarContent>
<Columns>
Expand Down Expand Up @@ -51,4 +51,36 @@
</PagerContent>
</MudDataGrid>
</MudTabPanel>
<MudTabPanel Text="Roles">
<MudDataGrid T="IdentityRole"
MultiSelection="false"
Items="@AllRoles"
Sortable="true"
Filterable="true"
ReadOnly="false"
EditMode="DataGridEditMode.Form"
EditTrigger="DataGridEditTrigger.Manual"
CommittedItemChanges="@CommittedRoleChangesAsync"
QuickFilter="@_roleQuickFilter"
Hideable="true">
<ToolBarContent>
<MudText Typo="Typo.h6">Roles</MudText>
<MudSpacer />
<MudTextField @bind-Value="_RoleSearchString" Placeholder="Search" Adornment="Adornment.Start" Immediate="true"
AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium" Class="mt-0"></MudTextField>
</ToolBarContent>
<Columns>
<Column T="IdentityRole" Field="Id" Title="Id" />
<Column T="IdentityRole" Field="Name" />
<Column T="IdentityRole" CellClass="d-flex justify-end">
<CellTemplate>
<MudIconButton Size="@Size.Small" Icon="@Icons.Outlined.Edit" OnClick="@context.Actions.StartEditingItem" />
</CellTemplate>
</Column>
</Columns>
<PagerContent>
<MudDataGridPager T="IdentityRole" />
</PagerContent>
</MudDataGrid>
</MudTabPanel>
</MudTabs>
47 changes: 28 additions & 19 deletions NetEvent/Client/Pages/Administration/Users.razor.cs
Original file line number Diff line number Diff line change
@@ -1,52 +1,59 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Identity;
using NetEvent.Client.Services;
using NetEvent.Shared.Dto;

namespace NetEvent.Client.Pages.Administration
{
public partial class Users
{
[Inject]
public HttpClient HttpClient { get; set; }

private IUserService UserService { get; set; } = default!;

[Inject]
private IRoleService RoleService { get; set; } = default!;

protected override async Task OnInitializedAsync()
{
AllUsers = await Utils.Get<List<UserDto>>(HttpClient, "api/users");
AllRoles = await Utils.Get<List<IdentityRole>>(HttpClient, "roles");
using var cancellationTokenSource = new CancellationTokenSource();

AllUsers = await UserService.GetUsersAsync(cancellationTokenSource.Token);
AllRoles = await RoleService.GetRolesAsync(cancellationTokenSource.Token);
}

#region Users

public List<UserDto>? AllUsers { get; private set; }
private string _usersSearchString;

private string? _UsersSearchString;

// quick filter - filter gobally across multiple columns with the same input
private Func<UserDto, bool> _usersQuickFilter => x =>
{
if (string.IsNullOrWhiteSpace(_usersSearchString))
if (string.IsNullOrWhiteSpace(_UsersSearchString))
return true;

if (x.UserName.Contains(_usersSearchString, StringComparison.OrdinalIgnoreCase))
if (x.UserName.Contains(_UsersSearchString, StringComparison.OrdinalIgnoreCase))
return true;

if (x.FirstName.Contains(_usersSearchString, StringComparison.OrdinalIgnoreCase))
if (x.FirstName.Contains(_UsersSearchString, StringComparison.OrdinalIgnoreCase))
return true;

if (x.LastName.Contains(_usersSearchString, StringComparison.OrdinalIgnoreCase))
if (x.LastName.Contains(_UsersSearchString, StringComparison.OrdinalIgnoreCase))
return true;

if (x.Email.Contains(_usersSearchString, StringComparison.OrdinalIgnoreCase))
if (x.Email.Contains(_UsersSearchString, StringComparison.OrdinalIgnoreCase))
return true;

return false;
};


void CommittedUserChanges(UserDto item)
private async Task CommittedUserChangesAsync(UserDto updatedUser)
{
_ = Utils.Put(HttpClient, $"api/users/{item.Id}", item);
using var cancellationTokenSource = new CancellationTokenSource();

await UserService.UpdateUserAsync(updatedUser, cancellationTokenSource.Token).ConfigureAwait(false);
}

#endregion
Expand All @@ -55,26 +62,28 @@ void CommittedUserChanges(UserDto item)

public List<IdentityRole>? AllRoles { get; private set; }

private string _roleSearchString;
private string? _RoleSearchString;

// quick filter - filter gobally across multiple columns with the same input
private Func<IdentityRole, bool> _roleQuickFilter => x =>
{
if (string.IsNullOrWhiteSpace(_usersSearchString))
if (string.IsNullOrWhiteSpace(_UsersSearchString))
return true;

if (x.Name.Contains(_usersSearchString, StringComparison.OrdinalIgnoreCase))
if (x.Name.Contains(_UsersSearchString, StringComparison.OrdinalIgnoreCase))
return true;

return false;
};


void CommittedRoleChanges(IdentityRole item)
private async Task CommittedRoleChangesAsync(IdentityRole updatedRole)
{
_ = Utils.Put(HttpClient, $"role/{item.Id}", item);
using var cancellationTokenSource = new CancellationTokenSource();

await RoleService.UpdateRoleAsync(updatedRole, cancellationTokenSource.Token).ConfigureAwait(false);
}

#endregion
}
}
}
8 changes: 4 additions & 4 deletions NetEvent/Client/Pages/Login.razor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components;
using NetEvent.Client.Services;
using NetEvent.Shared.Dto;

Expand All @@ -7,10 +7,10 @@ namespace NetEvent.Client.Pages
public partial class Login
{
[Inject]
public CustomStateProvider AuthenticationStateProvider { get; set; }
private NetEventAuthenticationStateProvider AuthenticationStateProvider { get; set; } = default!;

[Inject]
public NavigationManager NavigationManager { get; set; }
private NavigationManager NavigationManager { get; set; } = default!;


public LoginRequest LoginRequest { get; set; } = new ();
Expand Down Expand Up @@ -40,4 +40,4 @@ public async Task ExecuteLogin()
}
}
}
}
}
19 changes: 10 additions & 9 deletions NetEvent/Client/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using MudBlazor.Services;
Expand All @@ -8,22 +8,23 @@
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");


builder.Services.AddOptions();
builder.Services.AddAuthorizationCore();
builder.Services.AddScoped<CustomStateProvider>();
builder.Services.AddScoped<AuthenticationStateProvider>(s => s.GetRequiredService<CustomStateProvider>());
builder.Services.AddScoped<NetEventAuthenticationStateProvider>();
builder.Services.AddScoped<AuthenticationStateProvider>(s => s.GetRequiredService<NetEventAuthenticationStateProvider>());
builder.Services.AddScoped<IAuthService, AuthService>();
builder.Services.AddTransient(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

builder.Services.AddScoped<IOrganizationDataService, OrganizationDataService>();
builder.Services.AddScoped<IUserService,UserService>();
builder.Services.AddScoped<IThemeService, ThemeService>();
builder.Services.AddScoped<IRoleService, RoleService>();

builder.Services.AddHttpClient("NetEvent.ServerAPI")
builder.Services.AddHttpClient(Constants.BackendApiHttpClientName)
.ConfigureHttpClient(client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress));

builder.Services.AddHttpClient("NetEvent.ServerAPI.Secure")
builder.Services.AddHttpClient(Constants.BackendApiSecuredHttpClientName)
.ConfigureHttpClient(client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress))
.AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>();

builder.Services.AddMudServices();

await builder.Build().RunAsync();
await builder.Build().RunAsync();
Loading

0 comments on commit a61ff57

Please sign in to comment.