SHA256
- Added UserMessageService to have common methods for showing messages and errors to the user. - Added Result record so services can return status on operation error (so it can be shown in the UI messages). - Updated services to use the new Result record. - Updated pages to use the new IUserMessageService.
148 lines
4.8 KiB
Plaintext
148 lines
4.8 KiB
Plaintext
@using Somnia.GuestLog.Models.DTOs;
|
|
@using Somnia.GuestLog.Services
|
|
|
|
@inject ILogger<AddressQueryDialog> logger;
|
|
@inject IUserMessageService userMessage
|
|
@inject IGuestDocumentService guestDocumentService;
|
|
|
|
|
|
<MudDialog Style="max-height: 90%;">
|
|
<TitleContent>
|
|
<MudText Typo="Typo.h6">
|
|
<MudIcon Icon="@Icons.Material.Filled.PersonSearch" Class="mr-3 mb-n1" />
|
|
@LanguageLocale.control_GuestDocumentSearchDialog_dialogTitle
|
|
</MudText>
|
|
</TitleContent>
|
|
<DialogContent>
|
|
<GuestDocumentFilterForm @bind-Filter="@filter" />
|
|
<MudButton StartIcon="@Icons.Material.Filled.Search" OnClick="BtnSearchGuestDocuments" FullWidth
|
|
Variant="Variant.Filled" Disabled="@isLoading">
|
|
@LanguageLocale.general_btnSearch
|
|
</MudButton>
|
|
<MudDivider DividerType="DividerType.FullWidth" Class="my-4" />
|
|
|
|
<MudPaper Class="pa-2" MinHeight="120px">
|
|
@if (!isLoading && results.Count() == 0)
|
|
{
|
|
<MudText Typo="Typo.body1" Align="Align.Center">@LanguageLocale.general_noResults</MudText>
|
|
}
|
|
|
|
@if (isLoading)
|
|
{
|
|
<MudSkeleton SkeletonType="SkeletonType.Rectangle" Height="100px" />
|
|
}
|
|
|
|
@if (!isLoading)
|
|
{
|
|
@* Only show on first load *@
|
|
@if (loadCount == 1)
|
|
{
|
|
<MudText Align="Align.Center" GutterBottom>
|
|
@LanguageLocale.control_GuestDocumentSearchDialog_txtSuggestedGuests
|
|
</MudText>
|
|
}
|
|
|
|
<MudList T="GuestDocumentDTO" @bind-SelectedValue="SelectedResult"
|
|
SelectionMode="SelectionMode.SingleSelection" Color="Color.Info">
|
|
@foreach (GuestDocumentDTO result in results)
|
|
{
|
|
<MudListItem Value="result">
|
|
<ChildContent>
|
|
<MudTextField Value="@($"{result.DocumentType} - {result.DocumentNum}")"
|
|
Label="@LanguageLocale.dto_GuestDocument_DocumentNum" ReadOnly />
|
|
<MudTextField Value="@($"{result.Name} {result.Surname} {result.Surname2}")"
|
|
Label="@LanguageLocale.dto_GuestDocument_Name" ReadOnly />
|
|
</ChildContent>
|
|
</MudListItem>
|
|
}
|
|
</MudList>
|
|
}
|
|
</MudPaper>
|
|
|
|
</DialogContent>
|
|
<DialogActions>
|
|
<MudButton OnClick="Cancel">
|
|
@LanguageLocale.general_btnCancel
|
|
</MudButton>
|
|
<MudButton Color="Color.Primary" OnClick="btnSelectGuest">
|
|
@LanguageLocale.control_GuestDocumentSearchDialog_btnSelectDocument
|
|
</MudButton>
|
|
</DialogActions>
|
|
</MudDialog>
|
|
|
|
@code {
|
|
// Dialog Instance injected when open by the DialogService.
|
|
// This field is null when dialog is not open by the DialogService.
|
|
[CascadingParameter]
|
|
private IMudDialogInstance MudDialog { get; set; } = null!;
|
|
|
|
|
|
private GuestDocFilterDTO filter { get; set; } = new();
|
|
private IEnumerable<GuestDocumentDTO> results = [];
|
|
private GuestDocumentDTO? SelectedResult { get; set; }
|
|
|
|
private bool isLoading = false;
|
|
private int loadCount = 0;
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
//Load last 5 guests.
|
|
await LoadGuests(limit: 5);
|
|
}
|
|
|
|
|
|
private void Cancel() => MudDialog.Cancel();
|
|
|
|
|
|
private async Task LoadGuests(int limit = 25)
|
|
{
|
|
|
|
try
|
|
{
|
|
isLoading = true;
|
|
results = await guestDocumentService.GetDtoListByFilterAsync(filter);
|
|
isLoading = false;
|
|
loadCount++;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.LogError(ex, "GuestDocument Search returned an error!");
|
|
userMessage.ShowMessage($"Error searching: {ex.Message}", MessageKind.Error);
|
|
}
|
|
}
|
|
|
|
|
|
#region Event Handlers
|
|
|
|
private async Task BtnSearchGuestDocuments()
|
|
{
|
|
if (filter.IsEmpty)
|
|
{
|
|
userMessage.ShowMessage("Search can't be empty!", MessageKind.Warning);
|
|
return;
|
|
}
|
|
|
|
//Load unlimited guests using current filter.
|
|
await LoadGuests();
|
|
}
|
|
|
|
private async Task btnSelectGuest()
|
|
{
|
|
if (SelectedResult is null)
|
|
{
|
|
userMessage.ShowMessage("A guest document must be selected", MessageKind.Warning);
|
|
return;
|
|
}
|
|
|
|
DialogResult dialogResult = DialogResult.Ok<GuestDocumentDTO?>(SelectedResult);
|
|
|
|
//Close the dialog when opened by DialogService.
|
|
logger.LogDebug("GuestDocumentSearchDialog - Closed MudDialogInstance!");
|
|
MudDialog.Close(dialogResult);
|
|
return;
|
|
}
|
|
|
|
#endregion
|
|
|
|
} |