added resolver preloading and child component state management. (If something breaks in behavior, revert to this point)
This commit is contained in:
+7
-7
@@ -175,15 +175,15 @@
|
||||
|
||||
<!-- Main Full-Width Content Area -->
|
||||
<main class="trend-main-fullwidth">
|
||||
@if (isPageResolving() || (isTrendLoading() && !rawTrendResponse())) {
|
||||
<app-loading
|
||||
text="Trenddaten werden geladen..."
|
||||
icon="trending_up"
|
||||
[size]="200"
|
||||
[diameter]="200"></app-loading>
|
||||
} @else if (rawTrendResponse()) {
|
||||
@if (rawTrendResponse()) {
|
||||
<!-- Chart Holder Card (100% Full Width) -->
|
||||
<div class="chart-holder-card">
|
||||
@if (isTrendLoading() || isPageResolving()) {
|
||||
<div class="loader-overlay">
|
||||
<mat-spinner diameter="40"></mat-spinner>
|
||||
<p>Daten werden geladen...</p>
|
||||
</div>
|
||||
}
|
||||
@if (selectedTrendTopics().length > 0) {
|
||||
<div class="chart-topic-tabs">
|
||||
@for (topic of selectedTrendTopics(); track topic) {
|
||||
|
||||
+58
-20
@@ -530,14 +530,23 @@ export class UniTrendParentComponent implements OnInit {
|
||||
if (!res || !res.series || res.series.length === 0) return false;
|
||||
const startYr = this.startYear();
|
||||
const endYr = this.endYear();
|
||||
const mapped = this.getMappedTopic(topic).toLowerCase().trim();
|
||||
const topicLower = topic.toLowerCase().trim();
|
||||
const mappedLower = this.getMappedTopic(topic).toLowerCase().trim();
|
||||
|
||||
return !res.series.some((s) => {
|
||||
const yearlyList =
|
||||
s.topic_data?.[topic] ||
|
||||
s.topic_data?.[mapped] ||
|
||||
Object.values(s.topic_data || {})[0];
|
||||
if (!yearlyList) return false;
|
||||
if (!s.topic_data) return false;
|
||||
const matchingKey = Object.keys(s.topic_data).find((key) => {
|
||||
const kLower = key.toLowerCase().trim();
|
||||
return (
|
||||
kLower === topicLower ||
|
||||
kLower === mappedLower ||
|
||||
(kLower.startsWith('news_topic_') &&
|
||||
kLower.slice('news_topic_'.length) === topicLower)
|
||||
);
|
||||
});
|
||||
if (!matchingKey) return false;
|
||||
const yearlyList = s.topic_data[matchingKey];
|
||||
if (!yearlyList || !Array.isArray(yearlyList)) return false;
|
||||
const total = yearlyList
|
||||
.filter((y) => y.year >= startYr && y.year <= endYr)
|
||||
.reduce((sum, item) => sum + (item.raw || 0), 0);
|
||||
@@ -545,6 +554,12 @@ export class UniTrendParentComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
findFirstNonEmptyTopic(topics: string[]): string {
|
||||
if (!topics || topics.length === 0) return '';
|
||||
const nonEmpties = topics.filter((t) => !this.isTopicEmpty(t));
|
||||
return nonEmpties.length > 0 ? nonEmpties[0] : topics[0] || '';
|
||||
}
|
||||
|
||||
isVisible(id: string): boolean {
|
||||
return this.entityVisibilityMap().get(id) !== false;
|
||||
}
|
||||
@@ -892,10 +907,10 @@ export class UniTrendParentComponent implements OnInit {
|
||||
if (resolved.topics && resolved.topics.length > 0) {
|
||||
this.selectedTrendTopics.set(resolved.topics);
|
||||
this.fetchedTopics.set([...resolved.topics]);
|
||||
const firstNonEmpty = resolved.topics.find(
|
||||
(t: string) => !this.isTopicEmpty(t),
|
||||
);
|
||||
const targetTopic = firstNonEmpty || resolved.topics[0];
|
||||
const targetTopic =
|
||||
resolved.initialActiveTopic ||
|
||||
resolved.topics.find((t: string) => !this.isTopicEmpty(t)) ||
|
||||
resolved.topics[0];
|
||||
this.activeChartTopic.set(targetTopic);
|
||||
} else {
|
||||
this.fetchedTopics.set([...this.selectedTrendTopics()]);
|
||||
@@ -929,6 +944,14 @@ export class UniTrendParentComponent implements OnInit {
|
||||
this.fetchedAuthors.set([...this.comparisonAuthors()]);
|
||||
}
|
||||
|
||||
if (resolved.topSuggestions) {
|
||||
this.topSuggestions.set(resolved.topSuggestions);
|
||||
}
|
||||
|
||||
if (resolved.recommendedAuthors) {
|
||||
this.recommendedAuthors.set(resolved.recommendedAuthors);
|
||||
}
|
||||
|
||||
if (resolved.treemapData) {
|
||||
this.topicTreemap.set(resolved.treemapData);
|
||||
}
|
||||
@@ -972,11 +995,20 @@ export class UniTrendParentComponent implements OnInit {
|
||||
this.selectedTrendTopics.set(topics);
|
||||
}
|
||||
|
||||
// Initialize active chart topic to the first selected topic if empty or invalid
|
||||
// Initialize active chart topic to a valid non-empty topic
|
||||
const active = currentActive;
|
||||
const updatedSelections = untracked(() => this.selectedTrendTopics());
|
||||
if (!active || !updatedSelections.includes(active)) {
|
||||
this.activeChartTopic.set(updatedSelections[0] || '');
|
||||
const mappedActive = this.getMappedTopic(active);
|
||||
if (
|
||||
mappedActive &&
|
||||
updatedSelections.includes(mappedActive) &&
|
||||
!this.isTopicEmpty(mappedActive)
|
||||
) {
|
||||
this.activeChartTopic.set(mappedActive);
|
||||
} else {
|
||||
this.activeChartTopic.set(
|
||||
this.findFirstNonEmptyTopic(updatedSelections),
|
||||
);
|
||||
}
|
||||
|
||||
// If comparison list is empty, initialize default institutions/authors dynamically
|
||||
@@ -1048,7 +1080,11 @@ export class UniTrendParentComponent implements OnInit {
|
||||
: a.id.toLowerCase();
|
||||
return rawSeriesCleanIds.has(cleanA);
|
||||
});
|
||||
} else if (searchType === 'news' || searchType === 'all') {
|
||||
} else if (
|
||||
searchType === 'news' ||
|
||||
searchType === 'all' ||
|
||||
searchType === 'patents'
|
||||
) {
|
||||
allEntitiesFetched = true;
|
||||
} else {
|
||||
// publications, patents, projects
|
||||
@@ -1399,7 +1435,11 @@ export class UniTrendParentComponent implements OnInit {
|
||||
if (kws.length === 0) return;
|
||||
|
||||
const topics = this.state?.topicsList() ?? kws;
|
||||
const topic = topics[0] || kws[0] || 'Artificial Intelligence';
|
||||
const topic =
|
||||
this.findFirstNonEmptyTopic(topics) ||
|
||||
topics[0] ||
|
||||
kws[0] ||
|
||||
'Artificial Intelligence';
|
||||
|
||||
this.personsApiService
|
||||
.searchPersonsList(
|
||||
@@ -1595,7 +1635,6 @@ export class UniTrendParentComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
this.isTrendLoading.set(false);
|
||||
this.updateUrlParams();
|
||||
},
|
||||
error: () => {
|
||||
this.isTrendLoading.set(false);
|
||||
@@ -1695,8 +1734,8 @@ export class UniTrendParentComponent implements OnInit {
|
||||
this.selectedTrendTopics.set(updated);
|
||||
|
||||
const active = this.activeChartTopic();
|
||||
if (!updated.includes(active)) {
|
||||
this.activeChartTopic.set(updated[0] || '');
|
||||
if (!updated.includes(active) || this.isTopicEmpty(active)) {
|
||||
this.activeChartTopic.set(this.findFirstNonEmptyTopic(updated));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1871,13 +1910,12 @@ export class UniTrendParentComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
// Topic tab toggle (data reuses instantly)
|
||||
// Topic tab toggle (data reuses instantly, no router navigation to prevent chart flickering)
|
||||
updateActiveChartTopic(topic: string) {
|
||||
if (this.isTopicEmpty(topic)) {
|
||||
return;
|
||||
}
|
||||
this.activeChartTopic.set(topic);
|
||||
this.updateUrlParams();
|
||||
}
|
||||
|
||||
// Autocomplete query changes for institutions
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
import { inject } from '@angular/core';
|
||||
import { ResolveFn } from '@angular/router';
|
||||
import { catchError, of, Observable, map } from 'rxjs';
|
||||
import { TrendResponse, UniversityRankingsService } from '../api';
|
||||
import { catchError, of, Observable, map, forkJoin } from 'rxjs';
|
||||
import {
|
||||
TrendResponse,
|
||||
UniversityRankingsService,
|
||||
PersonsService,
|
||||
} from '../api';
|
||||
import { SearchResultsStateService } from '../modules/keywords-search/search-results/search-results-state.service';
|
||||
import { CredentialService } from '../shared/services/credential.service';
|
||||
|
||||
export interface CompareItem {
|
||||
id: string;
|
||||
@@ -19,6 +24,9 @@ export interface UniTrendResolvedData {
|
||||
countries: CompareItem[];
|
||||
regions: CompareItem[];
|
||||
authors: CompareItem[];
|
||||
initialActiveTopic?: string;
|
||||
topSuggestions?: any[];
|
||||
recommendedAuthors?: any[];
|
||||
treemapNode?: string | null;
|
||||
}
|
||||
|
||||
@@ -28,11 +36,18 @@ export const uniTrendResolver: ResolveFn<UniTrendResolvedData> = (
|
||||
): Observable<UniTrendResolvedData> => {
|
||||
const params = route.queryParamMap;
|
||||
const searchState = inject(SearchResultsStateService, { optional: true });
|
||||
const credentialService = inject(CredentialService, { optional: true });
|
||||
|
||||
const searchType = params.get('search_type') || 'publications';
|
||||
const fuzzy = params.get('fuzzy') !== 'false';
|
||||
const treemapNode = params.get('treemapNode');
|
||||
|
||||
// Primary institution from user token / credential service
|
||||
const primaryInstId =
|
||||
credentialService?.effectiveInstitutionId() || 'I62318514';
|
||||
const primaryInstName =
|
||||
credentialService?.organizationName() || 'Universität Duisburg-Essen';
|
||||
|
||||
// Extract keywords & topics
|
||||
let keywords = params.getAll('keyword');
|
||||
if (keywords.length === 0) {
|
||||
@@ -79,9 +94,17 @@ export const uniTrendResolver: ResolveFn<UniTrendResolvedData> = (
|
||||
const cleanId = parts[0].includes('/')
|
||||
? parts[0].split('/').pop() || parts[0]
|
||||
: parts[0];
|
||||
return { id: cleanId, name: parts[1] || cleanId };
|
||||
const isPrimary =
|
||||
cleanId.toLowerCase() === primaryInstId.toLowerCase() ||
|
||||
primaryInstId.toLowerCase().includes(cleanId.toLowerCase());
|
||||
const name = parts[1] || (isPrimary ? primaryInstName : parts[0]);
|
||||
return { id: cleanId, name };
|
||||
});
|
||||
|
||||
if (parsedInstitutions.length === 0 && searchType !== 'authors') {
|
||||
parsedInstitutions.push({ id: primaryInstId, name: primaryInstName });
|
||||
}
|
||||
|
||||
const countryParams = params.getAll('countries');
|
||||
const parsedCountries: CompareItem[] = countryParams.map((c) => {
|
||||
const parts = c.split('|');
|
||||
@@ -103,15 +126,22 @@ export const uniTrendResolver: ResolveFn<UniTrendResolvedData> = (
|
||||
const instIds =
|
||||
parsedInstitutions.length > 0
|
||||
? parsedInstitutions.map((i) => i.id)
|
||||
: ['I62318514'];
|
||||
: [primaryInstId];
|
||||
const countryIds =
|
||||
parsedCountries.length > 0 ? parsedCountries.map((c) => c.id) : ['DE'];
|
||||
const regionIds = parsedRegions.map((r) => r.id);
|
||||
const authorIds = parsedAuthors.map((a) => a.id);
|
||||
|
||||
const apiService = inject(UniversityRankingsService);
|
||||
const personsService = inject(PersonsService, { optional: true });
|
||||
|
||||
return apiService
|
||||
const primaryTopic = topics[0] || 'Artificial Intelligence';
|
||||
const countryFilter =
|
||||
parsedCountries.length > 0 ? parsedCountries[0].id : undefined;
|
||||
const regionFilter =
|
||||
parsedRegions.length > 0 ? parsedRegions[0].id : undefined;
|
||||
|
||||
const trendObs$ = apiService
|
||||
.getTrendApiInseServiceUniversityRankingsTrendGet(
|
||||
topics,
|
||||
keywords,
|
||||
@@ -122,9 +152,94 @@ export const uniTrendResolver: ResolveFn<UniTrendResolvedData> = (
|
||||
authorIds,
|
||||
searchType as any,
|
||||
)
|
||||
.pipe(
|
||||
catchError(() => of(null)),
|
||||
map((trendResponse) => ({
|
||||
.pipe(catchError(() => of(null)));
|
||||
|
||||
const topInstObs$ =
|
||||
searchType !== 'authors'
|
||||
? apiService
|
||||
.getTopInstitutionsApiInseServiceUniversityRankingsTopInstitutionsGet(
|
||||
primaryTopic,
|
||||
regionFilter,
|
||||
countryFilter,
|
||||
6,
|
||||
)
|
||||
.pipe(catchError(() => of([])))
|
||||
: of([]);
|
||||
|
||||
const recAuthorsObs$ =
|
||||
searchType === 'authors' && personsService
|
||||
? personsService
|
||||
.searchPersonsList(
|
||||
undefined,
|
||||
primaryInstId,
|
||||
'cited_by_count',
|
||||
'desc',
|
||||
[primaryTopic],
|
||||
1,
|
||||
6,
|
||||
undefined,
|
||||
)
|
||||
.pipe(
|
||||
map((res: any) => res.results || []),
|
||||
catchError(() => of([])),
|
||||
)
|
||||
: of([]);
|
||||
|
||||
return forkJoin({
|
||||
trendResponse: trendObs$,
|
||||
topSuggestions: topInstObs$,
|
||||
recommendedAuthors: recAuthorsObs$,
|
||||
}).pipe(
|
||||
map(({ trendResponse, topSuggestions, recommendedAuthors }) => {
|
||||
// Find the first topic with non-zero publication data
|
||||
let initialActiveTopic = primaryTopic;
|
||||
if (
|
||||
trendResponse?.series &&
|
||||
trendResponse.series.length > 0 &&
|
||||
topics.length > 0
|
||||
) {
|
||||
const nonEmptyTopic = topics.find((t) =>
|
||||
trendResponse.series.some((s) => {
|
||||
if (!s.topic_data) return false;
|
||||
const tLower = t.toLowerCase().trim();
|
||||
const matchingKey = Object.keys(s.topic_data).find((key) => {
|
||||
const kLower = key.toLowerCase().trim();
|
||||
return (
|
||||
kLower === tLower ||
|
||||
(kLower.startsWith('news_topic_') &&
|
||||
kLower.slice('news_topic_'.length) === tLower)
|
||||
);
|
||||
});
|
||||
if (!matchingKey) return false;
|
||||
const yearlyList = s.topic_data[matchingKey];
|
||||
if (!yearlyList || !Array.isArray(yearlyList)) return false;
|
||||
const total = yearlyList.reduce(
|
||||
(sum, item) => sum + (item.raw || 0),
|
||||
0,
|
||||
);
|
||||
return total > 0;
|
||||
}),
|
||||
);
|
||||
if (nonEmptyTopic) {
|
||||
initialActiveTopic = nonEmptyTopic;
|
||||
}
|
||||
}
|
||||
|
||||
// If in author mode and no explicit authors were passed in URL, populate default top authors
|
||||
if (
|
||||
searchType === 'authors' &&
|
||||
parsedAuthors.length === 0 &&
|
||||
recommendedAuthors?.length
|
||||
) {
|
||||
recommendedAuthors.slice(0, 3).forEach((author: any) => {
|
||||
parsedAuthors.push({
|
||||
id: author.id,
|
||||
name: author.display_name || 'Unbekannt',
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
trendResponse,
|
||||
searchType,
|
||||
topics,
|
||||
@@ -134,7 +249,11 @@ export const uniTrendResolver: ResolveFn<UniTrendResolvedData> = (
|
||||
countries: parsedCountries,
|
||||
regions: parsedRegions,
|
||||
authors: parsedAuthors,
|
||||
initialActiveTopic,
|
||||
topSuggestions: topSuggestions as any[],
|
||||
recommendedAuthors: recommendedAuthors as any[],
|
||||
treemapNode,
|
||||
})),
|
||||
);
|
||||
};
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user