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
@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"
@oninput="OnInputChanged"
BindValueMode="BindValueMode.OnDelayedInput"
InputDelay="500">
</DxTextBox>
@if (Predictions.Count > 0)
{
<DxComboBox Data="@Predictions"
ValueFieldName="Description"
TextFieldName="Description"
@bind-Value="SelectedPrediction">
</DxComboBox>
}
@if (Predictions.Count > 0)
{
<DxComboBox Data="@Predictions"
ValueFieldName="Description"
TextFieldName="Description"
@bind-Value="SelectedPrediction">
</DxComboBox>
}
else
{
<p>No address found</p>
}
@code {
@ -31,7 +32,21 @@
private string Address { get; set; }
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)
{
@ -48,7 +63,7 @@
}
}
private class PredictionItem
public class PredictionItem
{
public string Description { get; set; }
}

View File

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

View File

@ -25,7 +25,7 @@
<AuthComponent />
<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="col-12 col-lg-6">
<div class="card bg-white p-3">
@ -35,8 +35,6 @@
SubmitButtonText="ButtonSend"
TitleResourceString="TransferTitle"
SubtitleResourceString="TransferSubtitle"></InputWizard>
</div>
</div>
</div>

View File

@ -50,7 +50,7 @@
<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 class="row py-3">
@ -68,7 +68,20 @@
private LoggerClient<CreateAndManageTransfer> _logger;
private TransferWizardModel Data = new();
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>
{
nameof(TransferWizardModel.Id),
@ -82,6 +95,7 @@
nameof(TransferWizardModel.Price)
};
private bool isReloadVisible = false;
private bool SelectedHotelInitialized = false;
protected override void OnInitialized()
{
@ -92,7 +106,11 @@
if (SessionService.User.UserModelDto.Products.Any(x => x.ProductType == TIAM.Core.Enums.ProductType.Hotel))
{
Hotels = SessionService.GetHotels();
SelectedHotel = Hotels[0];
if(!SelectedHotelInitialized)
{
SelectedHotel = Hotels[0];
SelectedHotelInitialized = true;
}
}
}
@ -157,6 +175,7 @@
{
Data = new TransferWizardModel();
isReloadVisible = false;
StateHasChanged();
}

View File

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

View File

@ -1,10 +1,13 @@
@using System.Linq.Expressions
@using AyCode.Core.Extensions
@using AyCode.Core.Loggers
@using AyCode.Services.Loggers
@using TIAM.Core.Loggers
@using TIAM.Entities.Products
@using TIAM.Entities.Transfers
@using TIAM.Services
@using TIAMSharedUI.Pages
@using TIAMSharedUI.Pages.Components
@using TIAMSharedUI.Pages.User.SysAdmins
@using TIAMWebApp.Shared.Application.Interfaces
@using TIAMWebApp.Shared.Application.Services
@ -12,19 +15,47 @@
@inject IEnumerable<IAcLogWriterClientBase> LogWriters
@inject AdminSignalRClient _adminSignalRClient
@inject ITransferDataService TransferDataService
@using TIAMWebApp.Shared.Application.Services
@inject GooglePlacesService GooglePlacesService
<label for="cbOverview" class="demo-text cw-480 mb-1">
Select a destination
</label>
<DxComboBox Data="@Data"
InputCssClass="@CssClass"
@bind-Value="@SelectedDestination"
SearchMode="@ListSearchMode.AutoSearch"
SearchFilterCondition="@ListSearchFilterCondition.Contains"
ListRenderMode="ListRenderMode.Virtual"
TextFieldName="@nameof(TransferDestination.Name)"
CssClass="cw-480"
InputId="cbOverview" />
<DxTabs>
<DxTabPage Text="Preset addresses">
<DxComboBox Data="@Data"
InputCssClass="@CssClass"
@bind-Value="@SelectedDestination"
SearchMode="@ListSearchMode.AutoSearch"
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">
@GetSelectedItemDescription()
@ -46,6 +77,8 @@
[Parameter] public string CssClass { get; set; } = "";
[Parameter] public Guid? ProductId { get; set; }
public List<TransferDestination> Destinations = new List<TransferDestination>();
public DxTextBox TextField;
@ -56,6 +89,9 @@
IEnumerable<TransferDestination> Data { get; set; }
private string Address { get; set; }
private string ValidationMessage { get; set; }
private TransferDestination _selectedDestination;
public TransferDestination SelectedDestination
{
@ -65,14 +101,14 @@
if (_selectedDestination != value)
{
_selectedDestination = value;
SetNewDestination(value);
SetNewDestination(value.AddressString!);
}
}
}
protected override void OnParametersSet()
{
// StateHasChanged();
}
protected override async Task OnInitializedAsync()
@ -80,8 +116,29 @@
_logger = new LoggerClient<ComboboxItemSelector>(LogWriters.ToArray());
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()}");
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()
// {
@ -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)

View File

@ -1,7 +1,7 @@
@using BlazorAnimation
@using TIAMWebApp.Shared.Application.Models.ClientSide.UI
<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;">
@{
@ -15,7 +15,6 @@
</div>
</Animation>
</header>