ComboboxItemSelector.razor improvements, fixes, etc...

This commit is contained in:
Loretta 2024-08-29 18:01:30 +02:00
parent 5bc9663930
commit 1f59b4b8a3
2 changed files with 31 additions and 20 deletions

View File

@ -1,7 +1,9 @@
@using System.Linq.Expressions
@using AyCode.Core.Extensions
@using AyCode.Core.Helpers
@using AyCode.Core.Loggers
@using AyCode.Services.Loggers
@using AyCode.Services.SignalRs
@using TIAM.Core.Loggers
@using TIAM.Entities.Products
@using TIAM.Entities.Transfers
@ -79,7 +81,7 @@
[Parameter] public Guid? ProductId { get; set; }
public List<TransferDestination> Destinations = new List<TransferDestination>();
public List<TransferDestination> Destinations = [];
public DxTextBox TextField;
@ -87,22 +89,21 @@
ILogger _logger;
IEnumerable<TransferDestination> Data { get; set; }
List<TransferDestination> Data { get; set; } = [];
private string Address { get; set; }
private string ValidationMessage { get; set; }
private TransferDestination _selectedDestination;
public TransferDestination SelectedDestination
private TransferDestination? _selectedDestination;
public TransferDestination? SelectedDestination
{
get => _selectedDestination;
set
{
if (_selectedDestination != value)
{
_selectedDestination = value;
SetNewDestination(value.AddressString!);
}
if (_selectedDestination == value) return;
_selectedDestination = value;
SetNewDestination(value?.AddressString ?? string.Empty);
}
}
@ -115,8 +116,6 @@
{
_logger = new LoggerClient<ComboboxItemSelector>(LogWriters.ToArray());
Data = await _adminSignalRClient.GetAllAsync<List<TransferDestination>>(SignalRTags.GetAllTransferDestinations);
Guid? productAddressId = Guid.Empty;
if (!ProductId.IsNullOrEmpty())
{
@ -130,16 +129,28 @@
}
}
_logger.Debug($"List length: {Data.Count().ToString()}");
if (Data.Any(x => x.AddressId == (Guid)productAddressId))
_adminSignalRClient.GetAllAsync<List<TransferDestination>>(SignalRTags.GetAllTransferDestinations, response =>
{
SelectedDestination = Data.Where(x => x.AddressId == (Guid)productAddressId).FirstOrDefault()!;
}
else
{
SelectedDestination = Data.FirstOrDefault();
}
Data.Clear();
SelectedDestination = null;
if (response.Status != SignalResponseStatus.Success || response.ResponseData == null)
{
_logger.Error($"OnInitializedAsync->GetAllTransferDestinations; response.Status: {response.Status}");
return Task.CompletedTask;
}
Data.AddRange(response.ResponseData);
_logger.Debug($"TransferDestinations Data length: {Data.Count}");
SelectedDestination = productAddressId.IsNullOrEmpty() ? Data.FirstOrDefault() : Data.FirstOrDefault(x => x.AddressId == productAddressId);
return Task.CompletedTask;
}).Forget();
//await _adminSignalRClient.GetAllIntoAsync(Data, SignalRTags.GetAllTransferDestinations);
}
// RenderFragment GetSelectedItemDescription()
// {
// if (SelectedDestination != null)

View File

@ -61,9 +61,9 @@ namespace TIAMWebApp.Shared.Application.Services
//TODO: AdminSignalRClient.GetAllIntoAsync<Car>(_cars, SignalRTags.GetAllCarsByProductId, [productId]) - J.
return GetAllAsync<List<Car>>(SignalRTags.GetAllCarsByProductId, response =>
{
intoCars.Clear();
if (response is { Status: SignalResponseStatus.Success, ResponseData: not null })
{
intoCars.Clear();
intoCars.AddRange(response.ResponseData);
}