Reporting: Add UserName
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
@inherits ComponentBase
|
||||
@inherits LocalizableComponent
|
||||
@using Interfaces
|
||||
@implements Interfaces.IReportUI
|
||||
@inject IReportingHandler ReportingHandler
|
||||
|
||||
<button class="btn btn-warning btn-lg px-4" @onclick="ShowReportModal">
|
||||
<button type="button" class="btn btn-warning btn-lg px-4" @onclick="ShowReportModal">
|
||||
<i class="oi oi-warning me-2"></i> Melden
|
||||
</button>
|
||||
|
||||
@@ -29,63 +29,6 @@
|
||||
</div>
|
||||
}
|
||||
|
||||
<style>
|
||||
.hall-of-fame-details .card {
|
||||
background: #ffffff;
|
||||
}
|
||||
.hall-of-fame-details .breadcrumb-item a {
|
||||
text-decoration: none;
|
||||
color: var(--primary);
|
||||
}
|
||||
|
||||
@@media print {
|
||||
.no-print, header, footer, nav, .app-sidebar, .breadcrumb, .btn-link, .app-navbar {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
/* Reset containers for printing */
|
||||
html, body, .app-viewport, .app-main, .app-container, main, .hall-of-fame-details, .container {
|
||||
height: auto !important;
|
||||
min-height: auto !important;
|
||||
overflow: visible !important;
|
||||
position: static !important;
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
width: 100% !important;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: white !important;
|
||||
}
|
||||
|
||||
.card {
|
||||
box-shadow: none !important;
|
||||
border: none !important;
|
||||
position: relative !important;
|
||||
display: block !important; /* Force block instead of flex for better printing */
|
||||
}
|
||||
|
||||
.row {
|
||||
display: block !important; /* Stack columns vertically for print if needed, or keeping it but ensuring it doesn't clip */
|
||||
}
|
||||
|
||||
.col-lg-5, .col-lg-7 {
|
||||
width: 100% !important;
|
||||
display: block !important;
|
||||
float: none !important;
|
||||
}
|
||||
|
||||
.hall-of-fame-details {
|
||||
margin-top: 0 !important;
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: 100% !important;
|
||||
page-break-inside: avoid;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@code {
|
||||
public Type ReportType => typeof(ReportComponent);
|
||||
|
||||
@@ -95,23 +38,11 @@
|
||||
private bool _showReportModal = false;
|
||||
private string _reportReason = "";
|
||||
|
||||
private class ReportEntityTest : IReportable
|
||||
{
|
||||
public int EntityID { get; set; }
|
||||
public string ModuleName { get; set; }
|
||||
public int ModuleID { get; set; }
|
||||
}
|
||||
|
||||
protected override Task OnInitializedAsync()
|
||||
{
|
||||
ReportableEntity = new ReportEntityTest { EntityID = 1, ModuleID = 2, ModuleName = "TestModule" };
|
||||
return base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
private void ShowReportModal()
|
||||
private Task ShowReportModal()
|
||||
{
|
||||
_reportReason = "";
|
||||
_showReportModal = true;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private void CloseReportModal()
|
||||
@@ -119,21 +50,39 @@
|
||||
_showReportModal = false;
|
||||
}
|
||||
|
||||
private void ReportEntry()
|
||||
private async Task ReportEntry()
|
||||
{
|
||||
ReportingHandler.Report(ReportableEntity, _reportReason);
|
||||
Console.WriteLine($"Eintrag gemeldet mit Grund: {_reportReason}");
|
||||
CloseReportModal();
|
||||
}
|
||||
|
||||
public override Task SetParametersAsync(ParameterView parameters)
|
||||
{
|
||||
Console.WriteLine("ParameterView received in ReportComponent:");
|
||||
foreach (var parameter in parameters)
|
||||
// Basic null checks to avoid runtime NREs
|
||||
if (ReportingHandler == null)
|
||||
{
|
||||
Console.WriteLine(parameter.Name + "name - value" + parameter.Value);
|
||||
Console.WriteLine("ReportingHandler is not available (null). Ensure it is registered and injected.");
|
||||
CloseReportModal();
|
||||
return;
|
||||
}
|
||||
return base.SetParametersAsync(parameters);
|
||||
}
|
||||
|
||||
if (ReportableEntity == null)
|
||||
{
|
||||
Console.WriteLine("ReportableEntity is null. Cannot report.");
|
||||
CloseReportModal();
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// If the handler exposes an async API use it instead. We run the synchronous call off the UI thread to avoid blocking.
|
||||
await Task.Run(() => ReportingHandler.Report(ReportableEntity, _reportReason));
|
||||
Console.WriteLine($"Eintrag gemeldet mit Grund: {_reportReason}");
|
||||
AddModuleMessage($"Eintrag mit Grund {_reportReason} gemeldet.", MessageType.Success);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Reporting failed: {ex.Message}");
|
||||
AddModuleMessage($"Eintrag konnte nicht gemeldet werden, bitte melden sie sich direkt beim Absolventenverein: ({ex.StackTrace}).", MessageType.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
CloseReportModal();
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;"> </th>
|
||||
<th style="width: 1px;"> </th>
|
||||
<th style="width: 1px;"> </th>
|
||||
<th style="width: 1px;"> </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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;"> </th>
|
||||
<th style="width: 1px;"> </th>
|
||||
<th style="width: 1px;"> </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)
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Interfaces" Version="0.0.0-11" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="10.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Localization" Version="10.0.1" />
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace SZUAbsolventenverein.Module.ReportSystem.Services
|
||||
public void Report(IReportable reportable, string note)
|
||||
{
|
||||
CreateReportAsync(new Reporting
|
||||
{ ModuleId = reportable.ModuleID, EntityId = reportable.EntityID, Note = note, Reason = "Default Reason" });
|
||||
{ ModuleId = reportable.ModuleID, EntityId = reportable.EntityID, Note = note, UserName = reportable.UserName, Reason = "Default Reason" });
|
||||
}
|
||||
|
||||
public Task<Reporting> CreateReportAsync(Reporting reporting)
|
||||
|
||||
30
Server/Migrations/ReportSystem/01000001_AddUserName.cs
Normal file
30
Server/Migrations/ReportSystem/01000001_AddUserName.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Oqtane.Databases.Interfaces;
|
||||
using Oqtane.Migrations;
|
||||
using SZUAbsolventenverein.Module.AdminModules.Migrations.EntityBuilders;
|
||||
using SZUAbsolventenverein.Module.AdminModules.Repository;
|
||||
|
||||
namespace SZUAbsolventenverein.Module.ReportSystem.Migrations
|
||||
{
|
||||
[DbContext(typeof(ReportingContext))]
|
||||
[Migration("SZUAbsolventenverein.Module.ReportSystem.01.00.00.01")]
|
||||
public class AddUserName : MultiDatabaseMigration
|
||||
{
|
||||
public AddUserName(IDatabase database) : base(database)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
var entityBuilder = new ReportingEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
entityBuilder.AddStringColumn("UserName", 256, false, false, "");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
var entityBuilder = new ReportingEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
entityBuilder.DropColumn("UserName");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,7 +120,7 @@ namespace SZUAbsolventenverein.Module.ReportSystem.Services
|
||||
{
|
||||
// if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.Edit))
|
||||
{
|
||||
Reporting reporting = await CreateReportAsync(new Reporting {ModuleId = reportable.ModuleID, EntityId = reportable.EntityID, Note = note, Reason = "Default Reason"});
|
||||
Reporting reporting = await CreateReportAsync(new Reporting {ModuleId = reportable.ModuleID, EntityId = reportable.EntityID, UserName = reportable.UserName, Note = note, Reason = "Default Reason"});
|
||||
if (reporting != null)
|
||||
{
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Reporting recieved {ReportingId}", reporting.ReportingID);
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Interfaces;
|
||||
using Oqtane.Models;
|
||||
|
||||
namespace SZUAbsolventenverein.Module.AdminModules.Models
|
||||
{
|
||||
[Table("SZUAbsolventenvereinAdminModules")]
|
||||
public class AdminModules : IAuditable
|
||||
public class AdminModules : IAuditable, IReportable
|
||||
{
|
||||
[Key]
|
||||
public int AdminModulesId { get; set; }
|
||||
@@ -18,5 +19,13 @@ namespace SZUAbsolventenverein.Module.AdminModules.Models
|
||||
public DateTime CreatedOn { get; set; }
|
||||
public string ModifiedBy { get; set; }
|
||||
public DateTime ModifiedOn { get; set; }
|
||||
|
||||
[NotMapped] public string ModuleName => "";
|
||||
|
||||
[NotMapped] public int ModuleID => ModuleId;
|
||||
|
||||
[NotMapped] public int EntityID => AdminModulesId;
|
||||
|
||||
[NotMapped] public string UserName => CreatedBy;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ public class Reporting : IAuditable
|
||||
public int ReportingID { get; set; }
|
||||
public int ModuleId { get; set; }
|
||||
public int EntityId { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public string Note { get; set; }
|
||||
public string Reason { get; set; }
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Interfaces" Version="0.0.0-11" />
|
||||
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user