Browse Source

Admin: Refactor UserPicker component

pull/53/head
Engincan VESKE 5 years ago
parent
commit
4e4472bc48
  1. 124
      src/EventHub.Admin.Web/Components/UserPicker/UserPicker.razor
  2. 15
      src/EventHub.Admin.Web/Components/UserPicker/UserPicker.razor.cs
  3. 9
      src/EventHub.Admin.Web/Pages/AttendeeDetail.razor
  4. 7
      src/EventHub.Admin.Web/Pages/AttendeeDetail.razor.cs

124
src/EventHub.Admin.Web/Components/UserPicker/UserPicker.razor

@ -2,69 +2,71 @@
@inherits EventHubComponentBase
@inject IUserAppService UserAppService
<ModalContent Centered="true">
<ModalHeader>
<ModalTitle>@L["AddUser"]</ModalTitle>
<CloseButton Clicked="CloseUserPickerModalAsync" />
</ModalHeader>
<ModalBody>
<div id="UserFilterSection" class="row mt-3">
<Column ColumnSize="ColumnSize.Is12">
<Field>
<FieldLabel>@L["UserName"]</FieldLabel>
<TextEdit TValue="string" KeyPress="OnKeyPressed" @bind-Text="@Filter.Username" />
</Field>
</Column>
</div>
<Modal @ref="@UserPickerModal" Closing="@ClosingUserPickerModal">
<ModalContent Centered="true">
<ModalHeader>
<ModalTitle>@L["AddUser"]</ModalTitle>
<CloseButton Clicked="CloseUserPickerModalAsync" />
</ModalHeader>
<ModalBody>
<div id="UserFilterSection" class="row mt-3">
<Column ColumnSize="ColumnSize.Is12">
<Field>
<FieldLabel>@L["UserName"]</FieldLabel>
<TextEdit TValue="string" KeyPress="OnKeyPressed" @bind-Text="@Filter.Username" />
</Field>
</Column>
</div>
<DataGrid TItem="UserDto"
Data="UserList"
ReadData="OnDataGridReadAsync"
TotalItems="TotalCount"
ShowPager="true"
PageSize="PageSize"
Responsive="true">
<DataGridColumns>
<DataGridColumn Sortable="false" TItem="UserDto" Field="@nameof(UserDto.Id)">
<CaptionTemplate>
<Check TValue="bool" @bind-Checked="@AllUserSelected"></Check>
</CaptionTemplate>
<DisplayTemplate>
@if (SelectAllUsers.ContainsKey(context.Id))
{
<Check TValue="bool" @bind-Checked="@SelectAllUsers[context.Id]"></Check>
}
</DisplayTemplate>
</DataGridColumn>
<DataGrid TItem="UserDto"
Data="UserList"
ReadData="OnDataGridReadAsync"
TotalItems="TotalCount"
ShowPager="true"
PageSize="PageSize"
Responsive="true">
<DataGridColumns>
<DataGridColumn Sortable="false" TItem="UserDto" Field="@nameof(UserDto.Id)">
<CaptionTemplate>
<Check TValue="bool" @bind-Checked="@AllUserSelected"></Check>
</CaptionTemplate>
<DisplayTemplate>
@if (SelectAllUsers.ContainsKey(context.Id))
{
<Check TValue="bool" @bind-Checked="@SelectAllUsers[context.Id]"></Check>
}
</DisplayTemplate>
</DataGridColumn>
<DataGridColumn TItem="UserDto" Field="@nameof(UserDto.Username)" Caption="@L["UserName"].Value">
<DisplayTemplate>
@(context.Username)
</DisplayTemplate>
</DataGridColumn>
<DataGridColumn TItem="UserDto" Field="@nameof(UserDto.Username)" Caption="@L["UserName"].Value">
<DisplayTemplate>
@(context.Username)
</DisplayTemplate>
</DataGridColumn>
<DataGridColumn TItem="UserDto" Field="@nameof(UserDto.Name)" Caption="@L["Name"].Value">
<DisplayTemplate>
@(context.Name)
</DisplayTemplate>
</DataGridColumn>
<DataGridColumn TItem="UserDto" Field="@nameof(UserDto.Name)" Caption="@L["Name"].Value">
<DisplayTemplate>
@(context.Name)
</DisplayTemplate>
</DataGridColumn>
<DataGridColumn TItem="UserDto" Field="@nameof(UserDto.Surname)" Caption="@L["Surname"].Value">
<DisplayTemplate>
@(context.Surname)
</DisplayTemplate>
</DataGridColumn>
<DataGridColumn TItem="UserDto" Field="@nameof(UserDto.Surname)" Caption="@L["Surname"].Value">
<DisplayTemplate>
@(context.Surname)
</DisplayTemplate>
</DataGridColumn>
<DataGridColumn TItem="UserDto" Field="@nameof(UserDto.Email)" Caption="@L["Email"].Value">
<DisplayTemplate>
@(context.Email)
</DisplayTemplate>
</DataGridColumn>
</DataGridColumns>
</DataGrid>
</ModalBody>
<ModalFooter>
<Button Color="Color.Secondary" Clicked="CloseUserPickerModalAsync">@L["Cancel"]</Button>
<Button Color="Color.Primary" Clicked="SaveUserPickerFormAsync">@L["Save"]</Button>
</ModalFooter>
</ModalContent>
<DataGridColumn TItem="UserDto" Field="@nameof(UserDto.Email)" Caption="@L["Email"].Value">
<DisplayTemplate>
@(context.Email)
</DisplayTemplate>
</DataGridColumn>
</DataGridColumns>
</DataGrid>
</ModalBody>
<ModalFooter>
<Button Color="Color.Secondary" Clicked="CloseUserPickerModalAsync">@L["Cancel"]</Button>
<Button Color="Color.Primary" Clicked="SaveUserPickerFormAsync">@L["Save"]</Button>
</ModalFooter>
</ModalContent>
</Modal>

