add alternate entry page view

This commit is contained in:
X4Lo committed 2025-02-15 23:38:02 +01:00
1 parent a91ee9fcd5
commit bb36b2bd44
6 files changed
+1131

No files matched your search

@@ -0,0 +1,84 @@
body {
background-color: transparent !important;
}
/* Make the background wrapper fixed */
.background-wrapper {
position: fixed;
width: 100%;
height: 100vh;
top: 0;
left: 0;
z-index: -1;
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
}
/* Keep the image fixed and apply blur */
.banner-img {
width: 100%;
height: 100%;
object-fit: cover;
position: absolute;
top: 0;
left: 0;
filter: blur(10px) brightness(50%);
}
/* Make sure the content scrolls over the fixed background */
.content-wrapper {
position: relative;
z-index: 2;
color: white;
/* Keep text readable */
padding-top: 50px;
}
.banner-img {
width: 100%;
height: 100%;
object-fit: cover;
filter: blur(4px) brightness(50%);
}
.banner-overlay {
position: absolute;
width: 100%;
height: 100%;
background: linear-gradient(to bottom, rgba(0, 0, 0, 0.7), transparent 40%, rgba(255, 255, 255, 0.8) 90%);
}
.fade-overlay {
position: absolute;
width: 100%;
height: 200px;
bottom: 0;
left: 0;
background: linear-gradient(to bottom, rgba(255, 255, 255, 0) 0%, white 100%);
z-index: 1;
}
.title, .sub-title{
color: white;
}
.card-img-overlay:hover h5 {
color: var(--shz-blue-default) !important;
}
.card-img-overlay {
cursor: pointer;
}
.collection-card:hover{
transform: translateY(-20px);
transition: transform 0.3s ease-in-out;
}
.collection-card,
.collection-card img {
aspect-ratio: 16/9;
height: 100%;
}
@@ -0,0 +1,177 @@
<!-- Banner Background -->
<div class="background-wrapper position-absolute">
<img [src]="banner" alt="Banner Image" class="banner-img">
<div class="banner-overlay"></div>
</div>
<div class="container mt-5 content-wrapper position-relative mb-5">
<!-- <div class="fade-overlay"></div> -->
<div class="row">
<!-- Left Sidebar: Movie Poster & Info -->
<div class="col-lg-3 left-col">
<div class="poster text-center">
<img [src]="poster" alt="Movie Poster" class="img-fluid rounded shadow" (click)="enlargePoster()">
</div>
<div class="d-flex justify-content-center mt-3 rating color-white">
<rating [(ngModel)]="entry.entryRating.user_rating" [max]="10" [readonly]="false"
(click)="onRatingChange($event)"></rating>
</div>
<div class="card mt-4 info-card">
<div class="card-body">
<h6 class="card-title text-center">Movie Info</h6>
<ul class="list-group list-group-flush">
<li class="list-group-item"><strong>Premiere:</strong> {{entry.release_date | dateFormat:'MMM dd, yyyy'}}
</li>
<li class="list-group-item" *ngIf="entry.is_tvseries"><strong>Next Episode:</strong> {{nextEpisode}}</li>
<li class="list-group-item"><strong>Status:</strong> {{status}}</li>
<li class="list-group-item" *ngIf="entry.date_first_seen"><strong>First Seen:</strong>
{{entry.date_first_seen | dateFormat:'MMM dd, yyyy'}}</li>
<li class="list-group-item" *ngIf="entry.date_last_seen"><strong>Last Seen:</strong> {{entry.date_last_seen
| dateFormat:'MMM dd, yyyy'}}</li>
</ul>
</div>
</div>
<!-- Watch History Accordion -->
<div class="card info-card mt-4" *ngIf="!entry.is_tvseries">
<div class="card-body">
<h6 class="card-title">Watch History</h6>
<div class="accordion" id="accordionWatchHistory">
<div class="accordion-item" *ngFor="let seen of entry.entrySeen">
<h2 class="accordion-header" id="heading{{seen.id}}">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
[attr.data-bs-target]="'#collapse'+seen.id" aria-expanded="false"
[attr.aria-controls]="'collapse' + seen.id">
{{seen.date_seen | dateFormat:"yyyy-MM-dd"}}
</button>
</h2>
<div id="collapse{{seen.id}}" class="accordion-collapse collapse"
[attr.aria-labelledby]="'heading' + seen.id" data-bs-parent="#accordionWatchHistory">
<div class="accordion-body" *ngIf="seen.seen_with.length != 0">
<strong>Seen With:</strong><br>
{{seen.seen_with}}
</div>
<div class="d-flex justify-content-end">
<button type="button" class="btn btn-icon-only" (click)="removeEntrySeen(seen.id)">
<span class="bi bi-trash"></span>
</button>
<button type="button" class="btn btn-icon-only" (click)="editEntrySeen(seen)">
<span class="bi bi-pencil"></span>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Main Content Area -->
<div class="col-lg-9 right-col">
<div class="d-flex justify-content-between align-items-center">
<h2 class="title">{{entry.title}}</h2>
<div class="d-flex gap-2 entry-actions">
<button class="btn btn-outline-primary btn-sm" (click)="toggleFavorite()"
[ngClass]="{ 'faved': entry.favorit }">
<i class="bi bi-star"></i>
</button>
<button class="btn btn-outline-secondary btn-sm" (click)="toggleHidden()">
<i class="bi bi-eye"></i>
</button>
<button class="btn btn-outline-success btn-sm" (click)="addToCollectionModal()">
<i class="bi bi-collection"></i>
</button>
<button class="btn btn-outline-success btn-sm" (click)="refrechEntry()">
<i class="bi bi-arrow-clockwise"></i>
</button>
<button class="btn btn-outline-success btn-sm" (click)="fetchEntryCollection()">
<i class="bi bi-arrow-repeat"></i>
</button>
<button class="btn btn-outline-success btn-sm" (click)="mediaModal()">
<i class="bi bi-image"></i>
</button>
<button class="btn btn-outline-success btn-sm" (click)="settingsModal()">
<i class="bi bi-gear"></i>
</button>
</div>
</div>
<p class="text-section">{{entry.original_title}} • {{entry.release_date | dateFormat:'yyyy'}} • {{genres}}</p>
<p><strong>{{entry.tagline}}</strong></p>
<p>{{entry.storyline}}</p>
<div class="seasons" *ngIf="entry.is_tvseries">
<h3 class="sub-title">Seasons</h3>
<div class="row row-cols-1 row-cols-md-2 g-3">
<app-season-main-card *ngFor="let season of (showAll ? entry.seasons : entry.seasons | slice:0:initialCount)"
[season]="season">
</app-season-main-card>
</div>
<!-- Show More / Show Less -->
<p class="text-center clickable mt-2 color-default" *ngIf="entry.seasons" (click)="toggleShowAllSeasons()"
style="cursor: pointer;">
{{ showAll ? 'Show Less' : 'Show All' }}
</p>
</div>
<!-- Collections Section -->
<div class="row mt-4" *ngIf="entry.collections.length > 0">
<div class="d-flex justify-content-between align-items-center mb-2">
<h3 class="sub-title">Belongs to Collection(s)</h3>
<button class="btn btn-sm btn-success" (click)="addToCollectionModal()">
<i class="bi bi-collection"></i> Add to Collection
</button>
</div>
<div class="card-body p-3 pb-0">
<div class="row g-3">
<div class="col-md-4" *ngFor="let collection of entry.collections">
<div class="card h-100 collection-card" [routerLink]="['/collections', collection.id]">
<div class="card-img-overlay d-flex align-items-center justify-content-center"
style="background-color: rgba(0, 0, 0, 0.5);">
<h5 class="text-white">{{ collection.name }}</h5>
</div>
<img [src]="collection.selectedBackdrop" alt="{{ collection.name }}" class="card-img">
</div>
</div>
</div>
</div>
</div>
<!-- Watch History Table -->
<div class="mt-4" *ngIf="entry.is_tvseries && seenHistoryToShow.length > 0">
<div class="d-flex justify-content-between align-items-center mb-2">
<h3 class="sub-title">Watch History</h3>
<button class="btn btn-sm btn-success" (click)="addEpisodeSeen()">
<i class="bi bi-plus-lg"></i> Add Watch Entry
</button>
</div>
<table class="table table-striped">
<thead>
<tr>
<th>Season</th>
<th>Episode</th>
<th>Date Seen</th>
<th>Seen With</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let item of seenHistoryToShow">
<td>{{ item.season_number == 0 ? 'Special' : 'Season '+ item.season_number }}</td>
<td>{{ item.episode_number }}</td>
<td>{{ item.date_seen | dateFormat:'MMM dd, yyyy' }}</td>
<td>{{ item.seen_with }}</td>
<td>
<button class="btn btn-sm btn-danger" (click)="deleteEpisodeSeen(item)">Delete</button>
<button class="btn btn-sm btn-primary" (click)="editEpisodeSeen(item)">Edit</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
@@ -0,0 +1,28 @@
/* tslint:disable:no-unused-variable */
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { AlternateEntryPageComponent } from './alternate-entry-page.component';
describe('AlternateEntryPageComponent', () => {
let component: AlternateEntryPageComponent;
let fixture: ComponentFixture<AlternateEntryPageComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AlternateEntryPageComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AlternateEntryPageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,832 @@
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { trigger, style, transition, animate } from '@angular/animations';
import { ActivatedRoute, Router } from '@angular/router';
import { MatDialog } from '@angular/material/dialog';
import { Entry } from '../../../shared/models/entry.model';
import { EpisodeSeenDto } from '../../../shared/models/dtos/episode-seen.dto';
import { UserCollectionsModalComponent } from '../../../shared/components/modals/list-selection-modal/user-collections-modal.component';
import { SeenModalComponent } from '../../../shared/components/modals/seen-modal/seen-modal.component';
import { ConfirmModalComponent } from '../../../shared/components/modals/confirm-modal/confirm-modal.component';
import { EntrySeenService } from '../../../core/services/entry-seen.service';
import { EntryRatingsService } from '../../../core/services/entry-ratings.service';
import { EntryService } from '../../../core/services/entry.service';
import { EpisodeSeenService } from '../../../core/services/episode-seen.service';
import { SeasonService } from '../../../core/services/season.service';
import { LibraryService } from '../../../core/services/library.service';
import { ToastrService } from 'ngx-toastr';
import { EntrySeen } from '../../../shared/models/entry-seen.model';
import { EpisodeSeenModalComponent } from '../../../shared/components/modals/episode-seen-modal/episode-seen-modal.component';
import { MediaModalComponent } from '../media-modal/media-modal.component';
import { environment } from '../../../../environments/environment.prod';
import { Collection } from '../../../shared/models/collection.model';
import { EntrySettingsModalComponent } from '../entry-settings-modal/entry-settings-modal.component';
@Component({
selector: 'app-alternate-entry-page',
templateUrl: './alternate-entry-page.component.html',
styleUrls: ['./alternate-entry-page.component.css'],
encapsulation: ViewEncapsulation.None,
animations: [
trigger('fadeInOut', [
transition(':enter', [
// void => *
style({ opacity: 0 }),
animate('0.5s ease-in', style({ opacity: 1 })),
]),
transition(':leave', [
// * => void
animate('0.5s ease-out', style({ opacity: 0 })),
]),
]),
],
})
export class AlternateEntryPageComponent implements OnInit {
entry: Entry = {} as Entry;
public showAll = false;
public initialCount = 2;
lockActions: boolean = false;
seenHistory: any[] = [];
seenHistoryToShow: any[] = [];
itemsCount: number = 0;
maxPage: number = 10;
currentPage: number = 1;
pageSize: number = 10;
constructor(
private episodeSeenService: EpisodeSeenService,
private entryService: EntryService,
private seasonService: SeasonService,
private entrySeenService: EntrySeenService,
private entryRatingsService: EntryRatingsService,
private libraryService: LibraryService,
private dialog: MatDialog,
private route: ActivatedRoute,
private router: Router,
private toastr: ToastrService
) {}
ngOnInit(): void {
this.route.data.subscribe(
(data) => {
this.entry = data['entry'] as Entry;
this.entry.isInLibrary = true;
this.entry.collections = this.entry.collections.map((c) => {
c.mediasCount = c.medias.length;
c.selectedBackdrop = this.getCollectionBackdropPath(c);
c.medias = [];
return c;
});
if (this.entry.is_tvseries) {
// ? sorting seasons
this.entry.seasons = this.entry.seasons.sort((a, b) => {
if (b.season_number == 0) b.season_number = 30; // this will make the special season go last
if (a.season_number == 0) a.season_number = 30; // this will make the special season go last
return a.season_number - b.season_number;
});
// ? getting seaons episodes
this.entry.seasons.forEach((season) => {
this.seasonService.getSeasonEpisodes(season.id).subscribe({
next: (episodes) => {
// console.log(
// `Loaded Season ${season.season_number} Episodes (${episodes.length})`
// );
season.episodes = episodes;
},
error: (error) => {
// console.log(`Couldn't fetch season episodes data:`, error);
this.toastr.success(
'Error',
`Couldn't get season ${season.season_number} episodes.`,
{
tapToDismiss: true,
progressBar: true,
positionClass: 'bottom-right',
progressAnimation: 'increasing',
}
);
season.episodes = [];
},
});
});
}
if (!this.entry) {
this.router.navigate(['/error'], {
queryParams: { error: 'Entry not found' },
});
}
},
(error) => {
console.error('Error when trying to access route data', error);
this.router.navigate(['/error'], {
queryParams: { error: 'Error fetching data' },
});
}
);
this.getEpisodesSeenHistory();
}
onRatingChange(event: Event) {
this.entryService
.updateEntryRatings(this.entry.id, this.entry.entryRating)
.subscribe({
next: (entryRatings) => {
if (entryRatings) {
// TODO show notification
this.entry.entryRating = entryRatings;
this.libraryService.setEntry(this.entry);
}
},
error: (error) => {
// TODO show notification
console.error('Error updating entryRatings:', error);
},
});
}
// ! ENTRY SEEN
openEntrySeenModal(entrySeen: EntrySeen = {} as EntrySeen) {
if (!this.entry) return;
let oldData = {} as { watchDate: Date; watchedWith: string };
if (entrySeen.id) {
oldData.watchDate = entrySeen.date_seen;
oldData.watchedWith = entrySeen.seen_with;
}
const dialogRef = this.dialog.open(SeenModalComponent, {
width: '360px',
data: oldData.watchDate ? oldData : {},
});
dialogRef.afterClosed().subscribe((result) => {
if (result) {
if (result.watchDate == '') {
// TODO show no was passed date notification
return;
}
let watchDate = result.watchDate;
let watchedWith = result.watchedWith.split('\n').join(', ');
if (entrySeen.id) {
const es = {
id: entrySeen.id,
date_seen: watchDate,
seen_with: watchedWith,
} as EntrySeen;
// * Update
this.entrySeenService.updateEntrySeen(es).subscribe({
next: (updatedEntrySeen) => {
if (updatedEntrySeen) {
// TODO show confirm notification
// ? replace the entry-seen object with the updated one
for (let i = 0; i < this.entry.entrySeen.length; i++) {
if (this.entry.entrySeen[i].id == updatedEntrySeen.id)
this.entry.entrySeen[i] = updatedEntrySeen;
}
}
},
error: (error) => {
console.error('Error adding entrySeen:', error);
},
});
} else {
// * Create
this.entrySeenService
.createEntrySeen(this.entry.id.toString(), watchDate, watchedWith)
.subscribe({
next: (entrySeen) => {
if (entrySeen) {
// TODO show confirm notification
this.entry.entrySeen.push(entrySeen);
// ? if the entry was in watch list creating and entry-seen would have removed it
// ? from the watchlist, so now we need to refrech libraryService in order to
// ? update the watchlist page
if (this.entry.watchlist) {
this.entry.watchlist = false;
this.libraryService.setEntry(this.entry);
// this.libraryService.refetchEntries().subscribe();
}
}
},
error: (error) => {
console.error('Error adding entrySeen:', error);
},
});
}
// TODO show notification
} else {
// console.log('Seen dialog was cancelled');
}
});
}
editEntrySeen(entrySeen: EntrySeen) {
this.openEntrySeenModal(entrySeen);
}
removeEntrySeen(id: number) {
const dialogRef = this.dialog.open(ConfirmModalComponent, {
width: '400px',
data: {
title: 'Confirmation',
message: `Are you sure you want to delete this?`,
type: 'danger',
},
});
dialogRef.afterClosed().subscribe((result) => {
if (result) {
if (result.confirmed != true) return;
this.entrySeenService.removeEntrySeen(id).subscribe({
next: () => {
this.toastr.success('success', `Removed successfuly.`, {
tapToDismiss: true,
progressBar: true,
positionClass: 'bottom-right',
progressAnimation: 'increasing',
});
this.entry.entrySeen = this.entry.entrySeen.filter(
(item) => item.id !== id
);
},
error: (error) => {
// TODO show notification
console.error('Error deleting entrySeen:', error);
},
});
}
});
}
toggleFavorite() {
this.lockActions = true;
this.entry.favorit = !this.entry.favorit;
const entryData = { favorit: this.entry.favorit };
this.entryService.updateEntry(this.entry.id, entryData).subscribe({
next: (entry) => {
// console.log(`Entry updated: `, entry);
this.entry = entry;
this.entry.isInLibrary = true;
this.libraryService.setEntry(this.entry);
},
error: (error) => {
console.log(`Error updating entry: `, error);
this.entry.favorit = !this.entry.favorit;
},
complete: () => {
this.lockActions = false;
},
});
}
toggleHidden() {
this.lockActions = true;
this.entry.hidden = !this.entry.hidden;
const entryData = { hidden: this.entry.hidden };
this.entryService.updateEntry(this.entry.id, entryData).subscribe({
next: (entry) => {
// console.log(`Entry updated: `, entry);
this.entry = entry;
this.entry.isInLibrary = true;
this.libraryService.setEntry(this.entry);
},
error: (error) => {
console.log(`Error updating entry: `, error);
this.entry.favorit = !this.entry.favorit;
},
complete: () => {
this.lockActions = false;
},
});
}
addToCollectionModal() {
if (this.entry) {
const dialogRef = this.dialog.open(UserCollectionsModalComponent, {
width: '400px',
height: '55%',
data: {
entryId: this.entry.id,
},
});
dialogRef.afterClosed().subscribe((result) => {
// TODO update entry page collections
this.entryService.getEntryById(this.entry.id).subscribe({
next: (result) => {
this.entry.collections = result.collections.map((c) => {
c.mediasCount = c.medias.length;
c.selectedBackdrop = this.getCollectionBackdropPath(c);
c.medias = [];
return c;
});
result.collections;
},
});
});
}
}
getCollectionBackdropPath(collection: Collection) {
// console.log(`collection media:`, collection.medias);
if (collection.medias && collection.medias.length != 0) {
const backdrops = collection.medias.filter((m) => m.type == 'backdrop');
if (backdrops.length != 0) {
const selectedBackdrops = backdrops.filter(
(m) => m.type == 'backdrop' && m.isSelected
);
// console.log(selectedBackdrops);
let selectedBackdrop;
if (selectedBackdrops.length != 0) {
selectedBackdrop = selectedBackdrops[0].path;
} else {
selectedBackdrop = backdrops[0].path;
}
return (
environment.API_URL +
`/media/collections/backdrops/preview/${selectedBackdrop}`
);
}
}
// if (collection.entries && collection.entries.length != 0) {
// // * use the poster of the first entry in the collection
// // * if the collection is empty
// return this.getEntryBackdropPath(collection.entries[0]);
// } else
if (collection.backdropPath) {
// * use first remote tmdb poster
// * if collection has none and has no entry
return `https://image.tmdb.org/t/p/w1280/${collection.backdropPath}`;
} else {
// * use default poster
// * if collection has totaly no poster
return 'assets/images/default/default-backdrop.png';
}
}
getEntryBackdropPath(entry: Entry) {
return '';
}
refrechEntry() {
this.lockActions = true;
this.entryService.refrechEntryById(this.entry.id).subscribe({
next: (entry) => {
this.entry = entry;
this.entry.isInLibrary = true;
this.entry.collections = this.entry.collections.map((c) => {
c.mediasCount = c.medias.length;
c.selectedBackdrop = this.getCollectionBackdropPath(c);
c.medias = [];
return c;
});
// console.log(`Entry refreched: `, entry);
this.toastr.success(`Movie refreshed successfuly.`, 'Success', {
tapToDismiss: true,
progressBar: true,
positionClass: 'bottom-right',
progressAnimation: 'increasing',
});
},
error: (error) => {
// TODO show error notification
console.error('Error refreching movie info:', error);
},
complete: () => {
this.lockActions = false;
},
});
}
fetchEntryCollection() {
this.lockActions = true;
this.entryService.fetchEntryCollectionById(this.entry.id).subscribe({
next: (result) => {},
error: (error) => {
// TODO show error notification
console.error('Error refreching movie info:', error);
},
complete: () => {
this.lockActions = false;
},
});
}
// ! EPISODE SEEN
// ? episode marked as seen event
onEpisodeWatchedEvent() {
this.getEpisodesSeenHistory();
}
// ? fetch episodes seen history
getEpisodesSeenHistory() {
if (!this.entry.is_tvseries) return;
this.episodeSeenService.getEpisodeSeenByEntryId(this.entry.id).subscribe({
next: (data) => {
let episodeSeens = [] as EpisodeSeenDto[];
// mapping
data.forEach((item) => {
let e = {
id: item.id,
entryId: item.entry_id,
episodeId: item.episode_id,
season_number: item.episode.season.season_number,
episode_number: item.episode.episode_number,
date_seen: item.date_seen,
seen_with: item.seen_with,
createdAt: item.createdAt,
updatedAt: item.updatedAt,
} as EpisodeSeenDto;
episodeSeens.push(e);
});
this.seenHistory = episodeSeens;
// console.log(`Episode Seen History Received: `, episodeSeens);
this.filterEpisodesSeenHistory();
},
error: (error) => {
this.seenHistory = [] as EpisodeSeenDto[];
this.filterEpisodesSeenHistory();
console.log(`Error getting episodes watch history`, error);
},
});
}
// ? filter episode seen history
filterEpisodesSeenHistory() {
var temp = [] as EpisodeSeenDto[];
temp = this.seenHistory;
const startIndex = (this.currentPage - 1) * this.pageSize;
const endIndex = startIndex + this.pageSize;
this.itemsCount = temp.length;
this.maxPage = Math.ceil(this.itemsCount / this.pageSize);
this.seenHistoryToShow = temp.slice(startIndex, endIndex);
}
addEpisodeSeen() {
if (!this.entry) return;
this.seenHistory[0];
const dialogRef = this.dialog.open(EpisodeSeenModalComponent, {
width: '360px',
data: {
entryId: this.entry.id,
season_number: this.seenHistory[0].season_number,
episode_number: this.seenHistory[0].episode_number,
},
});
dialogRef.afterClosed().subscribe((result) => {
// ? if an episode-seen was created then refresh the watch history table
if (result && result.created) {
// ? call this function to fetch the new episode-seen history
this.getEpisodesSeenHistory();
// ? Updating the episodes seen progress bar in the season card
// ? by fetching a new updated episodes list
this.entry.seasons.forEach(async (season) => {
if (season.season_number == result.season_number) {
this.seasonService.getSeasonEpisodes(season.id).subscribe({
next: (episodes) => {
// console.log(
// `Loaded Season ${season.season_number} Episodes (${episodes.length})`
// );
season.episodes = episodes;
},
error: (error) => {
console.log(`Couldn't fetch season episodes data:`, error);
// TODO show notification
season.episodes = [];
},
});
}
});
}
});
}
editEpisodeSeen(episodeSeen: EpisodeSeenDto) {
if (episodeSeen == null) return;
const dialogRef = this.dialog.open(EpisodeSeenModalComponent, {
width: '360px',
data: {
entryId: this.entry.id,
episodeSeen: episodeSeen,
},
});
dialogRef.afterClosed().subscribe((result) => {
if (result == null) return;
if (!result.updated) return;
// ? call this function to fetch the new episode-seen history
this.getEpisodesSeenHistory();
});
}
deleteEpisodeSeen(episodeSeen: EpisodeSeenDto) {
if (episodeSeen.id == null) return;
const dialogRef = this.dialog.open(ConfirmModalComponent, {
width: '400px',
data: {
title: 'Confirmation',
message: `Are you sure you want to delete this?`,
type: 'danger',
},
});
dialogRef.afterClosed().subscribe((result) => {
if (result) {
if (result.confirmed != true) return;
// first start by calling the service and deleting the episode-seen
this.episodeSeenService.removeEpisodeSeen(episodeSeen.id).subscribe({
next: () => {
// console.log(`Episode seen deleted.`);
// ? call this function to fetch the new episode-seen history
// this.getEpisodesSeenHistory();
this.seenHistory = this.seenHistory.filter(
(eps) => eps.id != episodeSeen.id
);
this.filterEpisodesSeenHistory();
// ? Updating the episodes seen progress bar in the season card
// ? by fetching a new updated episodes list
this.entry.seasons.forEach(async (season) => {
if (season.season_number == episodeSeen.season_number) {
this.seasonService.getSeasonEpisodes(season.id).subscribe({
next: (episodes) => {
// console.log(
// `Loaded Season ${season.season_number} Episodes (${episodes.length})`
// );
season.episodes = episodes;
},
error: (error) => {
console.log(`Couldn't fetch season episodes data:`, error);
// TODO show notification
season.episodes = [];
},
});
}
});
// TODO show notification
},
error: (error) => {
console.log(`Episode seen delete error: `, error);
},
});
}
});
}
triggerEpisodeWatchedDeletedEvent() {
// console.log(`Emitted Episode Watched Deleted Event`);
}
// + end EPISODE SEEN
// ! pagination
goToPage(page: number) {
this.currentPage = page;
this.filterEpisodesSeenHistory();
}
get pageNumbers(): number[] {
let pagesToShow = 5; // Total pages to show at any time
let startPage: number, endPage: number;
if (this.maxPage <= pagesToShow) {
startPage = 1;
endPage = this.maxPage;
} else {
startPage = Math.max(this.currentPage - Math.floor(pagesToShow / 2), 1);
endPage = startPage + pagesToShow - 1;
if (endPage >= this.maxPage) {
endPage = this.maxPage;
startPage = endPage - pagesToShow + 1;
}
}
// Generate the page numbers array.
return Array.from(
{ length: endPage - startPage + 1 },
(_, i) => startPage + i
);
}
// + end pagination
toggleShowAllSeasons() {
this.showAll = !this.showAll;
}
redirectToTmdb() {
let type = this.entry.is_tvseries ? 'tv' : 'movie';
window.open(
`https://www.themoviedb.org/${type}/${this.entry.entryId.tmdb_id}`,
'_blank'
);
}
enlargePoster() {
let poster;
// * Not in library, use TMDB poster
if (!this.entry.isInLibrary)
poster = `https://image.tmdb.org/t/p/w300` + this.entry.poster_path;
// * Is in library: use a local poster
if (!poster && this.entry.medias) {
const selectedPosters = this.entry.medias.filter(
(m) => m.type == 'poster' && m.isSelected
);
if (
selectedPosters.length &&
selectedPosters[0] &&
selectedPosters[0].path
) {
poster =
environment.API_URL +
`/media/entries/posters/original/${selectedPosters[0].path}`;
}
}
// * No local poster available, Use TMDB poster
if (!poster && this.entry.poster_path)
poster = `https://image.tmdb.org/t/p/original` + this.entry.poster_path;
// * No poster found, use default poster image as a last stand
if (!poster) poster = 'assets/images/default/default-poster.png';
window.open(poster, '_blank');
}
mediaModal() {
const dialogRef = this.dialog.open(MediaModalComponent, {
width: '800px',
height: '600px',
minHeight: '50%',
panelClass: 'media-dialog-container',
data: {
entry: this.entry,
},
});
dialogRef.afterClosed().subscribe((result) => {
if (result) {
// TODO show notification
} else {
// console.log('Seen dialog was cancelled');
}
});
}
settingsModal() {
const dialogRef = this.dialog.open(EntrySettingsModalComponent, {
width: '400px',
// height: '600px',
minHeight: '50%',
panelClass: 'media-dialog-container',
data: {
entry: this.entry,
},
});
dialogRef.afterClosed().subscribe((result) => {
if (result) {
this.entry.watchlist = result.entry.watchlist;
this.entry.favorit = result.entry.favorit;
this.entry.hidden = result.entry.hidden;
this.entry.showInCalendar = result.entry.showInCalendar;
this.entry.autoSync = result.entry.autoSync;
this.libraryService.setEntry(this.entry);
}
});
}
// * getters
get status() {
return this.entry.status;
}
get runtime() {
return this.entry.runtime;
}
get genres(): string {
return this.entry.genres.join(', ');
}
get poster(): string {
// * Not in library, use TMDB poster
if (!this.entry.isInLibrary)
return `https://image.tmdb.org/t/p/w300` + this.entry.poster_path;
// * Is in library: use a local poster
if (this.entry.medias) {
const selectedPosters = this.entry.medias.filter(
(m) => m.type == 'poster' && m.isSelected
);
if (
selectedPosters.length &&
selectedPosters[0] &&
selectedPosters[0].path
) {
return (
environment.API_URL +
`/media/entries/posters/original/${selectedPosters[0].path}`
);
}
}
// * No local poster available, Use TMDB poster
if (this.entry.poster_path)
return `https://image.tmdb.org/t/p/w300` + this.entry.poster_path;
// * No poster found, use default poster image as a last stand
return 'assets/images/default/default-poster.png';
}
get banner(): string {
// * Is in library: use a local backdrop
if (this.entry.medias) {
const selectedBackdrop = this.entry.medias.filter(
(m) => m.type == 'backdrop' && m.isSelected
);
if (
selectedBackdrop.length &&
selectedBackdrop[0] &&
selectedBackdrop[0].path
) {
return (
environment.API_URL +
`/media/entries/backdrops/original/${selectedBackdrop[0].path}`
);
}
}
// * No local backdrop available, Use TMDB backdrop
if (this.entry.banner_path)
return `https://image.tmdb.org/t/p/w1280` + this.entry.banner_path;
// * No backdrop found, use default backdrop image as a last stand
return 'assets/images/default/default-poster.png';
}
get nextEpisode() {
if (!this.entry.is_tvseries) return 'This is a movie';
return 'sooon';
}
fetchEntry() {
this.entryService.getEntryById(this.entry.id).subscribe({
next: (result) => {
this.entry = { ...result, isInLibrary: true };
},
});
}
}
@@ -2,6 +2,7 @@ import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router'; import { Routes, RouterModule } from '@angular/router';
import { EntryPageComponent } from './entry-page/entry-page.component'; import { EntryPageComponent } from './entry-page/entry-page.component';
import { EntryResolverService } from '../../core/resolvers/entry-resolver.service'; import { EntryResolverService } from '../../core/resolvers/entry-resolver.service';
import { AlternateEntryPageComponent } from './alternate-entry-page/alternate-entry-page.component';
const routes: Routes = [ const routes: Routes = [
{ {
@@ -11,6 +12,13 @@ const routes: Routes = [
entry: EntryResolverService, entry: EntryResolverService,
}, },
}, },
{
path: ':id/alternate',
component: AlternateEntryPageComponent,
resolve: {
entry: EntryResolverService,
},
},
]; ];
@NgModule({ @NgModule({
@@ -8,10 +8,12 @@ import { SeasonMainCardComponent } from './season-main-card/season-main-card.com
import { MediaModalComponent } from './media-modal/media-modal.component'; import { MediaModalComponent } from './media-modal/media-modal.component';
import { MediaUploadModalComponent } from './media-upload-modal/media-upload-modal.component'; import { MediaUploadModalComponent } from './media-upload-modal/media-upload-modal.component';
import { EntrySettingsModalComponent } from './entry-settings-modal/entry-settings-modal.component'; import { EntrySettingsModalComponent } from './entry-settings-modal/entry-settings-modal.component';
import { AlternateEntryPageComponent } from './alternate-entry-page/alternate-entry-page.component';
@NgModule({ @NgModule({
declarations: [ declarations: [
EntryPageComponent, EntryPageComponent,
AlternateEntryPageComponent,
SeasonMainCardComponent, SeasonMainCardComponent,
MediaModalComponent, MediaModalComponent,
MediaUploadModalComponent, MediaUploadModalComponent,