load research timeline via generated works API
LocationBasedServices/smartguide/pipeline/head This commit looks good
LocationBasedServices/smartguide/pipeline/head This commit looks good
This commit is contained in:
@@ -1,20 +1,16 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Component, DestroyRef, OnInit, inject } from '@angular/core';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { ActivatedRoute, ParamMap } from '@angular/router';
|
||||
import { combineLatest, distinctUntilChanged, map } from 'rxjs';
|
||||
|
||||
import { TopicCount, TopicsByYear, WorksService } from '../../api';
|
||||
import {
|
||||
ResearchTimelineComponent,
|
||||
TopicTimelineElement,
|
||||
TopicTimelineTopic,
|
||||
} from './components/research-timeline/research-timeline.component';
|
||||
|
||||
interface TopicTimelineResponse {
|
||||
elements: TopicTimelineElement[];
|
||||
total: number;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-person-overview',
|
||||
standalone: true,
|
||||
@@ -24,7 +20,7 @@ interface TopicTimelineResponse {
|
||||
})
|
||||
export class PersonOverviewComponent implements OnInit {
|
||||
private readonly route = inject(ActivatedRoute);
|
||||
private readonly http = inject(HttpClient);
|
||||
private readonly worksService = inject(WorksService);
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
|
||||
topicTimelineElements: TopicTimelineElement[] = [];
|
||||
@@ -63,14 +59,13 @@ export class PersonOverviewComponent implements OnInit {
|
||||
this.timelineLoadFailed = false;
|
||||
|
||||
const topicCountLimit = 4;
|
||||
const url = `/inse-service/authors/${encodeURIComponent(authorId)}/topics-by-time?max_topics_per_year=${topicCountLimit}`;
|
||||
|
||||
this.http
|
||||
.get<TopicTimelineResponse>(url)
|
||||
this.worksService
|
||||
.getTopicsByTimeByAuthor(authorId, topicCountLimit)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: (response) => {
|
||||
this.topicTimelineElements = response.elements ?? [];
|
||||
this.topicTimelineElements = this.mapTimelineElements(response.elements);
|
||||
this.loadingTimeline = false;
|
||||
this.timelineLoadFailed = false;
|
||||
},
|
||||
@@ -82,4 +77,22 @@ export class PersonOverviewComponent implements OnInit {
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private mapTimelineElements(
|
||||
elements: TopicsByYear[] | undefined,
|
||||
): TopicTimelineElement[] {
|
||||
return (elements ?? []).map((element) => ({
|
||||
year: element.year,
|
||||
publication_count: element.publication_count ?? 0,
|
||||
topics: this.mapTopicCounts(element.topics),
|
||||
primary_topics: this.mapTopicCounts(element.primary_topics),
|
||||
}));
|
||||
}
|
||||
|
||||
private mapTopicCounts(topics: TopicCount[] | undefined): TopicTimelineTopic[] {
|
||||
return (topics ?? []).map((topic) => ({
|
||||
name: topic.name,
|
||||
count: topic.count ?? 0,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user