108 lines
3.1 KiB
TypeScript
108 lines
3.1 KiB
TypeScript
import { Component, OnInit, inject } from '@angular/core';
|
|
import { ActivatedRoute } from '@angular/router';
|
|
import { CommonModule } from '@angular/common';
|
|
import { MatCardModule } from '@angular/material/card';
|
|
import { MatIconModule } from '@angular/material/icon';
|
|
import { DfgProjectDetails } from '../../../api';
|
|
import { Router } from '@angular/router';
|
|
@Component({
|
|
selector: 'app-dfg-details',
|
|
standalone: true,
|
|
imports: [CommonModule, MatCardModule, MatIconModule],
|
|
templateUrl: './dfg-details.component.html',
|
|
styleUrl: './dfg-details.component.scss',
|
|
})
|
|
export class DfgDetailsComponent implements OnInit {
|
|
private route = inject(ActivatedRoute);
|
|
dfgProject: DfgProjectDetails | undefined;
|
|
|
|
constructor(private router: Router) {}
|
|
|
|
ngOnInit(): void {
|
|
this.route.data.subscribe(({ dfgSingleProject }) => {
|
|
console.log('DFG Project:', dfgSingleProject);
|
|
this.dfgProject = dfgSingleProject;
|
|
});
|
|
}
|
|
|
|
getInitials(name: string | null | undefined): string {
|
|
if (!name) return '';
|
|
const parts = name.trim().split(/\s+/);
|
|
if (parts.length > 1) {
|
|
return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase();
|
|
}
|
|
return parts[0][0].toUpperCase();
|
|
}
|
|
|
|
getFundingStatus(fundingEndDate: string | null | undefined): string {
|
|
if (!fundingEndDate) return 'N/A';
|
|
if (fundingEndDate === '2999') return 'Laufend';
|
|
const year = parseInt(fundingEndDate, 10);
|
|
if (isNaN(year)) return fundingEndDate;
|
|
return year >= new Date().getFullYear()
|
|
? `${fundingEndDate}`
|
|
: `${fundingEndDate}`;
|
|
}
|
|
|
|
getStatusDisplay(fundingEndDate: string | null | undefined): string {
|
|
if (!fundingEndDate) return 'N/A';
|
|
if (fundingEndDate === '2999') return 'Laufend';
|
|
const year = parseInt(fundingEndDate, 10);
|
|
return year >= new Date().getFullYear() ? `Laufend` : `Abgeschlossen`;
|
|
}
|
|
|
|
getStatusColor(status: string | null | undefined): string {
|
|
if (!status) return '#95a5a6';
|
|
const statusUpper = status.toUpperCase();
|
|
if (statusUpper.includes('ABGESCHLOSSEN')) {
|
|
return '#27ae60';
|
|
} else if (statusUpper.includes('LAUFEND')) {
|
|
return '#f39c12';
|
|
} else {
|
|
return '#95a5a6';
|
|
}
|
|
}
|
|
|
|
searchForPersonName(personName: string): void {
|
|
this.router.navigate(['/persons'], {
|
|
queryParams: {
|
|
query: personName,
|
|
},
|
|
});
|
|
}
|
|
searchForInstitutionName(institutionName: string): void {
|
|
this.router.navigate(['/institutions'], {
|
|
queryParams: {
|
|
search: institutionName,
|
|
},
|
|
});
|
|
}
|
|
/**
|
|
* All associated persons as a simple list (no role grouping).
|
|
*/
|
|
getAssociatedPersons(): string[] {
|
|
return this.dfgProject?.associated_persons || [];
|
|
}
|
|
|
|
/**
|
|
* All institutions as a simple list.
|
|
*/
|
|
getInstitutions(): string[] {
|
|
return this.dfgProject?.institutions || [];
|
|
}
|
|
getDuration(): string {
|
|
const start = this.dfgProject?.funding_start_date;
|
|
const end =
|
|
this.dfgProject?.funding_end_date === '2999'
|
|
? 'Heute'
|
|
: this.dfgProject?.funding_end_date;
|
|
|
|
if (!start || !end) return '';
|
|
|
|
return `von ${start} bis ${end}`;
|
|
}
|
|
goBack(): void {
|
|
window.history.back();
|
|
}
|
|
}
|