Reporting: Add UserName

This commit is contained in:
2026-02-19 16:37:45 +01:00
parent aae330f46a
commit 235ab23ed4
11 changed files with 137 additions and 101 deletions

View File

@@ -1,4 +1,5 @@
@using Oqtane.Modules.Controls
@using SZUAbsolventenverein.Module.AdminModules.Client.Components
@using SZUAbsolventenverein.Module.AdminModules.Services
@using SZUAbsolventenverein.Module.AdminModules.Models
@@ -24,6 +25,8 @@
<button type="button" class="btn btn-success" @onclick="Save">@Localizer["Save"]</button>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">@Localizer["Cancel"]</NavLink>
<br /><br />
<ReportComponent ReportableEntity="@AdminModules" RenderModeBoundary="@RenderModeBoundary" />
<br /><br />
@if (PageState.Action == "Edit")
{
<AuditInfo CreatedBy="@_createdby" CreatedOn="@_createdon" ModifiedBy="@_modifiedby" ModifiedOn="@_modifiedon"></AuditInfo>
@@ -54,6 +57,8 @@
private string _modifiedby;
private DateTime _modifiedon;
private AdminModules AdminModules;
protected override async Task OnInitializedAsync()
{
try
@@ -70,6 +75,7 @@
_createdon = AdminModules.CreatedOn;
_modifiedby = AdminModules.ModifiedBy;
_modifiedon = AdminModules.ModifiedOn;
this.AdminModules = AdminModules;
}
}
}

View File

@@ -1,3 +1,4 @@
@using Interfaces
@using SZUAbsolventenverein.Module.AdminModules.Services
@using SZUAbsolventenverein.Module.AdminModules.Models
@@ -6,6 +7,7 @@
@inject IAdminModulesService AdminModulesService
@inject NavigationManager NavigationManager
@inject IStringLocalizer<Index> Localizer
@inject IReportingHandler ReportingHandler;
@if (_AdminModuless == null)
{
@@ -23,11 +25,13 @@ else
<th style="width: 1px;">&nbsp;</th>
<th style="width: 1px;">&nbsp;</th>
<th style="width: 1px;">&nbsp;</th>
<th style="width: 1px;">&nbsp;</th>
<th>@Localizer["Name"]</th>
</Header>
<Row>
<td><ActionLink Action="Edit" Parameters="@($"id=" + context.AdminModulesId.ToString())" ResourceKey="Edit" /></td>
<td><ActionDialog Header="Delete AdminModules" Message="Are You Sure You Wish To Delete This AdminModules?" Action="Delete" Security="SecurityAccessLevel.Edit" Class="btn btn-danger" OnClick="@(async () => await Delete(context))" ResourceKey="Delete" Id="@context.AdminModulesId.ToString()" /></td>
<td><ActionDialog Header="Delete AdminModules" Message="Are You Sure You Wish To Delete This AdminModules?" Action="Delete" Security="SecurityAccessLevel.Edit" Class="btn btn-danger" OnClick="@(() => Delete(context))" ResourceKey="Delete" Id="@("Delete-"+context.AdminModulesId)" /></td>
<td><ActionDialog Header="Report AdminModules" Message="Are You Sure You Wish To Report This AdminModules?" Action="Report" Security="SecurityAccessLevel.Edit" Class="btn btn-danger" OnClick="@(() => Report(context))" ResourceKey="Report" Id="@("Report-"+context.AdminModulesId)" /></td>
<td><ActionLink Action="Send" Parameters="@($"id=" + context.AdminModulesId.ToString())" ResourceKey="Send" /></td>
<td>@context.Name</td>
</Row>
@@ -40,7 +44,7 @@ else
}
@code {
public override string RenderMode => RenderModes.Static;
public override string RenderMode => RenderModes.Interactive;
public override List<Resource> Resources => new List<Resource>()
{
@@ -78,4 +82,19 @@ else
AddModuleMessage(Localizer["Message.DeleteError"], MessageType.Error);
}
}
private async Task Report(AdminModules AdminModules)
{
try
{
ReportingHandler.Report(AdminModules, "Reported by User");
await logger.LogInformation("AdminModules Reported {AdminModules}", AdminModules);
StateHasChanged();
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Reportign AdminModules {AdminModules} {Error}", AdminModules, ex.Message);
AddModuleMessage(Localizer["Message.DeleteError"], MessageType.Error);
}
}
}

View File

@@ -7,8 +7,9 @@
@inject NavigationManager NavigationManager
@inject IReportSystemReportingService ReportingService
@inject IStringLocalizer<Index> Localizer
@inject IModuleService ModuleService
@if (reportings == null)
@if (_reportings == null)
{
<p><em>Loading...</em></p>
}
@@ -16,19 +17,24 @@ else
{
<br />
<br />
@if (reportings.Count != 0)
@if (_reportings.Count != 0)
{
<Pager Items="@reportings">
<Pager Items="@_reportings">
<Header>
<th style="width: 1px;">&nbsp;</th>
<th style="width: 1px;">&nbsp;</th>
<th style="width: 1px;">&nbsp;</th>
<th>@Localizer["Submitter"]</th>
<th>@Localizer["Note"]</th>
<th>@Localizer["Name"]</th>
</Header>
<Row>
<td><ActionLink Action="Edit" Parameters="@($"id=" + context.ReportingID)" ResourceKey="Edit" /></td>
<td><ActionDialog Header="Delete AdminModules" Message="Are You Sure You Wish To Delete This AdminModules?" Action="Delete" Security="SecurityAccessLevel.Edit" Class="btn btn-danger" OnClick="@(async () => await Delete(context))" ResourceKey="Delete" Id="@context.ReportingID.ToString()" /></td>
<td><ActionLink Action="Send" Parameters="@($"id=" + context.ReportingID)" ResourceKey="Send" /></td>
<td>@context.CreatedBy</td>
<td>@context.CreatedOn</td>
<td>@context.ModuleId</td>
<td>@context.ReportingID</td>
<td>@context.Note</td>
<td>@context.Reason</td>
</Row>
</Pager>
@@ -39,7 +45,6 @@ else
}
}
@code {
public override string RenderMode => RenderModes.Interactive;
@@ -49,13 +54,28 @@ else
new Script("_content/SZUAbsolventenverein.Module.ReportSystem/Module.js")
};
private List<Reporting> reportings = new List<Reporting>();
private List<Reporting> _reportings = new List<Reporting>();
private Dictionary<int, Module> _modules = new Dictionary<int, Module>();
protected override async Task OnInitializedAsync()
{
try
{
reportings = await ReportingService.GetReportsAsync(ModuleState.ModuleId);
_reportings = await ReportingService.GetReportsAsync(ModuleState.ModuleId);
foreach (var moduleId in _reportings.Select(r => r.ModuleId).Distinct())
{
Console.WriteLine(moduleId);
try
{
_modules.Add(moduleId, await ModuleService.GetModuleAsync(moduleId));
await logger.LogDebug(LogFunction.Create, "Module found {ModuleId} while loading Modules for Reportings.", moduleId);
}
catch (Exception ex)
{
_modules.Add(moduleId, new Module {Title = $"Module not found {ex.Message}"});
await logger.LogDebug("Module not found {ModuleId} while loading Modules for Reportings. {error}", moduleId, ex);
}
}
}
catch (Exception ex)
{
@@ -68,7 +88,7 @@ else
try
{
await ReportingService.DeleteReportingAsync(reporting.ReportingID, ModuleState.ModuleId);
reportings.Remove(reporting);
_reportings.Remove(reporting);
StateHasChanged();
}
catch (Exception ex)