259 lines
12 KiB
Plaintext
259 lines
12 KiB
Plaintext
@using AyCode.Blazor.Components.Components.Grids
|
|
@using AyCode.Core
|
|
@using AyCode.Core.Enums
|
|
@using AyCode.Core.Extensions
|
|
@using AyCode.Core.Helpers
|
|
@using AyCode.Core.Loggers
|
|
@using AyCode.Services.Loggers
|
|
@using AyCode.Services.SignalRs
|
|
@using AyCode.Utils.Extensions
|
|
@using TIAM.Core.Consts
|
|
@using TIAM.Core.Loggers
|
|
@using TIAM.Entities.Drivers
|
|
@using TIAM.Entities.Transfers
|
|
@using TIAM.Entities.Users
|
|
@using TIAM.Models.Dtos.Users
|
|
@using TIAM.Services
|
|
@using TIAMSharedUI.Shared.Components.Grids
|
|
@using TIAMWebApp.Shared.Application.Interfaces
|
|
@using TIAMWebApp.Shared.Application.Services
|
|
@using TIAMWebApp.Shared.Application.Utility
|
|
@inject IUserDataService UserDataService
|
|
@inject IEnumerable<IAcLogWriterClientBase> LogWriters
|
|
@inject AdminSignalRClient AdminSignalRClient;
|
|
|
|
<TransferToDriversDetailGrid @ref="_transferToDriversGrid"
|
|
ContextIds="@(ContextId.IsNullOrEmpty() ? throw new InvalidDataException($"ContextId.IsNullOrEmpty(); ContextId: {ContextId}") : [ContextId])"
|
|
DataSource="ParentData.TransferToDrivers"
|
|
Logger="_logger"
|
|
SignalRClient="AdminSignalRClient"
|
|
OnGridEditModelSaving="DataItemSaving"
|
|
OnGridItemDeleting="DataItemDeleting"
|
|
OnGridItemChanged="DataItemChanged"
|
|
ValidationEnabled="false"
|
|
CustomizeEditModel="CustomizeEditModel"
|
|
EditMode="GridEditMode.EditRow"
|
|
ColumnResizeMode="GridColumnResizeMode.NextColumn">
|
|
<Columns>
|
|
<DxGridCommandColumn Width="150" MinWidth="150" FixedPosition="GridColumnFixedPosition.Left"
|
|
Visible="CommandColumnVisible" NewButtonVisible="NewButtonVisible" DeleteButtonVisible="DeleteButtonVisible" EditButtonVisible="EditButtonVisible" />
|
|
<DxGridDataColumn FieldName="Id" ShowInColumnChooser="AcDomain.IsDeveloperVersion" Visible="AcDomain.IsDeveloperVersion" DisplayFormat="N" ReadOnly="true" />
|
|
@{
|
|
var userEmailFieldName = $"{nameof(TransferToDriver.UserProductMapping)}.{nameof(UserProductMapping.User)}.{nameof(User.EmailAddress)}";
|
|
|
|
var userEmailFieldNameComboItem = $"{nameof(UserProductMapping.User)}.{nameof(User.EmailAddress)}";
|
|
var userNameFieldNameComboItem = $"{nameof(UserProductMapping.User)}.{nameof(User.FullName)}";
|
|
}
|
|
<DxGridDataColumn FieldName="@userEmailFieldName" Caption="Driver" SortIndex="0" ReadOnly="!DriverId.IsNullOrEmpty()" Visible="DriverId.IsNullOrEmpty()">
|
|
<CellDisplayTemplate>
|
|
@{
|
|
//TODO: a ManageTransfers-en ha új sofőrt adunk hozzá a UserProductMapping null lesz és elszáll! - J.
|
|
var email = string.Empty;
|
|
var transferToDriverDataItem = ((TransferToDriver)context.DataItem);
|
|
|
|
if (HasReadPermission(transferToDriverDataItem.UserProductMappingId))
|
|
email = transferToDriverDataItem.UserProductMapping?.User.EmailAddress;
|
|
}
|
|
<text>@email</text>
|
|
</CellDisplayTemplate>
|
|
<CellEditTemplate>
|
|
@{
|
|
var transferToDriverEditModel = (TransferToDriver)context.EditModel;
|
|
}
|
|
|
|
<DxComboBox Data="@_drivers"
|
|
TData="@UserProductMapping"
|
|
TValue="@UserProductMapping"
|
|
ReadOnly="!DriverId.IsNullOrEmpty()"
|
|
TextFieldName="@userEmailFieldNameComboItem"
|
|
Value="@_drivers.FirstOrDefault(x => x.Id == transferToDriverEditModel.UserProductMappingId)"
|
|
ValueChanged="v => transferToDriverEditModel.UserProductMappingId = v.Id"
|
|
SearchFilterCondition="ListSearchFilterCondition.Contains" SearchMode="ListSearchMode.AutoSearch">
|
|
<Columns>
|
|
@* <DxListEditorColumn FieldName="Id"/> *@
|
|
<DxListEditorColumn FieldName="@userEmailFieldNameComboItem" Caption="Driver email" />
|
|
<DxListEditorColumn FieldName="@userNameFieldNameComboItem" Caption="Driver name" />
|
|
</Columns>
|
|
</DxComboBox>
|
|
|
|
</CellEditTemplate>
|
|
</DxGridDataColumn>
|
|
|
|
<DxGridDataColumn FieldName="CarId" Caption="Car" ReadOnly="!_hasEditPermission">
|
|
<CellDisplayTemplate>
|
|
@{
|
|
var transferToDriverDataItem = (TransferToDriver)context.DataItem;
|
|
<text>@_cars.FirstOrDefault(x => x.Id == transferToDriverDataItem?.CarId)?.LicencePlate</text>
|
|
}
|
|
</CellDisplayTemplate>
|
|
<CellEditTemplate>
|
|
@{
|
|
var transferToDriverEditModel = (TransferToDriver)context.EditModel;
|
|
}
|
|
|
|
<DxComboBox Data="@_cars.Where(x=>x.UserProductMappingId == transferToDriverEditModel.UserProductMappingId)"
|
|
TData="@Car"
|
|
TValue="@Car"
|
|
ReadOnly="!_hasEditPermission"
|
|
TextFieldName="LicencePlate"
|
|
Value="@_cars.FirstOrDefault(x => x.Id == transferToDriverEditModel.CarId)"
|
|
ValueChanged="v => { transferToDriverEditModel.CarId = v?.Id ?? Guid.Empty; transferToDriverEditModel.LicencePlate = v?.LicencePlate ?? string.Empty; }"
|
|
SearchFilterCondition="ListSearchFilterCondition.Contains"
|
|
SearchMode="ListSearchMode.AutoSearch">
|
|
<Columns>
|
|
@* <DxListEditorColumn FieldName="Id"/> *@
|
|
<DxListEditorColumn FieldName="LicencePlate" Caption="LicencePlate" Width="100" />
|
|
<DxListEditorColumn FieldName="Manufacture" Caption="Manufacture" />
|
|
<DxListEditorColumn FieldName="CarModel" Caption="Model" />
|
|
<DxListEditorColumn FieldName="SeatNumber" Caption="SeatNumber" />
|
|
</Columns>
|
|
</DxComboBox>
|
|
</CellEditTemplate>
|
|
</DxGridDataColumn>
|
|
|
|
@* <DxGridDataColumn FieldName="CarId">
|
|
<CellEditTemplate>
|
|
@{
|
|
var transferToDriverId = ((TransferToDriver)context.DataItem).Id;
|
|
}
|
|
|
|
<DxDropDownBox QueryDisplayText="QueryText"
|
|
DropDownWidthMode="DropDownWidthMode.ContentWidth"
|
|
ClearButtonDisplayMode="DataEditorClearButtonDisplayMode.Auto"
|
|
NullText="Select a car...">
|
|
<DropDownBodyTemplate>
|
|
<CarDetailGridComponent GetAllTag="SignalRTags.GetAllCars"/>
|
|
</DropDownBodyTemplate>
|
|
</DxDropDownBox>
|
|
</CellEditTemplate>
|
|
</DxGridDataColumn>
|
|
*@
|
|
@* <DxGridDataColumn FieldName="CarId">
|
|
<EditSettings>
|
|
<DxComboBoxSettings Data="_cars" SearchMode="ListSearchMode.AutoSearch"
|
|
ValueFieldName="Id"
|
|
TextFieldName="LicencePlate" />
|
|
</EditSettings>
|
|
</DxGridDataColumn>*@
|
|
|
|
|
|
<DxGridDataColumn FieldName="Price" ReadOnly="!_hasEditPermission">
|
|
<CellDisplayTemplate>
|
|
@{
|
|
var price = string.Empty;
|
|
var transferToDriverDataItem = ((TransferToDriver)context.DataItem);
|
|
|
|
if (HasReadPermission(transferToDriverDataItem.UserProductMappingId))
|
|
price = transferToDriverDataItem.Price.ToString("N0");
|
|
}
|
|
|
|
<text>@price</text>
|
|
</CellDisplayTemplate>
|
|
</DxGridDataColumn>
|
|
|
|
@* <DxGridDataColumn FieldName="LicencePlate" ReadOnly="true" /> *@
|
|
<DxGridDataColumn FieldName="Created" DisplayFormat="g" Width="140" CaptionAlignment="GridTextAlignment.Center" TextAlignment="GridTextAlignment.Center" ReadOnly="true" />
|
|
<DxGridDataColumn FieldName="Modified" DisplayFormat="g" Width="140" CaptionAlignment="GridTextAlignment.Center" TextAlignment="GridTextAlignment.Center" ReadOnly="true"/>
|
|
</Columns>
|
|
</TransferToDriversDetailGrid>
|
|
|
|
@code {
|
|
/// <summary>
|
|
/// UserProductMappingId! Not required...
|
|
/// </summary>
|
|
[Parameter] public Guid? DriverId { get; set; } = null;
|
|
[Parameter] public Guid ContextId { get; set; }
|
|
[Parameter] public ITransferToDriversRelation ParentData { get; set; } = null!;
|
|
[Parameter] public EventCallback<TransferToDriver> OnTransferToDriverChanged { get; set; }
|
|
|
|
[Parameter] public bool CommandColumnVisible { get; set; } = true;
|
|
[Parameter] public bool NewButtonVisible { get; set; } = true;
|
|
[Parameter] public bool EditButtonVisible { get; set; } = true;
|
|
[Parameter] public bool DeleteButtonVisible { get; set; } = true;
|
|
|
|
private bool _hasEditPermission = true;
|
|
private bool HasReadPermission(Guid userProductMappingId) => DriverId.IsNullOrEmpty() || DriverId == userProductMappingId;
|
|
|
|
private TransferToDriversDetailGrid _transferToDriversGrid = null!;
|
|
private LoggerClient<TransferToDriverGridComponent> _logger = null!;
|
|
|
|
private static List<Car> _cars = [];
|
|
private static List<UserProductMapping> _drivers = [];
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
_logger = new LoggerClient<TransferToDriverGridComponent>(LogWriters.ToArray());
|
|
|
|
_logger.Info($"DetailGridData: {ParentData.TransferToDrivers.Count}");
|
|
|
|
await base.OnInitializedAsync();
|
|
}
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
if (firstRender)
|
|
{
|
|
LoadComboBoxItems().Forget();
|
|
}
|
|
|
|
await base.OnAfterRenderAsync(firstRender);
|
|
}
|
|
|
|
void CustomizeEditModel(GridCustomizeEditModelEventArgs e)
|
|
{
|
|
if (!e.IsNew)
|
|
{
|
|
_hasEditPermission = HasReadPermission(((TransferToDriver)e.DataItem).UserProductMappingId);
|
|
return;
|
|
}
|
|
|
|
_hasEditPermission = true;
|
|
|
|
var newDriver = (TransferToDriver)e.EditModel;
|
|
newDriver.Id = Guid.NewGuid();
|
|
newDriver.CarId = Guid.Empty;
|
|
newDriver.LicencePlate = "";
|
|
newDriver.Car = new Car();
|
|
newDriver.Price = 0;
|
|
newDriver.TransferId = ParentData.Id;
|
|
}
|
|
|
|
private Task LoadComboBoxItems()
|
|
{
|
|
//TODO: CarModelDtoMin-t megcsinálni és azt lekérni a ComboBox-hoz! - J.
|
|
return AdminSignalRClient.GetAllCarsAndDriversByProductIdAsync(TiamConstClient.TransferProductId, _cars, _drivers, StateHasChanged);
|
|
}
|
|
|
|
private void DataItemChanged(GridDataItemChangedEventArgs<TransferToDriver> args)
|
|
{
|
|
//ParentData?.TransferToDrivers?.UpdateCollection(args.DataItem, args.TrackingState == TrackingState.Remove);
|
|
|
|
OnTransferToDriverChanged.InvokeAsync(args.DataItem);
|
|
}
|
|
|
|
private void DataItemSaving(GridEditModelSavingEventArgs args)
|
|
{
|
|
_logger.Debug($"DataItemSaving");
|
|
|
|
var transferToDriverEditModel = (TransferToDriver)args.EditModel;
|
|
|
|
if (transferToDriverEditModel.UserProductMappingId.IsNullOrEmpty() || transferToDriverEditModel.CarId.IsNullOrEmpty() ||
|
|
transferToDriverEditModel.LicencePlate.IsNullOrWhiteSpace())// || transferToDriverEditModel.Price <= 0)
|
|
{
|
|
args.Cancel = true;
|
|
_logger.Error($"transferToDriverEditModel.UserProductMappingId.IsNullOrEmpty() || transferToDriverEditModel.CarId.IsNullOrEmpty() || transferToDriverEditModel.LicencePlate.IsNullOrWhiteSpace()");// || transferToDriverEditModel.Price <= 0");
|
|
}
|
|
|
|
if (args.IsNew)
|
|
{
|
|
transferToDriverEditModel.TransferId = ContextId;
|
|
transferToDriverEditModel.Id = Guid.NewGuid();
|
|
transferToDriverEditModel.Car = null;
|
|
}
|
|
}
|
|
|
|
private void DataItemDeleting(GridDataItemDeletingEventArgs args)
|
|
{
|
|
_logger.Debug($"DataItemDeleting");
|
|
}
|
|
} |