Front/Back: add tv-series auto sync when vising the calendar
This commit is contained in:
1 parent
9530b52830
commit
7160669468
2 files changed
+34
-16
No files matched your search
@@ -8,26 +8,30 @@ const Media = require("../../models/Media");
|
|||||||
|
|
||||||
|
|
||||||
async function getEpisodesBetweenDates(startDate, endDate) {
|
async function getEpisodesBetweenDates(startDate, endDate) {
|
||||||
// Get the first and last day of the month based on the provided date
|
|
||||||
const formatedStartDate = moment(startDate).format('YYYY-MM-DD');
|
const formatedStartDate = moment(startDate).format('YYYY-MM-DD');
|
||||||
const formatedEndDate = moment(endDate).format('YYYY-MM-DD');
|
const formatedEndDate = moment(endDate).format('YYYY-MM-DD');
|
||||||
|
|
||||||
// Fetch episodes that aired within the current month
|
// fetch episodes that aired within the current month
|
||||||
const episodes = await Episode.findAll({
|
const episodes = await Episode.findAll({
|
||||||
where: {
|
where: {
|
||||||
air_date: {
|
air_date: {
|
||||||
[Op.between]: [formatedStartDate, formatedEndDate]
|
[Op.between]: [formatedStartDate, formatedEndDate]
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
model: Season,
|
model: Season,
|
||||||
as: 'season',
|
as: 'season',
|
||||||
include: {
|
include: {
|
||||||
model: Entry, as: 'entry', include: [
|
model: Entry,
|
||||||
|
as: 'entry',
|
||||||
|
include: [
|
||||||
{ model: EntryId, as: 'entryId' },
|
{ model: EntryId, as: 'entryId' },
|
||||||
{ model: Media, as: 'medias' },
|
{
|
||||||
]
|
model: Media,
|
||||||
|
as: 'medias',
|
||||||
|
},
|
||||||
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -7,10 +7,11 @@ import {
|
|||||||
} from '@fullcalendar/core';
|
} from '@fullcalendar/core';
|
||||||
import dayGridPlugin from '@fullcalendar/daygrid';
|
import dayGridPlugin from '@fullcalendar/daygrid';
|
||||||
import interactionPlugin from '@fullcalendar/interaction';
|
import interactionPlugin from '@fullcalendar/interaction';
|
||||||
import { Title } from '@angular/platform-browser';
|
|
||||||
import { environment } from '../../../../environments/environment.prod';
|
import { environment } from '../../../../environments/environment.prod';
|
||||||
import { Entry } from '../../../shared/models/entry.model';
|
import { Entry } from '../../../shared/models/entry.model';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
|
import { ToastService } from '../../../shared/services/toast.service';
|
||||||
|
import { EntryService } from '../../../core/services/entry.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-calendar-page',
|
selector: 'app-calendar-page',
|
||||||
@@ -36,7 +37,12 @@ export class CalendarPageComponent implements OnInit {
|
|||||||
height: 'auto',
|
height: 'auto',
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(private episodeService: EpisodeService, private router: Router) {}
|
constructor(
|
||||||
|
private episodeService: EpisodeService,
|
||||||
|
private toastService: ToastService,
|
||||||
|
private entryService: EntryService,
|
||||||
|
private router: Router
|
||||||
|
) {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
@@ -49,15 +55,24 @@ export class CalendarPageComponent implements OnInit {
|
|||||||
|
|
||||||
// console.log('First Day of First Week:', firstDayOfFirstWeek);
|
// console.log('First Day of First Week:', firstDayOfFirstWeek);
|
||||||
// console.log('Last Day of Last Week:', lastDayOfLastWeek);
|
// console.log('Last Day of Last Week:', lastDayOfLastWeek);
|
||||||
|
this.toastService.show('Welcome', 'hello', 'success');
|
||||||
this.fetchEpisodes(firstDayOfFirstWeek, lastDayOfLastWeek);
|
this.entryService.syncSeries().subscribe({
|
||||||
|
next: (result) => {
|
||||||
|
console.log(`Tv-Series Synced Successfully`);
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
console.log(`Error Syncing Tv-Series Successfully`);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
// this.fetchEpisodes(firstDayOfFirstWeek, lastDayOfLastWeek);
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchEpisodes(startDate: string, endDate: string) {
|
fetchEpisodes(startDate: string, endDate: string) {
|
||||||
this.episodeService.getMonthEpisodes(startDate, endDate).subscribe({
|
this.episodeService.getMonthEpisodes(startDate, endDate).subscribe({
|
||||||
next: (result) => {
|
next: (result) => {
|
||||||
|
// console.log(result);
|
||||||
this.calendarOptions.events = result
|
this.calendarOptions.events = result
|
||||||
.filter((e) => e.season.season_number != 0)
|
.filter((e) => e.season.season_number != 0 && e.entry.showInCalendar)
|
||||||
.map((e) => {
|
.map((e) => {
|
||||||
return {
|
return {
|
||||||
title: `S${e.season.season_number}E${e.episode_number}`,
|
title: `S${e.season.season_number}E${e.episode_number}`,
|
||||||
@@ -78,9 +93,9 @@ export class CalendarPageComponent implements OnInit {
|
|||||||
|
|
||||||
// ? month change
|
// ? month change
|
||||||
handleDatesSet(arg: DatesSetArg) {
|
handleDatesSet(arg: DatesSetArg) {
|
||||||
// console.log('View dates changed:', arg.startStr, arg.endStr);
|
console.log('View dates changed:', arg.startStr, arg.endStr);
|
||||||
|
|
||||||
this.fetchEpisodes(arg.startStr, arg.endStr);
|
this.fetchEpisodes(arg.startStr.split('T')[0], arg.endStr.split('T')[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleEventClick(clickInfo: EventClickArg) {
|
handleEventClick(clickInfo: EventClickArg) {
|
||||||
@@ -89,7 +104,6 @@ export class CalendarPageComponent implements OnInit {
|
|||||||
// const event = clickInfo.event as any;
|
// const event = clickInfo.event as any;
|
||||||
// console.log(event);
|
// console.log(event);
|
||||||
// this.router.navigate([`/entries/${clickInfo.event.publicId}`]);
|
// this.router.navigate([`/entries/${clickInfo.event.publicId}`]);
|
||||||
|
|
||||||
// Example: You can also access other event properties
|
// Example: You can also access other event properties
|
||||||
// console.log('Clicked event details:', clickInfo.event);
|
// console.log('Clicked event details:', clickInfo.event);
|
||||||
}
|
}
|
||||||
@@ -149,8 +163,8 @@ export class CalendarPageComponent implements OnInit {
|
|||||||
|
|
||||||
getPosterPath(entry: Entry) {
|
getPosterPath(entry: Entry) {
|
||||||
// * Not in library, use TMDB poster
|
// * Not in library, use TMDB poster
|
||||||
if (!entry.isInLibrary)
|
// if (!entry.isInLibrary)
|
||||||
return `https://image.tmdb.org/t/p/w342` + entry.poster_path;
|
// return `https://image.tmdb.org/t/p/w342` + entry.poster_path;
|
||||||
|
|
||||||
// * Is in library: use a local poster
|
// * Is in library: use a local poster
|
||||||
if (entry.medias) {
|
if (entry.medias) {
|
||||||
|
|||||||
Reference in new issue
Block a user