From 5fcab23479d5f9de75eca7bd72fb8450d98a627e Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 30 Jun 2024 14:44:00 +0200 Subject: [PATCH] bleh...miac... logger api --- TIAM.Database/DataLayers/Admins/AdminDal.cs | 7 + .../DbContexts/Admins/AdminDbContext.cs | 4 +- .../Pages/User/SysAdmins/LogViewer.razor | 75 ++++++ .../SysAdmins/LogViewerGridComponent.razor | 224 ++++++++++++++++++ .../Shared/Components/Grids/LogViewerGrid.cs | 33 +++ .../Shared/Components/Grids/TiamGrid.cs | 2 +- .../Server/Controllers/LoggerApiController.cs | 22 +- TIAMWebApp/Shared/Models/APIUrls.cs | 7 +- .../ClientSide/UI/LogitemViewerModel.cs | 28 +++ 9 files changed, 396 insertions(+), 6 deletions(-) create mode 100644 TIAMSharedUI/Pages/User/SysAdmins/LogViewer.razor create mode 100644 TIAMSharedUI/Pages/User/SysAdmins/LogViewerGridComponent.razor create mode 100644 TIAMSharedUI/Shared/Components/Grids/LogViewerGrid.cs create mode 100644 TIAMWebApp/Shared/Models/ClientSide/UI/LogitemViewerModel.cs diff --git a/TIAM.Database/DataLayers/Admins/AdminDal.cs b/TIAM.Database/DataLayers/Admins/AdminDal.cs index 7cf55d5b..592fefad 100644 --- a/TIAM.Database/DataLayers/Admins/AdminDal.cs +++ b/TIAM.Database/DataLayers/Admins/AdminDal.cs @@ -28,6 +28,7 @@ using DevExpress.Data.Filtering; using DevExpress.Data.Linq; using DevExpress.Data.Linq.Helpers; using TIAM.Database.DbSets.Drivers; +using AyCode.Entities.Server.LogItems; namespace TIAM.Database.DataLayers.Admins { @@ -627,5 +628,11 @@ namespace TIAM.Database.DataLayers.Admins #endregion + #region Logs + + public Task> GetLogItemsAsync() => SessionAsync(ctx => ctx.LogItems.ToList()); + + #endregion + } } diff --git a/TIAM.Database/DbContexts/Admins/AdminDbContext.cs b/TIAM.Database/DbContexts/Admins/AdminDbContext.cs index a5579c78..f386f33e 100644 --- a/TIAM.Database/DbContexts/Admins/AdminDbContext.cs +++ b/TIAM.Database/DbContexts/Admins/AdminDbContext.cs @@ -1,4 +1,5 @@ -using Microsoft.EntityFrameworkCore; +using AyCode.Entities.Server.LogItems; +using Microsoft.EntityFrameworkCore; using TIAM.Database.ModelBuilders.Companies; using TIAM.Database.ModelBuilders.Emails; using TIAM.Database.ModelBuilders.Products; @@ -18,6 +19,7 @@ namespace TIAM.Database.DbContexts.Admins { public class AdminDbContext : DbContextBase, IAdminDbContext { + public DbSet LogItems { get; set; } public DbSet Users { get; set; } public DbSet Profiles { get; set; } public DbSet Companies { get; set; } diff --git a/TIAMSharedUI/Pages/User/SysAdmins/LogViewer.razor b/TIAMSharedUI/Pages/User/SysAdmins/LogViewer.razor new file mode 100644 index 00000000..ec993678 --- /dev/null +++ b/TIAMSharedUI/Pages/User/SysAdmins/LogViewer.razor @@ -0,0 +1,75 @@ +@page "/sysadmin/logs" +@using BlazorAnimation +@using TIAM.Entities.Users +@using TIAM.Models.Dtos.Users +@using TIAM.Resources +@using TIAM.Services +@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 +@using TIAM.Core.Consts +@layout AdminLayout +@inject IEnumerable LogWriters +@inject IStringLocalizer Localizer +@inject ISessionService SessionService + +User permissions + +
+

Drivers

+

Manage drivers here!

+
+ + +
+
+
+ +
+
+
+ +
+ + + +
+ +
+
+
+ +
+
+ +
+
+ +@code { + private LoggerClient _logger; + //public UserModelDtoDetail UserModelDtoDetail = new(); + + + IGrid Grid { get; set; } + //object? MasterGridData { get; set; } + + protected override async Task OnInitializedAsync() + { + _logger = new LoggerClient(LogWriters.ToArray()); + + base.OnInitialized(); + } + + void ColumnChooserButton_Click() + { + Grid.ShowColumnChooser(); + } + +} diff --git a/TIAMSharedUI/Pages/User/SysAdmins/LogViewerGridComponent.razor b/TIAMSharedUI/Pages/User/SysAdmins/LogViewerGridComponent.razor new file mode 100644 index 00000000..480df5dc --- /dev/null +++ b/TIAMSharedUI/Pages/User/SysAdmins/LogViewerGridComponent.razor @@ -0,0 +1,224 @@ +@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 LogWriters +@inject AdminSignalRClient AdminSignalRClient +@inject IWizardProcessor WizardProcessor +@inject IUserDataService UserDataService + + + + + + + @{ + var userEmailFieldName = $"{nameof(UserProductMapping.User)}.{nameof(User.EmailAddress)}"; + } + + + @{ + var productNameFieldName = $"{nameof(UserProductMapping.Product)}.{nameof(Product.Name)}"; + } + + + + + @{ + + + + + + + + + + } + + + + + + @{ + var transfer2 = (UserProductMapping)UserEditFormContext.EditModel; + } + + + + @transfer2.UserId + @{ + var a = UserEditFormContext.GetEditor("UserId"); + } + @* Select user *@ + Select user + + + + @UserEditFormContext.GetEditor("Permissions") + + + + + + + + + +@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 _logger; + + private LogViewerGrid _logViewerGrid; + + private UserProductMapping _tempProductMapping; + + bool PopupVisible { get; set; } + private DxMaskedInput _emailInput; + private DxButton _button1; + private ElementReference _errorMessage; + private string _errorCss = "display: none;"; + private List FoundUsers { get; set; } = new List(); + + + 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(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"; + + // } + } +} \ No newline at end of file diff --git a/TIAMSharedUI/Shared/Components/Grids/LogViewerGrid.cs b/TIAMSharedUI/Shared/Components/Grids/LogViewerGrid.cs new file mode 100644 index 00000000..56bbd26e --- /dev/null +++ b/TIAMSharedUI/Shared/Components/Grids/LogViewerGrid.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Components; +using AyCode.Entities.LogItems; +using TIAM.Entities.Users; +using TIAM.Services; +using TIAM.Entities.Transfers; +using TIAMWebApp.Shared.Application.Models.ClientSide.UI; + +namespace TIAMSharedUI.Shared.Components.Grids; + +public class LogViewerGrid : TiamGrid +{ + public LogViewerGrid() : 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); + } +} \ No newline at end of file diff --git a/TIAMSharedUI/Shared/Components/Grids/TiamGrid.cs b/TIAMSharedUI/Shared/Components/Grids/TiamGrid.cs index b504101d..a57ee379 100644 --- a/TIAMSharedUI/Shared/Components/Grids/TiamGrid.cs +++ b/TIAMSharedUI/Shared/Components/Grids/TiamGrid.cs @@ -18,7 +18,7 @@ using TIAMWebApp.Shared.Application.Utility; namespace TIAMSharedUI.Shared.Components.Grids { - public class TiamGrid : DxGrid where TDataItem : class, IId + public class TiamGrid : DxGrid where TDataItem : class, IId { protected bool IsFirstInitializeParameters; private SignalRDataSource _dataSource = null!; diff --git a/TIAMWebApp/Server/Controllers/LoggerApiController.cs b/TIAMWebApp/Server/Controllers/LoggerApiController.cs index f39eb6f2..8f801cf4 100644 --- a/TIAMWebApp/Server/Controllers/LoggerApiController.cs +++ b/TIAMWebApp/Server/Controllers/LoggerApiController.cs @@ -3,8 +3,10 @@ using AyCode.Entities.Server.LogItems; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Mvc; +using TIAM.Database.DataLayers.Admins; using TIAMWebApp.Server.Services; using TIAMWebApp.Shared.Application.Models; +using TIAMWebApp.Shared.Application.Models.ClientSide.UI; namespace TIAMWebApp.Server.Controllers { @@ -12,13 +14,14 @@ namespace TIAMWebApp.Server.Controllers [ApiController] [EnableCors("_myAllowSpecificOrigins")] [Route("api/v1/[controller]")] - public class LoggerApiController(LoggerToLoggerApiController logger) : ControllerBase + public class LoggerApiController(LoggerToLoggerApiController logger, AdminDal _adminDal) : ControllerBase { + // = new TIAM.Core.Loggers.Logger(); [AllowAnonymous] [HttpPost] - [Route(APIUrls.LoggerRouteName)] + [Route(APIUrls.AddLogItemRouteName)] public async Task AddLogItem(AcLogItem? logItem) { try @@ -44,5 +47,20 @@ namespace TIAMWebApp.Server.Controllers Console.WriteLine($@"ERROR!!! {nameof(LoggerApiController)}->AddLogItem; ex: {ex.Message}{AcEnv.NL}{AcEnv.NL}{ex}"); } } + + [AllowAnonymous] + [HttpGet] + [Route(APIUrls.GetAllLogItemsRouteName)] + public async Task> GetAllLogItems() + { + var result = await _adminDal.GetLogItemsAsync(); + List returnList = new List(); + foreach (var item in result) + { + returnList.Add(new LogitemViewerModel(Guid.NewGuid(), item, item.LogHeaderId)); + } + return returnList; + } + } } \ No newline at end of file diff --git a/TIAMWebApp/Shared/Models/APIUrls.cs b/TIAMWebApp/Shared/Models/APIUrls.cs index bf8d9a31..ef09de07 100644 --- a/TIAMWebApp/Shared/Models/APIUrls.cs +++ b/TIAMWebApp/Shared/Models/APIUrls.cs @@ -20,8 +20,11 @@ namespace TIAMWebApp.Shared.Application.Models public const string MessageAPI = BaseUrlWithSlashAndVersion + "MessageAPI/"; public const string PaymentAPI = BaseUrlWithSlashAndVersion + "PaymentAPI/"; - public const string LoggerRouteName = "Logger"; - public const string Logger = LoggerApi + LoggerRouteName; + public const string AddLogItemRouteName = "AddLogItem"; + public const string AddLogItem = LoggerApi + AddLogItemRouteName; + + public const string GetAllLogItemsRouteName = "GetAllLogItems"; + public const string GetAllLogItems = LoggerApi + GetAllLogItemsRouteName; //userdata public const string UserTestRouteName = "test1"; diff --git a/TIAMWebApp/Shared/Models/ClientSide/UI/LogitemViewerModel.cs b/TIAMWebApp/Shared/Models/ClientSide/UI/LogitemViewerModel.cs new file mode 100644 index 00000000..b17bb238 --- /dev/null +++ b/TIAMWebApp/Shared/Models/ClientSide/UI/LogitemViewerModel.cs @@ -0,0 +1,28 @@ +using AyCode.Core.Interfaces; +using AyCode.Entities.LogItems; +using AyCode.Interfaces.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TIAMWebApp.Shared.Application.Models.ClientSide.UI +{ + public class LogitemViewerModel : IId + { + public AcLogItemClient AcLogItemClient { get; set; } + + public int LogHeaderId { get; set; } + public Guid Id { get ; set; } + + public LogitemViewerModel(Guid id, AcLogItemClient logItemClient, int logHeaderID) { + + Id = id; + AcLogItemClient = logItemClient; + LogHeaderId = logHeaderID; + + } + + } +}