add calendar page + backend
This commit is contained in:
1 parent
f73deb4f2d
commit
4fbbc4b113
16 files changed
+15635
-5474
No files matched your search
@@ -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 {}
|
||||
Reference in new issue
Block a user