Add specific episode-seen
This commit is contained in:
1 parent
728dae4e59
commit
29d6e3f503
13 files changed
+323
-22
No files matched your search
@@ -1,15 +1,18 @@
|
||||
const express = require('express');
|
||||
const entryRouter = express.Router();
|
||||
|
||||
const { fetchEntryData } = require('../services/tmdbService');
|
||||
const { saveEntry, refrechEntry } = require('../services/entryService');
|
||||
const { bulkImportMovies, bulkImportTmdb, bulkImportEpisodes } = require('../services/importerService');
|
||||
|
||||
const Entry = require('../models/Entry');
|
||||
const EntryId = require('../models/EntryId');
|
||||
const EntryRating = require('../models/EntryRating');
|
||||
const Genre = require('../models/Genre');
|
||||
const EntrySeen = require('../models/EntrySeen');
|
||||
const { saveEntry, refrechEntry } = require('../services/entryService');
|
||||
const Season = require('../models/Season');
|
||||
const { bulkImportMovies, bulkImportTmdb, bulkImportEpisodes } = require('../services/importerService');
|
||||
const Media = require('../models/Media');
|
||||
const entryRouter = express.Router();
|
||||
const Episode = require('../models/Episode');
|
||||
|
||||
// ! /entries
|
||||
// * GET - ALL ENTRIES
|
||||
@@ -85,6 +88,47 @@ entryRouter.get('/:id', async (req, res) => {
|
||||
console.log(error);
|
||||
}
|
||||
});
|
||||
|
||||
// * GET - Get seasons of an entry
|
||||
entryRouter.get('/:id/seasons', async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
|
||||
if (id == null) { // ! entry id not provided
|
||||
res.status(404).json({ message: 'Entry id not provided' });
|
||||
}
|
||||
|
||||
const entry = await Entry.findByPk(id);
|
||||
|
||||
if (!entry) {
|
||||
res.status(404).json({ message: 'Entry not found' });
|
||||
}
|
||||
|
||||
const seasons = await Season.findAll({
|
||||
where: {
|
||||
entry_id: id
|
||||
},
|
||||
attributes: ['id', 'season_number'],
|
||||
include: [
|
||||
{ model: Episode, as: 'episodes', attributes: ['id', 'episode_number'], }
|
||||
],
|
||||
order: [
|
||||
['season_number', 'ASC'],
|
||||
[{ model: Episode, as: 'episodes' }, 'episode_number', 'ASC'],
|
||||
]
|
||||
})
|
||||
|
||||
if (seasons.length == 0) { // ! no content
|
||||
res.status(404).json({ message: 'No seasons' });
|
||||
}
|
||||
|
||||
res.status(200).json(seasons);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
console.log(error);
|
||||
}
|
||||
});
|
||||
|
||||
// ! POST
|
||||
// * POST - CREATE ENTRY
|
||||
entryRouter.post('/', async (req, res) => {
|
||||
|
||||
@@ -4,7 +4,7 @@ const Episode = require('../models/Episode');
|
||||
const seasonRouter = express.Router();
|
||||
|
||||
// ! /seasons
|
||||
// POST /seasons - Create a new season
|
||||
// * POST - Create a new season
|
||||
seasonRouter.post('/', async (req, res) => {
|
||||
try {
|
||||
const season = await Season.create(req.body);
|
||||
@@ -14,7 +14,7 @@ seasonRouter.post('/', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// GET /seasons - Retrieve all seasons
|
||||
// * GET - Retrieve all seasons
|
||||
seasonRouter.get('/', async (req, res) => {
|
||||
try {
|
||||
const seasons = await Season.findAll();
|
||||
@@ -24,7 +24,7 @@ seasonRouter.get('/', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// GET /seasons/:id - Retrieve a specific season by id
|
||||
// * GET - Retrieve a specific season by id
|
||||
seasonRouter.get('/:id', async (req, res) => {
|
||||
try {
|
||||
const season = await Season.findByPk(req.params.id, {
|
||||
@@ -44,6 +44,7 @@ seasonRouter.get('/:id', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// * GET - Retrieve episodes of a season
|
||||
seasonRouter.get('/:id/episodes', async (req, res) => {
|
||||
try {
|
||||
const episodes = await Episode.findAll({
|
||||
@@ -62,7 +63,7 @@ seasonRouter.get('/:id/episodes', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// PUT /seasons/:id - Update a season
|
||||
// * PUT - Update a season
|
||||
seasonRouter.put('/:id', async (req, res) => {
|
||||
try {
|
||||
const [updated] = await Season.update(req.body, {
|
||||
@@ -79,7 +80,7 @@ seasonRouter.put('/:id', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// DELETE /seasons/:id - Delete a season
|
||||
// * DELETE - Delete a season
|
||||
seasonRouter.delete('/:id', async (req, res) => {
|
||||
try {
|
||||
const deleted = await Season.destroy({
|
||||
|
||||
@@ -31,4 +31,10 @@ export class SeasonService {
|
||||
`${this.backend_apiUrl}/${this.apiAction}/${id}/episodes`
|
||||
);
|
||||
}
|
||||
|
||||
getSeasonsWithEpisodesByEntryId(entryId: number) {
|
||||
return this.http.get<Season[]>(
|
||||
`${this.backend_apiUrl}/entries/${entryId}/seasons`
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -204,7 +204,19 @@
|
||||
<h3>Collections</h3>
|
||||
</div> -->
|
||||
<div class="row" *ngIf="this.entry.is_tvseries && this.seenHistory.length != 0">
|
||||
<h3>Watch History</h3>
|
||||
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||
<h3>Watch History</h3>
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-sm btn-filter dropdown-toggle dropdown-toggle-nocaret bg-transparent" 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)="addEpisodeSeen()"><a class="dropdown-item">Add a watch date</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-body p-3">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
|
||||
@@ -19,6 +19,7 @@ import { SeasonService } from '../../../core/services/season.service';
|
||||
import { LibraryService } from '../../../core/services/library.service';
|
||||
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';
|
||||
|
||||
@Component({
|
||||
selector: 'app-entry-page',
|
||||
@@ -397,6 +398,45 @@ export class EntryPageComponent implements OnInit {
|
||||
this.seenHistoryToShow = temp.slice(startIndex, endIndex);
|
||||
}
|
||||
|
||||
addEpisodeSeen() {
|
||||
if (!this.entry) return;
|
||||
|
||||
const dialogRef = this.dialog.open(EpisodeSeenModalComponent, {
|
||||
width: '360px',
|
||||
data: {
|
||||
entryId: this.entry.id,
|
||||
},
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((result) => {
|
||||
// ? if an episode-seen was created then refresh the watch history table
|
||||
if (result && result.created) {
|
||||
// ? call this function to fetch the new episode-seen history
|
||||
this.getEpisodesSeenHistory();
|
||||
|
||||
// ? Updating 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 == result.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 = [];
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
editEpisodeSeen(episodeSeen: EpisodeSeenDto) {
|
||||
if (episodeSeen == null) return;
|
||||
|
||||
@@ -456,11 +496,11 @@ export class EntryPageComponent implements OnInit {
|
||||
this.episodeSeenService.removeEpisodeSeen(episodeSeen.id).subscribe({
|
||||
next: () => {
|
||||
// console.log(`Episode seen deleted.`);
|
||||
// call this function to fetch the new episode-seen history
|
||||
// ? 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
|
||||
// ? Updating 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({
|
||||
|
||||
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">
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
|
||||
|
||||
// * modals
|
||||
import { SeenModalComponent } from './components/modals/seen-modal/seen-modal.component';
|
||||
import { ConfirmModalComponent } from './components/modals/confirm-modal/confirm-modal.component';
|
||||
@@ -14,6 +13,7 @@ import { RatingModule } from 'ngx-bootstrap/rating';
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { CollectionEditModalComponent } from '../features/collections/user-collection-info/collection-edit-modal/collection-edit-modal.component';
|
||||
import { FloatFormatPipe } from './pipes/float-format/float-format.pipe';
|
||||
import { EpisodeSeenModalComponent } from './components/modals/episode-seen-modal/episode-seen-modal.component';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
@@ -33,7 +33,7 @@ import { FloatFormatPipe } from './pipes/float-format/float-format.pipe';
|
||||
SeenModalComponent,
|
||||
CollectionEditModalComponent,
|
||||
ConfirmModalComponent,
|
||||
|
||||
EpisodeSeenModalComponent,
|
||||
],
|
||||
exports: [
|
||||
// * pipes
|
||||
|
||||
@@ -62,7 +62,7 @@ input::placeholder {
|
||||
/*header*/
|
||||
.top-header .navbar {
|
||||
background-color: #ffffff;
|
||||
height: 70px;
|
||||
height: 50px;
|
||||
position: fixed;
|
||||
left: 70px;
|
||||
right: 0;
|
||||
@@ -165,7 +165,7 @@ input::placeholder {
|
||||
}
|
||||
|
||||
.top-header .navbar .nav-item {
|
||||
height: 70px;
|
||||
height: 50px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
@@ -531,7 +531,7 @@ footer {
|
||||
height: calc(100vh - 70px);
|
||||
/* overflow: hidden; */
|
||||
|
||||
margin-top: 70px;
|
||||
margin-top: 50px;
|
||||
margin-left: 70px;
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ $dropdownAnimation: 0.6s cubic-bezier(0.25, 0.8, 0.25, 1) 0s normal forwards 1
|
||||
.top-header {
|
||||
.navbar {
|
||||
background-color: $headerbg;
|
||||
height: 70px;
|
||||
height: 50px;
|
||||
position: fixed;
|
||||
// border-bottom: 1px solid var(--bs-border-color);
|
||||
left: 260px;
|
||||
@@ -220,7 +220,7 @@ $dropdownAnimation: 0.6s cubic-bezier(0.25, 0.8, 0.25, 1) 0s normal forwards 1
|
||||
}
|
||||
|
||||
.nav-item {
|
||||
height: 70px;
|
||||
height: 50px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -437,7 +437,7 @@ $dropdownAnimation: 0.6s cubic-bezier(0.25, 0.8, 0.25, 1) 0s normal forwards 1
|
||||
align-items: center;
|
||||
justify-content: start;
|
||||
width: 260px;
|
||||
height: 70px;
|
||||
height: 50px;
|
||||
padding: 0 1rem;
|
||||
gap: 0.5rem;
|
||||
// border-bottom: 1px solid var(--bs-border-color);
|
||||
@@ -751,7 +751,7 @@ $dropdownAnimation: 0.6s cubic-bezier(0.25, 0.8, 0.25, 1) 0s normal forwards 1
|
||||
/* main content */
|
||||
|
||||
.main-wrapper {
|
||||
margin-top: 70px;
|
||||
margin-top: 50px;
|
||||
padding-bottom: 20px;
|
||||
margin-left: 260px;
|
||||
transition: ease-out 0.3s;
|
||||
|
||||
Reference in new issue
Block a user