userproductmapping

This commit is contained in:
Adam 2024-06-22 17:42:48 +02:00
parent 49635226c5
commit d161abcb73
20 changed files with 789 additions and 133 deletions

View File

@ -127,6 +127,7 @@ namespace TIAM.Database.DataLayers.Admins
public Task<bool> RemoveProductAsync(Product product) => TransactionAsync(ctx => ctx.RemoveProduct(product));
public UserProductMapping? GetUserProductMappingById(Guid userProductMappingId, bool autoInclude = true) => Session(ctx => ctx.GetUserProductMappingById(userProductMappingId, autoInclude));
public List<UserProductMapping>? GetAllUserProductMappings(bool autoInclude = true) => Session(ctx => ctx.UserProductMappings).ToList();
public Task<UserProductMapping?> GetUserProductMappingByIdAsync(Guid userProductMappingId, bool autoInclude = true) => SessionAsync(ctx => ctx.GetUserProductMappingById(userProductMappingId, autoInclude));
public List<PermissionContextMapping> GetPermissionContextsView(Guid subjectId, Guid contextId)

View File

@ -46,9 +46,12 @@ public class SignalRTags : AcSignalRTags
//public const int AddAddress = 39;
//public const int RemoveAddress = 40;
public const int CreateUserProductMapping = 47;
public const int UpdateUserProductMapping = 48;
public const int DeleteUserProductMapping = 49; //set permissions to 0
public const int CreateUserProductMapping = 40;
public const int UpdateUserProductMapping = 41;
public const int DeleteUserProductMapping = 42; //set permissions to 0
public const int GetAllUserProductMappings = 43;
public const int GetUserProductMappingsByProductId = 44;
public const int GetUserProductMappingsByUserId = 45;
public const int GetCarsForUserProductMapping = 50;
public const int CreateCar = 51;
@ -64,4 +67,5 @@ public class SignalRTags : AcSignalRTags
public const int UpdateProduct = 73;
public const int AddProduct = 74;
public const int RemoveProduct = 75;
public const int GetProductsById = 76;
}

View File

