95 lines
3.4 KiB
Plaintext
95 lines
3.4 KiB
Plaintext
@inherits LocalizableComponent
|
|
@using Interfaces
|
|
@implements Interfaces.IReportUI
|
|
@inject IReportingHandler ReportingHandler
|
|
|
|
<button type="button" class="btn btn-warning btn-lg px-4" @onclick="ShowReportModal">
|
|
<i class="oi oi-warning me-2"></i> Melden
|
|
</button>
|
|
|
|
@if (_showReportModal)
|
|
{
|
|
<div class="modal fade show" style="display: block; background: rgba(0,0,0,0.5); z-index: 1050;" tabindex="-1">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title">Eintrag melden</h5>
|
|
<button type="button" class="btn-close" @onclick="CloseReportModal"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<p>Warum möchtest du diesen Eintrag melden?</p>
|
|
<textarea class="form-control" @bind="_reportReason" rows="3" placeholder="Grund für die Meldung..."></textarea>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" @onclick="CloseReportModal">Abbrechen</button>
|
|
<button type="button" class="btn btn-danger" @onclick="ReportEntry">Melden</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
@code {
|
|
public Type ReportType => typeof(ReportComponent);
|
|
|
|
[Parameter]
|
|
public IReportable ReportableEntity { get; set; }
|
|
|
|
private bool _showReportModal = false;
|
|
private string _reportReason = "";
|
|
|
|
private Task ShowReportModal()
|
|
{
|
|
_reportReason = "";
|
|
_showReportModal = true;
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
private void CloseReportModal()
|
|
{
|
|
_showReportModal = false;
|
|
}
|
|
public Dictionary<string, object> ConstructParameterList(IReportable reportableEntity, object RenderModeBoundary) {
|
|
Dictionary<string, object> _parameters = new Dictionary<string, object>();
|
|
|
|
_parameters["ReportableEntity"] = _blackBoard;
|
|
_parameters["RenderModeBoundary"] = RenderModeBoundary;
|
|
|
|
return _parameters;
|
|
}
|
|
private async Task ReportEntry()
|
|
{
|
|
// Basic null checks to avoid runtime NREs
|
|
if (ReportingHandler == null)
|
|
{
|
|
Console.WriteLine("ReportingHandler is not available (null). Ensure it is registered and injected.");
|
|
CloseReportModal();
|
|
return;
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
} |