232 lines
9.7 KiB
Plaintext
232 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">
|
|
|
|
<!-- Active Watching Section -->
|
|
@if (ActiveWatchingEntities.Any())
|
|
{
|
|
<div class="mb-5">
|
|
<h2 class="mb-4">Aktiv am Schauen</h2>
|
|
<div class="row g-4">
|
|
@foreach (var entity in ActiveWatchingEntities)
|
|
{
|
|
@RenderEntityCard(entity)
|
|
}
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
<!-- Library / Completed Section -->
|
|
@if (LibraryEntities.Any())
|
|
{
|
|
<div class="mb-5">
|
|
<h2 class="mb-4">Bibliothek</h2>
|
|
<div class="row g-4">
|
|
@foreach (var entity in LibraryEntities)
|
|
{
|
|
@RenderEntityCard(entity)
|
|
}
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
@if (!PrivateEntities.Any())
|
|
{
|
|
<div class="text-center text-muted py-5">
|
|
<p>Keine Einträge vorhanden.</p>
|
|
</div>
|
|
}
|
|
</div>
|
|
|
|
@code
|
|
{
|
|
private List<PrivateEntity> PrivateEntities = new List<PrivateEntity>();
|
|
private List<UserWatchStatus> userWatchStatuses = new List<UserWatchStatus>();
|
|
ApplicationUser? AppUser = new();
|
|
|
|
private List<PrivateEntity> ActiveWatchingEntities => PrivateEntities.Where(x => x.UserWatchStatus?.Name == "Watching").ToList();
|
|
private List<PrivateEntity> LibraryEntities => PrivateEntities.Where(x => x.UserWatchStatus?.Name != "Watching").ToList();
|
|
|
|
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 RenderFragment RenderEntityCard(PrivateEntity Entity) => __builder =>
|
|
{
|
|
<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">
|
|
|
|
<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>
|
|
|
|
<!-- Content -->
|
|
<div class="col" style="min-width: 0;">
|
|
<div class="card-body d-flex flex-column h-100 py-2 px-3">
|
|
|
|
<!-- Header -->
|
|
<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>
|
|
|
|
<!-- Watch Status Dropdown -->
|
|
<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>
|
|
}
|
|
|
|
<!-- 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 -->
|
|
<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">
|
|
<button type="button" class="btn btn-danger" @onclick="@(e => RemoveEntityFromPrivateList(Entity))" data-bs-dismiss="modal">Aus PrivateList entfernen</button>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Schließen</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
};
|
|
|
|
private async Task RemoveEntityFromPrivateList(PrivateEntity entity)
|
|
{
|
|
//Delete DB
|
|
CouchLogDB.PrivateEntities.Remove(entity);
|
|
await CouchLogDB.SaveChangesAsync();
|
|
|
|
//Delete Memory List
|
|
PrivateEntities.Remove(entity);
|
|
}
|
|
|
|
private async Task UpdateWatchStatus(PrivateEntity entity, object? newValue)
|
|
{
|
|
if (int.TryParse(newValue?.ToString(), out int newId))
|
|
{
|
|
entity.UserWatchStatusId = newId;
|
|
entity.UserWatchStatus = userWatchStatuses.FirstOrDefault(s => s.Id == newId);
|
|
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();
|
|
}
|
|
}
|
|
} |