@ -26,91 +26,78 @@
<div class="container">
<div class="w-100 ch-220">
<CompanyGrid @ref="_gridCompany"
ContextId="@CompanyId"
Logger="_logger"
SignalRClient="AdminSignalRClient"
<CompanyByIdDetailGrid @ref="_gridCompany"
Context="myContext"
ContextIds="@CompanyId"
Logger="_logger"
SignalRClient="AdminSignalRClient"
AutoCollapseDetailRow="false"
KeyboardNavigationEnabled="true"
CustomizeElement="Grid_CustomizeElement"
CustomizeEditModel="Grid_CustomizeEditModel"
EditMode="GridEditMode.EditForm"
ColumnResizeMode="GridColumnResizeMode.NextColumn"
ShowFilterRow="true"
KeyFieldName="Id">
AutoCollapseDetailRow="false"
KeyboardNavigationEnabled="true"
CustomizeElement="Grid_CustomizeElement"
CustomizeEditModel="Grid_CustomizeEditModel"
EditMode="GridEditMode.EditForm"
ColumnResizeMode="GridColumnResizeMode.NextColumn"
ShowFilterRow="true"
KeyFieldName="Id">
<Columns>
<DxGridCommandColumn Width="135" MinWidth="135" FixedPosition="GridColumnFixedPosition.Left" />
<DxGridDataColumn FieldName="Id" SortIndex="0" ShowInColumnChooser="AcDomain.IsDeveloperVersion" Visible="AcDomain.IsDeveloperVersion" DisplayFormat="N" />
<DxGridDataColumn FieldName="Name" />
<Columns>
<DxGridCommandColumn Width="135" MinWidth="135" FixedPosition="GridColumnFixedPosition.Left" />
<DxGridDataColumn FieldName="Id" SortIndex="0" ShowInColumnChooser="AcDomain.IsDeveloperVersion" Visible="AcDomain.IsDeveloperVersion" DisplayFormat="N" />
<DxGridDataColumn FieldName="Name" />
<DxGridDataColumn FieldName="AffiliateId" DisplayFormat="N" />
<DxGridDataColumn FieldName="CommissionPercent" />
<DxGridDataColumn FieldName="Created" DisplayFormat="g" Width="140" />
<DxGridDataColumn FieldName="Modified" DisplayFormat="g" Width="140" />
@* <DxGridDataColumn FieldName="ContactEmail">
<DxGridDataColumn FieldName="AffiliateId" DisplayFormat="N" />
<DxGridDataColumn FieldName="CommissionPercent" />
<DxGridDataColumn FieldName="Created" DisplayFormat="g" Width="140" />
<DxGridDataColumn FieldName="Modified" DisplayFormat="g" Width="140" />
@* <DxGridDataColumn FieldName="ContactEmail">
</DxGridDataColumn> *@
</Columns>
@* <DetailRowTemplate>
<CompaniesNestedUserProductMapping CurrentCompany="(TIAM.Entities.ServiceProviders.Company)context.DataItem" KeyboardNavigationEnabled="true" />
</DetailRowTemplate> *@
<DetailRowTemplate>
<DxTabs>
<DxTabPage Text="Profile">
<ProfileGridComponent ParentData="((Company)myContext.DataItem)" KeyboardNavigationEnabled="true" />
</DxTabPage>
<DxTabPage Text="Products">
<ProductDetailGridComponent ParentData="((Company)myContext.DataItem)" KeyboardNavigationEnabled="true" />
</DxTabPage>
<DxTabPage Text="Address">
<AddressDetailGridComponent ParentData="((Company)myContext.DataItem).Profile" KeyboardNavigationEnabled="true" />
</DxTabPage>
</DxTabs>
</DetailRowTemplate>
<EditFormTemplate Context="EditFormContext">
@{
var transfer2 = (Company)EditFormContext.EditModel;
}
<DxFormLayout CssClass="w-100">
<DxFormLayoutItem Caption=@localizer.GetString(ResourceKeys.LastName) ColSpanMd="6" ColSpanLg="6" ColSpanSm="12">
@EditFormContext.GetEditor("Name")
</DxFormLayoutItem>
<DxFormLayoutItem Caption=@localizer.GetString(ResourceKeys.LastName) ColSpanMd="6" ColSpanLg="6" ColSpanSm="12">
@EditFormContext.GetEditor("CommissionPercent")
</DxFormLayoutItem>
</DxFormLayout>
</EditFormTemplate>
</CompanyByIdDetailGrid>
</DxGridDataColumn> *@
</Columns>
@* <DetailRowTemplate>
<CompaniesNestedUserProductMapping CurrentCompany="(TIAM.Entities.ServiceProviders.Company)context.DataItem" KeyboardNavigationEnabled="true" />
</DetailRowTemplate> *@
<DetailRowTemplate>
<DxTabs>
<DxTabPage Text="Profile">
<ProfileGridComponent ParentData="((Company)context.DataItem)" KeyboardNavigationEnabled="true" />
</DxTabPage>
<DxTabPage Text="Products">
<ProductDetailGridComponent ContextId="((Company)context.DataItem).Id" KeyboardNavigationEnabled="true" />
</DxTabPage>
<DxTabPage Text="Address">
<AddressDetailGridComponent ParentData="((Company)context.DataItem).Profile" KeyboardNavigationEnabled="true" />
</DxTabPage>
</DxTabs>
</DetailRowTemplate>
<EditFormTemplate Context="EditFormContext">
@{
var transfer2 = (Company)EditFormContext.EditModel;
}
<DxFormLayout CssClass="w-100">
<DxFormLayoutItem Caption=@localizer.GetString(ResourceKeys.LastName) ColSpanMd="6" ColSpanLg="6" ColSpanSm="12">
@EditFormContext.GetEditor("Name")
</DxFormLayoutItem>
<DxFormLayoutItem Caption=@localizer.GetString(ResourceKeys.LastName) ColSpanMd="6" ColSpanLg="6" ColSpanSm="12">
@EditFormContext.GetEditor("CommissionPercent")
</DxFormLayoutItem>
</DxFormLayout>
</EditFormTemplate>
</CompanyGrid>
<DxTabs>
@* <DxTabPage Text="Profile">
<ProfileComponent></ProfileComponent>
</DxTabPage> *@
@* <DxTabPage Text="Profile 2">
<ProfileGridComponent ProfileId="((Company)context.DataItem).ProfileId" KeyboardNavigationEnabled="true" />
</DxTabPage> *@
<DxTabPage Text="Products">
<ProductDetailGridComponent ContextId="@CompanyId" KeyboardNavigationEnabled="true" />
</DxTabPage>
@* <DxTabPage Text="Address">
<AddressDetailGridComponent ParentData="((Company)context.DataItem).Profile" KeyboardNavigationEnabled="true" />
</DxTabPage> *@
</DxTabs>
</div>
</div>
@code {
[Parameter]
public string Id { get; set; }
private Guid CompanyId;
private Guid[] CompanyId = new Guid[1];
private CompanyGrid _gridCompany;
private CompanyByIdDetailGrid _gridCompany;
public string ProfileUrl => $"/images/serviceprovider/{Id}.png";
@ -130,7 +117,7 @@
}
else
{
CompanyId = Guid.Parse(Id);
CompanyId[0] = Guid.Parse(Id);
}
base.OnParametersSet();
}

View File

@ -132,7 +132,7 @@
<ProfileGridComponent ParentData="((Company)context.DataItem)" KeyboardNavigationEnabled="true" />
</DxTabPage>
<DxTabPage Text="Products">
<ProductDetailGridComponent @ref="_productDetailGridComponent" OnGridEditModelSaving="OnProductGridItemSaving" ParentData="(Company)context.DataItem" KeyboardNavigationEnabled="true" />
<ProductDetailGridComponent @ref="_productDetailGridComponent" OnGridEditModelSaving="OnProductGridItemSaving" ContextId="((Company)context.DataItem).Id" ParentData="(Company)context.DataItem" KeyboardNavigationEnabled="true" />
</DxTabPage>
<DxTabPage Text="Address">
<AddressDetailGridComponent ParentData="((Company)context.DataItem).Profile" KeyboardNavigationEnabled="true" />

View File

