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
+157 -68

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
removeEntryById(entryId: string) {
return this.http.delete<Entry>(
@@ -161,6 +161,12 @@
</span>
</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()">
<span class="material-symbols-outlined">
image
@@ -183,7 +189,7 @@
</div>
<!-- Series Seasons -->
<div class="row" *ngIf="entry.is_tvseries">
<h3>Seasons</h3>
<h3 class="opacity-100">Seasons</h3>
<div class="card-body p-0">
<div class="p-3 ps ps--active-y">
<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 { 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';
@Component({
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 marked as seen event
onEpisodeWatchedEvent() {
@@ -402,10 +417,14 @@ export class EntryPageComponent implements OnInit {
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,
},
});
@@ -441,39 +460,20 @@ export class EntryPageComponent implements OnInit {
editEpisodeSeen(episodeSeen: EpisodeSeenDto) {
if (episodeSeen == null) return;
const dialogRef = this.dialog.open(SeenModalComponent, {
const dialogRef = this.dialog.open(EpisodeSeenModalComponent, {
width: '360px',
data: {
watchDate: episodeSeen.date_seen,
watchedWith: episodeSeen.seen_with,
entryId: this.entry.id,
episodeSeen: episodeSeen,
},
});
dialogRef.afterClosed().subscribe((result) => {
// ? dialog closed
if (result == null) return;
// ? dialog confimed
// 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;
}
if (!result.updated) return;
episodeSeen.date_seen = result.watchDate;
episodeSeen.seen_with = result.watchedWith.split('\n').join(', ');
this.episodeSeenService.updateEpisodeSeen(episodeSeen).subscribe({
next: () => {
// console.log(`Episode seen updated.`);
// ? call this function to fetch the new episode-seen history
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
if (!poster && this.entry.medias) {
const selectedPosters = this.entry.medias.filter(
(m) => m.type == 'poster' && m.is_selected
(m) => m.type == 'poster' && m.isSelected
);
if (
@@ -595,7 +595,9 @@ export class EntryPageComponent implements OnInit {
selectedPosters[0] &&
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
if (this.entry.medias) {
const selectedPosters = this.entry.medias.filter(
(m) => m.type == 'poster' && m.is_selected
(m) => m.type == 'poster' && m.isSelected
);
if (
@@ -658,7 +660,10 @@ export class EntryPageComponent implements OnInit {
selectedPosters[0] &&
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
if (this.entry.medias) {
const selectedBackdrop = this.entry.medias.filter(
(m) => m.type == 'backdrop' && m.is_selected
(m) => m.type == 'backdrop' && m.isSelected
);
if (
@@ -682,7 +687,10 @@ export class EntryPageComponent implements OnInit {
selectedBackdrop[0] &&
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">
<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 class="col-md-12">
@@ -9,11 +9,11 @@ import {
animate,
} from '@angular/animations';
import { formatDate } from '@angular/common';
import flatpickr from 'flatpickr';
import { Season } from '../../../models/season.model';
import { SeasonService } from '../../../../core/services/season.service';
import { Episode } from '../../../models/episode.models';
import { EpisodeSeenService } from '../../../../core/services/episode-seen.service';
import { EpisodeSeenDto } from '../../../models/dtos/episode-seen.dto';
@Component({
selector: 'app-episode-seen-modal',
@@ -41,6 +41,7 @@ export class EpisodeSeenModalComponent {
public entryId: number = 0;
public watchDate: string = '';
public watchedWith: string = '';
public episodeSeen: EpisodeSeenDto = {} as EpisodeSeenDto;
public seasons: Season[] = [];
public selectedSeason: Season | null = {} as Season;
@@ -54,28 +55,84 @@ export class EpisodeSeenModalComponent {
) {}
ngOnInit(): void {
if (!this.data.entryId) return;
if (!this.data) return;
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
.getSeasonsWithEpisodesByEntryId(this.data.entryId)
.subscribe({
next: (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) => {
console.log(`Error gettings seasons: `, error);
},
});
flatpickr('#myDatepicker', {
inline: true,
defaultDate: this.watchDate,
altInput: true,
allowInput: false,
altFormat: 'F j, Y',
dateFormat: 'Y-m-d',
});
// flatpickr('#myDatepicker', {
// inline: true,
// defaultDate: this.watchDate,
// altInput: true,
// allowInput: false,
// altFormat: 'F j, Y',
// dateFormat: 'Y-m-d',
// });
}
onSeasonChange(event: any): void {
@@ -83,21 +140,31 @@ export class EpisodeSeenModalComponent {
}
onConfirm(): void {
if (!this.selectedSeason) {
return;
}
if (!this.selectedEpisode) {
return;
}
if (!this.watchDate) {
if (!this.selectedSeason || !this.selectedEpisode || !this.watchDate) {
return;
}
const date_seen = new Date(this.watchDate);
const seen_with = this.watchedWith.split('\n').join(', ');
this.episodeSeen.date_seen = date_seen;
this.episodeSeen.seen_with = seen_with;
if (this.episodeSeen.id) {
this.episodeSeenService.updateEpisodeSeen(this.episodeSeen).subscribe({
next: (episodeSeen) => {
if (episodeSeen) {
return this.dialogRef.close({
updated: true,
});
}
},
error: (error) => {
console.log(`Episode seen update error: `, error);
// TODO show notification
},
});
} else {
// ? create
this.episodeSeenService
.createEpisodeSeen(
this.entryId,
@@ -121,10 +188,7 @@ export class EpisodeSeenModalComponent {
// TODO show notification
},
});
this.dialogRef.close({
created: false,
});
}
}
onClose(): void {
@@ -1,18 +1,19 @@
<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>
<button type="button" class="btn-close" (click)="onClose()" aria-label="Close"></button>
</div>
<div class="card-body p-4">
<div class="card-body p-4 pt-1">
<form class="row g-3">
<div class="col-md-12">
<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 class="col-md-12">
<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 class="col-md-12">
@@ -48,18 +48,22 @@ export class SeenModalComponent implements OnInit {
this.watchDate = formatDate(new Date(), 'yyyy-MM-dd', 'en-US');
} else {
// ? 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');
}
flatpickr('#myDatepicker', {
inline: true,
defaultDate: this.watchDate,
altInput: true,
allowInput: false,
altFormat: 'F j, Y',
dateFormat: 'Y-m-d',
});
// flatpickr('#myDatepicker', {
// inline: true,
// defaultDate: this.watchDate,
// altInput: true,
// allowInput: false,
// altFormat: 'F j, Y',
// dateFormat: 'Y-m-d',
// });
}
onConfirm(): void {