216 lines
9.7 KiB
Plaintext
216 lines
9.7 KiB
Plaintext
@page "/PrivateList"
|
|
@rendermode InteractiveServer
|
|
|
|
@using Microsoft.AspNetCore.Authorization
|
|
@using CouchLog.Data
|
|
@using Microsoft.AspNetCore.Identity
|
|
@using Microsoft.EntityFrameworkCore
|
|
|
|
@inject ApplicationDbContext CouchLogDB
|
|
@inject UserManager<ApplicationUser> UserManager
|
|
@inject AuthenticationStateProvider AuthenticationStateProvider
|
|
@inject NavigationManager NavigationManager
|
|
|
|
@attribute [Authorize]
|
|
|
|
<PageTitle>Private List</PageTitle>
|
|
|
|
<div class="container-fluid mt-4 px-4">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h2>Private List</h2>
|
|
</div>
|
|
|
|
<!-- Grid-Layout -->
|
|
<div class="row g-4">
|
|
@foreach (var Entity in PrivateEntities)
|
|
{
|
|
<div class="col-12 col-lg-6 col-xxl-4">
|
|
|
|
<div class="card shadow-sm border-0 overflow-hidden private-entity-card">
|
|
<div class="row g-0 h-100">
|
|
|
|
<!-- Feste Breite für das Bild, kein Umbruch -->
|
|
<div class="col-auto" style="flex: 0 0 auto; min-width: 120px; max-width: 150px;">
|
|
@if (!string.IsNullOrEmpty(Entity.GlobalEntity?.PicturePath))
|
|
{
|
|
<img src="/@Entity.GlobalEntity.PicturePath"
|
|
class="entity-img w-100 h-100"
|
|
style="object-fit: cover;"
|
|
alt="@Entity.GlobalEntity.Title">
|
|
}
|
|
else
|
|
{
|
|
<div class="d-flex align-items-center justify-content-center h-100 bg-light text-muted small">
|
|
Kein Bild
|
|
</div>
|
|
}
|
|
</div>
|
|
|
|
<!-- Der Rest nimmt den verbleibenden Platz -->
|
|
<div class="col" style="min-width: 0;">
|
|
<div class="card-body d-flex flex-column h-100 py-2 px-3">
|
|
|
|
<!-- Header mit besserer Text-Behandlung -->
|
|
<div class="d-flex justify-content-between align-items-start mb-2">
|
|
<div style="min-width: 0; flex: 1;">
|
|
<h5 class="card-title fw-bold mb-0" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
|
|
@Entity.GlobalEntity?.Title
|
|
</h5>
|
|
<small class="text-muted meta-text">
|
|
@Entity.CreationTime.ToShortDateString()
|
|
</small>
|
|
</div>
|
|
|
|
<div class="dropdown ms-2" style="flex-shrink: 0;">
|
|
<button class="btn btn-link menu-btn" type="button" data-bs-toggle="modal" data-bs-target="#modal-@Entity.Id">
|
|
⋮
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<select class="form-select"
|
|
value="@Entity.UserWatchStatusId"
|
|
@onchange="@(e => UpdateWatchStatus(Entity, e.Value))">
|
|
|
|
@foreach (var status in userWatchStatuses)
|
|
{
|
|
<option value="@status.Id">@status.Name</option>
|
|
}
|
|
</select>
|
|
|
|
@if (Entity.GlobalEntity?.MediaType.Name == "Series" || Entity.GlobalEntity?.MediaType.Name == "Anime")
|
|
{
|
|
<select class="form-select" value="@Entity.Season" @onchange="@(e => UpdateSeason(Entity, e.Value))">
|
|
@{
|
|
int currentSeason = Entity.Season ?? 1;
|
|
|
|
int startOffsetSeason = currentSeason > 1 ? -1 : 0;
|
|
}
|
|
|
|
@for (int i = startOffsetSeason; i <= 5; i++)
|
|
{
|
|
int season = currentSeason + i;
|
|
|
|
<option value="@season">
|
|
Staffel @season
|
|
</option>
|
|
}
|
|
</select>
|
|
|
|
<select class="form-select" value="@Entity.Episode" @onchange="@(e => UpdateEpisode(Entity, e.Value))">
|
|
@{
|
|
int currentEpisode = Entity.Episode ?? 1;
|
|
|
|
int startOffsetEpisode = currentEpisode > 1 ? -1 : 0;
|
|
}
|
|
|
|
@for (int i = startOffsetEpisode; i <= 5; i++)
|
|
{
|
|
int episode = currentEpisode + i;
|
|
|
|
<option value="@episode">
|
|
Episode @episode
|
|
</option>
|
|
}
|
|
</select>
|
|
}
|
|
|
|
<!-- Beschreibung -->
|
|
<!--<p class="card-text text-truncate-multiline flex-grow-1 text-muted small mt-1 mb-2">
|
|
@(!string.IsNullOrWhiteSpace(Entity.Description)
|
|
? Entity.Description
|
|
: (Entity.Description ?? "Keine Beschreibung."))
|
|
</p>
|
|
-->
|
|
<!-- Footer Button -->
|
|
<div class="mt-auto d-flex justify-content-end">
|
|
<button class="btn btn-outline-secondary btn-sm btn-details" type="button">Details</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Modal (unverändert) -->
|
|
<div class="modal fade" id="modal-@Entity.Id" tabindex="-1" aria-hidden="true">
|
|
<div class="modal-dialog modal-dialog-centered">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title">Optionen</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body">Optionen...</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Schließen</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
</div>
|
|
</div>
|
|
|
|
@code
|
|
{
|
|
private List<PrivateEntity> PrivateEntities = new List<PrivateEntity>();
|
|
private List<UserWatchStatus> userWatchStatuses = new List<UserWatchStatus>();
|
|
ApplicationUser? AppUser = new();
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
var AuthState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
|
AppUser = await UserManager.GetUserAsync(AuthState.User);
|
|
|
|
if (AppUser != null)
|
|
{
|
|
PrivateEntities = await CouchLogDB.PrivateEntities
|
|
.Where(x => x.UserId == AppUser.Id)
|
|
.Include(x => x.GlobalEntity)
|
|
.Include(x => x.UserWatchStatus)
|
|
.Include(x => x.GlobalEntity.MediaType)
|
|
.OrderByDescending(Entity => Entity.LastChange ?? Entity.CreationTime)
|
|
.ToListAsync();
|
|
|
|
userWatchStatuses = await CouchLogDB.UserWatchStatuses.OrderByDescending(Entity => Entity.Id).ToListAsync();
|
|
}
|
|
}
|
|
|
|
private async Task UpdateWatchStatus(PrivateEntity entity, object? newValue)
|
|
{
|
|
// Wir holen uns die gewählte ID aus dem Dropdown
|
|
if (int.TryParse(newValue?.ToString(), out int newId))
|
|
{
|
|
// 1. ID im Objekt aktualisieren
|
|
entity.UserWatchStatusId = newId;
|
|
|
|
// 2. Navigation Property aktualisieren (damit die UI nicht flackert)
|
|
// Wir suchen das passende Objekt aus der geladenen Liste
|
|
entity.UserWatchStatus = userWatchStatuses.FirstOrDefault(s => s.Id == newId);
|
|
|
|
// 3. Ab in die Datenbank
|
|
await CouchLogDB.SaveChangesAsync();
|
|
}
|
|
}
|
|
|
|
private async Task UpdateSeason(PrivateEntity entity, object? newSeasonValue)
|
|
{
|
|
if(int.TryParse(newSeasonValue?.ToString(), out int newSeason))
|
|
{
|
|
entity.Season = newSeason;
|
|
entity.Episode = 1;
|
|
|
|
await CouchLogDB.SaveChangesAsync();
|
|
}
|
|
}
|
|
|
|
private async Task UpdateEpisode(PrivateEntity entity, object? newEpisodeValue)
|
|
{
|
|
if (int.TryParse(newEpisodeValue?.ToString(), out int newEpisode))
|
|
{
|
|
entity.Episode = newEpisode;
|
|
|
|
await CouchLogDB.SaveChangesAsync();
|
|
}
|
|
}
|
|
} |