Feature: Hall of Fame Module Implementation (1.0.1)
- Added Hall of Fame module logic (Models, Controller, Service). - Implemented 'One Entry Per User' and 'Publish/Draft' workflow. - Updated UI to Grid Layout (Index.razor) and Unified Form (Edit.razor). - Added Database Migration 01000001 for new columns. - Bumped version to 1.0.1.
This commit is contained in:
@@ -10,15 +10,54 @@
|
||||
|
||||
<form @ref="form" class="@(validated ? " was-validated" : "needs-validation" )" novalidate>
|
||||
<div class="container">
|
||||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="name" HelpText="Enter a name" ResourceKey="Name">Name: </Label>
|
||||
<div class="row mb-3 align-items-center">
|
||||
<Label Class="col-sm-3 col-form-label" For="name" HelpText="Gib deinen Namen ein" ResourceKey="Name">Name: </Label>
|
||||
<div class="col-sm-9">
|
||||
<input id="name" class="form-control" @bind="@_name" required />
|
||||
<input id="name" class="form-control" @bind="@_name" required maxlength="120" />
|
||||
<div class="invalid-feedback">Bitte gib einen Namen ein (max. 120 Zeichen).</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-3 align-items-center">
|
||||
<Label Class="col-sm-3 col-form-label" For="year" HelpText="Jahrgang (z.B. 2020)" ResourceKey="Year">Jahrgang: </Label>
|
||||
<div class="col-sm-9">
|
||||
<input id="year" type="number" class="form-control" @bind="@_year" required min="1990" max="2100" />
|
||||
<div class="invalid-feedback">Bitte gib einen gültigen Jahrgang ein.</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-3 align-items-center">
|
||||
<Label Class="col-sm-3 col-form-label" For="description" HelpText="Kurzbeschreibung / Werdegang" ResourceKey="Description">Beschreibung: </Label>
|
||||
<div class="col-sm-9">
|
||||
<textarea id="description" class="form-control" @bind="@_description" required rows="5" maxlength="1500"></textarea>
|
||||
<div class="invalid-feedback">Bitte gib eine Beschreibung ein.</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-3 align-items-center">
|
||||
<Label Class="col-sm-3 col-form-label" For="image" HelpText="Bild URL (optional)" ResourceKey="Image">Bild URL: </Label>
|
||||
<div class="col-sm-9">
|
||||
<input id="image" class="form-control" @bind="@_image" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-3 align-items-center">
|
||||
<Label Class="col-sm-3 col-form-label" For="link" HelpText="Externer Link (optional)" ResourceKey="Link">Link: </Label>
|
||||
<div class="col-sm-9">
|
||||
<input id="link" type="url" class="form-control" @bind="@_link" placeholder="https://" />
|
||||
<div class="invalid-feedback">Bitte gib eine gültige URL ein (startet mit http:// oder https://).</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-3 align-items-center">
|
||||
<Label Class="col-sm-3 col-form-label" For="status" HelpText="Status" ResourceKey="Status">Status: </Label>
|
||||
<div class="col-sm-9">
|
||||
<p>Aktuell: <strong>@(_status ?? "Neu")</strong></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="btn btn-success" @onclick="Save">@Localizer["Save"]</button>
|
||||
<NavLink class="btn btn-secondary" href="@NavigateUrl()">@Localizer["Cancel"]</NavLink>
|
||||
|
||||
<div class="mt-4">
|
||||
<button type="button" class="btn btn-secondary me-2" @onclick="@(() => Save("Draft"))">Als Entwurf speichern</button>
|
||||
<button type="button" class="btn btn-primary" @onclick="@(() => Save("Published"))">Veröffentlichen</button>
|
||||
<NavLink class="btn btn-link ms-2" href="@NavigateUrl()">Abbrechen</NavLink>
|
||||
</div>
|
||||
|
||||
<br /><br />
|
||||
@if (PageState.Action == "Edit")
|
||||
{
|
||||
@@ -27,11 +66,11 @@
|
||||
</form>
|
||||
|
||||
@code {
|
||||
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Edit;
|
||||
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.View; // Logic handles checking user own entry
|
||||
|
||||
public override string Actions => "Add,Edit";
|
||||
|
||||
public override string Title => "Manage HallOfFame";
|
||||
public override string Title => "Hall of Fame Eintrag verwalten";
|
||||
|
||||
public override List<Resource> Resources => new List<Resource>()
|
||||
{
|
||||
@@ -43,6 +82,12 @@
|
||||
|
||||
private int _id;
|
||||
private string _name;
|
||||
private int _year = DateTime.Now.Year;
|
||||
private string _description;
|
||||
private string _image;
|
||||
private string _link;
|
||||
private string _status = "Draft";
|
||||
|
||||
private string _createdby;
|
||||
private DateTime _createdon;
|
||||
private string _modifiedby;
|
||||
@@ -56,15 +101,39 @@
|
||||
{
|
||||
_id = Int32.Parse(PageState.QueryString["id"]);
|
||||
HallOfFame HallOfFame = await HallOfFameService.GetHallOfFameAsync(_id, ModuleState.ModuleId);
|
||||
|
||||
// Security check: only allow editing own entry
|
||||
if (HallOfFame != null)
|
||||
{
|
||||
if (HallOfFame.UserId != PageState.User.UserId)
|
||||
{
|
||||
NavigationManager.NavigateTo(NavigateUrl());
|
||||
return;
|
||||
}
|
||||
|
||||
_name = HallOfFame.Name;
|
||||
_year = HallOfFame.Year;
|
||||
_description = HallOfFame.Description;
|
||||
_image = HallOfFame.Image;
|
||||
_link = HallOfFame.Link;
|
||||
_status = HallOfFame.Status;
|
||||
|
||||
_createdby = HallOfFame.CreatedBy;
|
||||
_createdon = HallOfFame.CreatedOn;
|
||||
_modifiedby = HallOfFame.ModifiedBy;
|
||||
_modifiedon = HallOfFame.ModifiedOn;
|
||||
}
|
||||
}
|
||||
else // Add Mode
|
||||
{
|
||||
// Check if user already has an entry to prevent duplicates
|
||||
var existing = await HallOfFameService.GetHallOfFameByUserIdAsync(PageState.User.UserId, ModuleState.ModuleId);
|
||||
if (existing != null)
|
||||
{
|
||||
// Use NavigateUrl with parameters properly (simplified here)
|
||||
NavigationManager.NavigateTo(EditUrl(existing.HallOfFameId.ToString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -73,7 +142,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
private async Task Save()
|
||||
private async Task Save(string status)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -81,20 +150,39 @@
|
||||
var interop = new Oqtane.UI.Interop(JSRuntime);
|
||||
if (await interop.FormValid(form))
|
||||
{
|
||||
_status = status;
|
||||
|
||||
if (PageState.Action == "Add")
|
||||
{
|
||||
HallOfFame HallOfFame = new HallOfFame();
|
||||
HallOfFame.ModuleId = ModuleState.ModuleId;
|
||||
HallOfFame.UserId = PageState.User.UserId; // Set Owner
|
||||
HallOfFame.Name = _name;
|
||||
HallOfFame.Year = _year;
|
||||
HallOfFame.Description = _description;
|
||||
HallOfFame.Image = _image;
|
||||
HallOfFame.Link = _link;
|
||||
HallOfFame.Status = _status;
|
||||
|
||||
HallOfFame = await HallOfFameService.AddHallOfFameAsync(HallOfFame);
|
||||
await logger.LogInformation("HallOfFame Added {HallOfFame}", HallOfFame);
|
||||
}
|
||||
else
|
||||
{
|
||||
HallOfFame HallOfFame = await HallOfFameService.GetHallOfFameAsync(_id, ModuleState.ModuleId);
|
||||
HallOfFame.Name = _name;
|
||||
await HallOfFameService.UpdateHallOfFameAsync(HallOfFame);
|
||||
await logger.LogInformation("HallOfFame Updated {HallOfFame}", HallOfFame);
|
||||
// Ensure we don't overwrite with invalid user logic, though server checks too
|
||||
if (HallOfFame.UserId == PageState.User.UserId)
|
||||
{
|
||||
HallOfFame.Name = _name;
|
||||
HallOfFame.Year = _year;
|
||||
HallOfFame.Description = _description;
|
||||
HallOfFame.Image = _image;
|
||||
HallOfFame.Link = _link;
|
||||
HallOfFame.Status = _status;
|
||||
|
||||
await HallOfFameService.UpdateHallOfFameAsync(HallOfFame);
|
||||
await logger.LogInformation("HallOfFame Updated {HallOfFame}", HallOfFame);
|
||||
}
|
||||
}
|
||||
NavigationManager.NavigateTo(NavigateUrl());
|
||||
}
|
||||
|
||||
@@ -13,27 +13,55 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
<ActionLink Action="Add" Security="SecurityAccessLevel.Edit" Text="Add HallOfFame" ResourceKey="Add" />
|
||||
<br />
|
||||
<br />
|
||||
<div class="row mb-4">
|
||||
<div class="col text-end">
|
||||
@if (PageState.User != null)
|
||||
{
|
||||
if (_myEntry != null)
|
||||
{
|
||||
<ActionLink Action="Edit" Parameters="@($"id=" + _myEntry.HallOfFameId.ToString())" Text="Hall-of-Fame-Eintrag bearbeiten" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<ActionLink Action="Add" Text="Neuen Hall-of-Fame-Eintrag erstellen" />
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<p class="text-muted">Einloggen, um einen Eintrag zu erstellen.</p>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (@_HallOfFames.Count != 0)
|
||||
{
|
||||
<Pager Items="@_HallOfFames">
|
||||
<Header>
|
||||
<th style="width: 1px;"> </th>
|
||||
<th style="width: 1px;"> </th>
|
||||
<th>@Localizer["Name"]</th>
|
||||
</Header>
|
||||
<Row>
|
||||
<td><ActionLink Action="Edit" Parameters="@($"id=" + context.HallOfFameId.ToString())" ResourceKey="Edit" /></td>
|
||||
<td><ActionDialog Header="Delete HallOfFame" Message="Are You Sure You Wish To Delete This HallOfFame?" Action="Delete" Security="SecurityAccessLevel.Edit" Class="btn btn-danger" OnClick="@(async () => await Delete(context))" ResourceKey="Delete" Id="@context.HallOfFameId.ToString()" /></td>
|
||||
<td>@context.Name</td>
|
||||
</Row>
|
||||
</Pager>
|
||||
<div class="row">
|
||||
@foreach (var item in _HallOfFames)
|
||||
{
|
||||
<div class="col-md-4 mb-3">
|
||||
<div class="card h-100">
|
||||
@if (!string.IsNullOrEmpty(item.Image))
|
||||
{
|
||||
<img src="@item.Image" class="card-img-top" alt="@item.Name" style="max-height: 200px; object-fit: cover;">
|
||||
}
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">@item.Name (@item.Year)</h5>
|
||||
<p class="card-text">@item.Description</p>
|
||||
@if (!string.IsNullOrEmpty(item.Link))
|
||||
{
|
||||
<a href="@item.Link" target="_blank" class="btn btn-sm btn-outline-primary">Mehr Infos</a>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p>@Localizer["Message.DisplayNone"]</p>
|
||||
<div class="alert alert-info">
|
||||
Es sind noch keine Hall-of-Fame-Einträge veröffentlicht.
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,12 +75,18 @@ else
|
||||
};
|
||||
|
||||
List<HallOfFame> _HallOfFames;
|
||||
HallOfFame _myEntry;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
_HallOfFames = await HallOfFameService.GetHallOfFamesAsync(ModuleState.ModuleId);
|
||||
|
||||
if (PageState.User != null)
|
||||
{
|
||||
_myEntry = await HallOfFameService.GetHallOfFameByUserIdAsync(PageState.User.UserId, ModuleState.ModuleId);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -60,20 +94,4 @@ else
|
||||
AddModuleMessage(Localizer["Message.LoadError"], MessageType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task Delete(HallOfFame HallOfFame)
|
||||
{
|
||||
try
|
||||
{
|
||||
await HallOfFameService.DeleteHallOfFameAsync(HallOfFame.HallOfFameId, ModuleState.ModuleId);
|
||||
await logger.LogInformation("HallOfFame Deleted {HallOfFame}", HallOfFame);
|
||||
_HallOfFames = await HallOfFameService.GetHallOfFamesAsync(ModuleState.ModuleId);
|
||||
StateHasChanged();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await logger.LogError(ex, "Error Deleting HallOfFame {HallOfFame} {Error}", HallOfFame, ex.Message);
|
||||
AddModuleMessage(Localizer["Message.DeleteError"], MessageType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user