address search fix

This commit is contained in:
Adam 2024-08-17 09:43:03 +02:00
parent 97c6cb3009
commit 7e9bb7939a
7 changed files with 161 additions and 48 deletions

View File

@ -2,25 +2,26 @@
@using TIAMWebApp.Shared.Application.Services @using TIAMWebApp.Shared.Application.Services
@inject GooglePlacesService GooglePlacesService @inject GooglePlacesService GooglePlacesService
<h4>
@NullText
</h4>
<DxTextBox @bind-Text="Address"
CssClass="form-field"
@oninput="OnInputChanged"
BindValueMode="BindValueMode.OnDelayedInput"
InputDelay="700">
</DxTextBox>
<DxTextBox @bind-Text="Address" @if (Predictions.Count > 0)
@oninput="OnInputChanged" {
BindValueMode="BindValueMode.OnDelayedInput" <DxComboBox Data="@Predictions"
InputDelay="500"> ValueFieldName="Description"
</DxTextBox> TextFieldName="Description"
@bind-Value="SelectedPrediction">
@if (Predictions.Count > 0) </DxComboBox>
{ }
<DxComboBox Data="@Predictions" else
ValueFieldName="Description" {
TextFieldName="Description" <p>No address found</p>
@bind-Value="SelectedPrediction"> }
</DxComboBox>
}
@code { @code {
@ -31,7 +32,21 @@
private string Address { get; set; } private string Address { get; set; }
private List<PredictionItem> Predictions { get; set; } = new(); private List<PredictionItem> Predictions { get; set; } = new();
private PredictionItem SelectedPrediction { get; set; } private PredictionItem selectedPrediction { get; set; }
public PredictionItem SelectedPrediction
{
get => selectedPrediction;
set
{
SetNewDestination(value.Description);
selectedPrediction = value;
}
}
public async Task SetNewDestination(string address)
{
await AddressChanged.InvokeAsync(address);
}
private async Task OnInputChanged(ChangeEventArgs e) private async Task OnInputChanged(ChangeEventArgs e)
{ {
@ -48,7 +63,7 @@
} }
} }
private class PredictionItem public class PredictionItem
{ {
public string Description { get; set; } public string Description { get; set; }
} }

View File