@ -0,0 +1,185 @@
@page "/user/userproductmappings"
@using BlazorAnimation
@using TIAM.Models.Dtos.Users
@using TIAM.Resources
@using TIAMSharedUI.Pages.Components
@using TIAMSharedUI.Shared
@using TIAMWebApp.Shared.Application.Interfaces
@using TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels
@using TIAMWebApp.Shared.Application.Models.PageModels
@using TIAMWebApp.Shared.Application.Utility
@using AyCode.Services.Loggers
@layout AdminLayout
@inject IEnumerable<IAcLogWriterClientBase> LogWriters
@inject IStringLocalizer<TIAMResources> Localizer
@inject ISessionService SessionService
@inject IWizardProcessor WizardProcessor
@inject IUserDataService UserDataService
<PageTitle>User permissions</PageTitle>
<div class="text-center m-5">
<h1>User permissions</h1>
<h2 style="font-size:small">Manage transfers here!</h2>
</div>
<div class="container">
<div class="row">
<div class=" col-12">
<Animation Effect="@Effect.FadeInUp" Class="glass" Speed="@Speed.Fast" Delay="@TimeSpan.FromMilliseconds(250)">
<div class="card">
<div class="d-flex flex-column mb-4 pb-2">
<div class="align-self-end pl-2 pb-2">
<DxButton Text="Column Chooser"
RenderStyle="ButtonRenderStyle.Secondary"
IconCssClass="btn-column-chooser"
Click="ColumnChooserButton_Click" />
</div>
<UserProductMappingGridComponent></UserProductMappingGridComponent>
</div>
</div>
</Animation>
</div>
<div class=" col-12 col-xl-6">
</div>
</div>
</div>
@code {
private LoggerClient<ManageUserProductMappings> _logger;
//public UserModelDtoDetail UserModelDtoDetail = new();
bool PopupVisible { get; set; }
IGrid Grid { get; set; }
//object? MasterGridData { get; set; }
bool AutoCollapseDetailRow { get; set; }
public List<string> IgnoreList =
[
"ReceiverEmailAddress",
"ReceiverId",
"SenderEmailAddress",
"SenderId",
"ContextId"
];
void Grid_CustomizeElement(GridCustomizeElementEventArgs e)
{
if (e.ElementType == GridElementType.DataRow && e.VisibleIndex % 2 == 1)
{
e.CssClass = "bg-alt";
}
else if (e.ElementType == GridElementType.HeaderCell)
{
e.Style = "background-color: rgba(0, 0, 0, 0.08); font-style=bold";
}
}
void Grid_CustomizeEditModel(GridCustomizeEditModelEventArgs e)
{
if (!e.IsNew) return;
var userEditModel = (UserModelDtoDetail)e.EditModel; //TODO not valid cast
userEditModel.Id = Guid.NewGuid();
userEditModel.UserDto = new UserDtoDetail
{
AffiliateId = Guid.NewGuid(),
EmailAddress = "",
PhoneNumber = ""
};
userEditModel.ProfileDto = new TIAM.Entities.Profiles.Profile
{
Name = "New user"
};
userEditModel.Products = [];
userEditModel.ServiceProviders = [];
userEditModel.UserProductMappings = [];
}
async Task Grid_EditModelSaving(GridEditModelSavingEventArgs e)
{
var userModelDtoDetail = ((UserModelDtoDetail)e.EditModel);
if (e.IsNew)
{
//add new orderData to orderData array
var registration = new RegistrationModel();
//TODO: Refractor to userDataService
var random = new Random();
const string chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
var password = new string(Enumerable.Repeat(chars, 10)
.Select(s => s[random.Next(s.Length)]).ToArray());
registration.Email = userModelDtoDetail.UserDto.EmailAddress;
registration.PhoneNumber = userModelDtoDetail.UserDto.PhoneNumber;
registration.Password = password;
registration.ReferralId = null;
await UserDataService.CreateGuestUser(registration);
_logger.Info("New user created added");
}
else
{
_logger.Info("orderData updated at id " + userModelDtoDetail.Id);
//await transferDataService.UpdateTransferAsync((TransferWizardModel)e.EditModel);
//modify transferData where transferData.Id == e.EditModel.Id
}
//get transfer from TransferData by Id
// foreach (var transferToModify in (List<Transfer>)TransferData)
// {
// myModel = (Transfer)e.EditModel;
// if (transferToModify.Id == myModel.Id)
// {
// //transferToModify.Driver = myModel.Driver;
// }
// }
//TODO: ne a teljes grid-et refresh-eljük, elég lenne csak az adott sort! - J.
await UpdateDataAsync();
}
async Task Grid_DataItemDeleting(GridDataItemDeletingEventArgs e)
{
//await NwindDataService.RemoveEmployeeAsync((EditableEmployee)e.DataItem);
//remove orderData from orderData array
_logger.Info("orderData deleted");
//await UpdateDataAsync();
}
async Task UpdateDataAsync()
{
//refresh grid
_logger.Info("orderData grid refreshed");
}
protected override async Task OnInitializedAsync()
{
_logger = new LoggerClient<ManageUserProductMappings>(LogWriters.ToArray());
base.OnInitialized();
}
void ColumnChooserButton_Click()
{
Grid.ShowColumnChooser();
}
}

View File

@ -15,7 +15,7 @@
@inject ISessionService SessionService
@inject IWizardProcessor WizardProcessor
@inject IUserDataService UserDataService
<PageTitle>Transfers</PageTitle>
<PageTitle>Users</PageTitle>
<div class="text-center m-5">
<h1>User management</h1>
@ -82,17 +82,18 @@
<DxGridDataColumn Name="@Localizer.GetString("Created")" FieldName="UserDto.Created" />
<DxGridDataColumn Name="@Localizer.GetString("EmailConfirmed")" FieldName="UserDto.EmailConfirmed" />
<DxGridDataColumn FieldName="UserDto.RefferalId" />
<DxGridDataColumn FieldName="UserDto.EmailAddress">
<DxGridDataColumn Width="240px" FieldName="UserDto.EmailAddress"/>
<DxGridDataColumn Width="110px" FieldName="UserDto.EmailAddress">
<CellDisplayTemplate>
@{
var keyField = context.Value;
var keyItem = (UserModelDtoDetail)context.DataItem;
var buttonText = "Contact";
<p>@keyField </p><DxButton Click="() => SendMail(keyItem)" Text="@buttonText" RenderStyle="ButtonRenderStyle.Primary" />
var keyItem = (UserModelDtoDetail)context.DataItem;
var buttonText = "Contact";
<DxButton Click="() => SendMail(keyItem)" IconCssClass="btn-icon-envelope" Text="@buttonText" RenderStyle="ButtonRenderStyle.Primary" />
}
</CellDisplayTemplate>
</DxGridDataColumn>
</DxGridDataColumn>
</Columns>
<DetailRowTemplate>
<DxTabs>

