added new resolvers for EU cordis autocompletion, projects retrieval, reworked routing logic for projects
This commit is contained in:
@@ -41,11 +41,15 @@ import { SearchResultsStateService } from './modules/keywords-search/search-resu
|
||||
import { roleGuard } from './shared/guards/role.guard';
|
||||
import { UserRole } from './api';
|
||||
import { personCordisEuProjectPageResolver } from './resolvers/person-cordis-eu-project-page.resolver';
|
||||
import { euCordisProjectsResolver } from './resolvers/eu-cordis-projects.resolver';
|
||||
import { selectedAuthorsResolver } from './resolvers/selected-authors.resolver';
|
||||
import { workClassificationResolver } from './resolvers/work-classification.resolver';
|
||||
import { selectedDfgAuthorsResolver } from './resolvers/selected-dfg-authors.resolver';
|
||||
import { selectedDfgInstitutionsResolver } from './resolvers/selected-dfg-institutions.resolver';
|
||||
import { primaryCategoryYearAggregationPageResolver } from './resolvers/primary-category-year-aggregation-page.resolver';
|
||||
import { selectedEuInstitutionsResolver } from './resolvers/selected-eu-institutions.resolver';
|
||||
import { EuProjectsComponent } from './shared/ui/eu-projects/eu-projects.component';
|
||||
import { DfgProjectsComponent } from './shared/ui/dfg-projects/dfg-projects.component';
|
||||
export const routes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
@@ -173,19 +177,41 @@ export const routes: Routes = [
|
||||
{
|
||||
path: 'projects',
|
||||
component: KeywordsToProjectsResultsComponent,
|
||||
runGuardsAndResolvers: 'always',
|
||||
resolve: {
|
||||
dfgProjectPage: dfgProjectsResolver,
|
||||
personCordisEuProjectPage: personCordisEuProjectPageResolver,
|
||||
selectedDfgInstitutionsPage: selectedDfgInstitutionsResolver,
|
||||
selectedDfgAuthorsPage: selectedDfgAuthorsResolver,
|
||||
selectedTopicsPage: selectedTopicsResolver,
|
||||
selectedEuInstitutionsPage: selectedInstitutionsResolver,
|
||||
selectedEuAuthorsPage: selectedAuthorsResolver,
|
||||
},
|
||||
data: {
|
||||
resolvingFor: RESOLVING_PROJECT_PAGE_FOR.KEYWORDS_SEARCH,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
pathMatch: 'full',
|
||||
redirectTo: 'dfg',
|
||||
},
|
||||
{
|
||||
path: 'dfg',
|
||||
component: DfgProjectsComponent,
|
||||
resolve: {
|
||||
dfgProjectPage: dfgProjectsResolver,
|
||||
selectedDfgInstitutionsPage: selectedDfgInstitutionsResolver,
|
||||
selectedDfgAuthorsPage: selectedDfgAuthorsResolver,
|
||||
selectedTopicsPage: selectedTopicsResolver,
|
||||
},
|
||||
runGuardsAndResolvers: 'always',
|
||||
data: {
|
||||
resolvingFor: RESOLVING_PROJECT_PAGE_FOR.KEYWORDS_SEARCH,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'eu',
|
||||
component: EuProjectsComponent,
|
||||
resolve: {
|
||||
euCordisProjectPage: euCordisProjectsResolver,
|
||||
selectedEuInstitutionsPage: selectedEuInstitutionsResolver,
|
||||
selectedEuAuthorsPage: selectedAuthorsResolver,
|
||||
selectedTopicsPage: selectedTopicsResolver,
|
||||
},
|
||||
runGuardsAndResolvers: 'always',
|
||||
data: {
|
||||
resolvingFor: RESOLVING_PROJECT_PAGE_FOR.KEYWORDS_SEARCH,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{ path: 'patents', component: KeywordsToPatentsResultsComponent },
|
||||
{
|
||||
@@ -402,19 +428,41 @@ export const routes: Routes = [
|
||||
import('./modules/person-projects/person-projects.component').then(
|
||||
(mod) => mod.PersonProjectsComponent,
|
||||
),
|
||||
resolve: {
|
||||
dfgProjectPage: dfgProjectsResolver,
|
||||
personCordisEuProjectPage: personCordisEuProjectPageResolver,
|
||||
selectedDfgInstitutionsPage: selectedDfgInstitutionsResolver,
|
||||
selectedDfgAuthorsPage: selectedDfgAuthorsResolver,
|
||||
selectedTopicsPage: selectedTopicsResolver,
|
||||
selectedEuInstitutionsPage: selectedInstitutionsResolver,
|
||||
selectedEuAuthorsPage: selectedAuthorsResolver,
|
||||
},
|
||||
runGuardsAndResolvers: 'always',
|
||||
data: {
|
||||
resolvingFor: RESOLVING_PROJECT_PAGE_FOR.PERSON,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
pathMatch: 'full',
|
||||
redirectTo: 'dfg',
|
||||
},
|
||||
{
|
||||
path: 'dfg',
|
||||
component: DfgProjectsComponent,
|
||||
resolve: {
|
||||
dfgProjectPage: dfgProjectsResolver,
|
||||
selectedDfgInstitutionsPage: selectedDfgInstitutionsResolver,
|
||||
selectedDfgAuthorsPage: selectedDfgAuthorsResolver,
|
||||
selectedTopicsPage: selectedTopicsResolver,
|
||||
},
|
||||
runGuardsAndResolvers: 'always',
|
||||
data: {
|
||||
resolvingFor: RESOLVING_PROJECT_PAGE_FOR.PERSON,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'eu',
|
||||
component: EuProjectsComponent,
|
||||
resolve: {
|
||||
euCordisProjectPage: euCordisProjectsResolver,
|
||||
selectedEuInstitutionsPage: selectedEuInstitutionsResolver,
|
||||
selectedEuAuthorsPage: selectedAuthorsResolver,
|
||||
selectedTopicsPage: selectedTopicsResolver,
|
||||
},
|
||||
runGuardsAndResolvers: 'always',
|
||||
data: {
|
||||
resolvingFor: RESOLVING_PROJECT_PAGE_FOR.PERSON,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: 'publications',
|
||||
|
||||
@@ -36,8 +36,6 @@ export const dfgProjectsResolver: ResolveFn<DfgProjectPage> = (
|
||||
route.data,
|
||||
);
|
||||
|
||||
const rawAuthorId = route.parent?.params['id'];
|
||||
|
||||
const page = Number(route.queryParamMap.get(projectQueryParamKeys.page)) || 0;
|
||||
const size =
|
||||
Number(route.queryParamMap.get(projectQueryParamKeys.size)) || 10;
|
||||
@@ -65,7 +63,9 @@ export const dfgProjectsResolver: ResolveFn<DfgProjectPage> = (
|
||||
.getAll(projectQueryParamKeys.authorId)
|
||||
.map((id) => Number(id))
|
||||
.filter((id) => !isNaN(id));
|
||||
|
||||
if (resolvingFor === RESOLVING_PROJECT_PAGE_FOR.PERSON) {
|
||||
const rawAuthorId = route.parent?.parent?.params['id'];
|
||||
return inject(ProjectsService).getDfgProjects(
|
||||
rawAuthorId,
|
||||
authorIds,
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
import { inject } from '@angular/core';
|
||||
import { ResolveFn } from '@angular/router';
|
||||
import { ProjectsService } from '../api';
|
||||
import { EuCordisProjectSearchPage } from '../api/model/euCordisProjectSearchPage';
|
||||
|
||||
export const euProjectQueryParamKeys = {
|
||||
page: 'page',
|
||||
size: 'size',
|
||||
title: 'title',
|
||||
|
||||
institutionId: 'institutionId',
|
||||
|
||||
funding_start: 'funding_start',
|
||||
funding_end: 'funding_end',
|
||||
|
||||
authorId: 'authorId',
|
||||
topicId: 'topicId',
|
||||
|
||||
projectType: 'projectType',
|
||||
|
||||
country: 'country',
|
||||
frameworkProgramme: 'frameworkProgramme',
|
||||
fundingScheme: 'fundingScheme',
|
||||
status: 'status',
|
||||
|
||||
sortBy: 'sort_by',
|
||||
sortDirection: 'sort_direction',
|
||||
|
||||
legend: 'legend',
|
||||
legend_expanded: 'legend_expanded',
|
||||
} as const;
|
||||
|
||||
const RESOLVING_PROJECT_PAGE_FOR_KEY = 'resolvingFor';
|
||||
|
||||
export const RESOLVING_PROJECT_PAGE_FOR = {
|
||||
PERSON: 'PERSON',
|
||||
KEYWORDS_SEARCH: 'KEYWORDS_SEARCH',
|
||||
} as const;
|
||||
|
||||
type ResolvingEuProjectPageFor =
|
||||
(typeof RESOLVING_PROJECT_PAGE_FOR)[keyof typeof RESOLVING_PROJECT_PAGE_FOR];
|
||||
|
||||
function getRepeatedOrCsv(routeQueryParamMap: any, key: string): string[] {
|
||||
const repeatedValues = routeQueryParamMap.getAll(key) ?? [];
|
||||
|
||||
const csvValues =
|
||||
routeQueryParamMap
|
||||
.get(key)
|
||||
?.split(',')
|
||||
.map((value: string) => value.trim())
|
||||
.filter(Boolean) ?? [];
|
||||
|
||||
return Array.from(
|
||||
new Set(
|
||||
[...repeatedValues, ...csvValues]
|
||||
.map((value) => String(value).trim())
|
||||
.filter(Boolean),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export const euCordisProjectsResolver: ResolveFn<EuCordisProjectSearchPage> = (
|
||||
route,
|
||||
state,
|
||||
) => {
|
||||
const resolvingFor: ResolvingEuProjectPageFor =
|
||||
route.data[RESOLVING_PROJECT_PAGE_FOR_KEY] ||
|
||||
RESOLVING_PROJECT_PAGE_FOR.PERSON;
|
||||
|
||||
console.log(
|
||||
'Resolving EU project page for',
|
||||
resolvingFor,
|
||||
'with route data:',
|
||||
route.data,
|
||||
);
|
||||
|
||||
/**
|
||||
* For EU author filtering, this should be an OpenAlex author ID.
|
||||
* Backend resolves:
|
||||
* OpenAlex author -> publication DOIs -> CORDIS publications -> CORDIS project IDs
|
||||
*/
|
||||
|
||||
const page =
|
||||
Number(route.queryParamMap.get(euProjectQueryParamKeys.page)) || 0;
|
||||
const size =
|
||||
Number(route.queryParamMap.get(euProjectQueryParamKeys.size)) || 10;
|
||||
|
||||
const searchTerm =
|
||||
route.queryParamMap.get(euProjectQueryParamKeys.title) ?? undefined;
|
||||
|
||||
const sortBy =
|
||||
route.queryParamMap.get(euProjectQueryParamKeys.sortBy) || 'title';
|
||||
|
||||
const sortDirection =
|
||||
route.queryParamMap.get(euProjectQueryParamKeys.sortDirection) || 'asc';
|
||||
|
||||
const fundingStart = route.queryParamMap.getAll(
|
||||
euProjectQueryParamKeys.funding_start,
|
||||
);
|
||||
|
||||
const fundingEnd = route.queryParamMap.getAll(
|
||||
euProjectQueryParamKeys.funding_end,
|
||||
);
|
||||
|
||||
const filteredTopicIds = route.queryParamMap.getAll(
|
||||
euProjectQueryParamKeys.topicId,
|
||||
);
|
||||
|
||||
/**
|
||||
* EU project types:
|
||||
* fp7 | h2020 | heu
|
||||
*/
|
||||
const projectTypes = route.queryParamMap.getAll(
|
||||
euProjectQueryParamKeys.projectType,
|
||||
);
|
||||
|
||||
/**
|
||||
* CORDIS organisation IDs are strings, not numeric DFG institution IDs.
|
||||
*/
|
||||
const organizationIds = route.queryParamMap.getAll(
|
||||
euProjectQueryParamKeys.institutionId,
|
||||
);
|
||||
|
||||
/**
|
||||
* Additional OpenAlex author IDs from query params.
|
||||
* Keep them as strings.
|
||||
*/
|
||||
const authorIds = route.queryParamMap
|
||||
.getAll(euProjectQueryParamKeys.authorId)
|
||||
.map((id) => id.split('/').pop() || id); // Extract the last part of the OpenAlex ID if it's a URL
|
||||
const countries = route.queryParamMap.getAll(euProjectQueryParamKeys.country);
|
||||
|
||||
const frameworkProgrammes = route.queryParamMap.getAll(
|
||||
euProjectQueryParamKeys.frameworkProgramme,
|
||||
);
|
||||
|
||||
const fundingSchemes = route.queryParamMap.getAll(
|
||||
euProjectQueryParamKeys.fundingScheme,
|
||||
);
|
||||
|
||||
const statuses = route.queryParamMap.getAll(euProjectQueryParamKeys.status);
|
||||
|
||||
if (resolvingFor === RESOLVING_PROJECT_PAGE_FOR.PERSON) {
|
||||
const rawAuthorId = route.parent?.parent?.params['id'];
|
||||
return inject(ProjectsService).searchEuCordisProjectsSummary(
|
||||
rawAuthorId,
|
||||
authorIds,
|
||||
organizationIds,
|
||||
[],
|
||||
projectTypes as any,
|
||||
searchTerm,
|
||||
[],
|
||||
[],
|
||||
filteredTopicIds,
|
||||
fundingStart,
|
||||
fundingEnd,
|
||||
countries,
|
||||
frameworkProgrammes,
|
||||
fundingSchemes,
|
||||
statuses,
|
||||
page,
|
||||
size,
|
||||
sortBy,
|
||||
sortDirection,
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
if (resolvingFor === RESOLVING_PROJECT_PAGE_FOR.KEYWORDS_SEARCH) {
|
||||
const keywords = getRepeatedOrCsv(route.queryParamMap, 'keywords');
|
||||
const selectedTopicIds = route.queryParamMap.getAll('topics');
|
||||
const fuzzySearch = route.queryParamMap.get('fuzzy') === 'true';
|
||||
|
||||
return inject(ProjectsService).searchEuCordisProjectsSummary(
|
||||
undefined,
|
||||
authorIds,
|
||||
organizationIds,
|
||||
[],
|
||||
projectTypes as any,
|
||||
searchTerm,
|
||||
keywords,
|
||||
selectedTopicIds,
|
||||
filteredTopicIds,
|
||||
fundingStart,
|
||||
fundingEnd,
|
||||
countries,
|
||||
frameworkProgrammes,
|
||||
fundingSchemes,
|
||||
statuses,
|
||||
page,
|
||||
size,
|
||||
sortBy,
|
||||
sortDirection,
|
||||
fuzzySearch,
|
||||
);
|
||||
}
|
||||
|
||||
throw new Error(`Unknown resolvingFor value: ${resolvingFor}`);
|
||||
};
|
||||
@@ -11,12 +11,13 @@ export const selectedDfgAuthorsResolver: ResolveFn<DfgPersonSummaryPage> = (
|
||||
const authorIdQueryParamKey =
|
||||
(route.data['authorIdQueryParamKey'] as string) || 'authorId';
|
||||
|
||||
const authorIds = route.queryParamMap.getAll(authorIdQueryParamKey);
|
||||
const authorIds = route.queryParamMap
|
||||
.getAll(authorIdQueryParamKey)
|
||||
.map((id) => Number(id))
|
||||
.filter((id) => !isNaN(id));
|
||||
if (authorIds.length === 0) {
|
||||
return { elements: [] };
|
||||
}
|
||||
|
||||
return inject(DFGPersonsService).getDfgPersonsByIds(
|
||||
authorIds.map((id) => id.trim()).filter((id) => id.length > 0),
|
||||
);
|
||||
return inject(DFGPersonsService).getDfgPersonsByIds(authorIds.map(String));
|
||||
};
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { inject } from '@angular/core';
|
||||
import { ResolveFn } from '@angular/router';
|
||||
import { ProjectsService } from '../api';
|
||||
import { EuCordisOrganizationSelectorPage } from '../api/model/euCordisOrganizationSelectorPage';
|
||||
export const selectedEuInstitutionsResolver: ResolveFn<
|
||||
EuCordisOrganizationSelectorPage
|
||||
> = (route, state) => {
|
||||
const institutionIdQueryParamKey =
|
||||
(route.data['institutionIdQueryParamKey'] as string) || 'institutionId';
|
||||
|
||||
const institutionIds = route.queryParamMap
|
||||
.getAll(institutionIdQueryParamKey)
|
||||
.map((id) => id.trim())
|
||||
.filter((id) => id.length > 0);
|
||||
|
||||
return inject(ProjectsService).getEuOrganizationsByIds(institutionIds);
|
||||
};
|
||||
Reference in New Issue
Block a user