226 lines
9.6 KiB
Plaintext
226 lines
9.6 KiB
Plaintext
@using SZUAbsolventenverein.Module.PremiumArea.Services
|
|
@using SZUAbsolventenverein.Module.PremiumArea.Models
|
|
@namespace SZUAbsolventenverein.Module.PremiumArea
|
|
@inherits ModuleBase
|
|
@inject IEngineerApplicationService ApplicationService
|
|
@inject NavigationManager NavManager
|
|
@inject Oqtane.Services.IUserService UserService
|
|
|
|
@if (Oqtane.Security.UserSecurity.IsAuthorized(PageState.User, RoleNames.Admin) || Oqtane.Security.UserSecurity.IsAuthorized(PageState.User, "Premium Member"))
|
|
{
|
|
<h3 class="pa-section-title">Ingenieur-Anträge</h3>
|
|
|
|
@if (_applications == null)
|
|
{
|
|
<p>Prüfe Premium-Zugang...</p>
|
|
}
|
|
else if (_applications.Count == 0)
|
|
{
|
|
<div class="pa-alert pa-alert-warning">
|
|
⚠ Keine Anträge gefunden.
|
|
</div>
|
|
}
|
|
else
|
|
{
|
|
<div class="row">
|
|
@foreach (var app in _applications)
|
|
{
|
|
<div class="col-md-4 mb-3">
|
|
<div class="pa-app-card">
|
|
<div class="pa-app-card-body">
|
|
<div class="d-flex justify-content-between align-items-start">
|
|
<div class="pa-app-card-title">@(string.IsNullOrEmpty(app.Title) ? "Ingenieur-Antrag" : app.Title)</div>
|
|
@if (Oqtane.Security.UserSecurity.IsAuthorized(PageState.User, RoleNames.Admin))
|
|
{
|
|
@if (_confirmDeleteId == app.ApplicationId)
|
|
{
|
|
<div class="pa-d-flex pa-gap-2">
|
|
<button class="pa-btn pa-btn-danger pa-btn-sm" @onclick="@(() => DeleteApp(app))" title="Bestätigen">
|
|
<span class="oi oi-check"></span>
|
|
</button>
|
|
<button class="pa-btn pa-btn-secondary pa-btn-sm" @onclick="@(() => _confirmDeleteId = -1)" title="Abbrechen">
|
|
<span class="oi oi-x"></span>
|
|
</button>
|
|
</div>
|
|
}
|
|
else
|
|
{
|
|
<button class="pa-btn pa-btn-outline-danger pa-btn-sm" @onclick="@(() => _confirmDeleteId = app.ApplicationId)" title="Antrag löschen">
|
|
<span class="oi oi-trash"></span>
|
|
</button>
|
|
}
|
|
}
|
|
</div>
|
|
<div class="pa-app-card-author">von @GetUserName(app.UserId)</div>
|
|
@if (!string.IsNullOrEmpty(app.ShortDescription))
|
|
{
|
|
<div class="pa-app-card-desc">@app.ShortDescription</div>
|
|
}
|
|
<div class="pa-app-card-meta">
|
|
<span class="oi oi-calendar"></span>
|
|
<span>@(app.ApprovedOn?.ToShortDateString() ?? app.CreatedOn.ToShortDateString())</span>
|
|
</div>
|
|
<div class="pa-app-card-actions">
|
|
<button class="pa-btn pa-btn-primary pa-btn-sm" @onclick="@(async () => ShowDetail(app))">PDF ansehen</button>
|
|
<a href="@(PageState.Alias.Path == "" ? "" : "/" + PageState.Alias.Path)/api/file/download/@(app.FileId)/attach" target="_blank" class="pa-btn pa-btn-outline-secondary pa-btn-sm">Herunterladen</a>
|
|
<button class="pa-btn pa-btn-outline-danger pa-btn-sm" @onclick="@(() => InitReport(app))">Melden</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
</div>
|
|
}
|
|
}
|
|
else
|
|
{
|
|
<div class="pa-alert pa-alert-warning">
|
|
⚠ Sie müssen Premium Kunde sein um diese Funktion zu nutzen.
|
|
</div>
|
|
}
|
|
|
|
@if (_selectedApp != null)
|
|
{
|
|
<div class="modal d-block" tabindex="-1">
|
|
<div class="modal-dialog modal-lg">
|
|
<div class="modal-content pa-modal-content">
|
|
<div class="modal-header pa-modal-header">
|
|
<h5 class="modal-title">Antrags-PDF</h5>
|
|
<button type="button" class="btn-close" @onclick="@(() => _selectedApp = null)"></button>
|
|
</div>
|
|
<div class="modal-body pa-modal-body" style="padding: 0 !important;">
|
|
<div style="min-height: 600px; height: 75vh;">
|
|
<iframe src="@(PageState.Alias.Path == "" ? "" : "/" + PageState.Alias.Path)/api/file/download/@(_selectedApp.FileId)" style="width: 100%; height: 100%; border: none;" allowfullscreen></iframe>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer pa-modal-footer">
|
|
<button type="button" class="pa-btn pa-btn-secondary" @onclick="@(() => _selectedApp = null)">Schließen</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="modal-backdrop fade show"></div>
|
|
}
|
|
|
|
@if (_reportApp != null)
|
|
{
|
|
<div class="modal d-block" tabindex="-1">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content pa-modal-content">
|
|
<div class="modal-header pa-modal-header">
|
|
<h5 class="modal-title">Antrag melden</h5>
|
|
<button type="button" class="btn-close" @onclick="@(() => _reportApp = null)"></button>
|
|
</div>
|
|
<div class="modal-body pa-modal-body">
|
|
<p>Bitte geben Sie einen Grund an, warum Sie diesen Antrag melden (von @GetUserName(_reportApp.UserId)).</p>
|
|
<textarea class="pa-form-control" rows="3" style="width: 100%;" @bind="_reportReason" placeholder="Grund..."></textarea>
|
|
</div>
|
|
<div class="modal-footer pa-modal-footer">
|
|
<button type="button" class="pa-btn pa-btn-secondary" @onclick="@(() => _reportApp = null)">Abbrechen</button>
|
|
<button type="button" class="pa-btn pa-btn-danger" @onclick="SubmitReport">Meldung absenden</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="modal-backdrop fade show"></div>
|
|
}
|
|
|
|
@code {
|
|
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.View;
|
|
|
|
public override List<Resource> Resources => new List<Resource>()
|
|
{
|
|
new Stylesheet("_content/SZUAbsolventenverein.Module.PremiumArea/Module.css")
|
|
};
|
|
|
|
private List<EngineerApplication> _applications;
|
|
private EngineerApplication _selectedApp;
|
|
private EngineerApplication _reportApp;
|
|
private string _reportReason;
|
|
private Dictionary<int, string> _userNames = new();
|
|
private int _confirmDeleteId = -1;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
try
|
|
{
|
|
var published = await ApplicationService.GetApplicationsAsync(ModuleState.ModuleId, "Published");
|
|
var approved = await ApplicationService.GetApplicationsAsync(ModuleState.ModuleId, "Approved");
|
|
|
|
_applications = new List<EngineerApplication>();
|
|
if (published != null) _applications.AddRange(published);
|
|
if (approved != null) _applications.AddRange(approved);
|
|
|
|
_applications = _applications.GroupBy(a => a.ApplicationId).Select(g => g.First()).ToList();
|
|
|
|
// Benutzernamen laden
|
|
foreach (var userId in _applications.Select(a => a.UserId).Distinct())
|
|
{
|
|
try
|
|
{
|
|
var user = await UserService.GetUserAsync(userId, ModuleState.SiteId);
|
|
_userNames[userId] = user?.DisplayName ?? $"Benutzer {userId}";
|
|
}
|
|
catch
|
|
{
|
|
_userNames[userId] = $"Benutzer {userId}";
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
_applications = null;
|
|
}
|
|
}
|
|
|
|
private void ShowDetail(EngineerApplication app)
|
|
{
|
|
_selectedApp = app;
|
|
}
|
|
|
|
private void InitReport(EngineerApplication app)
|
|
{
|
|
_reportApp = app;
|
|
_reportReason = "";
|
|
}
|
|
|
|
private async Task SubmitReport()
|
|
{
|
|
if (_reportApp == null || string.IsNullOrWhiteSpace(_reportReason)) return;
|
|
|
|
try
|
|
{
|
|
await ApplicationService.ReportApplicationAsync(_reportApp.ApplicationId, ModuleState.ModuleId, _reportReason);
|
|
_reportApp = null;
|
|
AddModuleMessage("Antrag erfolgreich gemeldet.", MessageType.Success);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
AddModuleMessage("Fehler beim Melden: " + ex.Message, MessageType.Error);
|
|
}
|
|
}
|
|
|
|
private async Task DeleteApp(EngineerApplication app)
|
|
{
|
|
try
|
|
{
|
|
await ApplicationService.DeleteApplicationAsync(app.ApplicationId, ModuleState.ModuleId);
|
|
_applications.Remove(app);
|
|
_confirmDeleteId = -1;
|
|
AddModuleMessage("Antrag erfolgreich gelöscht.", MessageType.Success);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
AddModuleMessage("Fehler beim Löschen: " + ex.Message, MessageType.Error);
|
|
_confirmDeleteId = -1;
|
|
}
|
|
}
|
|
|
|
private string GetUserName(int userId)
|
|
{
|
|
return _userNames.TryGetValue(userId, out var name) ? name : $"Benutzer {userId}";
|
|
}
|
|
|
|
}
|