SHA256
GuestLog - Integrated AddressQuery dialog in GuestDocument creation and fixes.
- Added new CountryCodeUtils to map ISO-3166:Alpha2 country codes to ISO-3166:Alpha3 codes. - Added new config for results language of AddressQuery services.
This commit is contained in:
@@ -5,23 +5,24 @@
|
||||
@inject IAddressQueryFactory addressQueryFactory;
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudDialog>
|
||||
<MudDialog @ref="@DialogRef">
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">
|
||||
<MudIcon Icon="@Icons.Material.Filled.NotListedLocation" Class="mr-3 mb-n1" />
|
||||
Search Address
|
||||
@LanguageLocale.control_AddressQueryDialog_dialogTitle
|
||||
</MudText>
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
<MudStack row>
|
||||
<MudTextField @ref="txtSearch" @bind-Value="SearchText" Label="Search address" Required />
|
||||
<MudTextField @bind-Value="SearchText" Label="@LanguageLocale.control_AddressQueryDialog_searchText"
|
||||
Required />
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Search" OnClick="btnSearchAddress" />
|
||||
</MudStack>
|
||||
|
||||
<MudPaper Class="mt-4 pa-2">
|
||||
@if (addressResults.Count == 0)
|
||||
{
|
||||
<MudText Typo="Typo.body1">No results!</MudText>
|
||||
<MudText Typo="Typo.body1">@LanguageLocale.general_noResults</MudText>
|
||||
}
|
||||
|
||||
<MudList T="AddressResultDTO" @bind-SelectedValue="SelectedAddressResult"
|
||||
@@ -30,16 +31,21 @@
|
||||
{
|
||||
<MudListItem Value="result">
|
||||
<ChildContent>
|
||||
<MudTextField Value="@($"{result.AddressRoad}, {result.HouseNumber}")" Label="Address"
|
||||
ReadOnly />
|
||||
<MudTextField Value="@($"{result.AddressRoad}, {result.HouseNumber}")"
|
||||
Label="@LanguageLocale.general_address_address" ReadOnly />
|
||||
<MudStack row>
|
||||
<MudTextField Value="@result.AddressCity" Label="City" ReadOnly />
|
||||
<MudTextField Value="@result.AddressProvince" Label="Province" ReadOnly />
|
||||
<MudTextField Value="@result.AddressState" Label="State" ReadOnly />
|
||||
<MudTextField Value="@result.AddressCity" Label="@LanguageLocale.general_address_city"
|
||||
ReadOnly />
|
||||
<MudTextField Value="@result.AddressProvince"
|
||||
Label="@LanguageLocale.general_address_province" ReadOnly />
|
||||
<MudTextField Value="@result.AddressState" Label="@LanguageLocale.general_address_state"
|
||||
ReadOnly />
|
||||
</MudStack>
|
||||
<MudStack row>
|
||||
<MudTextField Value="@result.AddressCountry" Label="Country" ReadOnly />
|
||||
<MudTextField Value="@result.ZipCode" Label="Zip Code" ReadOnly />
|
||||
<MudTextField Value="@result.AddressCountry" Label="@LanguageLocale.general_address_country"
|
||||
ReadOnly />
|
||||
<MudTextField Value="@result.ZipCode" Label="@LanguageLocale.general_address_zipCode"
|
||||
ReadOnly />
|
||||
</MudStack>
|
||||
</ChildContent>
|
||||
</MudListItem>
|
||||
@@ -49,24 +55,46 @@
|
||||
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="Cancel">Cancel</MudButton>
|
||||
<MudButton Color="Color.Primary" OnClick="btnSelectAddress">Select Address</MudButton>
|
||||
<MudButton OnClick="Cancel">
|
||||
@LanguageLocale.general_btnCancel
|
||||
</MudButton>
|
||||
<MudButton Color="Color.Primary" OnClick="btnSelectAddress">
|
||||
@LanguageLocale.control_AddressQueryDialog_btnSelectAddress
|
||||
</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!;
|
||||
// Reference to the Dialog when open by the ShowAsync Method. (When dialog is used inline).
|
||||
// This field is null when dialog is not open using the internal methods.
|
||||
private IDialogReference? _reference;
|
||||
|
||||
public string SearchText { get; set; } = "";
|
||||
//Reference to the MudDialog component. Used to manage the internal dialog when the component is inline.
|
||||
private MudDialog DialogRef { get; set; } = null!;
|
||||
|
||||
private string SearchText { get; set; } = "";
|
||||
private List<AddressResultDTO> addressResults = [];
|
||||
private AddressResultDTO? SelectedAddressResult { get; set; }
|
||||
|
||||
private MudTextField<string> txtSearch = null!;
|
||||
|
||||
|
||||
|
||||
private void Cancel() => MudDialog.Cancel();
|
||||
private void Cancel()
|
||||
{
|
||||
if (MudDialog is not null)
|
||||
{
|
||||
MudDialog.Cancel();
|
||||
return;
|
||||
}
|
||||
else if (_reference is not null)
|
||||
{
|
||||
DialogRef.CloseAsync(DialogResult.Cancel());
|
||||
return;
|
||||
}
|
||||
throw new InvalidOperationException("Unable to cancel (close) the dialog!");
|
||||
}
|
||||
|
||||
private async Task btnSearchAddress()
|
||||
{
|
||||
@@ -88,7 +116,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
private void btnSelectAddress()
|
||||
private async Task btnSelectAddress()
|
||||
{
|
||||
if (SelectedAddressResult is null)
|
||||
{
|
||||
@@ -96,8 +124,37 @@
|
||||
return;
|
||||
}
|
||||
|
||||
//In a real world scenario this bool would probably be a service to delete the item from api/database
|
||||
Snackbar.Add("Address Selected", Severity.Success);
|
||||
MudDialog.Close(DialogResult.Ok<AddressResultDTO?>(SelectedAddressResult));
|
||||
DialogResult dialogResult = DialogResult.Ok<AddressResultDTO?>(SelectedAddressResult);
|
||||
|
||||
//Close the dialog when opened by DialogService.
|
||||
if (MudDialog != null)
|
||||
{
|
||||
logger.LogDebug("AddressQueryDialog - Closed MudDialogInstance!");
|
||||
MudDialog.Close(dialogResult);
|
||||
return;
|
||||
}
|
||||
//Close the dialog when is a Inline dialog.
|
||||
else if (_reference is not null)
|
||||
{
|
||||
logger.LogDebug("AddressQueryDialog - Closed inline dialog instance!");
|
||||
await DialogRef.CloseAsync(dialogResult);
|
||||
return;
|
||||
}
|
||||
//Throw if the dialog can't be closed (as none of the above is true).
|
||||
throw new InvalidOperationException("Dialog cannot be closed! No reference to close!");
|
||||
}
|
||||
|
||||
|
||||
public async Task<IDialogReference> ShowAsync(DialogOptions? options = null)
|
||||
{
|
||||
_reference = await DialogRef.ShowAsync(options: options);
|
||||
return _reference;
|
||||
}
|
||||
|
||||
public async Task CloseAsync()
|
||||
{
|
||||
await DialogRef.CloseAsync();
|
||||
_reference = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user