Frontend: Added PeopleDetails Component
This commit is contained in:
1 parent
740a51f1e9
commit
095dc91ab2
4 files changed
+569
No files matched your search
@@ -0,0 +1,164 @@
|
||||
.person-details-container {
|
||||
padding: 20px 0;
|
||||
}
|
||||
|
||||
.person-header {
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.profile-image-container {
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.profile-image {
|
||||
width: 100%;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.person-name {
|
||||
font-size: 2rem;
|
||||
font-weight: 700;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
/* Biography section */
|
||||
.biography-section {
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.biography-section h3 {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.biography-text {
|
||||
line-height: 1.6;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.missing-biography {
|
||||
padding: 15px;
|
||||
background-color: #f8f9fa;
|
||||
border-radius: 6px;
|
||||
font-style: italic;
|
||||
color: #6c757d;
|
||||
}
|
||||
|
||||
/* Personal info sidebar */
|
||||
.person-info-sidebar {
|
||||
background-color: #f8f9fa;
|
||||
border-radius: 8px;
|
||||
padding: 15px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.person-info-sidebar h5 {
|
||||
font-weight: 600;
|
||||
margin-bottom: 15px;
|
||||
padding-bottom: 10px;
|
||||
border-bottom: 1px solid #dee2e6;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
display: block;
|
||||
font-weight: 600;
|
||||
font-size: 0.85rem;
|
||||
color: #6c757d;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
display: block;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
/* Credits section */
|
||||
.credits-section h3 {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
margin-bottom: 15px;
|
||||
padding-bottom: 10px;
|
||||
border-bottom: 1px solid #dee2e6;
|
||||
}
|
||||
|
||||
.credits-list {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.credit-card {
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
cursor: pointer;
|
||||
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.credit-card:hover {
|
||||
transform: translateY(-3px);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.credit-poster {
|
||||
height: 225px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.entry-poster {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.credit-info {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.credit-title {
|
||||
font-weight: 600;
|
||||
font-size: 0.9rem;
|
||||
margin-bottom: 3px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.credit-character, .credit-job {
|
||||
font-size: 0.85rem;
|
||||
color: #6c757d;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.credit-year {
|
||||
font-size: 0.8rem;
|
||||
color: #adb5bd;
|
||||
}
|
||||
|
||||
/* Loading container */
|
||||
.loading-container, .error-container, .not-found-container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 400px;
|
||||
}
|
||||
|
||||
/* Responsive adjustments */
|
||||
@media (max-width: 767px) {
|
||||
.person-info-sidebar {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.credits-list {
|
||||
grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
<!--breadcrumb-->
|
||||
<div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
|
||||
<div class="breadcrumb-title pe-3">Other</div>
|
||||
<div class="ps-3">
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb mb-0 p-0">
|
||||
<li class="breadcrumb-item"><a [routerLink]="['/people']">People</a></li>
|
||||
<li class="breadcrumb-item active" aria-current="page">{{ person?.name || 'Details' }}</li>
|
||||
</ol>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
<!--end breadcrumb-->
|
||||
|
||||
<div class="person-details-container" *ngIf="!loading && person">
|
||||
<div class="person-header">
|
||||
<div class="row">
|
||||
<!-- Profile Image -->
|
||||
<div class="col-md-3">
|
||||
<div class="profile-image-container">
|
||||
<img [src]="getProfileImageUrl()" [alt]="person.name" class="profile-image">
|
||||
</div>
|
||||
|
||||
<div class="person-actions mt-3">
|
||||
<button class="btn btn-primary btn-sm w-100 mb-2" (click)="refreshPersonDetails()">
|
||||
<i class="bi bi-arrow-clockwise me-2"></i>Refresh Data
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Personal Info Section -->
|
||||
<div class="person-info-sidebar mt-4">
|
||||
<h5>Personal Info</h5>
|
||||
|
||||
<div class="info-item">
|
||||
<span class="info-label">Known For</span>
|
||||
<span class="info-value">{{ person.known_for_department || 'Unknown' }}</span>
|
||||
</div>
|
||||
|
||||
<div class="info-item">
|
||||
<span class="info-label">Gender</span>
|
||||
<span class="info-value">{{ getGenderText() }}</span>
|
||||
</div>
|
||||
|
||||
<div class="info-item">
|
||||
<span class="info-label">Birthday</span>
|
||||
<span class="info-value">{{ formatDate(person.birthday) }}</span>
|
||||
</div>
|
||||
|
||||
<div class="info-item" *ngIf="person.deathday">
|
||||
<span class="info-label">Day of Death</span>
|
||||
<span class="info-value">{{ formatDate(person.deathday) }}</span>
|
||||
</div>
|
||||
|
||||
<div class="info-item">
|
||||
<span class="info-label">Age</span>
|
||||
<span class="info-value">{{ calculateAge(person.birthday, person.deathday) }}</span>
|
||||
</div>
|
||||
|
||||
<div class="info-item" *ngIf="person.place_of_birth">
|
||||
<span class="info-label">Place of Birth</span>
|
||||
<span class="info-value">{{ person.place_of_birth }}</span>
|
||||
</div>
|
||||
|
||||
<div class="info-item">
|
||||
<span class="info-label">Popularity</span>
|
||||
<span class="info-value">{{ person.popularity | number:'1.1-1' }}</span>
|
||||
</div>
|
||||
|
||||
<div class="info-item" *ngIf="person.imdb_id">
|
||||
<span class="info-label">IMDB</span>
|
||||
<span class="info-value">
|
||||
<a href="https://www.imdb.com/name/{{ person.imdb_id }}" target="_blank">
|
||||
View on IMDB <i class="bi bi-box-arrow-up-right"></i>
|
||||
</a>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Biography and Credits -->
|
||||
<div class="col-md-9">
|
||||
<div class="person-header-content">
|
||||
<h2 class="person-name">{{ person.name }}</h2>
|
||||
|
||||
<!-- Biography -->
|
||||
<div class="biography-section" *ngIf="person.biography">
|
||||
<h3>Biography</h3>
|
||||
<div class="biography-text" [innerHtml]="person.biography | paragraph"></div>
|
||||
</div>
|
||||
<div *ngIf="!person.biography" class="missing-biography">
|
||||
<p>We don't have a biography for {{ person.name }}.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Credits Section - Cast -->
|
||||
<div class="credits-section mt-4" *ngIf="castCredits.length > 0">
|
||||
<h3>Acting</h3>
|
||||
<div class="credits-list">
|
||||
<div class="credit-card" *ngFor="let credit of castCredits" (click)="navigateToEntry(credit.entry?.id)">
|
||||
<div class="credit-poster">
|
||||
<img [src]="getEntryImageUrl(credit)" [alt]="credit.entry?.title" class="entry-poster">
|
||||
</div>
|
||||
<div class="credit-info">
|
||||
<div class="credit-title">{{ credit.entry?.title }}</div>
|
||||
<div class="credit-character" *ngIf="credit.character">{{ credit.character }}</div>
|
||||
<div class="credit-year" *ngIf="credit.entry?.release_date">
|
||||
{{ credit.entry?.release_date | date:'yyyy' }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Credits Section - Crew -->
|
||||
<div class="credits-section mt-4" *ngIf="crewCredits.length > 0">
|
||||
<h3>Production</h3>
|
||||
<div class="credits-list">
|
||||
<div class="credit-card" *ngFor="let credit of crewCredits" (click)="navigateToEntry(credit.entry?.id)">
|
||||
<div class="credit-poster">
|
||||
<img [src]="getEntryImageUrl(credit)" [alt]="credit.entry?.title" class="entry-poster">
|
||||
</div>
|
||||
<div class="credit-info">
|
||||
<div class="credit-title">{{ credit.entry?.title }}</div>
|
||||
<div class="credit-job">{{ credit.job }}</div>
|
||||
<div class="credit-year" *ngIf="credit.entry?.release_date">
|
||||
{{ credit.entry?.release_date | date:'yyyy' }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="loading-container" *ngIf="loading">
|
||||
<div class="spinner-border text-primary" role="status">
|
||||
<span class="visually-hidden">Loading...</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="error-container" *ngIf="!loading && error">
|
||||
<div class="alert alert-danger" role="alert">
|
||||
{{ error }}
|
||||
<button class="btn btn-primary ms-3" [routerLink]="['/people']">Back to People</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="not-found-container" *ngIf="!loading && !person && !error">
|
||||
<div class="alert alert-warning" role="alert">
|
||||
Person not found
|
||||
<button class="btn btn-primary ms-3" [routerLink]="['/people']">Back to People</button>
|
||||
</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 { PeopleDetailsComponent } from './people-details.component';
|
||||
|
||||
describe('PeopleDetailsComponent', () => {
|
||||
let component: PeopleDetailsComponent;
|
||||
let fixture: ComponentFixture<PeopleDetailsComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ PeopleDetailsComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(PeopleDetailsComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,222 @@
|
||||
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { Subject, takeUntil } from 'rxjs';
|
||||
import { PeopleService } from '../../../core/services/people.service';
|
||||
import { ConfigService } from '../../../core/services/config.service';
|
||||
import { Person } from '../../../shared/models/person.model';
|
||||
import { Credit } from '../../../shared/models/credit.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-people-details',
|
||||
templateUrl: './people-details.component.html',
|
||||
styleUrls: ['./people-details.component.css'],
|
||||
})
|
||||
export class PeopleDetailsComponent implements OnInit, OnDestroy {
|
||||
person: Person | null = null;
|
||||
loading: boolean = true;
|
||||
error: string | null = null;
|
||||
backendUrl: string;
|
||||
defaultImage = 'assets/images/default-profile.png';
|
||||
|
||||
// For credits
|
||||
castCredits: Credit[] = [];
|
||||
crewCredits: Credit[] = [];
|
||||
|
||||
private destroy$ = new Subject<void>();
|
||||
|
||||
constructor(
|
||||
private peopleService: PeopleService,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private configService: ConfigService
|
||||
) {
|
||||
this.backendUrl = this.configService.getBackendApiUrl();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.params.pipe(takeUntil(this.destroy$)).subscribe((params) => {
|
||||
const id = params['id'];
|
||||
if (id) {
|
||||
this.loadPersonDetails(Number(id));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
loadPersonDetails(id: number) {
|
||||
this.loading = true;
|
||||
this.error = null;
|
||||
|
||||
this.peopleService
|
||||
.getPersonById(id)
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe({
|
||||
next: (person) => {
|
||||
this.person = person;
|
||||
this.processPerson();
|
||||
this.loading = false;
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Error loading person details:', err);
|
||||
this.error = 'Failed to load person details. Please try again later.';
|
||||
this.loading = false;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private processPerson() {
|
||||
if (!this.person || !this.person.credits) return;
|
||||
|
||||
// Separate cast and crew credits
|
||||
this.castCredits = this.person.credits.filter(
|
||||
(credit) =>
|
||||
credit.job?.toLowerCase() === 'actor' ||
|
||||
credit.job?.toLowerCase() === 'actress' ||
|
||||
credit.department?.toLowerCase() === 'acting'
|
||||
);
|
||||
|
||||
this.crewCredits = this.person.credits.filter(
|
||||
(credit) =>
|
||||
credit.job?.toLowerCase() !== 'actor' &&
|
||||
credit.job?.toLowerCase() !== 'actress' &&
|
||||
credit.department?.toLowerCase() !== 'acting'
|
||||
);
|
||||
|
||||
// Sort credits by entry popularity or release date
|
||||
this.castCredits.sort((a, b) => {
|
||||
if (a.entry?.entryRating.tmdb_rating && b.entry?.entryRating.tmdb_rating) {
|
||||
return b.entry.entryRating.tmdb_rating - a.entry.entryRating.tmdb_rating;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
this.crewCredits.sort((a, b) => {
|
||||
if (a.entry?.entryRating.tmdb_rating && b.entry?.entryRating.tmdb_rating) {
|
||||
return b.entry.entryRating.tmdb_rating - a.entry.entryRating.tmdb_rating;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
refreshPersonDetails() {
|
||||
if (!this.person || !this.person.id) return;
|
||||
|
||||
this.loading = true;
|
||||
this.peopleService
|
||||
.refreshPerson(this.person.id)
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe({
|
||||
next: (person) => {
|
||||
this.person = person;
|
||||
this.processPerson();
|
||||
this.loading = false;
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Error refreshing person details:', err);
|
||||
this.error =
|
||||
'Failed to refresh person details. Please try again later.';
|
||||
this.loading = false;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
getProfileImageUrl(): string {
|
||||
if (!this.person) return this.defaultImage;
|
||||
|
||||
// First check if we have a local media
|
||||
// if (this.person.medias && this.person.medias.length > 0) {
|
||||
// const profileMedia = this.person.medias.find((m) => m.type === 'profile');
|
||||
// if (profileMedia) {
|
||||
// return `${this.backendUrl}/images/people/profiles/${profileMedia.file_name}`;
|
||||
// }
|
||||
// }
|
||||
|
||||
// Fallback to TMDB image if available
|
||||
if (this.person.profile_path) {
|
||||
return `https://image.tmdb.org/t/p/w342${this.person.profile_path}`;
|
||||
}
|
||||
|
||||
// Default image if nothing else is available
|
||||
return this.defaultImage;
|
||||
}
|
||||
|
||||
getEntryImageUrl(credit: Credit): string {
|
||||
if (!credit.entry) return this.defaultImage;
|
||||
|
||||
// First check if we have a local media
|
||||
// if (credit.entry.medias && credit.entry.medias.length > 0) {
|
||||
// const posterMedia = credit.entry.medias.find((m) => m.type === 'poster');
|
||||
// if (posterMedia) {
|
||||
// return `${this.backendUrl}/images/entries/posters/${posterMedia.file_name}`;
|
||||
// }
|
||||
// }
|
||||
|
||||
// Fallback to TMDB image if available
|
||||
if (credit.entry.poster_path) {
|
||||
return `https://image.tmdb.org/t/p/w185${credit.entry.poster_path}`;
|
||||
}
|
||||
|
||||
// Default image if nothing else is available
|
||||
return this.defaultImage;
|
||||
}
|
||||
|
||||
getGenderText(): string {
|
||||
if (!this.person || this.person.gender === undefined)
|
||||
return 'Not specified';
|
||||
|
||||
switch (this.person.gender) {
|
||||
case 0:
|
||||
return 'Not specified';
|
||||
case 1:
|
||||
return 'Female';
|
||||
case 2:
|
||||
return 'Male';
|
||||
case 3:
|
||||
return 'Non-binary';
|
||||
default:
|
||||
return 'Not specified';
|
||||
}
|
||||
}
|
||||
|
||||
formatDate(dateString?: string): string {
|
||||
if (!dateString) return 'Unknown';
|
||||
|
||||
const date = new Date(dateString);
|
||||
if (isNaN(date.getTime())) return 'Unknown';
|
||||
|
||||
return date.toLocaleDateString('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
day: 'numeric',
|
||||
});
|
||||
}
|
||||
|
||||
calculateAge(birthDate?: string, deathDate?: string | null): string {
|
||||
if (!birthDate) return 'Unknown';
|
||||
|
||||
const birth = new Date(birthDate);
|
||||
if (isNaN(birth.getTime())) return 'Unknown';
|
||||
|
||||
let end = deathDate ? new Date(deathDate) : new Date();
|
||||
if (deathDate && isNaN(end.getTime())) end = new Date();
|
||||
|
||||
let age = end.getFullYear() - birth.getFullYear();
|
||||
const monthDiff = end.getMonth() - birth.getMonth();
|
||||
|
||||
if (monthDiff < 0 || (monthDiff === 0 && end.getDate() < birth.getDate())) {
|
||||
age--;
|
||||
}
|
||||
|
||||
return `${age} years`;
|
||||
}
|
||||
|
||||
navigateToEntry(entryId?: number) {
|
||||
if (entryId) {
|
||||
this.router.navigate(['/entries', entryId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user