Add specific episode-seen
This commit is contained in:
1 parent
728dae4e59
commit
29d6e3f503
13 files changed
+323
-22
No files matched your search
Whitespace-only changes.
+43
@@ -0,0 +1,43 @@
|
||||
<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">
|
||||
<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">
|
||||
<form class="row g-3">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">Seasons</label>
|
||||
<select name="seasons" class="form-select" [(ngModel)]="selectedSeason" (change)="onSeasonChange($event)" aria-placeholder="Select a season">
|
||||
<option value="" disabled selected>Select a season</option>
|
||||
<option [ngValue]="season" *ngFor="let season of seasons">Season {{ season.season_number }}</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">Episodes</label>
|
||||
<select name="episodes" class="form-select" [(ngModel)]="selectedEpisode">
|
||||
<option value="" disabled selected>Select an episode</option>
|
||||
<option [ngValue]="episode" *ngFor="let episode of selectedSeason?.episodes">Episode {{ episode.episode_number }}</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<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>
|
||||
</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">
|
||||
</div>
|
||||
|
||||
<div class="col-md-12">
|
||||
<div class="d-md-flex d-grid align-items-center gap-3">
|
||||
<button type="button" class="btn btn-primary px-4 rounded-0" (click)="onConfirm()">OK</button>
|
||||
<button type="button" class="btn btn-secondary px-4 rounded-0" (click)="onClose()">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { EpisodeSeenModalComponent } from './episode-seen-modal.component';
|
||||
|
||||
describe('EpisodeSeenModalComponent', () => {
|
||||
let component: EpisodeSeenModalComponent;
|
||||
let fixture: ComponentFixture<EpisodeSeenModalComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [EpisodeSeenModalComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(EpisodeSeenModalComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
import { Component, Inject } from '@angular/core';
|
||||
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
||||
|
||||
import {
|
||||
trigger,
|
||||
state,
|
||||
style,
|
||||
transition,
|
||||
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';
|
||||
|
||||
@Component({
|
||||
selector: 'app-episode-seen-modal',
|
||||
templateUrl: './episode-seen-modal.component.html',
|
||||
styleUrl: './episode-seen-modal.component.css',
|
||||
animations: [
|
||||
trigger('fadeInOut', [
|
||||
state('in', style({ opacity: 1 })),
|
||||
transition(':enter', [style({ opacity: 0 }), animate(600)]),
|
||||
transition(':leave', [animate(600, style({ opacity: 0 }))]),
|
||||
]),
|
||||
trigger('scaleInOut', [
|
||||
transition(':enter', [
|
||||
state('in', style({ opacity: 1 })),
|
||||
style({ transform: 'scale(0)' }),
|
||||
animate('200ms ease-in-out', style({ transform: 'scale(1)' })),
|
||||
]),
|
||||
transition(':leave', [
|
||||
animate('200ms ease-in-out', style({ transform: 'scale(0)' })),
|
||||
]),
|
||||
]),
|
||||
],
|
||||
})
|
||||
export class EpisodeSeenModalComponent {
|
||||
public entryId: number = 0;
|
||||
public watchDate: string = '';
|
||||
public watchedWith: string = '';
|
||||
public seasons: Season[] = [];
|
||||
|
||||
public selectedSeason: Season | null = {} as Season;
|
||||
public selectedEpisode: Episode | null = {} as Episode;
|
||||
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<EpisodeSeenModalComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any,
|
||||
private seasonsService: SeasonService,
|
||||
private episodeSeenService: EpisodeSeenService
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
if (!this.data.entryId) return;
|
||||
this.entryId = this.data.entryId;
|
||||
|
||||
this.seasonsService
|
||||
.getSeasonsWithEpisodesByEntryId(this.data.entryId)
|
||||
.subscribe({
|
||||
next: (seasons) => {
|
||||
this.seasons = seasons;
|
||||
},
|
||||
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',
|
||||
});
|
||||
}
|
||||
|
||||
onSeasonChange(event: any): void {
|
||||
this.selectedEpisode = null;
|
||||
}
|
||||
|
||||
onConfirm(): void {
|
||||
if (!this.selectedSeason) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.selectedEpisode) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.watchDate) {
|
||||
return;
|
||||
}
|
||||
|
||||
const date_seen = new Date(this.watchDate);
|
||||
const seen_with = this.watchedWith.split('\n').join(', ');
|
||||
|
||||
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
|
||||
},
|
||||
});
|
||||
|
||||
this.dialogRef.close({
|
||||
created: false,
|
||||
});
|
||||
}
|
||||
|
||||
onClose(): void {
|
||||
this.dialogRef.close();
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
<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">
|
||||
<form class="row g-3">
|
||||
|
||||
Reference in new issue
Block a user