54 lines
2.0 KiB
TypeScript
54 lines
2.0 KiB
TypeScript
|
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
import { UniversityRankingService } from '../university-ranking/services/uni-ranking-service';
|
|
import {UniversityLineChartComponent} from '../university-ranking/uni-line-chart/uni-line-chart.component';
|
|
import { UniversityRankingTableComponent } from '../university-ranking/uni-ranking-table/uni-ranking-table.component';
|
|
import { UniversityTopicData, UniversityRanking } from '../../api';
|
|
export type ResearchTopic = 'Artificial Intelligence' | 'Quantum Computing' | 'Renewable Energy' | 'Biotechnology';
|
|
export type DashboardMetric = 'publications' | 'citations';
|
|
|
|
@Component({
|
|
selector: 'dashboard',
|
|
imports: [UniversityLineChartComponent,UniversityRankingTableComponent],
|
|
templateUrl: './dashboard.component.html',
|
|
styleUrl: './dashboard.component.scss',
|
|
})
|
|
export class DashboardComponent implements OnInit {
|
|
topics: ResearchTopic[] = ['Artificial Intelligence', 'Quantum Computing', 'Renewable Energy', 'Biotechnology'];
|
|
selectedTopic: ResearchTopic = 'Artificial Intelligence';
|
|
metric: DashboardMetric = 'publications';
|
|
|
|
rawDataSource: UniversityTopicData[] = [];
|
|
computedRankings: UniversityRanking[] = [];
|
|
isLoading = false;
|
|
|
|
constructor(private dataService: UniversityRankingService) {}
|
|
|
|
ngOnInit() {
|
|
this.loadData();
|
|
}
|
|
|
|
onTopicChange(topic: ResearchTopic) {
|
|
this.selectedTopic = topic;
|
|
this.loadData(); // Re-fetch as rankings depend on the topic
|
|
}
|
|
|
|
setMetric(metric: DashboardMetric) {
|
|
this.metric = metric;
|
|
this.loadData(); // Re-fetch as ranking order changes based on metric
|
|
}
|
|
|
|
private loadData() {
|
|
this.isLoading = true;
|
|
this.dataService.getRankingData(this.selectedTopic, this.metric).subscribe(response => {
|
|
// Map backend snake_case properties to frontend camelCase if necessary,
|
|
// though OpenAPI Generator usually handles this.
|
|
console.log(response);
|
|
this.rawDataSource = (response.timeseries as any) || [];
|
|
this.computedRankings = (response.rankings as any) || [];
|
|
this.isLoading = false;
|
|
});
|
|
}
|
|
}
|