15
src/EventHub.Admin.Web/Components/UserPicker/UserPicker.razor.cs

@ -13,7 +13,6 @@ namespace EventHub.Admin.Web.Components.UserPicker
{
public partial class UserPicker
{
[Parameter]
public Modal UserPickerModal { get; set; }
[Parameter]
@ -29,8 +28,8 @@ namespace EventHub.Admin.Web.Components.UserPicker
private string CurrentSorting { get; set; }
private int TotalCount { get; set; }
private int PageSize { get; }
public Dictionary<Guid, bool> SelectAllUsers = new();
private bool AllUserSelected
{
get => SelectAllUsers.All(x => x.Value);
@ -102,6 +101,13 @@ namespace EventHub.Admin.Web.Components.UserPicker
await InvokeAsync(StateHasChanged);
}
public Task OpenUserPickerModalAsync()
{
UserPickerModal.Show();
return Task.CompletedTask;
}
public Task CloseUserPickerModalAsync()
{
UserPickerModal.Hide();
@ -113,5 +119,10 @@ namespace EventHub.Admin.Web.Components.UserPicker
{
await SaveFormAsync.InvokeAsync();
}
private void ClosingUserPickerModal(ModalClosingEventArgs eventArgs)
{
eventArgs.Cancel = eventArgs.CloseReason == CloseReason.FocusLostClosing;
}
}
}

9
src/EventHub.Admin.Web/Pages/AttendeeDetail.razor

@ -7,17 +7,15 @@
@inject IEventRegistrationAppService EventRegistrationAppService
@inject IUserAppService UserAppService
<!--<UserPicker />-->
<Card>
<CardHeader>
@* ************************* PAGE HEADER ************************* *@
<h2>@L["Attendees"]</h2>
<Paragraph Alignment="TextAlignment.Right">
@if (CanAddAttendee)
{
<Button Color="Color.Primary"
Clicked="() => AddAttendeeModal.Show()">
Clicked="OpenUserPickerModal">
@L["AddNewUser"]
</Button>
}
@ -25,7 +23,6 @@
</CardHeader>
<CardBody>
@* ************************* DATA GRID ************************* *@
<DataGrid TItem="EventAttendeeDto"
Data="AttendeeList"
ReadData="OnDataGridReadAsync"
@ -69,6 +66,4 @@
</Card>
<Modal @ref="@AddAttendeeModal" Closing="@ClosingUserPickerModal">
<UserPicker @ref="UserPickerModalRef" UserPickerModal="AddAttendeeModal" SelectedUserIds="SelectedUserIds" SaveFormAsync="AddSelectedUsersToEventAsync"></UserPicker>
</Modal>
<UserPicker @ref="UserPickerModalRef" SelectedUserIds="SelectedUserIds" SaveFormAsync="AddSelectedUsersToEventAsync" />

7
src/EventHub.Admin.Web/Pages/AttendeeDetail.razor.cs

@ -23,7 +23,6 @@ namespace EventHub.Admin.Web.Pages
private int TotalCount { get; set; }
private int PageSize { get; }
private bool CanAddAttendee { get; set; }
private Modal AddAttendeeModal { get; set; }
private GetEventRegistrationListInput Filter { get; set; }
public UserPicker UserPickerModalRef { get; set; }
@ -90,7 +89,7 @@ namespace EventHub.Admin.Web.Pages
await EventRegistrationAppService.RegisterUsersAsync(EventId, selectedUserIds);
AddAttendeeModal.Hide();
await UserPickerModalRef.CloseUserPickerModalAsync();
await GetAttendeesAsync();
await InvokeAsync(StateHasChanged);
@ -101,9 +100,9 @@ namespace EventHub.Admin.Web.Pages
}
}
private void ClosingUserPickerModal(ModalClosingEventArgs eventArgs)
private async Task OpenUserPickerModal()
{
eventArgs.Cancel = eventArgs.CloseReason == CloseReason.FocusLostClosing;
await UserPickerModalRef.OpenUserPickerModalAsync();
}
}
}

Loading…
Cancel
Save