added searchForPublication function to publications list
This commit is contained in:
@@ -568,7 +568,7 @@
|
||||
</div>
|
||||
<div class="publications-list">
|
||||
@for (pub of euProject.publications; track pub.doi) {
|
||||
<div class="publication-item">
|
||||
<div class="publication-item" (click)="searchForPublication(pub)">
|
||||
<div class="pub-icon">
|
||||
<mat-icon>article</mat-icon>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// eu-details.component.ts (updated)
|
||||
import { Component, OnInit, inject } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
// eu-details.component.ts (refactored)
|
||||
import { Component, OnInit, inject, OnDestroy } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
@@ -8,7 +8,7 @@ import { MatChipsModule } from '@angular/material/chips';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatDividerModule } from '@angular/material/divider';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import { Router } from '@angular/router';
|
||||
import { Subscription } from 'rxjs';
|
||||
import {
|
||||
formatGermanDate,
|
||||
formatCurrency,
|
||||
@@ -16,6 +16,8 @@ import {
|
||||
import { EuProjectData } from '../../../api/model/euProjectData';
|
||||
import { TopicChipComponent } from '../../../shared/ui/topic-chip/topic-chip.component';
|
||||
import { OrganizationsTableComponent } from './organizations-table/organizations-table/organizations-table.component';
|
||||
import { HEUPublication } from '../../../api';
|
||||
|
||||
export type TabType =
|
||||
| 'overview'
|
||||
| 'organizations'
|
||||
@@ -40,77 +42,123 @@ export type TabType =
|
||||
templateUrl: './eu-details.component.html',
|
||||
styleUrl: './eu-details.component.scss',
|
||||
})
|
||||
export class EuDetailsComponent implements OnInit {
|
||||
export class EuDetailsComponent implements OnInit, OnDestroy {
|
||||
private route = inject(ActivatedRoute);
|
||||
private router = inject(Router);
|
||||
|
||||
// Data
|
||||
euProject: EuProjectData | undefined;
|
||||
programType: string = '';
|
||||
|
||||
// UI State
|
||||
activeTab: TabType = 'overview';
|
||||
programType: String = '';
|
||||
// Track if tabs have content
|
||||
isLoading = true;
|
||||
|
||||
// Tab content flags
|
||||
hasOrganizations = false;
|
||||
hasPublications = false;
|
||||
hasIprs = false;
|
||||
hasDeliverables = false;
|
||||
|
||||
// Subscriptions
|
||||
private subscriptions: Subscription = new Subscription();
|
||||
|
||||
// Tab configuration
|
||||
private readonly tabConfig: Record<TabType, { label: string; icon: string; order: number }> = {
|
||||
overview: { label: 'Übersicht', icon: 'info', order: 0 },
|
||||
organizations: { label: 'Organisationen', icon: 'business', order: 1 },
|
||||
publications: { label: 'Publikationen', icon: 'article', order: 2 },
|
||||
iprs: { label: 'IPRs', icon: 'gavel', order: 3 },
|
||||
deliverables: { label: 'Ergebnisse', icon: 'assignment', order: 4 }
|
||||
};
|
||||
|
||||
ngOnInit(): void {
|
||||
// Subscribe to route data for project
|
||||
this.route.data.subscribe(({ euSingleProject }) => {
|
||||
console.log('EU Project:', euSingleProject);
|
||||
this.euProject = euSingleProject.eu_project_data;
|
||||
// Subscribe to route data
|
||||
this.subscriptions.add(
|
||||
this.route.data.subscribe(({ euSingleProject }) => {
|
||||
console.log('EU Project:', euSingleProject);
|
||||
this.euProject = euSingleProject.eu_project_data;
|
||||
this.isLoading = false;
|
||||
|
||||
// Determine program type
|
||||
if (this.euProject) {
|
||||
if (euSingleProject.iprs !== undefined) {
|
||||
this.programType = 'fp7';
|
||||
} else if (euSingleProject.ercPrincipalInvestigators !== undefined) {
|
||||
this.programType = 'h2020';
|
||||
} else if (euSingleProject.deliverables !== undefined) {
|
||||
this.programType = 'heu';
|
||||
if (this.euProject) {
|
||||
this.determineProgramType(euSingleProject);
|
||||
this.updateTabContentFlags();
|
||||
this.handleTabFromQueryParams();
|
||||
}
|
||||
// Check which tabs have content
|
||||
this.hasOrganizations =
|
||||
(this.euProject.organizations &&
|
||||
this.euProject.organizations.length > 0) ||
|
||||
false;
|
||||
this.hasPublications =
|
||||
(this.euProject.publications &&
|
||||
this.euProject.publications.length > 0) ||
|
||||
false;
|
||||
this.hasIprs =
|
||||
(this.euProject.iprs && this.euProject.iprs.length > 0) || false;
|
||||
this.hasDeliverables =
|
||||
(this.euProject.deliverables &&
|
||||
this.euProject.deliverables.length > 0) ||
|
||||
false;
|
||||
}
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
// Subscribe to query params for tab synchronization
|
||||
this.route.queryParams.subscribe((params) => {
|
||||
const tabParam = params['tab'] as TabType;
|
||||
if (tabParam && this.isValidTab(tabParam)) {
|
||||
if (this.tabHasContent(tabParam)) {
|
||||
this.activeTab = tabParam;
|
||||
} else {
|
||||
// Subscribe to query params changes
|
||||
this.subscriptions.add(
|
||||
this.route.queryParams.subscribe((params) => {
|
||||
// Only handle if data is already loaded
|
||||
if (this.euProject) {
|
||||
this.handleTabFromQueryParams(params);
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.subscriptions.unsubscribe();
|
||||
}
|
||||
|
||||
// ============= PRIVATE METHODS =============
|
||||
|
||||
/**
|
||||
* Determine program type based on available data
|
||||
*/
|
||||
private determineProgramType(euSingleProject: any): void {
|
||||
if (euSingleProject.iprs !== undefined) {
|
||||
this.programType = 'fp7';
|
||||
} else if (euSingleProject.ercPrincipalInvestigators !== undefined) {
|
||||
this.programType = 'h2020';
|
||||
} else if (euSingleProject.deliverables !== undefined) {
|
||||
this.programType = 'heu';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update flags for which tabs have content
|
||||
*/
|
||||
private updateTabContentFlags(): void {
|
||||
this.hasOrganizations =
|
||||
(this.euProject?.organizations && this.euProject.organizations.length > 0) || false;
|
||||
this.hasPublications =
|
||||
(this.euProject?.publications && this.euProject.publications.length > 0) || false;
|
||||
this.hasIprs =
|
||||
(this.euProject?.iprs && this.euProject.iprs.length > 0) || false;
|
||||
this.hasDeliverables =
|
||||
(this.euProject?.deliverables && this.euProject.deliverables.length > 0) || false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle tab selection from query params
|
||||
*/
|
||||
private handleTabFromQueryParams(params?: any): void {
|
||||
const queryParams = params || this.route.snapshot.queryParams;
|
||||
const tabParam = queryParams['tab'] as TabType;
|
||||
|
||||
if (tabParam && this.isValidTab(tabParam)) {
|
||||
if (this.tabHasContent(tabParam)) {
|
||||
this.activeTab = tabParam;
|
||||
} else {
|
||||
// Only update if it's a different tab
|
||||
if (this.activeTab !== 'overview') {
|
||||
this.updateTabQueryParam('overview');
|
||||
}
|
||||
} else {
|
||||
this.updateTabQueryParam('overview');
|
||||
}
|
||||
});
|
||||
} else if (!queryParams['tab'] && this.activeTab !== 'overview') {
|
||||
// Set default tab only if no tab param exists
|
||||
this.updateTabQueryParam('overview');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a tab value is valid
|
||||
*/
|
||||
private isValidTab(tab: string): tab is TabType {
|
||||
return [
|
||||
'overview',
|
||||
'organizations',
|
||||
'publications',
|
||||
'iprs',
|
||||
'deliverables',
|
||||
].includes(tab);
|
||||
return ['overview', 'organizations', 'publications', 'iprs', 'deliverables'].includes(tab);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,21 +185,45 @@ export class EuDetailsComponent implements OnInit {
|
||||
* Update URL query param for tab
|
||||
*/
|
||||
private updateTabQueryParam(tab: TabType): void {
|
||||
// Prevent unnecessary navigation
|
||||
const currentTab = this.route.snapshot.queryParams['tab'];
|
||||
if (currentTab === tab) return;
|
||||
|
||||
this.router.navigate([], {
|
||||
relativeTo: this.route,
|
||||
queryParams: { tab: tab },
|
||||
queryParamsHandling: 'merge', // Preserve other query params
|
||||
});
|
||||
queryParamsHandling: 'merge',
|
||||
}).catch(err => console.error('Tab navigation failed:', err));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get color for keyword based on index
|
||||
*/
|
||||
private getKeywordColor(index: number): string {
|
||||
const colors = [
|
||||
'#3498db', // Blue
|
||||
'#e67e22', // Orange
|
||||
'#27ae60', // Green
|
||||
'#8e44ad', // Purple
|
||||
'#e74c3c', // Red
|
||||
'#1abc9c', // Teal
|
||||
'#f39c12', // Gold
|
||||
'#2c3e50', // Navy
|
||||
];
|
||||
return colors[index % colors.length];
|
||||
}
|
||||
|
||||
// ============= PUBLIC METHODS =============
|
||||
|
||||
/**
|
||||
* Set active tab and update URL
|
||||
*/
|
||||
setTab(tab: TabType): void {
|
||||
if (this.activeTab === tab) return;
|
||||
|
||||
|
||||
// Check if tab has content
|
||||
if (!this.tabHasContent(tab)) {
|
||||
console.warn(`Tab "${tab}" has no content`);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -166,18 +238,25 @@ export class EuDetailsComponent implements OnInit {
|
||||
return this.activeTab === tab;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if tab is visible (has content)
|
||||
*/
|
||||
isTabVisible(tab: TabType): boolean {
|
||||
return this.tabHasContent(tab);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tab label with count
|
||||
*/
|
||||
getTabLabel(tab: TabType): string {
|
||||
const labels: Record<TabType, string> = {
|
||||
overview: 'Übersicht',
|
||||
organizations: 'Organisationen',
|
||||
publications: 'Publikationen',
|
||||
iprs: 'IPRs',
|
||||
deliverables: 'Ergebnisse',
|
||||
};
|
||||
return labels[tab];
|
||||
return this.tabConfig[tab].label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tab icon
|
||||
*/
|
||||
getTabIcon(tab: TabType): string {
|
||||
return this.tabConfig[tab].icon;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -198,6 +277,17 @@ export class EuDetailsComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sorted tabs that have content
|
||||
*/
|
||||
getVisibleTabs(): TabType[] {
|
||||
return (['overview', 'organizations', 'publications', 'iprs', 'deliverables'] as TabType[])
|
||||
.filter(tab => this.tabHasContent(tab))
|
||||
.sort((a, b) => this.tabConfig[a].order - this.tabConfig[b].order);
|
||||
}
|
||||
|
||||
// ============= FORMATTING METHODS =============
|
||||
|
||||
getFundingStatus(endDate: string | null | undefined): string {
|
||||
if (!endDate) return 'N/A';
|
||||
const end = new Date(endDate);
|
||||
@@ -210,22 +300,21 @@ export class EuDetailsComponent implements OnInit {
|
||||
|
||||
getDuration(start: string | undefined, end: string | undefined): string {
|
||||
if (!start || !end) return '';
|
||||
|
||||
return `von ${formatGermanDate(start)} bis ${formatGermanDate(end)}`;
|
||||
}
|
||||
|
||||
formatDate(date: string | undefined) {
|
||||
formatDate(date: string | undefined): string | undefined {
|
||||
if (date) {
|
||||
return formatGermanDate(date);
|
||||
}
|
||||
return date;
|
||||
}
|
||||
|
||||
formatCurr(value: number | undefined | null) {
|
||||
formatCurr(value: number | undefined | null): string | null | undefined {
|
||||
if (value) {
|
||||
return formatCurrency(value);
|
||||
}
|
||||
return value;
|
||||
return String(value);
|
||||
}
|
||||
|
||||
getStatusColor(status: string | null | undefined): string {
|
||||
@@ -234,10 +323,7 @@ export class EuDetailsComponent implements OnInit {
|
||||
const statusUpper = status.toUpperCase();
|
||||
if (statusUpper.includes('CLOSED') || statusUpper.includes('COMPLETED')) {
|
||||
return '#27ae60';
|
||||
} else if (
|
||||
statusUpper.includes('ONGOING') ||
|
||||
statusUpper.includes('ACTIVE')
|
||||
) {
|
||||
} else if (statusUpper.includes('ONGOING') || statusUpper.includes('ACTIVE')) {
|
||||
return '#f39c12';
|
||||
} else if (statusUpper.includes('SIGNED')) {
|
||||
return '#3498db';
|
||||
@@ -283,15 +369,13 @@ export class EuDetailsComponent implements OnInit {
|
||||
if (!scheme) return 'N/A';
|
||||
|
||||
const schemeMap: { [key: string]: string } = {
|
||||
'MSCA-IF-EF-SE':
|
||||
'MSCA Individual Fellowship - European Fellowship - Standard',
|
||||
'MSCA-IF-EF-SE': 'MSCA Individual Fellowship - European Fellowship - Standard',
|
||||
'MSCA-IF-EF': 'MSCA Individual Fellowship - European Fellowship',
|
||||
'MSCA-IF-GF': 'MSCA Individual Fellowship - Global Fellowship',
|
||||
'MSCA-IF': 'MSCA Individual Fellowship',
|
||||
'MSCA-ITN': 'MSCA Innovative Training Networks',
|
||||
'MSCA-RISE': 'MSCA Research and Innovation Staff Exchange',
|
||||
'MSCA-COFUND':
|
||||
'MSCA Co-funding of Regional, National and International Programmes',
|
||||
'MSCA-COFUND': 'MSCA Co-funding of Regional, National and International Programmes',
|
||||
};
|
||||
|
||||
return schemeMap[scheme] || scheme;
|
||||
@@ -333,7 +417,6 @@ export class EuDetailsComponent implements OnInit {
|
||||
const keywords = this.getKeywords(this.euProject?.keywords);
|
||||
if (keywords.length === 0) return [];
|
||||
|
||||
// Simple keyword list
|
||||
return keywords.map((keyword, index) => ({
|
||||
label: keyword,
|
||||
count: 1,
|
||||
@@ -346,27 +429,8 @@ export class EuDetailsComponent implements OnInit {
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get color for keyword based on index
|
||||
*/
|
||||
private getKeywordColor(index: number): string {
|
||||
const colors = [
|
||||
'#3498db', // Blue
|
||||
'#e67e22', // Orange
|
||||
'#27ae60', // Green
|
||||
'#8e44ad', // Purple
|
||||
'#e74c3c', // Red
|
||||
'#1abc9c', // Teal
|
||||
'#f39c12', // Gold
|
||||
'#2c3e50', // Navy
|
||||
];
|
||||
return colors[index % colors.length];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get path segments from a path string
|
||||
* Example: "natural sciences/chemical sciences/polymer sciences"
|
||||
* => ["natural sciences", "chemical sciences", "polymer sciences"]
|
||||
*/
|
||||
getPathSegments(path: string | undefined): string[] {
|
||||
if (!path) return [];
|
||||
@@ -390,34 +454,106 @@ export class EuDetailsComponent implements OnInit {
|
||||
return Array.from(countries);
|
||||
}
|
||||
|
||||
// Search functions
|
||||
// ============= SEARCH / NAVIGATION METHODS =============
|
||||
|
||||
/**
|
||||
* Navigate to projects with topic filter
|
||||
*/
|
||||
searchByTopic(topic: string): void {
|
||||
if (!topic) {
|
||||
console.warn('Cannot search with empty topic');
|
||||
return;
|
||||
}
|
||||
|
||||
this.router.navigate(['/eu-projects'], {
|
||||
queryParams: { topic: topic },
|
||||
});
|
||||
}).catch(err => console.error('Navigation to topic failed:', err));
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigate to projects with keyword filter
|
||||
*/
|
||||
searchByKeyword(keyword: string): void {
|
||||
if (!keyword) {
|
||||
console.warn('Cannot search with empty keyword');
|
||||
return;
|
||||
}
|
||||
|
||||
this.router.navigate(['/eu-projects'], {
|
||||
queryParams: { keyword: keyword },
|
||||
});
|
||||
}).catch(err => console.error('Navigation to keyword failed:', err));
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigate to projects with framework filter
|
||||
*/
|
||||
searchByFramework(framework: string): void {
|
||||
if (!framework) {
|
||||
console.warn('Cannot search with empty framework');
|
||||
return;
|
||||
}
|
||||
|
||||
this.router.navigate(['/eu-projects'], {
|
||||
queryParams: { framework: framework },
|
||||
});
|
||||
}).catch(err => console.error('Navigation to framework failed:', err));
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigate to projects with funding scheme filter
|
||||
*/
|
||||
searchByFundingScheme(scheme: string): void {
|
||||
if (!scheme) {
|
||||
console.warn('Cannot search with empty funding scheme');
|
||||
return;
|
||||
}
|
||||
|
||||
this.router.navigate(['/eu-projects'], {
|
||||
queryParams: { fundingScheme: scheme },
|
||||
});
|
||||
}).catch(err => console.error('Navigation to funding scheme failed:', err));
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigate to projects with status filter
|
||||
*/
|
||||
searchByStatus(status: string): void {
|
||||
if (!status) {
|
||||
console.warn('Cannot search with empty status');
|
||||
return;
|
||||
}
|
||||
|
||||
this.router.navigate(['/eu-projects'], {
|
||||
queryParams: { status: status },
|
||||
});
|
||||
}).catch(err => console.error('Navigation to status failed:', err));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigate to publication details
|
||||
*/
|
||||
searchForPublication(pub: HEUPublication): void {
|
||||
if (!pub) {
|
||||
console.warn('Cannot navigate with empty publication');
|
||||
return;
|
||||
}
|
||||
|
||||
const doi = pub.doi?.trim() ?? "unknown";
|
||||
|
||||
// Encode DOI and navigate
|
||||
const encodedDoi = encodeURIComponent(doi);
|
||||
|
||||
this.router.navigate(['/publication', encodedDoi], {
|
||||
queryParams: {
|
||||
title: pub.title || ''
|
||||
},
|
||||
}).catch(err => console.error('Navigation to publication failed:', err));
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigate back to projects list with optional filter
|
||||
*/
|
||||
goBack(filters?: { [key: string]: any }): void {
|
||||
this.router.navigate(['/eu-projects'], {
|
||||
queryParams: filters || {},
|
||||
queryParamsHandling: 'merge',
|
||||
}).catch(err => console.error('Navigation back failed:', err));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user