add calendar page + backend

This commit is contained in:
X4Lo committed 2024-09-10 01:24:02 +01:00
1 parent f73deb4f2d
commit 4fbbc4b113
16 files changed
+15635 -5474

No files matched your search

+5 -1
View File
@@ -43,7 +43,11 @@
"node_modules/ngx-toastr/toastr.css", "node_modules/ngx-toastr/toastr.css",
"node_modules/perfect-scrollbar/css/perfect-scrollbar.css", "node_modules/perfect-scrollbar/css/perfect-scrollbar.css",
"node_modules/flatpickr/dist/flatpickr.min.css", "node_modules/flatpickr/dist/flatpickr.min.css",
"frontend/src/assets/sass/responsive.css" "frontend/src/assets/sass/responsive.css",
"node_modules/primeng/resources/themes/saga-blue/theme.css",
"node_modules/primeng/resources/primeng.min.css",
"node_modules/primeicons/primeicons.css"
], ],
"scripts": [ "scripts": [
"frontend/src/assets/js/jquery.min.js", "frontend/src/assets/js/jquery.min.js",
+11
View File
@@ -1,6 +1,17 @@
const express = require('express'); const express = require('express');
const { getEpisodesBetweenDates } = require('../services/models-services/episodeService');
const episodeRouter = express.Router(); const episodeRouter = express.Router();
// ! /episodes // ! /episodes
episodeRouter.get('/month/:startDate/:endDate', async (req, res) => {
const { startDate, endDate } = req.params;
try {
const episodes = await getEpisodesBetweenDates(startDate, endDate)
res.status(200).json(episodes);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
module.exports = episodeRouter; module.exports = episodeRouter;
+2
View File
@@ -11,6 +11,7 @@ const maintenanceRouter = require('./maintenance.routes');
const statisticsRouter = require('./statistics.routes'); const statisticsRouter = require('./statistics.routes');
const customMediaRouter = require('./custom-media.routes'); const customMediaRouter = require('./custom-media.routes');
const mediaRouter = require('./media.routes'); const mediaRouter = require('./media.routes');
const episodeRouter = require('./episode.routes');
const router = express.Router(); const router = express.Router();
router.use('/media', mediaRouter); router.use('/media', mediaRouter);
@@ -21,6 +22,7 @@ router.use('/entry-ids', entryIdsRouter);
router.use('/entry-ratings', entryRatingsRouter); router.use('/entry-ratings', entryRatingsRouter);
router.use('/seasons', seasonRouter); router.use('/seasons', seasonRouter);
router.use('/episodes', episodeRouter);
router.use('/episode-seen', episodeSeenRouter); router.use('/episode-seen', episodeSeenRouter);
router.use('/custom-media', customMediaRouter); router.use('/custom-media', customMediaRouter);
+5
View File
@@ -30,6 +30,11 @@ const routes: Routes = [
loadChildren: () => loadChildren: () =>
import('./features/media/media.module').then((m) => m.MediaModule), import('./features/media/media.module').then((m) => m.MediaModule),
}, },
{
path: 'calendar',
loadChildren: () =>
import('./features/calendar/calendar.module').then((m) => m.CalendarModule),
},
{ path: 'favorit', component: FavoritComponent }, { path: 'favorit', component: FavoritComponent },
{ path: 'watchlist', component: WatchlistComponent }, { path: 'watchlist', component: WatchlistComponent },
{ {
+8 -1
View File
@@ -16,10 +16,17 @@ import { ThemeService } from './services/theme.service';
import { SeasonService } from './services/season.service'; import { SeasonService } from './services/season.service';
import { SearchPopupComponent } from './components/search-popup/search-popup.component'; import { SearchPopupComponent } from './components/search-popup/search-popup.component';
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { SharedModule } from '../shared/shared.module';
@NgModule({ @NgModule({
declarations: [SidebarComponent, NavbarComponent, SearchPopupComponent], declarations: [SidebarComponent, NavbarComponent, SearchPopupComponent],
imports: [CommonModule, RouterModule, FormsModule, ReactiveFormsModule], imports: [
CommonModule,
SharedModule,
RouterModule,
FormsModule,
ReactiveFormsModule,
],
providers: [ providers: [
TmdbService, TmdbService,
LibraryService, LibraryService,
@@ -1,6 +1,8 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { environment } from '../../../environments/environment.prod'; import { environment } from '../../../environments/environment.prod';
import { EpisodeDTO } from '../../shared/models/dtos/episode.dto';
import { Observable } from 'rxjs';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
@@ -10,4 +12,13 @@ export class EpisodeService {
private apiAction = 'episodes'; private apiAction = 'episodes';
constructor(private http: HttpClient) {} constructor(private http: HttpClient) {}
getMonthEpisodes(
startDate: string,
endDate: string
): Observable<EpisodeDTO[]> {
return this.http.get<EpisodeDTO[]>(
`${this.backend_apiUrl}/${this.apiAction}/month/${startDate}/${endDate}`
);
}
} }
@@ -0,0 +1,36 @@
.full-calendar {
margin: 40px auto;
height: auto;
max-height: 800px;
}
::ng-deep full-calendar div.fc-daygrid-event-harness {
display: block;
}
::ng-deep full-calendar .fc-daygrid-day-events {
display: flex;
flex-wrap: wrap; /* Adjust this if items overflow */
}
/* Ensure the event harness keeps the layout */
::ng-deep full-calendar .fc-daygrid-event-harness {
display: flex;
align-items: center; /* Center items vertically within the harness */
}
/* Align the inner div of each event to row */
::ng-deep full-calendar .fc-event > div {
display: flex;
flex-direction: row; /* Align images and titles horizontally */
align-items: center; /* Center items vertically */
gap: 5px; /* Space between image and title */
}
/* Set image sizes to ensure consistency */
::ng-deep full-calendar .fc-event img {
width: 70px; /* Set consistent width for images */
height: auto; /* Maintain aspect ratio */
}
@@ -0,0 +1,7 @@
<div class="card">
<div class="card-body">
<div class="table-responsive">
<full-calendar [options]="calendarOptions"></full-calendar>
</div>
</div>
</div>
@@ -0,0 +1,28 @@
/* tslint:disable:no-unused-variable */
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { CalendarPageComponent } from './calendar-page.component';
describe('CalendarPageComponent', () => {
let component: CalendarPageComponent;
let fixture: ComponentFixture<CalendarPageComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CalendarPageComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CalendarPageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,178 @@
import { Component, OnInit } from '@angular/core';
import { EpisodeService } from '../../../core/services/episode.service';
import {
CalendarOptions,
DatesSetArg,
EventClickArg,
} from '@fullcalendar/core';
import dayGridPlugin from '@fullcalendar/daygrid';
import interactionPlugin from '@fullcalendar/interaction';
import { Title } from '@angular/platform-browser';
import { environment } from '../../../../environments/environment.prod';
import { Entry } from '../../../shared/models/entry.model';
import { Router } from '@angular/router';
@Component({
selector: 'app-calendar-page',
templateUrl: './calendar-page.component.html',
styleUrls: ['./calendar-page.component.css'],
})
export class CalendarPageComponent implements OnInit {
calendarOptions: CalendarOptions = {
initialView: 'dayGridMonth', // Set the initial view
plugins: [dayGridPlugin, interactionPlugin], // Include necessary plugins
headerToolbar: {
left: 'prev,next today',
center: 'title',
// right: 'dayGridMonth,dayGridWeek,dayGridDay',
},
firstDay: 1,
events: [],
eventContent: this.renderEventContent.bind(this), // render images
dateClick: this.handleDateClick.bind(this), // Bind the date click event handler
datesSet: this.handleDatesSet.bind(this), // month change
eventClick: this.handleEventClick.bind(this), // Handle event clicks
dayMaxEvents: 4, // Limit the number of events displayed per day
height: 'auto',
};
constructor(private episodeService: EpisodeService, private router: Router) {}
ngOnInit() {
const today = new Date();
const firstDayOfFirstWeek = this.getFirstMondayOfMonth(today)
.toISOString()
.split('T')[0];
const lastDayOfLastWeek = this.getLastSundayOfMonth(today)
.toISOString()
.split('T')[0];
// console.log('First Day of First Week:', firstDayOfFirstWeek);
// console.log('Last Day of Last Week:', lastDayOfLastWeek);
this.fetchEpisodes(firstDayOfFirstWeek, lastDayOfLastWeek);
}
fetchEpisodes(startDate: string, endDate: string) {
this.episodeService.getMonthEpisodes(startDate, endDate).subscribe({
next: (result) => {
this.calendarOptions.events = result
.filter((e) => e.season.season_number != 0)
.map((e) => {
return {
title: `S${e.season.season_number}E${e.episode_number}`,
date: e.air_date,
photo: this.getPosterPath(e.entry),
url: `/entries/${e.entry.id}`,
};
});
},
error: (error) => {},
});
}
// ! click events
handleDateClick(arg: any) {
// alert('Date clicked: ' + arg.dateStr);
}
// ? month change
handleDatesSet(arg: DatesSetArg) {
// console.log('View dates changed:', arg.startStr, arg.endStr);
this.fetchEpisodes(arg.startStr, arg.endStr);
}
handleEventClick(clickInfo: EventClickArg) {
// Example: Display an alert with event title
// alert(`Event clicked: ${clickInfo.event.title}`);
// const event = clickInfo.event as any;
// console.log(event);
// this.router.navigate([`/entries/${clickInfo.event.publicId}`]);
// Example: You can also access other event properties
// console.log('Clicked event details:', clickInfo.event);
}
renderEventContent(eventInfo: any) {
const container = document.createElement('div');
container.style.display = 'flex';
container.style.flexDirection = 'column'; // Stacks elements vertically
container.style.alignItems = 'center'; // Centers content horizontally
if (eventInfo.event.extendedProps.photo) {
const img = document.createElement('img');
img.src = eventInfo.event.extendedProps.photo;
img.style.width = '70px';
// img.style.height = '20px';
container.appendChild(img);
}
const title = document.createElement('div');
title.innerText = eventInfo.event.title;
title.style.fontSize = '12px';
container.appendChild(title);
return { domNodes: [container] };
}
// ! getters
getFirstMondayOfMonth(date: Date): Date {
// Get the first day of the current month
const firstDayOfMonth = new Date(date.getFullYear(), date.getMonth(), 1);
// Calculate the day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday)
const dayOfWeek = firstDayOfMonth.getDay();
// If it's not Monday, adjust back to the previous Monday
const offset = dayOfWeek === 0 ? -5 : 1 - dayOfWeek; // Backtrack to Monday
const firstMonday = new Date(firstDayOfMonth);
firstMonday.setDate(firstDayOfMonth.getDate() + offset);
return firstMonday;
}
getLastSundayOfMonth(date: Date): Date {
// Get the last day of the current month
const lastDayOfMonth = new Date(date.getFullYear(), date.getMonth() + 1, 0);
// Calculate the day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday)
const dayOfWeek = lastDayOfMonth.getDay();
// If it's not Sunday, adjust forward to the next Sunday
const offset = dayOfWeek === 0 ? 0 : 8 - dayOfWeek; // Move forward to Sunday
const lastSunday = new Date(lastDayOfMonth);
lastSunday.setDate(lastDayOfMonth.getDate() + offset);
return lastSunday;
}
getPosterPath(entry: Entry) {
// * Not in library, use TMDB poster
if (!entry.isInLibrary)
return `https://image.tmdb.org/t/p/w342` + entry.poster_path;
// * Is in library: use a local poster
if (entry.medias) {
const selectedPosters = entry.medias.filter(
(m) => m.type == 'poster' && m.isSelected
);
if (
selectedPosters.length &&
selectedPosters[0] &&
selectedPosters[0].path
) {
const name = selectedPosters[0].path;
return environment.API_URL + `/media/entries/posters/preview/${name}`;
}
}
// * No local poster available, Use TMDB poster
if (entry.poster_path)
return `https://image.tmdb.org/t/p/w300` + entry.poster_path;
// * No poster found, use default poster image as a last stand
return 'assets/images/default/default-poster.png';
}
}
@@ -0,0 +1,17 @@
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { CalendarPageComponent } from './calendar-page/calendar-page.component';
// ! /calendar
const routes: Routes = [
{
path: '',
component: CalendarPageComponent,
},
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class CalendarRoutingModule {}
@@ -0,0 +1,22 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { SharedModule } from '../../shared/shared.module';
import { CalendarPageComponent } from './calendar-page/calendar-page.component';
import { CalendarRoutingModule } from './calendar-routing.module';
import { FullCalendarModule } from '@fullcalendar/angular';
@NgModule({
imports: [
CommonModule,
SharedModule,
CalendarRoutingModule,
FullCalendarModule,
],
declarations: [CalendarPageComponent],
exports: [],
})
export class CalendarModule {}
@@ -0,0 +1,37 @@
import { Entry } from '../entry.model';
import { EpisodeSeen } from '../episodeSeen.model';
import { Season } from '../season.model';
export interface EpisodeDTO {
id: number;
tmdb_id: string;
imdb_id: string;
season_id: number;
season: Season;
entry: Entry;
episodeSeen: EpisodeSeen[];
name: string;
overview: string;
episode_number: number;
runtime: number;
air_date: Date;
user_rating: number;
tmdb_rating: number;
imdb_rating: number;
// temp fields
poster_path: string;
banner_path: string;
date_first_seen: Date;
date_last_seen: Date;
createdAt: Date;
updatedAt: Date;
}
+3980 -5471
View File
File diff suppressed because it is too large. Load diff
+7 -1
View File
@@ -42,6 +42,10 @@
"@angular/platform-browser": "^17.0.0", "@angular/platform-browser": "^17.0.0",
"@angular/platform-browser-dynamic": "^17.0.0", "@angular/platform-browser-dynamic": "^17.0.0",
"@angular/router": "^17.0.0", "@angular/router": "^17.0.0",
"@fullcalendar/angular": "^6.1.15",
"@fullcalendar/core": "^6.1.15",
"@fullcalendar/daygrid": "^6.1.15",
"@fullcalendar/interaction": "^6.1.15",
"angular-star-rating": "^7.0.0", "angular-star-rating": "^7.0.0",
"apexcharts": "^3.49.0", "apexcharts": "^3.49.0",
"axios": "^1.6.8", "axios": "^1.6.8",
@@ -54,11 +58,13 @@
"mysql2": "^3.9.3", "mysql2": "^3.9.3",
"ngx-bootstrap": "^12.0.0", "ngx-bootstrap": "^12.0.0",
"ngx-toastr": "^18.0.0", "ngx-toastr": "^18.0.0",
"p-limit": "^6.1.0",
"perfect-scrollbar": "^1.5.5", "perfect-scrollbar": "^1.5.5",
"primeicons": "^7.0.0", "primeicons": "^7.0.0",
"primeng": "^17.18.0", "primeng": "^17.18.9",
"rxjs": "~7.8.0", "rxjs": "~7.8.0",
"sequelize": "^6.37.1", "sequelize": "^6.37.1",
"sharp": "^0.33.5",
"tslib": "^2.3.0", "tslib": "^2.3.0",
"zone.js": "~0.14.3" "zone.js": "~0.14.3"
}, },
+11281
View File
File diff suppressed because it is too large. Load diff