View File

@ -0,0 +1,193 @@
@using TIAM.Entities.Products
@using TIAM.Entities.ServiceProviders
@using TIAM.Entities.Transfers
@using TIAM.Entities.Drivers
@using TIAM.Entities.Users
@using TIAM.Models.Dtos.Users
@using TIAM.Resources
@using TIAMWebApp.Shared.Application.Interfaces
@using TIAMWebApp.Shared.Application.Utility
@using AyCode.Services.Loggers
@using TIAM.Core.Loggers
@using Address = TIAM.Entities.Addresses.Address
@using Profile = TIAM.Entities.Profiles.Profile
@using TIAMSharedUI.Shared.Components.Grids
@using TIAMSharedUI.Pages.Components.EditComponents
@using TIAMWebApp.Shared.Application.Services
@using AyCode.Interfaces.Addresses
@inject IStringLocalizer<TIAMResources> Localizer
@inject IServiceProviderDataService serviceProviderDataService
@inject IUserDataService userDataService
@inject ITransferDataService transferDataService
@inject IEnumerable<IAcLogWriterClientBase> LogWriters
@inject AdminSignalRClient AdminSignalRClient;
<ProductDetailGrid @ref="_productGrid"
DataSource = "productList"
ContextIds="new[] {(Guid)ContextId}"
Logger="_logger"
SignalRClient="AdminSignalRClient"
OnGridEditModelSaving="DataItemSaving"
OnGridItemDeleting="DataItemDeleting"
OnGridItemChanged="DataItemChanged"
PageSize="5"
AutoExpandAllGroupRows="true"
KeyboardNavigationEnabled="KeyboardNavigationEnabled"
KeyFieldName="Id"
ValidationEnabled="false"
EditMode="GridEditMode.EditForm"
ColumnResizeMode="GridColumnResizeMode.NextColumn"
ShowFilterRow="true">
<Columns>
<DxGridCommandColumn NewButtonVisible="true" Width="8%" FixedPosition="GridColumnFixedPosition.Left" />
<DxGridDataColumn FieldName="Id" GroupIndex="0" />
<DxGridDataColumn Caption=@Localizer.GetString(ResourceKeys.ProductName) FieldName="Name" />
<DxGridDataColumn Caption=@Localizer.GetString(ResourceKeys.ProductType) FieldName="ProductType" Width="140" />
<DxGridDataColumn Caption=@Localizer.GetString(ResourceKeys.Price) FieldName="Price" Width="40" />
<DxGridDataColumn FieldName="ServiceProviderId" Width="40" />
<DxGridDataColumn Caption=@Localizer.GetString(ResourceKeys.ProductDescription) FieldName="Description" Width="40" />
</Columns>
<DetailRowTemplate>
<DxTabs>
<DxTabPage Text="Profile">
<ProfileGridComponent ParentData="((Product)context.DataItem)" KeyboardNavigationEnabled="true" />
</DxTabPage>
</DxTabs>
</DetailRowTemplate>
<EditFormTemplate Context="EditFormContext">
@{
var transfer2 = (Product)EditFormContext.EditModel;
}
<DxFormLayout CssClass="w-100">
<DxFormLayoutItem Caption=@Localizer.GetString(ResourceKeys.ProductName) ColSpanMd="4">
@EditFormContext.GetEditor("Name")
</DxFormLayoutItem>
<DxFormLayoutItem Caption=@Localizer.GetString(ResourceKeys.ProductType) ColSpanMd="4">
@EditFormContext.GetEditor("ProductType")
</DxFormLayoutItem>
<DxFormLayoutItem Caption=@Localizer.GetString(ResourceKeys.Price) ColSpanMd="4">
@EditFormContext.GetEditor("Price")
</DxFormLayoutItem>
<DxFormLayoutItem Caption=@Localizer.GetString(ResourceKeys.ProductDescription) ColSpanMd="4">
@EditFormContext.GetEditor("Description")
</DxFormLayoutItem>
</DxFormLayout>
</EditFormTemplate>
</ProductDetailGrid>
@code {
[Parameter] public bool KeyboardNavigationEnabled { get; set; }
[Parameter] public Guid? ContextId { get; set; } = null;
[Parameter] public IProductsRelation ParentData { get; set; } = null!;
[Parameter] public EventCallback<GridEditModelSavingEventArgs> OnGridEditModelSaving { get; set; }
private ProductDetailGrid _productGrid;
private List<Product> productList = new List<Product>();
private LoggerClient<ProductDetailGridComponent> _logger = null!;
protected override void OnInitialized()
{
_logger = new LoggerClient<ProductDetailGridComponent>(LogWriters.ToArray());
//DataSource = new List<Address>();
}
protected override async Task OnParametersSetAsync()
{
// if (ParentData != null)
// {
// productList.AddRange(ParentData.Products);
// }
// else if (ContextId != null)
// {
// //_productGrid.ContextIds = new Guid[1];
// //_productGrid.ContextIds[0] = (Guid)ContextId;
// var data = await serviceProviderDataService.GetProductByIdAsync((Guid)ContextId);
// List<Product> result = new List<Product>();
// result.Add(data);
// _productGrid.DataSource = result;
// }
// else
base.OnParametersSet();
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
// if(firstRender)
// {
// var a = _productGrid;
// if (ParentData != null)
// {
// _productGrid.DataSource = new List<Product>();
// _productGrid.DataSource = ParentData.Products;
// }
// }
}
private void DataItemChanged(GridDataItemChangedEventArgs<Product> args)
{
_logger.Debug($"Saving: {args.DataItem.Name}, {args.DataItem.ServiceProviderId}");
//ProductGrid.SaveChangesAsync();
}
public async Task DataItemSaving(GridEditModelSavingEventArgs e)
{
await OnGridEditModelSaving.InvokeAsync(e);
if (e.Cancel) return;
var product = ((Product)e.EditModel);
if (e.IsNew)
{
_logger.Debug($"DataItemSaving");
var profileId = Guid.NewGuid();
product.Profile = new Profile(profileId, product.Name);
product.ProfileId = profileId;
var addressId = Guid.NewGuid();
product.Profile.Address = new Address(addressId);
product.Profile.AddressId = addressId;
//((Product)e.EditModel).UserProductMappings.Add(new UserProductMapping(Guid.NewGuid, ParentData.));
}
else
{
}
_logger.Debug($"Saving: {product.Name}, {product.ServiceProviderId}");
//var result = serviceProviderDataService.CreateProductAsync((Product)e.EditModel);
//_logger.Debug($"saved product: {product.ServiceProviderId}");
}
private void DataItemDeleting(GridDataItemDeletingEventArgs obj)
{
_logger.Debug($"DataItemDeleting");
}
void CustomizeEditModel(GridCustomizeEditModelEventArgs e)
{
if (!e.IsNew) return;
var newProduct = (Product)e.EditModel;
newProduct.Id = Guid.NewGuid();
newProduct.Name = "Type a name";
newProduct.ServiceProviderId = (Guid)ContextId!;
newProduct.Price = 0;
newProduct.ProductType = TIAM.Core.Enums.ProductType.Hotel;
newProduct.Description = "Type a description";
}
}

