TourIAm/TIAMSharedUI/Pages/User/SysAdmins/LogViewerGridComponent.razor

224 lines
7.6 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
<LogViewerGrid Logger="_logger"
@ref="_logViewerGrid"
ContextIds="new [] {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="Permissions" />
</Columns>
<DetailRowTemplate>
@{
<DxTabs>
<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="Permissions" ColSpanMd="4">
@UserEditFormContext.GetEditor("Permissions")
</DxFormLayoutItem>
</DxFormLayout>
</EditFormTemplate>
</LogViewerGrid>
@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 LogViewerGrid _logViewerGrid;
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 OnInitialized()
{
_logger = new LoggerClient<UserProductMappingGridComponent>(LogWriters.ToArray());
base.OnInitialized();
}
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";
// }
}
}