TourIAm/TIAMSharedUI/Shared/ComboboxItemSelector.razor

116 lines
3.6 KiB
Plaintext

@using System.Linq.Expressions
@using AyCode.Core.Loggers
@using AyCode.Services.Loggers
@using TIAM.Core.Loggers
@using TIAM.Entities.Transfers
@using TIAM.Services
@using TIAMSharedUI.Pages
@using TIAMSharedUI.Pages.User.SysAdmins
@using TIAMWebApp.Shared.Application.Interfaces
@using TIAMWebApp.Shared.Application.Services
@using TIAMWebApp.Shared.Application.Utility
@inject IEnumerable<IAcLogWriterClientBase> LogWriters
@inject AdminSignalRClient _adminSignalRClient
@inject ITransferDataService TransferDataService
<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" />
@* <p class="demo-text cw-480 mt-3">
@GetSelectedItemDescription()
</p> *@
@*
<DxComboBox Data="@Data"
ValueExpression="@valueExpression"
TextFieldName="@nameof(TransferDestination.Name)"
CssClass="cw-480"
InputId="cbOverview"
ValueChanged="@((TransferDestination destination) => SetNewDestination(destination))" /> *@
@code {
[Parameter] public EventCallback<string> OnSliderChanged { get; set; }
[Parameter] public string TextValue { get; set; } = "";
[Parameter] public string CssClass { get; set; } = "";
public List<TransferDestination> Destinations = new List<TransferDestination>();
public DxTextBox TextField;
TransferDestination Result;
ILogger _logger;
IEnumerable<TransferDestination> Data { get; set; }
private TransferDestination _selectedDestination;
public TransferDestination SelectedDestination
{
get => _selectedDestination;
set
{
if (_selectedDestination != value)
{
_selectedDestination = value;
SetNewDestination(value);
}
}
}
protected override void OnParametersSet()
{
}
protected override async Task OnInitializedAsync()
{
_logger = new LoggerClient<ComboboxItemSelector>(LogWriters.ToArray());
Data = await _adminSignalRClient.GetAllAsync<List<TransferDestination>>(SignalRTags.GetAllTransferDestinations);
_logger.Debug($"List length: {Data.Count().ToString()}");
SelectedDestination = Data.FirstOrDefault();
}
// RenderFragment GetSelectedItemDescription()
// {
// if (SelectedDestination != null)
// {
// SetNewDestination(SelectedDestination);
// return @<text>
// Selected Item: (
// @GetFieldDescription(nameof(TransferDestination.Name), SelectedDestination.Name),
// @GetFieldDescription(nameof(TransferDestination.AddressString), SelectedDestination.AddressString),
// @GetFieldDescription(nameof(TransferDestination.Description), SelectedDestination.Description)
// )
// </text>;
// }
// return @<text>Selected Item: <b>null</b></text>;
// }
public void SetNewDestination(TransferDestination destination)
{
OnSliderChanged.InvokeAsync(destination.AddressString);
}
// RenderFragment GetFieldDescription(string fieldName, object value)
// {
// return @<text>@fieldName: <b>@value</b></text>;
// }
}