@ -4,10 +4,14 @@
@using AyCode.Services.Loggers @using AyCode.Services.Loggers
@using System.Reflection @using System.Reflection
@using AyCode.Blazor.Components.Components @using AyCode.Blazor.Components.Components
@using TIAM.Entities.Products
@using TIAM.Entities.Transfers @using TIAM.Entities.Transfers
@using TIAM.Models.Dtos.Users
@using TIAMSharedUI.Shared @using TIAMSharedUI.Shared
@using TIAMWebApp.Shared.Application.Interfaces
@using TIAMWebApp.Shared.Application.Utility @using TIAMWebApp.Shared.Application.Utility
@inject IEnumerable<IAcLogWriterClientBase> LogWriters @inject IEnumerable<IAcLogWriterClientBase> LogWriters
@inject ISessionService _sessionService
@if (isEditing) @if (isEditing)
{ {
@ -47,6 +51,9 @@ else
[Parameter] public List<string> IgnoreReflection { get; set; } [Parameter] public List<string> IgnoreReflection { get; set; }
[Parameter] public EventCallback<object> OnSubmit { get; set; } [Parameter] public EventCallback<object> OnSubmit { get; set; }
[Parameter] public bool isEditing { get; set; } = false; [Parameter] public bool isEditing { get; set; } = false;
[Parameter] public bool userAvailable { get; set; }
[Parameter] public UserModelDtoDetail userModelDtodetail { get; set; }
[Parameter] public Product CurrentProduct { get; set; }
string _formSubmitResult = ""; string _formSubmitResult = "";
private string _spinnerClass = ""; private string _spinnerClass = "";
@ -62,6 +69,12 @@ else
base.OnInitialized(); base.OnInitialized();
} }
protected override void OnParametersSet()
{
StateHasChanged();
base.OnParametersSet();
}
// void HandleValidSubmit() // void HandleValidSubmit()
// { // {
// FormSubmitResult = "You have been registered successfully."; // FormSubmitResult = "You have been registered successfully.";
@ -237,10 +250,15 @@ else
break; break;
} }
else if (property.PropertyType == typeof(string) && string.Compare(attrList.CustomDataType, "TransferDestination", true) == 0) else if (property.PropertyType == typeof(string) && string.Compare(attrList.CustomDataType, "TransferDestination", true) == 0)
{ {
editor.OpenComponent<ComboboxItemSelector>(j); editor.OpenComponent<ComboboxItemSelector>(j);
editor.AddAttribute(j++, "TextValue", property.GetValue(Data)); editor.AddAttribute(j++, "TextValue", property.GetValue(Data));
editor.AddAttribute(j++, "CssClass", "form-field"); editor.AddAttribute(j++, "CssClass", "form-field");
if (CurrentProduct != null)
{
editor.AddAttribute(j++, "ProductId", CurrentProduct.Id);
}
// editor.AddAttribute(j++, "ValExpression", lambda); // editor.AddAttribute(j++, "ValExpression", lambda);
editor.AddAttribute(j++, "OnSliderChanged", EventCallback.Factory.Create<string>(this, result => editor.AddAttribute(j++, "OnSliderChanged", EventCallback.Factory.Create<string>(this, result =>
{ {

View File

@ -25,7 +25,7 @@
<AuthComponent /> <AuthComponent />
<HeroSlider SliderItems="@sliders" PBottom="50px" Height="50vh"></HeroSlider> <HeroSlider SliderItems="@sliders" PBottom="50px" Height="50vh"></HeroSlider>
<div class="container" style="position: relative; z-index: 2;"> <div class="container-fluid" style="position: relative; z-index: 2;">
<div class="row d-flex justify-content-center"> <div class="row d-flex justify-content-center">
<div class="col-12 col-lg-6"> <div class="col-12 col-lg-6">
<div class="card bg-white p-3"> <div class="card bg-white p-3">
@ -35,8 +35,6 @@
SubmitButtonText="ButtonSend" SubmitButtonText="ButtonSend"
TitleResourceString="TransferTitle" TitleResourceString="TransferTitle"
SubtitleResourceString="TransferSubtitle"></InputWizard> SubtitleResourceString="TransferSubtitle"></InputWizard>
</div> </div>
</div> </div>
</div> </div>

View File

@ -50,7 +50,7 @@
<div class="row py-3"> <div class="row py-3">
<DynamicEditForm Data="Data" isEditing="true" IgnoreReflection="TransferIgnorList" OnSubmit="SubmitForm"></DynamicEditForm> <DynamicEditForm Data="Data" CurrentProduct="@SelectedHotel" isEditing="true" IgnoreReflection="TransferIgnorList" OnSubmit="SubmitForm"></DynamicEditForm>
</div> </div>
<div class="row py-3"> <div class="row py-3">
@ -68,7 +68,20 @@
private LoggerClient<CreateAndManageTransfer> _logger; private LoggerClient<CreateAndManageTransfer> _logger;
private TransferWizardModel Data = new(); private TransferWizardModel Data = new();
private List<Product> Hotels = new List<Product>(); private List<Product> Hotels = new List<Product>();
private Product SelectedHotel; private Product selectedHotel { get; set; }
public Product SelectedHotel
{
get
{
return selectedHotel;
}
set
{
selectedHotel = value;
StateHasChanged();
}
}
public List<string> TransferIgnorList = new List<string> public List<string> TransferIgnorList = new List<string>
{ {
nameof(TransferWizardModel.Id), nameof(TransferWizardModel.Id),
@ -82,6 +95,7 @@
nameof(TransferWizardModel.Price) nameof(TransferWizardModel.Price)
}; };
private bool isReloadVisible = false; private bool isReloadVisible = false;
private bool SelectedHotelInitialized = false;
protected override void OnInitialized() protected override void OnInitialized()
{ {
@ -92,7 +106,11 @@
if (SessionService.User.UserModelDto.Products.Any(x => x.ProductType == TIAM.Core.Enums.ProductType.Hotel)) if (SessionService.User.UserModelDto.Products.Any(x => x.ProductType == TIAM.Core.Enums.ProductType.Hotel))
{ {
Hotels = SessionService.GetHotels(); Hotels = SessionService.GetHotels();
SelectedHotel = Hotels[0]; if(!SelectedHotelInitialized)
{
SelectedHotel = Hotels[0];
SelectedHotelInitialized = true;
}
} }
} }
@ -157,6 +175,7 @@
{ {
Data = new TransferWizardModel(); Data = new TransferWizardModel();
isReloadVisible = false; isReloadVisible = false;
StateHasChanged(); StateHasChanged();
} }

View File

@ -3,7 +3,7 @@
<div class="card-body card-admin-body py-2 px-4"> <div class="card-body card-admin-body py-2 px-4">
<div class="d-flex flex-column mb-4 pb-2"> <div class="d-flex flex-column mb-4 pb-2">
<p>@userId.ToString()</p>
</div> </div>
</div> </div>

View File

@ -1,10 +1,13 @@
@using System.Linq.Expressions @using System.Linq.Expressions
@using AyCode.Core.Extensions
@using AyCode.Core.Loggers @using AyCode.Core.Loggers
@using AyCode.Services.Loggers @using AyCode.Services.Loggers
@using TIAM.Core.Loggers @using TIAM.Core.Loggers
@using TIAM.Entities.Products
@using TIAM.Entities.Transfers @using TIAM.Entities.Transfers
@using TIAM.Services @using TIAM.Services
@using TIAMSharedUI.Pages @using TIAMSharedUI.Pages
@using TIAMSharedUI.Pages.Components
@using TIAMSharedUI.Pages.User.SysAdmins @using TIAMSharedUI.Pages.User.SysAdmins
@using TIAMWebApp.Shared.Application.Interfaces @using TIAMWebApp.Shared.Application.Interfaces
@using TIAMWebApp.Shared.Application.Services @using TIAMWebApp.Shared.Application.Services
@ -12,27 +15,55 @@
@inject IEnumerable<IAcLogWriterClientBase> LogWriters @inject IEnumerable<IAcLogWriterClientBase> LogWriters
@inject AdminSignalRClient _adminSignalRClient @inject AdminSignalRClient _adminSignalRClient
@inject ITransferDataService TransferDataService @inject ITransferDataService TransferDataService
@using TIAMWebApp.Shared.Application.Services
@inject GooglePlacesService GooglePlacesService
<label for="cbOverview" class="demo-text cw-480 mb-1"> <label for="cbOverview" class="demo-text cw-480 mb-1">
Select a destination Select a destination
</label> </label>
<DxComboBox Data="@Data" <DxTabs>
InputCssClass="@CssClass" <DxTabPage Text="Preset addresses">
@bind-Value="@SelectedDestination"
SearchMode="@ListSearchMode.AutoSearch"
SearchFilterCondition="@ListSearchFilterCondition.Contains" <DxComboBox Data="@Data"
ListRenderMode="ListRenderMode.Virtual" InputCssClass="@CssClass"
TextFieldName="@nameof(TransferDestination.Name)" @bind-Value="@SelectedDestination"
CssClass="cw-480" SearchMode="@ListSearchMode.AutoSearch"
InputId="cbOverview" /> SearchFilterCondition="@ListSearchFilterCondition.Contains"
ListRenderMode="ListRenderMode.Virtual"
TextFieldName="@nameof(TransferDestination.Name)"
InputId="cbOverview" />
</DxTabPage>
<DxTabPage Text="Address locator">
<AddressSearchAndSelectComponent AddressChanged="@OnSelectedAddressChanged">
</AddressSearchAndSelectComponent>
@* <DxFormLayoutItem Caption="Type a custom address">
<DxTextBox @bind-Text="Address" />
</DxFormLayoutItem>
<DxFormLayoutItem>
<DxButton Context="ButtonContext" Click="ValidateAddress">Validate Address</DxButton>
</DxFormLayoutItem>
<DxFormLayoutItem>
<p>@ValidationMessage</p>
</DxFormLayoutItem> *@
</DxTabPage>
</DxTabs>
<p>Selected address: @Address</p>
@* <p class="demo-text cw-480 mt-3"> @* <p class="demo-text cw-480 mt-3">
@GetSelectedItemDescription() @GetSelectedItemDescription()
</p> *@ </p> *@
@* @*
<DxComboBox Data="@Data" <DxComboBox Data="@Data"
ValueExpression="@valueExpression" ValueExpression="@valueExpression"
TextFieldName="@nameof(TransferDestination.Name)" TextFieldName="@nameof(TransferDestination.Name)"
CssClass="cw-480" CssClass="cw-480"
InputId="cbOverview" InputId="cbOverview"
@ -46,6 +77,8 @@
[Parameter] public string CssClass { get; set; } = ""; [Parameter] public string CssClass { get; set; } = "";
[Parameter] public Guid? ProductId { get; set; }
public List<TransferDestination> Destinations = new List<TransferDestination>(); public List<TransferDestination> Destinations = new List<TransferDestination>();
public DxTextBox TextField; public DxTextBox TextField;
@ -56,6 +89,9 @@
IEnumerable<TransferDestination> Data { get; set; } IEnumerable<TransferDestination> Data { get; set; }
private string Address { get; set; }
private string ValidationMessage { get; set; }
private TransferDestination _selectedDestination; private TransferDestination _selectedDestination;
public TransferDestination SelectedDestination public TransferDestination SelectedDestination
{ {
@ -65,23 +101,44 @@
if (_selectedDestination != value) if (_selectedDestination != value)
{ {
_selectedDestination = value; _selectedDestination = value;
SetNewDestination(value); SetNewDestination(value.AddressString!);
} }
} }
} }
protected override void OnParametersSet() protected override void OnParametersSet()
{ {
// StateHasChanged();
} }
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
_logger = new LoggerClient<ComboboxItemSelector>(LogWriters.ToArray()); _logger = new LoggerClient<ComboboxItemSelector>(LogWriters.ToArray());
Data = await _adminSignalRClient.GetAllAsync<List<TransferDestination>>(SignalRTags.GetAllTransferDestinations); Data = await _adminSignalRClient.GetAllAsync<List<TransferDestination>>(SignalRTags.GetAllTransferDestinations);
Guid? productAddressId = Guid.Empty;
if (!ProductId.IsNullOrEmpty())
{
var currentProduct = await _adminSignalRClient.GetByIdAsync<Product>(SignalRTags.GetProductById, ProductId);
if (currentProduct != null)
{
if (!currentProduct.Profile.AddressId.IsNullOrEmpty())
{
productAddressId = currentProduct.Profile.AddressId;
}
}
}
_logger.Debug($"List length: {Data.Count().ToString()}"); _logger.Debug($"List length: {Data.Count().ToString()}");
SelectedDestination = Data.FirstOrDefault(); if (Data.Any(x => x.AddressId == (Guid)productAddressId))
{
SelectedDestination = Data.Where(x => x.AddressId == (Guid)productAddressId).FirstOrDefault()!;
}
else
{
SelectedDestination = Data.FirstOrDefault();
}
} }
// RenderFragment GetSelectedItemDescription() // RenderFragment GetSelectedItemDescription()
// { // {
@ -100,9 +157,16 @@
// } // }
public void SetNewDestination(TransferDestination destination) public void OnSelectedAddressChanged(string address)
{ {
OnSliderChanged.InvokeAsync(destination.AddressString); Address = address;
OnSliderChanged.InvokeAsync(address);
}
public void SetNewDestination(string address)
{
Address = address;
OnSliderChanged.InvokeAsync(address);
} }
// RenderFragment GetFieldDescription(string fieldName, object value) // RenderFragment GetFieldDescription(string fieldName, object value)

View File

@ -1,7 +1,7 @@
@using BlazorAnimation @using BlazorAnimation
@using TIAMWebApp.Shared.Application.Models.ClientSide.UI @using TIAMWebApp.Shared.Application.Models.ClientSide.UI
<header style="padding-bottom: @PBottom;"> <header style="padding-bottom: @PBottom;">
<Animation Effect="@Effect.FadeIn" Speed="@Speed.Fast" Delay="@TimeSpan.FromMilliseconds(250)">
<div id="owl-demo" class="owl-carousel owl-theme" style="position:absolute; z-index: 1;"> <div id="owl-demo" class="owl-carousel owl-theme" style="position:absolute; z-index: 1;">
@{ @{
@ -14,8 +14,7 @@
} }
</div> </div>
</Animation>
</header> </header>