View File

@ -24,7 +24,8 @@
<ProductDetailGrid @ref="_productGrid"
DataSource="ParentData.Products"
DataSource = "productList"
ContextIds="new[] {(Guid)ContextId}"
Logger="_logger"
SignalRClient="AdminSignalRClient"
OnGridEditModelSaving="DataItemSaving"
@ -79,21 +80,59 @@
</ProductDetailGrid>
@code {
[Parameter] public bool KeyboardNavigationEnabled { get; set; }
[Parameter] public Guid? ContextId { get; set; }
[Parameter] public bool KeyboardNavigationEnabled { get; set; }
[Parameter] public Guid? ContextId { get; set; } = null;
[Parameter] public IProductsRelation ParentData { get; set; } = null!;
[Parameter] public EventCallback<GridEditModelSavingEventArgs> OnGridEditModelSaving { get; set; }
[Parameter] public int GetAllTag { get; set; }
private ProductDetailGrid _productGrid = null!;
private ProductDetailGrid _productGrid;
private List<Product> productList = new List<Product>();
private LoggerClient<ProductDetailGridComponent> _logger = null!;
protected override void OnInitialized()
{
{
_logger = new LoggerClient<ProductDetailGridComponent>(LogWriters.ToArray());
//DataSource = new List<Address>();
}
protected override async Task OnParametersSetAsync()
{
// if (ParentData != null)
// {
// productList.AddRange(ParentData.Products);
// }
// else if (ContextId != null)
// {
// //_productGrid.ContextIds = new Guid[1];
// //_productGrid.ContextIds[0] = (Guid)ContextId;
// var data = await serviceProviderDataService.GetProductByIdAsync((Guid)ContextId);
// List<Product> result = new List<Product>();
// result.Add(data);
// _productGrid.DataSource = result;
// }
// else
base.OnParametersSet();
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if(firstRender)
{
_productGrid.GetAllMessageTag = GetAllTag;
// if (ParentData != null)
// {
// _productGrid.DataSource = new List<Product>();
// _productGrid.DataSource = ParentData.Products;
// }
}
}
private void DataItemChanged(GridDataItemChangedEventArgs<Product> args)
{
_logger.Debug($"Saving: {args.DataItem.Name}, {args.DataItem.ServiceProviderId}");

View File

@ -18,7 +18,7 @@
<CompanyDetailGrid Data="_detailGridData"
Logger="_logger"
SignalRClient="AdminSignalRClient"
ContextId="ContextId"
ContextIds="ContextIds"
PageSize="5"
AutoExpandAllGroupRows="true"
KeyboardNavigationEnabled="KeyboardNavigationEnabled"
@ -39,7 +39,7 @@
<DxTabs>
<DxTabPage Text="Products">
<ProductDetailGridComponent ContextId="((Company)context.DataItem).Id" KeyboardNavigationEnabled="true" />
<ProductDetailGridComponent ParentData="(Company)context.DataItem" ContextId="((Company)context.DataItem).Id" KeyboardNavigationEnabled="true" />
</DxTabPage>
</DxTabs>
@ -71,6 +71,8 @@
[Parameter] public UserModelDtoDetail UserModelDtoDetail { get; set; }
[Parameter] public Guid? ContextId { get; set; }
public Guid[]? ContextIds = new Guid[1];
List<Company> _detailGridData;
List<Company> _availableServices;
@ -84,12 +86,18 @@
_logger = new LoggerClient<ServiceProviderGridComponent>(LogWriters.ToArray());
// ReSharper disable once NullCoalescingConditionIsAlwaysNotNullAccordingToAPIContract
_detailGridData = UserModelDtoDetail.ServiceProviders ?? [];
//_detailGridData = UserModelDtoDetail.ServiceProviders ?? [];
//_availableServices = await ServiceProviderDataService.GetServiceProvidersAsync();
//_logger.Info($"DetailGridData: {_detailGridData.Count}");
}
protected override void OnParametersSet()
{
ContextIds[0] = (Guid)ContextId!;
base.OnParametersSet();
}
// void CustomizeEditModel(GridCustomizeEditModelEventArgs e)
// {
// if (!e.IsNew) return;
@ -126,6 +134,6 @@
// {
// //refresh grid
// _logger.Info("orderData grid refreshed");
// }
// }
}

View File

@ -3,7 +3,10 @@
@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
@ -11,27 +14,37 @@
@using AyCode.Core
@inject IServiceProviderDataService ServiceProviderDataService
@inject IEnumerable<IAcLogWriterClientBase> LogWriters
@inject AdminSignalRClient AdminSignalRClient
<DxGrid Data="_detailGridData"
PageSize="5"
<UserProductMappingGrid
Logger="_logger"
SignalRClient="AdminSignalRClient"
PageSize="10"
AutoExpandAllGroupRows="true"
KeyboardNavigationEnabled="KeyboardNavigationEnabled"
KeyFieldName="Id"
ValidationEnabled="false"
CustomizeEditModel="CustomizeEditModel"
EditModelSaving="EditModelSaving"
DataItemDeleting="DataItemDeleting"
CustomizeEditModel="CustomizeEditModel"
EditMode="GridEditMode.EditForm"
ColumnResizeMode="GridColumnResizeMode.NextColumn"
ShowFilterRow="true">
<Columns>
<DxGridCommandColumn NewButtonVisible="true" Width="8%" FixedPosition="GridColumnFixedPosition.Left" />
<DxGridDataColumn FieldName="Id" GroupIndex="0" ShowInColumnChooser="AcDomain.IsDeveloperVersion" Visible="AcDomain.IsDeveloperVersion" />
<DxGridDataColumn FieldName="Id" ShowInColumnChooser="AcDomain.IsDeveloperVersion" Visible="AcDomain.IsDeveloperVersion" />
<DxGridDataColumn FieldName="UserId" />
<DxGridDataColumn FieldName="ProductId" Width="40%" />
<DxGridDataColumn FieldName="Permissions" />
</Columns>
<DetailRowTemplate>
<DxTabs>
<DxTabPage Text="Products">
<ProductDetailGridComponent @ref="bleh" ContextId="((UserProductMapping)context.DataItem).ProductId" KeyboardNavigationEnabled="true" />
</DxTabPage>
</DxTabs>
</DetailRowTemplate>
<EditFormTemplate Context="UserEditFormContext">
@{
var transfer2 = (UserProductMapping)UserEditFormContext.EditModel;
@ -52,47 +65,56 @@
</DxFormLayout>
</EditFormTemplate>
</DxGrid>
</UserProductMappingGrid>
@code {
[Parameter]
public bool KeyboardNavigationEnabled { get; set; }
[Parameter]
public UserModelDtoDetail UserModelDtoDetail { get; set; }
[Parameter] public IUserProductMappingForeignKey ParentData { get; set; } = null!;
private LoggerClient<UserProductMappingGridComponent> _logger;
List<UserProductMapping> _detailGridData;
List<Product> _availableProducts;
private ProductDetailGridComponent bleh;
protected override async Task OnInitializedAsync()
{
_logger = new LoggerClient<UserProductMappingGridComponent>(LogWriters.ToArray());
_detailGridData = UserModelDtoDetail.UserProductMappings ?? new List<UserProductMapping>();
_availableProducts = await ServiceProviderDataService.GetAllProductsAsync();
_logger.Info($"DetailGridData: {_detailGridData.Count}");
//_logger.Info($"DetailGridData: {_detailGridData.Count}");
}
void CustomizeEditModel(GridCustomizeEditModelEventArgs e)
{
if (!e.IsNew) return;
var newProductMapping = new UserProductMapping
{
ProductId = Guid.NewGuid(),
UserId = UserModelDtoDetail.Id,
Permissions = 1
};
// var newProductMapping = new UserProductMapping
// {
// ProductId = Guid.NewGuid(),
// UserId = UserModelDtoDetail.Id,
// Permissions = 1
// };
e.EditModel = newProductMapping;
//e.EditModel = newProductMapping;
}
protected override void OnAfterRender(bool firstRender)
{
if(firstRender)
{
bleh.GetAllTag = SignalRTags.GetProductsById;
}
base.OnAfterRender(firstRender);
}
async Task EditModelSaving(GridEditModelSavingEventArgs e)
{
if (e.IsNew)
//add new orderData to orderData array
_logger.Info("New orderData added");
else
_logger.Info("orderData updated");
@ -102,9 +124,9 @@
async Task DataItemDeleting(GridDataItemDeletingEventArgs e)
{
//remove orderData from orderData array
_logger.Info("orderData deleted");
//await UpdateDataAsync();
}
async Task UpdateDataAsync()

View File

@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Components;
using TIAM.Services;
namespace TIAMSharedUI.Shared.Components.Grids;
public class CompanyByIdDetailGrid : CompanyGrid
{
public CompanyByIdDetailGrid() : base()
{
GetAllMessageTag = SignalRTags.GetCompany;
AddMessageTag = SignalRTags.AddCompany;
UpdateMessageTag = SignalRTags.UpdateCompany;
RemoveMessageTag = SignalRTags.RemoveCompany;
}
protected override Task SetParametersAsyncCore(ParameterView parameters)
{
var isFirst = IsFirstInitializeParameters;
return base.SetParametersAsyncCore(parameters);
if (isFirst)
{
}
}
}

View File

@ -0,0 +1,31 @@
using Microsoft.AspNetCore.Components;
using TIAM.Entities.ServiceProviders;
using TIAM.Entities.Users;
using TIAM.Services;
namespace TIAMSharedUI.Shared.Components.Grids;
public class UserProductMappingGrid : TiamGrid<UserProductMapping>
{
public UserProductMappingGrid() : base()
{
GetAllMessageTag = SignalRTags.GetAllUserProductMappings;
AddMessageTag = SignalRTags.CreateUserProductMapping;
UpdateMessageTag = SignalRTags.UpdateUserProductMapping;
RemoveMessageTag = SignalRTags.DeleteUserProductMapping;
}
protected override Task SetParametersAsyncCore(ParameterView parameters)
{
if (!IsFirstInitializeParameters)
{
//ShowFilterRow = true;
//ShowGroupPanel = true;
//AllowSort = false;
//etc...
}
return base.SetParametersAsyncCore(parameters);
}
}

View File

@ -0,0 +1,31 @@
using Microsoft.AspNetCore.Components;
using TIAM.Entities.ServiceProviders;
using TIAM.Entities.Users;
using TIAM.Services;
namespace TIAMSharedUI.Shared.Components.Grids;
public class UserProductMappingProductDetailGrid : UserProductMappingGrid
{
public UserProductMappingProductDetailGrid() : base()
{
GetAllMessageTag = SignalRTags.GetUserProductMappingsByProductId;
AddMessageTag = SignalRTags.CreateUserProductMapping;
UpdateMessageTag = SignalRTags.UpdateUserProductMapping;
RemoveMessageTag = SignalRTags.DeleteUserProductMapping;
}
protected override Task SetParametersAsyncCore(ParameterView parameters)
{
if (!IsFirstInitializeParameters)
{
//ShowFilterRow = true;
//ShowGroupPanel = true;
//AllowSort = false;
//etc...
}
return base.SetParametersAsyncCore(parameters);
}
}

View File

@ -0,0 +1,31 @@
using Microsoft.AspNetCore.Components;
using TIAM.Entities.ServiceProviders;
using TIAM.Entities.Users;
using TIAM.Services;
namespace TIAMSharedUI.Shared.Components.Grids;
public class UserProductMappingUserDetailGrid : UserProductMappingGrid
{
public UserProductMappingUserDetailGrid() : base()
{
GetAllMessageTag = SignalRTags.GetUserProductMappingsByUserId;
AddMessageTag = SignalRTags.CreateUserProductMapping;
UpdateMessageTag = SignalRTags.UpdateUserProductMapping;
RemoveMessageTag = SignalRTags.DeleteUserProductMapping;
}
protected override Task SetParametersAsyncCore(ParameterView parameters)
{
if (!IsFirstInitializeParameters)
{
//ShowFilterRow = true;
//ShowGroupPanel = true;
//AllowSort = false;
//etc...
}
return base.SetParametersAsyncCore(parameters);
}
}

View File

@ -17,6 +17,7 @@
<DxMenuItem NavigateUrl="user/sysadmin" Text="Dashboard" />
<DxMenuItem NavigateUrl="user/transfers" Text="Transfers" />
<DxMenuItem NavigateUrl="user/companies" Text="Companies" />
<DxMenuItem NavigateUrl="user/userproductmappings" Text="Permissions" />
<DxMenuItem NavigateUrl="user/users" Text="Users" />
<DxMenuItem NavigateUrl="user/destinations" Text="Destinations" />
</Items>

View File

@ -210,8 +210,8 @@ select {
.dxbl-tabs.dxbl-tabs-top {
--dxbl-tabs-bg: #ffffff45;
background-color: #ffffff45;
box-shadow: 0 8px 32px 0 rgba( 31, 38, 135, 0.37 );
backdrop-filter: blur( 6px );
/*box-shadow: 0 8px 32px 0 rgba( 31, 38, 135, 0.37 );
backdrop-filter: blur( 6px );*/
-webkit-backdrop-filter: blur( 6px );
border-radius: 10px;
}

View File

@ -114,11 +114,13 @@ namespace TIAMWebApp.Server.Controllers
[HttpPost]
[Route(APIUrls.GetServiceProviderByIdRouteName)]
[SignalR(SignalRTags.GetCompany)]
public async Task<Company?> GetServiceProviderById([FromBody] Guid id)
public async Task<string> GetServiceProviderById([FromBody] Guid id)
{
_logger.Info($@"GetServiceProviderById called with id: {id}");
return await adminDal.GetServiceProviderByIdAsync(id);
List<Company> compList = new List<Company>();
var result = await adminDal.GetServiceProviderByIdAsync(id);
compList.Add(result);
return compList.ToJson();
}
@ -211,19 +213,50 @@ namespace TIAMWebApp.Server.Controllers
//23.
[AllowAnonymous]
[HttpPost]
[Route(APIUrls.GetUserProductMappingsForProductRouteName)]
public async Task<Dictionary<Guid, string>> GetUserProductMappingsForProduct(Guid serviceProviderId)
[Route(APIUrls.GetUserProductMappingsByProductRouteName)]
[SignalR(SignalRTags.GetUserProductMappingsByProductId)]
public async Task<string> GetUserProductMappingsForProduct(Guid productId)
{
_logger.Info($@"GetUserProductMappingsForServiceProvider called with serviceProviderId: {serviceProviderId}");
_logger.Info($@"GetUserProductMappingsByUserId called with serviceProviderId: {productId}");
var userProductMappingDictionary = new Dictionary<Guid, string>();
var userProductMappings = adminDal.GetAllUserProductMappings();
var serviceProviders = await adminDal.GetServiceProvidersAsync();
var myServiceproviders = serviceProviders.Where(x => x.Id == serviceProviderId).ToDictionary(x => x.Id, x => x.Name);
var myUserProductMappings = userProductMappings.Where(x => x.ProductId == productId).ToList();
//put serviceprovider id and name into a dictionary
return myServiceproviders;
return myUserProductMappings.ToJson();
}
[AllowAnonymous]
[HttpPost]
[Route(APIUrls.GetUserProductMappingsByUserRouteName)]
[SignalR(SignalRTags.GetUserProductMappingsByUserId)]
public async Task<string> GetUserProductMappingsByProduct(Guid userId)
{
_logger.Info($@"GetUserProductMappingsByUserId called with userId: {userId}");
var userProductMappings = adminDal.GetAllUserProductMappings();
var myUserProductMappings = userProductMappings.Where(x => x.UserId == userId).OrderBy(x => x.ProductId).ToList();
//put serviceprovider id and name into a dictionary
return myUserProductMappings.ToJson();
}
[AllowAnonymous]
[HttpPost]
[Route(APIUrls.GetAllUserProductMappingsRouteName)]
[SignalR(SignalRTags.GetAllUserProductMappings)]
public async Task<string> GetAllUserProductMappings()
{
_logger.Info($@"GetAllUserProductMappings called");
var serviceProviders = adminDal.GetAllUserProductMappings()!.OrderBy(x => x.ProductId);
//put serviceprovider id and name into a dictionary
return serviceProviders.ToJson();
}
[AllowAnonymous]
@ -419,5 +452,37 @@ namespace TIAMWebApp.Server.Controllers
}
}
[AllowAnonymous]
[HttpPost]
[Route(APIUrls.GetProductByIdRouteName)]
[Tags("In-Progress", "Product")]
[SignalR(SignalRTags.GetProductById)]
public async Task<Product> GetProductById(Guid productId)
{
_logger.Info("GetAllProducts called");
var products = adminDal.GetProductById(productId);
return products;
}
[NonAction]
[ApiExplorerSettings(IgnoreApi = true)]
[SignalR(SignalRTags.GetProductsById)]
public async Task<List<Product>> GetProductsById(Guid productId)
{
_logger.Info("GetAllProducts called");
var product = await GetProductById(productId);
var products = new List<Product>();
if (product != null) {
products.Add(product);
}
return products;
}
}
}

View File

@ -49,6 +49,7 @@ namespace TIAMWebApp.Shared.Application.Interfaces
public Task<IEnumerable<Product>> GetProductsForServiceProviderAsync(Guid serviceProviderId);
public Task<List<Product>> GetAllProductsAsync();
public Task<Product> GetProductByIdAsync(Guid id);
}
}

