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 @inherits EventHubComponentBase
@inject IUserAppService UserAppService @inject IUserAppService UserAppService
<ModalContent Centered="true"> <Modal @ref="@UserPickerModal" Closing="@ClosingUserPickerModal">
<ModalHeader> <ModalContent Centered="true">
<ModalTitle>@L["AddUser"]</ModalTitle> <ModalHeader>
<CloseButton Clicked="CloseUserPickerModalAsync" /> <ModalTitle>@L["AddUser"]</ModalTitle>
</ModalHeader> <CloseButton Clicked="CloseUserPickerModalAsync" />
<ModalBody> </ModalHeader>
<div id="UserFilterSection" class="row mt-3"> <ModalBody>
<Column ColumnSize="ColumnSize.Is12"> <div id="UserFilterSection" class="row mt-3">
<Field> <Column ColumnSize="ColumnSize.Is12">
<FieldLabel>@L["UserName"]</FieldLabel> <Field>
<TextEdit TValue="string" KeyPress="OnKeyPressed" @bind-Text="@Filter.Username" /> <FieldLabel>@L["UserName"]</FieldLabel>
</Field> <TextEdit TValue="string" KeyPress="OnKeyPressed" @bind-Text="@Filter.Username" />
</Column> </Field>
</div> </Column>
</div>
<DataGrid TItem="UserDto" <DataGrid TItem="UserDto"
Data="UserList" Data="UserList"
ReadData="OnDataGridReadAsync" ReadData="OnDataGridReadAsync"
TotalItems="TotalCount" TotalItems="TotalCount"
ShowPager="true" ShowPager="true"
PageSize="PageSize" PageSize="PageSize"
Responsive="true"> Responsive="true">
<DataGridColumns> <DataGridColumns>
<DataGridColumn Sortable="false" TItem="UserDto" Field="@nameof(UserDto.Id)"> <DataGridColumn Sortable="false" TItem="UserDto" Field="@nameof(UserDto.Id)">
<CaptionTemplate> <CaptionTemplate>
<Check TValue="bool" @bind-Checked="@AllUserSelected"></Check> <Check TValue="bool" @bind-Checked="@AllUserSelected"></Check>
</CaptionTemplate> </CaptionTemplate>
<DisplayTemplate> <DisplayTemplate>
@if (SelectAllUsers.ContainsKey(context.Id)) @if (SelectAllUsers.ContainsKey(context.Id))
{ {
<Check TValue="bool" @bind-Checked="@SelectAllUsers[context.Id]"></Check> <Check TValue="bool" @bind-Checked="@SelectAllUsers[context.Id]"></Check>
} }
</DisplayTemplate> </DisplayTemplate>
</DataGridColumn> </DataGridColumn>
<DataGridColumn TItem="UserDto" Field="@nameof(UserDto.Username)" Caption="@L["UserName"].Value"> <DataGridColumn TItem="UserDto" Field="@nameof(UserDto.Username)" Caption="@L["UserName"].Value">
<DisplayTemplate> <DisplayTemplate>
@(context.Username) @(context.Username)
</DisplayTemplate> </DisplayTemplate>
</DataGridColumn> </DataGridColumn>
<DataGridColumn TItem="UserDto" Field="@nameof(UserDto.Name)" Caption="@L["Name"].Value"> <DataGridColumn TItem="UserDto" Field="@nameof(UserDto.Name)" Caption="@L["Name"].Value">
<DisplayTemplate> <DisplayTemplate>
@(context.Name) @(context.Name)
</DisplayTemplate> </DisplayTemplate>
</DataGridColumn> </DataGridColumn>
<DataGridColumn TItem="UserDto" Field="@nameof(UserDto.Surname)" Caption="@L["Surname"].Value"> <DataGridColumn TItem="UserDto" Field="@nameof(UserDto.Surname)" Caption="@L["Surname"].Value">
<DisplayTemplate> <DisplayTemplate>
@(context.Surname) @(context.Surname)
</DisplayTemplate> </DisplayTemplate>
</DataGridColumn> </DataGridColumn>
<DataGridColumn TItem="UserDto" Field="@nameof(UserDto.Email)" Caption="@L["Email"].Value"> <DataGridColumn TItem="UserDto" Field="@nameof(UserDto.Email)" Caption="@L["Email"].Value">
<DisplayTemplate> <DisplayTemplate>
@(context.Email) @(context.Email)
</DisplayTemplate> </DisplayTemplate>
</DataGridColumn> </DataGridColumn>
</DataGridColumns> </DataGridColumns>
</DataGrid> </DataGrid>
</ModalBody> </ModalBody>
<ModalFooter> <ModalFooter>
<Button Color="Color.Secondary" Clicked="CloseUserPickerModalAsync">@L["Cancel"]</Button> <Button Color="Color.Secondary" Clicked="CloseUserPickerModalAsync">@L["Cancel"]</Button>
<Button Color="Color.Primary" Clicked="SaveUserPickerFormAsync">@L["Save"]</Button> <Button Color="Color.Primary" Clicked="SaveUserPickerFormAsync">@L["Save"]</Button>
</ModalFooter> </ModalFooter>
</ModalContent> </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 public partial class UserPicker
{ {
[Parameter]
public Modal UserPickerModal { get; set; } public Modal UserPickerModal { get; set; }
[Parameter] [Parameter]
@ -29,8 +28,8 @@ namespace EventHub.Admin.Web.Components.UserPicker
private string CurrentSorting { get; set; } private string CurrentSorting { get; set; }
private int TotalCount { get; set; } private int TotalCount { get; set; }
private int PageSize { get; } private int PageSize { get; }
public Dictionary<Guid, bool> SelectAllUsers = new(); public Dictionary<Guid, bool> SelectAllUsers = new();
private bool AllUserSelected private bool AllUserSelected
{ {
get => SelectAllUsers.All(x => x.Value); get => SelectAllUsers.All(x => x.Value);
@ -102,6 +101,13 @@ namespace EventHub.Admin.Web.Components.UserPicker
await InvokeAsync(StateHasChanged); await InvokeAsync(StateHasChanged);
} }
public Task OpenUserPickerModalAsync()
{
UserPickerModal.Show();
return Task.CompletedTask;
}
public Task CloseUserPickerModalAsync() public Task CloseUserPickerModalAsync()
{ {
UserPickerModal.Hide(); UserPickerModal.Hide();
@ -113,5 +119,10 @@ namespace EventHub.Admin.Web.Components.UserPicker
{ {
await SaveFormAsync.InvokeAsync(); 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 IEventRegistrationAppService EventRegistrationAppService
@inject IUserAppService UserAppService @inject IUserAppService UserAppService
<!--<UserPicker />-->
<Card> <Card>
<CardHeader> <CardHeader>
@* ************************* PAGE HEADER ************************* *@
<h2>@L["Attendees"]</h2> <h2>@L["Attendees"]</h2>
<Paragraph Alignment="TextAlignment.Right"> <Paragraph Alignment="TextAlignment.Right">
@if (CanAddAttendee) @if (CanAddAttendee)
{ {
<Button Color="Color.Primary" <Button Color="Color.Primary"
Clicked="() => AddAttendeeModal.Show()"> Clicked="OpenUserPickerModal">
@L["AddNewUser"] @L["AddNewUser"]
</Button> </Button>
} }
@ -25,7 +23,6 @@
</CardHeader> </CardHeader>
<CardBody> <CardBody>
@* ************************* DATA GRID ************************* *@
<DataGrid TItem="EventAttendeeDto" <DataGrid TItem="EventAttendeeDto"
Data="AttendeeList" Data="AttendeeList"
ReadData="OnDataGridReadAsync" ReadData="OnDataGridReadAsync"
@ -69,6 +66,4 @@
</Card> </Card>
<Modal @ref="@AddAttendeeModal" Closing="@ClosingUserPickerModal"> <UserPicker @ref="UserPickerModalRef" SelectedUserIds="SelectedUserIds" SaveFormAsync="AddSelectedUsersToEventAsync" />
<UserPicker @ref="UserPickerModalRef" UserPickerModal="AddAttendeeModal" SelectedUserIds="SelectedUserIds" SaveFormAsync="AddSelectedUsersToEventAsync"></UserPicker>
</Modal>

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 TotalCount { get; set; }
private int PageSize { get; } private int PageSize { get; }
private bool CanAddAttendee { get; set; } private bool CanAddAttendee { get; set; }
private Modal AddAttendeeModal { get; set; }
private GetEventRegistrationListInput Filter { get; set; } private GetEventRegistrationListInput Filter { get; set; }
public UserPicker UserPickerModalRef { get; set; } public UserPicker UserPickerModalRef { get; set; }
@ -90,7 +89,7 @@ namespace EventHub.Admin.Web.Pages
await EventRegistrationAppService.RegisterUsersAsync(EventId, selectedUserIds); await EventRegistrationAppService.RegisterUsersAsync(EventId, selectedUserIds);
AddAttendeeModal.Hide(); await UserPickerModalRef.CloseUserPickerModalAsync();
await GetAttendeesAsync(); await GetAttendeesAsync();
await InvokeAsync(StateHasChanged); 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