add edit/delete episode seens in episode seen history
This commit is contained in:
1 parent
dbeb0ee524
commit
a3f1b16376
9 files changed
+326
-57
No files matched your search
@@ -16,7 +16,8 @@
|
||||
<!-- Movie Side Info -->
|
||||
<ul class="list-group side-info">
|
||||
<li class="list-group-item"><strong>Rating:</strong> {{tmdbRating}}/10</li>
|
||||
<li class="list-group-item"><strong>Premiere:</strong> {{this.entry.release_date | dateFormat:'MMM dd, yyyy'}}</li>
|
||||
<li class="list-group-item"><strong>Premiere:</strong> {{this.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"><strong>Genre:</strong> {{genres}}</li>
|
||||
@@ -102,7 +103,8 @@
|
||||
<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" (episodeWatchedEvent)="onEpisodeWatchedEvent()">
|
||||
[@fadeInOut] [season]="season" (episodeWatchedEvent)="onEpisodeWatchedEvent()"
|
||||
(episodeWatchedDeletedEvent)="triggerEpisodeWatchedDeletedEvent()">
|
||||
</app-season-main-card>
|
||||
</div>
|
||||
<!-- show all/less when entry has more that 2 seasons -->
|
||||
@@ -122,7 +124,7 @@
|
||||
<h3>Collections</h3>
|
||||
</div>
|
||||
|
||||
<div class="row" *ngIf="this.entry.is_tvseries">
|
||||
<div class="row" *ngIf="this.entry.is_tvseries && this.seenHistory.length != 0">
|
||||
<h3>Watch History</h3>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
@@ -131,7 +133,7 @@
|
||||
<th>Episode</th>
|
||||
<th>Date Seen</th>
|
||||
<th>Seen With</th>
|
||||
<!-- Add more table headers as needed -->
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -140,6 +142,19 @@
|
||||
<td>{{ item.episode_number }}</td>
|
||||
<td>{{ item.date_seen | dateFormat:'MMM dd, yyyy' }}</td>
|
||||
<td>{{ item.seen_with }}</td>
|
||||
<td>
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-sm btn-filter dropdown-toggle dropdown-toggle-nocaret" type="button"
|
||||
data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="bi bi-three-dots"></i>
|
||||
</button>
|
||||
<ul class="dropdown-menu" style="cursor: pointer;">
|
||||
<li (click)="editEpisodeSeen(item)"><a class="dropdown-item">Edit</a></li>
|
||||
<li (click)="deleteEpisodeSeen(item)"><a class="dropdown-item">Delete</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -14,11 +14,9 @@ import { SeenModalComponent } from '../../../shared/components/modals/seen-modal
|
||||
|
||||
import { EntrySeenService } from '../../../core/services/entry-seen.service';
|
||||
import { EntryRatingsService } from '../../../core/services/entry-ratings.service';
|
||||
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';
|
||||
import { SeasonService } from '../../../core/services/season.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-entry-page',
|
||||
@@ -58,6 +56,7 @@ export class EntryPageComponent implements OnInit {
|
||||
public dialog: MatDialog,
|
||||
private episodeSeenService: EpisodeSeenService,
|
||||
private entryService: EntryService,
|
||||
private seasonService: SeasonService,
|
||||
private entrySeenService: EntrySeenService,
|
||||
private entryRatingsService: EntryRatingsService,
|
||||
private datePipe: DatePipe
|
||||
@@ -67,10 +66,31 @@ 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)
|
||||
);
|
||||
console.log(this.entry);
|
||||
|
||||
if (this.entry.is_tvseries) {
|
||||
// ? sorting seasons
|
||||
this.entry.seasons = this.entry.seasons.sort((a, b) =>
|
||||
a.name.localeCompare(b.name)
|
||||
);
|
||||
|
||||
// ? 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);
|
||||
// TODO show notification
|
||||
season.episodes = [];
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (!this.entry) {
|
||||
this.router.navigate(['/error'], {
|
||||
queryParams: { error: 'Entry not found' },
|
||||
@@ -106,14 +126,11 @@ export class EntryPageComponent implements OnInit {
|
||||
return;
|
||||
}
|
||||
|
||||
let watchDate = result.watchDate;
|
||||
let watchedWith = result.watchedWith.split('\n').join(', ');
|
||||
|
||||
this.entrySeenService
|
||||
.createEntrySeen(
|
||||
this.entry.id.toString(),
|
||||
result.watchDate,
|
||||
watchedWith
|
||||
)
|
||||
.createEntrySeen(this.entry.id.toString(), watchDate, watchedWith)
|
||||
.subscribe({
|
||||
next: (entrySeen) => {
|
||||
if (entrySeen) {
|
||||
@@ -151,10 +168,6 @@ export class EntryPageComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
onEpisodeWatchedEvent() {
|
||||
this.getEpisodesSeenHistory();
|
||||
}
|
||||
|
||||
removeEntrySeen(id: number) {
|
||||
// TODO add confirm modal
|
||||
this.entrySeenService.removeEntrySeen(id).subscribe({
|
||||
@@ -200,6 +213,13 @@ export class EntryPageComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
// ! EPISODE SEEN
|
||||
// ? episode marked as seen event
|
||||
onEpisodeWatchedEvent() {
|
||||
this.getEpisodesSeenHistory();
|
||||
}
|
||||
|
||||
// ? fetch episodes seen history
|
||||
getEpisodesSeenHistory() {
|
||||
if (!this.entry.is_tvseries) return;
|
||||
|
||||
@@ -233,21 +253,14 @@ export class EntryPageComponent implements OnInit {
|
||||
this.filterEpisodesSeenHistory();
|
||||
},
|
||||
error: (error) => {
|
||||
this.seenHistory = [] as EpisodeSeenDto[];
|
||||
this.filterEpisodesSeenHistory();
|
||||
console.log(error);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// nextPage(): void {
|
||||
// this.currentPage++;
|
||||
// }
|
||||
|
||||
// previousPage(): void {
|
||||
// if (this.currentPage > 1) {
|
||||
// this.currentPage--;
|
||||
// }
|
||||
// }
|
||||
|
||||
// ? filter episode seen history
|
||||
filterEpisodesSeenHistory() {
|
||||
var temp = [] as EpisodeSeenDto[];
|
||||
|
||||
@@ -261,11 +274,90 @@ export class EntryPageComponent implements OnInit {
|
||||
this.seenHistoryToShow = temp.slice(startIndex, endIndex);
|
||||
}
|
||||
|
||||
// totalPageCount(): number {
|
||||
// return this.seenHistory.length / this.pageSize;
|
||||
// }
|
||||
editEpisodeSeen(episodeSeen: EpisodeSeenDto) {
|
||||
if (episodeSeen == null) return;
|
||||
|
||||
// ? pagination
|
||||
const dialogRef = this.dialog.open(SeenModalComponent, {
|
||||
width: '400px',
|
||||
data: {
|
||||
watchDate: episodeSeen.date_seen,
|
||||
watchedWith: episodeSeen.seen_with,
|
||||
},
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((result) => {
|
||||
// ? dialog closed
|
||||
if (result == null) {
|
||||
return console.log('Seen dialog was cancelled');
|
||||
}
|
||||
|
||||
// ? dialog confimed
|
||||
console.log('Episode seen dialog closed with:', result);
|
||||
if (result.watchDate == '') {
|
||||
// TODO show no date was passed notification
|
||||
return console.log(`Episode seen dialog closed with no date.`);
|
||||
}
|
||||
|
||||
episodeSeen.date_seen = result.watchDate;
|
||||
episodeSeen.seen_with = result.watchedWith.split('\n').join(', ');
|
||||
|
||||
this.episodeSeenService.updateEpisodeSeen(episodeSeen).subscribe({
|
||||
next: () => {
|
||||
console.log(`Episode seen updated.`);
|
||||
this.getEpisodesSeenHistory();
|
||||
// TODO show notification
|
||||
},
|
||||
error: (error) => {
|
||||
console.log(`Episode seen update error: `, error);
|
||||
// TODO show notification
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
deleteEpisodeSeen(episodeSeen: EpisodeSeenDto) {
|
||||
if (episodeSeen.id == null) 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();
|
||||
|
||||
// trying to update 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();
|
||||
@@ -294,7 +386,7 @@ export class EntryPageComponent implements OnInit {
|
||||
(_, i) => startPage + i
|
||||
);
|
||||
}
|
||||
// ? end pagination
|
||||
// + end pagination
|
||||
|
||||
toggleShowAllSeasons() {
|
||||
this.showAll = !this.showAll;
|
||||
|
||||
Reference in new issue
Block a user