View File

@ -135,6 +135,12 @@ namespace TIAMWebApp.Shared.Application.Models
public const string GetAllProductsRouteName = "GetAllProducts/";
public const string GetAllProducts = ServiceProviderAPI + GetAllProductsRouteName;
public const string GetProductByIdRouteName = "GetProductById/";
public const string GetProductById = ServiceProviderAPI + GetProductByIdRouteName;
public const string GetProductsByIdRouteName = "GetProductsById/";
public const string GetProductsById = ServiceProviderAPI + GetProductsByIdRouteName;
public const string GetProductsByServiceProviderIdRouteName = "GetProductsByServiceProviderId";
public const string GetProductsByServiceProviderId = ServiceProviderAPI + GetProductsByServiceProviderIdRouteName;
@ -150,8 +156,14 @@ namespace TIAMWebApp.Shared.Application.Models
public const string GetServiceProvidersRouteName = "GetServiceProviders";
public const string GetServiceProviders = ServiceProviderAPI + GetServiceProvidersRouteName;
public const string GetUserProductMappingsForProductRouteName = "GetUserProductMappingsForProduct";
public const string GetUserProductMappingsForProduct = ServiceProviderAPI + GetUserProductMappingsForProductRouteName;
public const string GetAllUserProductMappingsRouteName = "GetAllUserProductMappings";
public const string GetAllUserProductMappings = ServiceProviderAPI + GetAllUserProductMappingsRouteName;
public const string GetUserProductMappingsByProductRouteName = "GetUserProductMappingsByProduct";
public const string GetUserProductMappingsByProduct = ServiceProviderAPI + GetUserProductMappingsByProductRouteName;
public const string GetUserProductMappingsByUserRouteName = "GetUserProductMappingsByUser";
public const string GetUserProductMappingsByUser = ServiceProviderAPI + GetUserProductMappingsByUserRouteName;
public const string GetCarsForUserProductMappingRouteName = "GetCarsForUserProductMapping";
public const string GetCarsForUserProductMapping = ServiceProviderAPI + GetCarsForUserProductMappingRouteName;

View File

@ -244,5 +244,23 @@ namespace TIAMWebApp.Shared.Application.Services
return null;
}
}
public async Task<Product> GetProductByIdAsync(Guid id)
{
var result = await _adminSignalRClient.GetByIdAsync<Product>(SignalRTags.GetProductById);
//var url = $"{Setting.ApiBaseUrl}/{APIUrls.GetProductById}";
//var response = await http.GetFromJsonAsync(url, typeof(Product));
//if (response != null)
//{
// return (Product)response;
//}
//else
//{
// return null;
//}
return result;
}
}
}