326 lines
14 KiB
Plaintext
326 lines
14 KiB
Plaintext
@using TIAM.Entities.Products
|
|
@using TIAM.Entities.Transfers
|
|
@using TIAM.Entities.Drivers
|
|
@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
|
|
@using TIAM.Core.Loggers
|
|
@using AyCode.Core.Loggers
|
|
@using AyCode.Services.Loggers
|
|
@using AyCode.Core
|
|
@using AyCode.Core.Extensions
|
|
@inject IServiceProviderDataService ServiceProviderDataService
|
|
@inject IEnumerable<IAcLogWriterClientBase> LogWriters
|
|
@inject AdminSignalRClient AdminSignalRClient
|
|
@inject IWizardProcessor WizardProcessor
|
|
@inject IUserDataService UserDataService
|
|
|
|
<DxPopup CssClass="popup-demo-events"
|
|
@bind-Visible="@PopupVisible"
|
|
ShowFooter="true"
|
|
CloseOnEscape="true"
|
|
CloseOnOutsideClick="false"
|
|
ShowCloseButton="false"
|
|
HeaderText="Select driver"
|
|
Closing="SelectDriverPopupClosing"
|
|
Closed="SelectDriverPopupClosed">
|
|
<BodyContentTemplate>
|
|
<label for="emailID" class="demo-text mt-4 mb-1">
|
|
Put user email here
|
|
</label>
|
|
<DxMaskedInput @ref="_emailInput"
|
|
@bind-Value="@Email"
|
|
CssClass="cw-320"
|
|
Mask="@EmailMask"
|
|
InputId="emailID"
|
|
MaskMode="MaskMode.RegEx" />
|
|
<DxButton @ref="_button1" CssClass="popup-button my-1 ms-2" Visible="true" RenderStyle="ButtonRenderStyle.Primary" Text="Find user" Click="@FindUser" />
|
|
<div style="@_errorCss" @ref="_errorMessage"><p>User not found, type another email please</p></div>
|
|
<DxGrid Data="@FoundUsers" RowClick="@OnRowClick">
|
|
<Columns>
|
|
<DxGridDataColumn FieldName="Id" Caption="ID" />
|
|
<DxGridDataColumn FieldName="Id" Caption="ID" />
|
|
@* <DxGridDataColumn FieldName="Created" DisplayFormat="g" Width="140" CaptionAlignment="GridTextAlignment.Center" TextAlignment="GridTextAlignment.Center" />
|
|
<DxGridDataColumn FieldName="Modified" DisplayFormat="g" Width="140" CaptionAlignment="GridTextAlignment.Center" TextAlignment="GridTextAlignment.Center" />
|
|
*@ </Columns>
|
|
</DxGrid>
|
|
</BodyContentTemplate>
|
|
<FooterContentTemplate Context="PopupContext">
|
|
<div class="popup-demo-events-footer">
|
|
|
|
|
|
<!--DxButton CssClass="popup-demo-events-button ms-2" RenderStyle="ButtonRenderStyle.Primary" Text="OK" Click="Context.CloseCallback" /-->
|
|
<DxButton CssClass="popup-demo-events-button ms-2" RenderStyle="ButtonRenderStyle.Secondary" Text="Cancel" Click="CancelCreateClick" />
|
|
</div>
|
|
</FooterContentTemplate>
|
|
</DxPopup>
|
|
|
|
<UserProductMappingDriverGrid Logger="_logger"
|
|
@ref="_driverGrid"
|
|
ContextIds="new object[] {ContextId}"
|
|
GetAllMessageTag="GetAllTag"
|
|
SignalRClient="AdminSignalRClient"
|
|
PageSize="10"
|
|
ValidationEnabled="false"
|
|
CustomizeElement="Grid_CustomizeElement"
|
|
CustomizeEditModel="CustomizeEditModel"
|
|
EditMode="GridEditMode.EditForm"
|
|
ColumnResizeMode="GridColumnResizeMode.NextColumn"
|
|
DetailExpandButtonDisplayMode="DetailExpandButtonDisplayMode"
|
|
ShowFilterRow="true">
|
|
<Columns>
|
|
<DxGridCommandColumn Width="135" MinWidth="135" FixedPosition="GridColumnFixedPosition.Left" />
|
|
<DxGridDataColumn FieldName="Id" ShowInColumnChooser="AcDomain.IsDeveloperVersion" Visible="AcDomain.IsDeveloperVersion" DisplayFormat="N" />
|
|
@{
|
|
var userEmailFieldName = $"{nameof(UserProductMapping.User)}.{nameof(User.EmailAddress)}";
|
|
}
|
|
<DxGridDataColumn FieldName="@userEmailFieldName" Caption="User email" SortIndex="0" />
|
|
<DxGridDataColumn FieldName="ProductId" Caption="ServiceId" ShowInColumnChooser="AcDomain.IsDeveloperVersion" Visible="AcDomain.IsDeveloperVersion" DisplayFormat="N" />
|
|
@{
|
|
var productNameFieldName = $"{nameof(UserProductMapping.Product)}.{nameof(Product.Name)}";
|
|
}
|
|
<DxGridDataColumn FieldName="@productNameFieldName" Caption="Service name" />
|
|
<DxGridDataColumn FieldName="DriverBalance" Caption="Balance" Width="120" />
|
|
<DxGridDataColumn FieldName="Permissions" />
|
|
</Columns>
|
|
<DetailRowTemplate>
|
|
@{
|
|
<DxTabs>
|
|
<DxTabPage Text="Transfers">
|
|
<TransferDetailGrid @ref="_gridTransfer"
|
|
Logger="_logger"
|
|
GetAllMessageTag="SignalRTags.GetTransfersByUserProductMappingId"
|
|
SignalRClient="AdminSignalRClient"
|
|
ContextIds="new object[] {((UserProductMapping)context.DataItem).Id}"
|
|
ShowGroupPanel="true"
|
|
CustomGroup="Grid_CustomGroup"
|
|
CustomizeGroupValueDisplayText="Grid_CustomizeGroupValueDisplayText"
|
|
ColumnResizeMode="GridColumnResizeMode.NextColumn"
|
|
AllowSelectRowByClick="false"
|
|
PageSize="13"
|
|
ShowFilterRow="true">
|
|
|
|
<Columns>
|
|
<DxGridDataColumn FieldName="Id" ShowInColumnChooser="AcDomain.IsDeveloperVersion" Visible="AcDomain.IsDeveloperVersion" DisplayFormat="N" />
|
|
<DxGridDataColumn FieldName="Appointment" SortOrder="GridColumnSortOrder.Descending" GroupIndex="0" GroupInterval="GridColumnGroupInterval.Custom" DisplayFormat="g" Width="125" />
|
|
<DxGridDataColumn FieldName="OrderId" Caption="Order" SortIndex="1" SortOrder="GridColumnSortOrder.Descending" Width="70" />
|
|
|
|
<DxGridDataColumn FieldName="FromAddress" />
|
|
<DxGridDataColumn FieldName="ToAddress" />
|
|
<DxGridDataColumn FieldName="PassengerCount" Caption="Passengers" Width="90" TextAlignment="GridTextAlignment.Center" CaptionAlignment="GridTextAlignment.Center" />
|
|
<DxGridDataColumn FieldName="LuggageCount" Caption="Luggages" Width="80" TextAlignment="GridTextAlignment.Center" CaptionAlignment="GridTextAlignment.Center" />
|
|
<DxGridDataColumn FieldName="FlightNumber" Caption="FlightNum" Width="95" TextAlignment="GridTextAlignment.Center" CaptionAlignment="GridTextAlignment.Center" />
|
|
<DxGridDataColumn FieldName="Price" Caption="Price" Width="70" CaptionAlignment="GridTextAlignment.Center" />
|
|
<DxGridDataColumn FieldName="Revenue" Caption="Revenue" Width="70" CaptionAlignment="GridTextAlignment.Center" />
|
|
<DxGridDataColumn FieldName="FullName" />
|
|
<DxGridDataColumn FieldName="ContactPhone" Width="120" />
|
|
<DxGridDataColumn FieldName="ContactEmail" Width="120" />
|
|
<DxGridDataColumn FieldName="Created" DisplayFormat="g" Width="125" Visible="false" CaptionAlignment="GridTextAlignment.Center" TextAlignment="GridTextAlignment.Center" />
|
|
</Columns>
|
|
|
|
</TransferDetailGrid>
|
|
</DxTabPage>
|
|
<DxTabPage Text="Products">
|
|
<ProductDetailGridComponent GetAllTag="SignalRTags.GetProductsById" ContextId="((UserProductMapping)context.DataItem).ProductId" />
|
|
</DxTabPage>
|
|
<DxTabPage Text="Cars">
|
|
<CarDetailGridComponent GetAllTag="SignalRTags.GetCarsForUserProductMapping" ContextId="((UserProductMapping)context.DataItem).Id" />
|
|
</DxTabPage>
|
|
</DxTabs>
|
|
}
|
|
</DetailRowTemplate>
|
|
|
|
<EditFormTemplate Context="UserEditFormContext">
|
|
|
|
|
|
@{
|
|
var transfer2 = (UserProductMapping)UserEditFormContext.EditModel;
|
|
}
|
|
<DxFormLayout CssClass="w-100">
|
|
|
|
<DxFormLayoutItem Caption="UserId" ColSpanLg="6" ColSpanMd="12">
|
|
@transfer2.UserId
|
|
@{
|
|
var a = UserEditFormContext.GetEditor("UserId");
|
|
}
|
|
@* <DxButton Click="() => ShowPopup((UserProductMapping)UserEditFormContext.EditModel)" Context="ButtonContext">Select user</DxButton> *@
|
|
<DxButton Click="@(async (MouseEventArgs e) => await ShowPopup((UserProductMapping)UserEditFormContext.EditModel))" Context="ButtonContext">Select user</DxButton>
|
|
</DxFormLayoutItem>
|
|
|
|
<DxFormLayoutItem Caption="Balance" ColSpanLg="3">
|
|
@UserEditFormContext.GetEditor("DriverBalance")
|
|
</DxFormLayoutItem>
|
|
|
|
<DxFormLayoutItem Caption="Permissions" ColSpanLg="3">
|
|
@UserEditFormContext.GetEditor("Permissions")
|
|
</DxFormLayoutItem>
|
|
|
|
|
|
|
|
</DxFormLayout>
|
|
</EditFormTemplate>
|
|
|
|
</UserProductMappingDriverGrid>
|
|
|
|
@code {
|
|
[Parameter] public Guid ContextId { get; set; }
|
|
[Parameter] public IProductRelation ParentData { get; set; } = null!;
|
|
[Parameter] public int GetAllTag { get; set; } = SignalRTags.GetAllUserProductMappings;
|
|
[Parameter] public GridDetailExpandButtonDisplayMode DetailExpandButtonDisplayMode { get; set; } = GridDetailExpandButtonDisplayMode.Never;
|
|
|
|
private LoggerClient<UserProductMappingGridComponent> _logger;
|
|
|
|
private UserProductMappingDriverGrid _driverGrid;
|
|
|
|
private UserProductMapping _tempProductMapping;
|
|
|
|
bool PopupVisible { get; set; }
|
|
private DxMaskedInput<string> _emailInput;
|
|
private DxButton _button1;
|
|
private ElementReference _errorMessage;
|
|
private string _errorCss = "display: none;";
|
|
private List<UserModelDto> FoundUsers { get; set; } = new List<UserModelDto>();
|
|
private TransferGrid _gridTransfer;
|
|
|
|
private string Email { get; set; } = "email@email.com";
|
|
string EmailMask { get; set; } = @"(\w|[.-])+@(\w|-)+\.(\w|-){2,4}";
|
|
UserModelDto _chosenUser = null!;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
_logger = new LoggerClient<UserProductMappingGridComponent>(LogWriters.ToArray());
|
|
|
|
base.OnInitialized();
|
|
}
|
|
|
|
void Grid_CustomGroup(GridCustomGroupEventArgs e)
|
|
{
|
|
if (e.FieldName == "Appointment")
|
|
{
|
|
e.SameGroup = Grid_CompareColumnValues(((DateTime)e.Value1).Date, ((DateTime)e.Value2).Date);
|
|
e.Handled = true;
|
|
}
|
|
}
|
|
bool Grid_CompareColumnValues(DateTime value1, DateTime value2)
|
|
{
|
|
if (value1.Year == value2.Year && value1.Month == value2.Month)
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
void Grid_CustomizeGroupValueDisplayText(GridCustomizeGroupValueDisplayTextEventArgs e)
|
|
{
|
|
if (e.FieldName == "Appointment")
|
|
{
|
|
|
|
string displayText = ((DateTime)e.Value).Date.ToString();
|
|
e.DisplayText = displayText;
|
|
}
|
|
}
|
|
|
|
void CustomizeEditModel(GridCustomizeEditModelEventArgs e)
|
|
{
|
|
if (!e.IsNew) return;
|
|
|
|
if (ContextId.IsNullOrEmpty())
|
|
{
|
|
_logger.Warning($"ContextId.IsNullOrEmpty()");
|
|
return;
|
|
}
|
|
|
|
var newUpm = (UserProductMapping)e.EditModel;
|
|
newUpm.ProductId = ContextId;
|
|
|
|
var newProductMapping = new UserProductMapping
|
|
{
|
|
Id = Guid.NewGuid(),
|
|
ProductId = (Guid)ContextId,
|
|
Permissions = 2
|
|
};
|
|
|
|
//e.EditModel = newProductMapping;
|
|
}
|
|
|
|
async Task FindUser()
|
|
{
|
|
var userModelDto = await UserDataService.GetUserByEmailAsync(Email);
|
|
if (userModelDto != null)
|
|
{
|
|
_chosenUser = userModelDto;
|
|
FoundUsers.Add(_chosenUser);
|
|
_emailInput.Enabled = false;
|
|
_button1.Visible = false;
|
|
}
|
|
else
|
|
{
|
|
_emailInput.Value = "email@email.com";
|
|
_errorCss = "display: block";
|
|
}
|
|
}
|
|
|
|
void CancelCreateClick()
|
|
{
|
|
PopupVisible = false;
|
|
}
|
|
|
|
void SelectDriverPopupClosed()
|
|
{
|
|
//cancel clicked
|
|
}
|
|
|
|
void SelectDriverPopupClosing(PopupClosingEventArgs args)
|
|
{
|
|
//myModel = new TransferWizardModel();
|
|
|
|
}
|
|
|
|
public Task SubmitForm(object result)
|
|
{
|
|
_logger.Info($"Submitted nested form: {result.GetType().FullName}");
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task ShowPopup(UserProductMapping emptyProductMapping)
|
|
{
|
|
_tempProductMapping = emptyProductMapping;
|
|
PopupVisible = true;
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
private async Task OnUserSelected(Guid userId)
|
|
{
|
|
// Logic after the user is selected
|
|
await Task.Run(() => Console.WriteLine($"Selected User ID: {userId}"));
|
|
}
|
|
|
|
private async Task OnRowClick(GridRowClickEventArgs e)
|
|
{
|
|
await SelectUser((Guid)e.Grid.GetRowValue(e.VisibleIndex, "Id"));
|
|
}
|
|
|
|
private async Task SelectUser(Guid id)
|
|
{
|
|
PopupVisible = false;
|
|
_tempProductMapping.UserId = id;
|
|
|
|
await OnUserSelected(id);
|
|
}
|
|
|
|
void Grid_CustomizeElement(GridCustomizeElementEventArgs e)
|
|
{
|
|
if (e.ElementType == GridElementType.DataRow && (int)e.Grid.GetRowValue(e.VisibleIndex, "Permissions") == 1)
|
|
{
|
|
e.Style = "display: none";
|
|
}
|
|
// else if (e.ElementType == GridElementType.HeaderCell)
|
|
// {
|
|
// e.Style = "background-color: rgba(0, 0, 0, 0.08); font-style=bold";
|
|
|
|
// }
|
|
}
|
|
} |