add episode seen history in entry page

This commit is contained in:
X4Lo committed 2024-04-22 17:41:30 +01:00
1 parent cf305cabae
commit dbeb0ee524
11 files changed
+288 -64

No files matched your search

@@ -67,7 +67,7 @@
<!-- Interraction buttons -->
<div class="row">
<button class="btn btn-icon-only-success wh-48" *ngIf="!entry.is_tvseries" (click)="openDialog()">
<button class="btn btn-icon-only-success wh-48" *ngIf="!entry.is_tvseries" (click)="openEntrySeenModal()">
<span class="material-symbols-outlined">
visibility
</span>
@@ -102,7 +102,7 @@
<div class="d-flex flex-column gap-3">
<app-season-main-card
*ngFor="let season of (showAll ? entry.seasons : entry.seasons | slice:0:initialCount); let i = index"
[@fadeInOut] [season]="season">
[@fadeInOut] [season]="season" (episodeWatchedEvent)="onEpisodeWatchedEvent()">
</app-season-main-card>
</div>
<!-- show all/less when entry has more that 2 seasons -->
@@ -121,6 +121,49 @@
<div class="row">
<h3>Collections</h3>
</div>
<div class="row" *ngIf="this.entry.is_tvseries">
<h3>Watch History</h3>
<table class="table table-striped">
<thead>
<tr>
<th>Season</th>
<th>Episode</th>
<th>Date Seen</th>
<th>Seen With</th>
<!-- Add more table headers as needed -->
</tr>
</thead>
<tbody>
<tr *ngFor="let item of seenHistoryToShow; let i = index">
<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>
</tr>
</tbody>
</table>
<div class="pagination-container d-flex justify-content-end" *ngIf="maxPage > 1">
<ul class="pagination pagination-sm">
<li class="page-item" [class.disabled]="currentPage === 1">
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage - 1)">Previous</a>
</li>
<!-- Dynamically generate page numbers -->
<li class="page-item" *ngFor="let page of pageNumbers" [class.active]="currentPage === page">
<a class="page-link" href="javascript:;" (click)="goToPage(page)">{{ page }}</a>
</li>
<li class="page-item" [class.disabled]="currentPage == maxPage">
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage + 1)">Next</a>
</li>
</ul>
</div>
<!--
<div>
<button (click)="previousPage()" [disabled]="currentPage === 1">Previous</button>
<button (click)="nextPage()" [disabled]="currentPage === totalPageCount()">Next</button>
</div> -->
</div>
</div>
@@ -1,10 +1,11 @@
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { trigger, state, style, transition, animate } from '@angular/animations';
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 { DatePipe } from '@angular/common';
@@ -16,6 +17,8 @@ import { EntryRatingsService } from '../../../core/services/entry-ratings.servic
import { TmdbService } from '../../../core/services/tmdb.service';
import { LibraryService } from '../../../core/services/library.service';
import { EntryService } from '../../../core/services/entry.service';
import { EpisodeSeenService } from '../../../core/services/episode-seen.service';
import e from 'express';
@Component({
selector: 'app-entry-page',
@@ -24,14 +27,16 @@ import { EntryService } from '../../../core/services/entry.service';
encapsulation: ViewEncapsulation.None,
animations: [
trigger('fadeInOut', [
transition(':enter', [ // void => *
transition(':enter', [
// void => *
style({ opacity: 0 }),
animate('0.5s ease-in', style({ opacity: 1 }))
animate('0.5s ease-in', style({ opacity: 1 })),
]),
transition(':leave', [ // * => void
animate('0.5s ease-out', style({ opacity: 0 }))
])
])
transition(':leave', [
// * => void
animate('0.5s ease-out', style({ opacity: 0 })),
]),
]),
],
})
export class EntryPageComponent implements OnInit {
@@ -39,12 +44,19 @@ export class EntryPageComponent implements OnInit {
public showAll = false;
public initialCount = 2;
seenHistory: any[] = [];
seenHistoryToShow: any[] = [];
itemsCount: number = 0;
maxPage: number = 10;
currentPage: number = 1;
pageSize: number = 10;
constructor(
private route: ActivatedRoute,
private router: Router,
public dialog: MatDialog,
private tmdbService: TmdbService,
private libraryService: LibraryService,
private episodeSeenService: EpisodeSeenService,
private entryService: EntryService,
private entrySeenService: EntrySeenService,
private entryRatingsService: EntryRatingsService,
@@ -55,7 +67,9 @@ export class EntryPageComponent implements OnInit {
this.route.data.subscribe(
(data) => {
this.entry = data['entry'] as Entry;
this.entry.seasons = this.entry.seasons.sort((a, b) => a.name.localeCompare(b.name));
this.entry.seasons = this.entry.seasons.sort((a, b) =>
a.name.localeCompare(b.name)
);
console.log(this.entry);
if (!this.entry) {
this.router.navigate(['/error'], {
@@ -70,9 +84,11 @@ export class EntryPageComponent implements OnInit {
});
}
);
this.getEpisodesSeenHistory();
}
openDialog() {
openEntrySeenModal() {
if (!this.entry) return;
const dialogRef = this.dialog.open(SeenModalComponent, {
@@ -135,6 +151,10 @@ export class EntryPageComponent implements OnInit {
});
}
onEpisodeWatchedEvent() {
this.getEpisodesSeenHistory();
}
removeEntrySeen(id: number) {
// TODO add confirm modal
this.entrySeenService.removeEntrySeen(id).subscribe({
@@ -180,6 +200,102 @@ export class EntryPageComponent implements OnInit {
});
}
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) => {
console.log(error);
},
});
}
// nextPage(): void {
// this.currentPage++;
// }
// previousPage(): void {
// if (this.currentPage > 1) {
// this.currentPage--;
// }
// }
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);
}
// totalPageCount(): number {
// return this.seenHistory.length / this.pageSize;
// }
// ? 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;
}