297 lines
9.7 KiB
Plaintext
297 lines
9.7 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
|
|
@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" />
|
|
</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="ContextIds"
|
|
GetAllMessageTag="GetAllTag"
|
|
SignalRClient="AdminSignalRClient"
|
|
PageSize="10"
|
|
AutoExpandAllGroupRows="true"
|
|
KeyboardNavigationEnabled="KeyboardNavigationEnabled"
|
|
KeyFieldName="Id"
|
|
ValidationEnabled="false"
|
|
CustomizeElement="Grid_CustomizeElement"
|
|
CustomizeEditModel="CustomizeEditModel"
|
|
EditMode="GridEditMode.EditForm"
|
|
ColumnResizeMode="GridColumnResizeMode.NextColumn"
|
|
ShowFilterRow="true">
|
|
<Columns>
|
|
<DxGridCommandColumn NewButtonVisible="true" Width="8%" FixedPosition="GridColumnFixedPosition.Left" />
|
|
<DxGridDataColumn FieldName="Id" ShowInColumnChooser="AcDomain.IsDeveloperVersion" Visible="AcDomain.IsDeveloperVersion" />
|
|
<DxGridDataColumn FieldName="UserId" />
|
|
<DxGridDataColumn FieldName="ProductId" Width="40%" />
|
|
<DxGridDataColumn FieldName="Permissions" />
|
|
</Columns>
|
|
<DetailRowTemplate>
|
|
@{
|
|
if (ShowNestedRows)
|
|
{
|
|
<DxTabs>
|
|
|
|
<DxTabPage Text="Products">
|
|
<ProductDetailGridComponent GetAllTag="SignalRTags.GetProductsById" ContextId="((UserProductMapping)context.DataItem).ProductId" KeyboardNavigationEnabled="true" />
|
|
</DxTabPage>
|
|
<DxTabPage Text="Cars">
|
|
<CarDetailGridComponent GetAllTag="SignalRTags.GetCarsForUserProductMapping" ContextId="((UserProductMapping)context.DataItem).Id" KeyboardNavigationEnabled="true" />
|
|
</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="Permissions" ColSpanMd="4">
|
|
@UserEditFormContext.GetEditor("Permissions")
|
|
</DxFormLayoutItem>
|
|
|
|
|
|
|
|
</DxFormLayout>
|
|
</EditFormTemplate>
|
|
|
|
</UserProductMappingDriverGrid>
|
|
|
|
@code {
|
|
[Parameter]
|
|
public bool KeyboardNavigationEnabled { get; set; }
|
|
|
|
[Parameter] public IProductRelation ParentData { get; set; } = null!;
|
|
|
|
[Parameter] public int GetAllTag { get; set; } = SignalRTags.GetAllUserProductMappings;
|
|
|
|
[Parameter] public bool ShowNestedRows { get; set; } = false;
|
|
|
|
[Parameter] public Guid? ContextId { get; set; }
|
|
|
|
private Guid[] ContextIds = new Guid[0];
|
|
|
|
private LoggerClient<UserProductMappingGridComponent> _logger;
|
|
|
|
List<Product> _availableProducts;
|
|
|
|
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 string Email { get; set; } = "email@email.com";
|
|
string EmailMask { get; set; } = @"(\w|[.-])+@(\w|-)+\.(\w|-){2,4}";
|
|
UserModelDto ChosenUser = null;
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
if (ContextId != null)
|
|
{
|
|
ContextIds = new Guid[1];
|
|
ContextIds[0] = (Guid)ContextId;
|
|
}
|
|
base.OnParametersSet();
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
_logger = new LoggerClient<UserProductMappingGridComponent>(LogWriters.ToArray());
|
|
|
|
|
|
//_logger.Info($"DetailGridData: {_detailGridData.Count}");
|
|
}
|
|
|
|
void CustomizeEditModel(GridCustomizeEditModelEventArgs e)
|
|
{
|
|
if (!e.IsNew) return;
|
|
UserProductMapping newUPM = (UserProductMapping)e.EditModel;
|
|
newUPM.ProductId = (Guid)ContextId!;
|
|
var newProductMapping = new UserProductMapping
|
|
{
|
|
Id = Guid.NewGuid(),
|
|
ProductId = (Guid)ContextId,
|
|
Permissions = 2
|
|
};
|
|
|
|
//e.EditModel = newProductMapping;
|
|
}
|
|
|
|
|
|
async Task EditModelSaving(GridEditModelSavingEventArgs e)
|
|
{
|
|
if (e.IsNew)
|
|
|
|
_logger.Info("New orderData added");
|
|
else
|
|
_logger.Info("orderData updated");
|
|
|
|
await UpdateDataAsync();
|
|
}
|
|
|
|
async Task DataItemDeleting(GridDataItemDeletingEventArgs e)
|
|
{
|
|
|
|
_logger.Info("orderData deleted");
|
|
|
|
}
|
|
|
|
async Task UpdateDataAsync()
|
|
{
|
|
//refresh grid
|
|
_logger.Info("orderData grid refreshed");
|
|
}
|
|
|
|
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 async Task SubmitForm(object result)
|
|
{
|
|
|
|
|
|
_logger.Info($"Submitted nested form: {result.GetType().FullName}");
|
|
}
|
|
|
|
public async Task ShowPopup(UserProductMapping emptyProductMapping)
|
|
{
|
|
tempProductMapping = emptyProductMapping;
|
|
PopupVisible = true;
|
|
}
|
|
|
|
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";
|
|
|
|
// }
|
|
}
|
|
|
|
|
|
|
|
} |