add fetch entry collection + change to seen modals & improvements

This commit is contained in:
X4Lo committed 2024-09-10 01:19:17 +01:00
1 parent 776506b232
commit 41666cc6a3
7 files changed
+171 -82

No files matched your search

@@ -69,6 +69,12 @@ export class EntryService {
); );
} }
fetchEntryCollectionById(entryId: number) {
return this.http.get<any>(
`${this.backend_apiUrl}/${this.apiAction}/${entryId}/fetch-collection`
);
}
// delete entry // delete entry
removeEntryById(entryId: string) { removeEntryById(entryId: string) {
return this.http.delete<Entry>( return this.http.delete<Entry>(
@@ -161,6 +161,12 @@
</span> </span>
</button> </button>
<button class="btn btn-icon-only-success wh-48" (click)="fetchEntryCollection()">
<span class="material-symbols-outlined">
published_with_changes
</span>
</button>
<button class="btn btn-icon-only-success wh-48" (click)="mediaModal()"> <button class="btn btn-icon-only-success wh-48" (click)="mediaModal()">
<span class="material-symbols-outlined"> <span class="material-symbols-outlined">
image image
@@ -183,7 +189,7 @@
</div> </div>
<!-- Series Seasons --> <!-- Series Seasons -->
<div class="row" *ngIf="entry.is_tvseries"> <div class="row" *ngIf="entry.is_tvseries">
<h3>Seasons</h3> <h3 class="opacity-100">Seasons</h3>
<div class="card-body p-0"> <div class="card-body p-0">
<div class="p-3 ps ps--active-y"> <div class="p-3 ps ps--active-y">
<div class="d-flex flex-column gap-3"> <div class="d-flex flex-column gap-3">
@@ -21,6 +21,7 @@ import { ToastrService } from 'ngx-toastr';
import { EntrySeen } from '../../../shared/models/entrySeen.model'; import { EntrySeen } from '../../../shared/models/entrySeen.model';
import { EpisodeSeenModalComponent } from '../../../shared/components/modals/episode-seen-modal/episode-seen-modal.component'; import { EpisodeSeenModalComponent } from '../../../shared/components/modals/episode-seen-modal/episode-seen-modal.component';
import { MediaModalComponent } from '../media-modal/media-modal.component'; import { MediaModalComponent } from '../media-modal/media-modal.component';
import { environment } from '../../../../environments/environment.prod';
@Component({ @Component({
selector: 'app-entry-page', selector: 'app-entry-page',
@@ -338,6 +339,20 @@ export class EntryPageComponent implements OnInit {
}); });
} }
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 SEEN
// ? episode marked as seen event // ? episode marked as seen event
onEpisodeWatchedEvent() { onEpisodeWatchedEvent() {
@@ -402,10 +417,14 @@ export class EntryPageComponent implements OnInit {
addEpisodeSeen() { addEpisodeSeen() {
if (!this.entry) return; if (!this.entry) return;
this.seenHistory[0]
const dialogRef = this.dialog.open(EpisodeSeenModalComponent, { const dialogRef = this.dialog.open(EpisodeSeenModalComponent, {
width: '360px', width: '360px',
data: { data: {
entryId: this.entry.id, entryId: this.entry.id,
season_number: this.seenHistory[0].season_number,
episode_number: this.seenHistory[0].episode_number,
}, },
}); });
@@ -441,39 +460,20 @@ export class EntryPageComponent implements OnInit {
editEpisodeSeen(episodeSeen: EpisodeSeenDto) { editEpisodeSeen(episodeSeen: EpisodeSeenDto) {
if (episodeSeen == null) return; if (episodeSeen == null) return;
const dialogRef = this.dialog.open(SeenModalComponent, { const dialogRef = this.dialog.open(EpisodeSeenModalComponent, {
width: '360px', width: '360px',
data: { data: {
watchDate: episodeSeen.date_seen, entryId: this.entry.id,
watchedWith: episodeSeen.seen_with, episodeSeen: episodeSeen,
}, },
}); });
dialogRef.afterClosed().subscribe((result) => { dialogRef.afterClosed().subscribe((result) => {
// ? dialog closed
if (result == null) return; if (result == null) return;
// ? dialog confimed if (!result.updated) return;
// console.log('Episode seen dialog closed with:', result);
if (result.watchDate == '') {
// TODO show no date was passed notification
console.log(`Episode seen dialog closed with no date.`);
return;
}
episodeSeen.date_seen = result.watchDate; // ? call this function to fetch the new episode-seen history
episodeSeen.seen_with = result.watchedWith.split('\n').join(', '); this.getEpisodesSeenHistory();
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
},
});
}); });
} }
@@ -587,7 +587,7 @@ export class EntryPageComponent implements OnInit {
// * Is in library: use a local poster // * Is in library: use a local poster
if (!poster && this.entry.medias) { if (!poster && this.entry.medias) {
const selectedPosters = this.entry.medias.filter( const selectedPosters = this.entry.medias.filter(
(m) => m.type == 'poster' && m.is_selected (m) => m.type == 'poster' && m.isSelected
); );
if ( if (
@@ -595,7 +595,9 @@ export class EntryPageComponent implements OnInit {
selectedPosters[0] && selectedPosters[0] &&
selectedPosters[0].path selectedPosters[0].path
) { ) {
poster = `http://localhost:4000/api/v1/media/entries/posters/${selectedPosters[0].path}`; poster =
environment.API_URL +
`/media/entries/posters/original/${selectedPosters[0].path}`;
} }
} }
@@ -650,7 +652,7 @@ export class EntryPageComponent implements OnInit {
// * Is in library: use a local poster // * Is in library: use a local poster
if (this.entry.medias) { if (this.entry.medias) {
const selectedPosters = this.entry.medias.filter( const selectedPosters = this.entry.medias.filter(
(m) => m.type == 'poster' && m.is_selected (m) => m.type == 'poster' && m.isSelected
); );
if ( if (
@@ -658,7 +660,10 @@ export class EntryPageComponent implements OnInit {
selectedPosters[0] && selectedPosters[0] &&
selectedPosters[0].path selectedPosters[0].path
) { ) {
return `http://localhost:4000/api/v1/media/entries/posters/${selectedPosters[0].path}`; return (
environment.API_URL +
`/media/entries/posters/original/${selectedPosters[0].path}`
);
} }
} }
@@ -674,7 +679,7 @@ export class EntryPageComponent implements OnInit {
// * Is in library: use a local backdrop // * Is in library: use a local backdrop
if (this.entry.medias) { if (this.entry.medias) {
const selectedBackdrop = this.entry.medias.filter( const selectedBackdrop = this.entry.medias.filter(
(m) => m.type == 'backdrop' && m.is_selected (m) => m.type == 'backdrop' && m.isSelected
); );
if ( if (
@@ -682,7 +687,10 @@ export class EntryPageComponent implements OnInit {
selectedBackdrop[0] && selectedBackdrop[0] &&
selectedBackdrop[0].path selectedBackdrop[0].path
) { ) {
return `http://localhost:4000/api/v1/media/entries/backdrops/${selectedBackdrop[0].path}`; return (
environment.API_URL +
`/media/entries/backdrops/original/${selectedBackdrop[0].path}`
);
} }
} }
@@ -29,7 +29,7 @@
<div class="col-md-12"> <div class="col-md-12">
<label class="form-label">Date Watched</label> <label class="form-label">Date Watched</label>
<input type="text" class="form-control rounded-0" name="watch-date" [(ngModel)]="watchDate" id="myDatepicker"> <input type="date" class="form-control rounded-0" name="watch-date" [(ngModel)]="watchDate" id="myDatepicker">
</div> </div>
<div class="col-md-12"> <div class="col-md-12">
@@ -9,11 +9,11 @@ import {
animate, animate,
} from '@angular/animations'; } from '@angular/animations';
import { formatDate } from '@angular/common'; import { formatDate } from '@angular/common';
import flatpickr from 'flatpickr';
import { Season } from '../../../models/season.model'; import { Season } from '../../../models/season.model';
import { SeasonService } from '../../../../core/services/season.service'; import { SeasonService } from '../../../../core/services/season.service';
import { Episode } from '../../../models/episode.models'; import { Episode } from '../../../models/episode.models';
import { EpisodeSeenService } from '../../../../core/services/episode-seen.service'; import { EpisodeSeenService } from '../../../../core/services/episode-seen.service';
import { EpisodeSeenDto } from '../../../models/dtos/episode-seen.dto';
@Component({ @Component({
selector: 'app-episode-seen-modal', selector: 'app-episode-seen-modal',
@@ -41,6 +41,7 @@ export class EpisodeSeenModalComponent {
public entryId: number = 0; public entryId: number = 0;
public watchDate: string = ''; public watchDate: string = '';
public watchedWith: string = ''; public watchedWith: string = '';
public episodeSeen: EpisodeSeenDto = {} as EpisodeSeenDto;
public seasons: Season[] = []; public seasons: Season[] = [];
public selectedSeason: Season | null = {} as Season; public selectedSeason: Season | null = {} as Season;
@@ -54,28 +55,84 @@ export class EpisodeSeenModalComponent {
) {} ) {}
ngOnInit(): void { ngOnInit(): void {
if (!this.data.entryId) return; if (!this.data) return;
this.entryId = this.data.entryId; this.entryId = this.data.entryId;
if (this.data.episodeSeen) {
this.episodeSeen = this.data.episodeSeen;
this.watchDate = formatDate(
new Date(this.data.episodeSeen.date_seen),
'yyyy-MM-dd',
'en-US'
);
this.watchedWith = this.data.episodeSeen.seen_with;
} else {
this.watchDate = formatDate(new Date(), 'yyyy-MM-dd', 'en-US');
// ? these season and episode number are from the latest watched episode
// ? used to determine the next episode to watch and automaticaly select it
this.episodeSeen.season_number = this.data.season_number;
this.episodeSeen.episode_number = this.data.episode_number;
}
this.seasonsService this.seasonsService
.getSeasonsWithEpisodesByEntryId(this.data.entryId) .getSeasonsWithEpisodesByEntryId(this.data.entryId)
.subscribe({ .subscribe({
next: (seasons) => { next: (seasons) => {
this.seasons = seasons; this.seasons = seasons;
// * on update mode
if (this.data.episodeSeen) {
this.seasons.forEach((s) => {
if (s.season_number == this.episodeSeen.season_number) {
this.selectedSeason = s;
s.episodes.forEach((e) => {
if (e.episode_number == this.episodeSeen.episode_number) {
this.selectedEpisode = e;
}
});
}
});
} else {
// * create mode
let season = this.seasons.find(
(s) => s.season_number == this.episodeSeen.season_number
);
let episode = season?.episodes.find(
(e) => e.episode_number == this.episodeSeen.episode_number + 1
);
if (episode) {
this.selectedSeason = season!;
this.selectedEpisode = episode;
} else {
season = this.seasons.find(
(s) => s.season_number == this.episodeSeen.season_number + 1
);
if (season) {
episode = season?.episodes.find((e) => e.episode_number == 1);
if (episode) {
this.selectedSeason = season!;
this.selectedEpisode = episode!;
}
}
}
}
}, },
error: (error) => { error: (error) => {
console.log(`Error gettings seasons: `, error); console.log(`Error gettings seasons: `, error);
}, },
}); });
flatpickr('#myDatepicker', { // flatpickr('#myDatepicker', {
inline: true, // inline: true,
defaultDate: this.watchDate, // defaultDate: this.watchDate,
altInput: true, // altInput: true,
allowInput: false, // allowInput: false,
altFormat: 'F j, Y', // altFormat: 'F j, Y',
dateFormat: 'Y-m-d', // dateFormat: 'Y-m-d',
}); // });
} }
onSeasonChange(event: any): void { onSeasonChange(event: any): void {
@@ -83,48 +140,55 @@ export class EpisodeSeenModalComponent {
} }
onConfirm(): void { onConfirm(): void {
if (!this.selectedSeason) { if (!this.selectedSeason || !this.selectedEpisode || !this.watchDate) {
return;
}
if (!this.selectedEpisode) {
return;
}
if (!this.watchDate) {
return; return;
} }
const date_seen = new Date(this.watchDate); const date_seen = new Date(this.watchDate);
const seen_with = this.watchedWith.split('\n').join(', '); const seen_with = this.watchedWith.split('\n').join(', ');
this.episodeSeenService this.episodeSeen.date_seen = date_seen;
.createEpisodeSeen( this.episodeSeen.seen_with = seen_with;
this.entryId, if (this.episodeSeen.id) {
this.selectedEpisode?.id, this.episodeSeenService.updateEpisodeSeen(this.episodeSeen).subscribe({
date_seen,
seen_with
)
.subscribe({
next: (episodeSeen) => { next: (episodeSeen) => {
if (episodeSeen) { if (episodeSeen) {
return this.dialogRef.close({ return this.dialogRef.close({
created: true, updated: true,
// ? returning the season number so it can be used to refrech the-
// ? season card progress bar in the entry page
season_number: this.selectedSeason?.season_number,
}); });
} }
}, },
error: (error) => { error: (error) => {
console.log(`Episode seen create error: `, error); console.log(`Episode seen update error: `, error);
// TODO show notification // TODO show notification
}, },
}); });
} else {
this.dialogRef.close({ // ? create
created: false, this.episodeSeenService
}); .createEpisodeSeen(
this.entryId,
this.selectedEpisode?.id,
date_seen,
seen_with
)
.subscribe({
next: (episodeSeen) => {
if (episodeSeen) {
return this.dialogRef.close({
created: true,
// ? returning the season number so it can be used to refrech the-
// ? season card progress bar in the entry page
season_number: this.selectedSeason?.season_number,
});
}
},
error: (error) => {
console.log(`Episode seen create error: `, error);
// TODO show notification
},
});
}
} }
onClose(): void { onClose(): void {
@@ -1,18 +1,19 @@
<div class="card border-top border-3 border-primary rounded-0" style="margin-bottom: 0 !important;"> <div class="card border-top border-3 border-primary rounded-0" style="margin-bottom: 0 !important;">
<div class="modal-header card-header py-3 px-4" > <div class="modal-header card-header py-3 px-4">
<h5 class="mb-0 text-primary">Watch Details</h5> <h5 class="mb-0 text-primary">Watch Details</h5>
<button type="button" class="btn-close" (click)="onClose()" aria-label="Close"></button> <button type="button" class="btn-close" (click)="onClose()" aria-label="Close"></button>
</div> </div>
<div class="card-body p-4"> <div class="card-body p-4 pt-1">
<form class="row g-3"> <form class="row g-3">
<div class="col-md-12"> <div class="col-md-12">
<label class="form-label">Seen With</label> <label class="form-label">Seen With</label>
<textarea class="form-control rounded-0" [(ngModel)]="watchedWith" [ngModelOptions]="{ standalone: true }" placeholder="Enter names" rows="3"></textarea> <textarea class="form-control rounded-0" [(ngModel)]="watchedWith" [ngModelOptions]="{ standalone: true }"
placeholder="Enter names" rows="3"></textarea>
</div> </div>
<div class="col-md-12"> <div class="col-md-12">
<label class="form-label">Date Watched</label> <label class="form-label">Date Watched</label>
<input type="text" class="form-control rounded-0" name="watch-date" [(ngModel)]="watchDate" id="myDatepicker"> <input type="date" class="form-control rounded-0" name="watch-date" [(ngModel)]="watchDate" id="myDatepicker">
</div> </div>
<div class="col-md-12"> <div class="col-md-12">
@@ -48,18 +48,22 @@ export class SeenModalComponent implements OnInit {
this.watchDate = formatDate(new Date(), 'yyyy-MM-dd', 'en-US'); this.watchDate = formatDate(new Date(), 'yyyy-MM-dd', 'en-US');
} else { } else {
// ? if data is passed, populate fields // ? if data is passed, populate fields
this.watchDate = formatDate(new Date(this.data.watchDate), 'yyyy-MM-dd', 'en-US'); this.watchDate = formatDate(
new Date(this.data.watchDate),
'yyyy-MM-dd',
'en-US'
);
this.watchedWith = this.data.watchedWith.split(', ').join('\n'); this.watchedWith = this.data.watchedWith.split(', ').join('\n');
} }
flatpickr('#myDatepicker', { // flatpickr('#myDatepicker', {
inline: true, // inline: true,
defaultDate: this.watchDate, // defaultDate: this.watchDate,
altInput: true, // altInput: true,
allowInput: false, // allowInput: false,
altFormat: 'F j, Y', // altFormat: 'F j, Y',
dateFormat: 'Y-m-d', // dateFormat: 'Y-m-d',
}); // });
} }
onConfirm(): void { onConfirm(): void {