This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
from datetime import date
|
||||
import datetime
|
||||
from enum import StrEnum
|
||||
from typing import List, Optional
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import BaseModel, Field, field_validator
|
||||
|
||||
from inse.models.bund_project import BundProject
|
||||
from inse.models.eu_project import EuProject
|
||||
@@ -131,3 +133,95 @@ class CordisEuProjectPage(Page):
|
||||
elements: List[CordisEuProject] = Field(
|
||||
default_factory=list, description="The CORDIS EU projects on this page."
|
||||
)
|
||||
|
||||
|
||||
class FundingProject(BaseModel):
|
||||
type: ProjectType = Field(
|
||||
description="The type of the project.",
|
||||
examples=[ProjectType.BUND, ProjectType.EU, ProjectType.DFG],
|
||||
)
|
||||
id: str = Field(description="The unique identifier of the project.")
|
||||
title: Optional[str] = Field(default=None, description="The title of the project.")
|
||||
start_date: Optional[date] = Field(
|
||||
default=None, description="The funding start date of the project."
|
||||
)
|
||||
end_date: Optional[date] = Field(
|
||||
default=None, description="The funding end date of the project."
|
||||
)
|
||||
funding_amount: Optional[float] = Field(
|
||||
default=None, description="The total funding amount for the project."
|
||||
)
|
||||
|
||||
@field_validator("start_date", "end_date", mode="before")
|
||||
@classmethod
|
||||
def parse_all_date_formats(cls, value):
|
||||
if isinstance(value, str):
|
||||
value = value.strip()
|
||||
|
||||
if len(value) == 4 and value.isdigit():
|
||||
return f"{value}-01-01"
|
||||
|
||||
if "." in value:
|
||||
return datetime.datetime.strptime(value, "%d.%m.%Y").date()
|
||||
|
||||
return value
|
||||
|
||||
return value
|
||||
|
||||
@classmethod
|
||||
def from_cordis_projects_hit(cls, hit: dict) -> "FundingProject":
|
||||
if not hit.get("_index", "").startswith("cordis_eu_") and not hit.get(
|
||||
"_index", ""
|
||||
).endswith("_projects"):
|
||||
raise ValueError(
|
||||
"The provided hit does not belong to an index starting with 'cordis_eu_' and ending with '_projects'."
|
||||
)
|
||||
|
||||
source = hit.get("_source", {})
|
||||
return cls(
|
||||
type=ProjectType.EU,
|
||||
id=hit.get("_id", ""),
|
||||
title=source.get("title"),
|
||||
start_date=source.get("startDate"),
|
||||
end_date=source.get("endDate"),
|
||||
funding_amount=source.get("ecMacContribution"),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_bund_projects_hit(cls, hit: dict) -> "FundingProject":
|
||||
if hit.get("_index") != "projects_bund_v1":
|
||||
raise ValueError(
|
||||
"The provided hit does not belong to the 'projects_bund_v1' index."
|
||||
)
|
||||
|
||||
source = hit.get("_source", {})
|
||||
return cls(
|
||||
type=ProjectType.BUND,
|
||||
id=hit.get("_id", ""),
|
||||
title=source.get("Thema"),
|
||||
start_date=source.get("funding_start"),
|
||||
end_date=source.get("funding_end"),
|
||||
funding_amount=source.get("Fördersumme"),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_dfg_projects_hit(cls, hit: dict) -> "FundingProject":
|
||||
if hit.get("_index") != "projects_dfg_all":
|
||||
raise ValueError(
|
||||
"The provided hit does not belong to the 'projects_dfg_all' index."
|
||||
)
|
||||
|
||||
source = hit.get("_source", {})
|
||||
return cls(
|
||||
type=ProjectType.DFG,
|
||||
id=hit.get("_id", ""),
|
||||
title=source.get("title"),
|
||||
start_date=source.get("funding_start"),
|
||||
end_date=source.get("funding_end"),
|
||||
)
|
||||
|
||||
|
||||
class FundingProjectPage(Page):
|
||||
elements: List[FundingProject] = Field(
|
||||
default_factory=list, description="The funding projects on this page."
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import json
|
||||
import logging
|
||||
from typing import Any, Dict, List, Literal, Optional
|
||||
from typing import Any, Dict, List, Literal, Optional, Set
|
||||
|
||||
import httpx
|
||||
|
||||
@@ -12,6 +12,9 @@ from inse.projects.model import (
|
||||
DfgProjectPage,
|
||||
DfgProjectSummary,
|
||||
EuProjectPage,
|
||||
FundingProject,
|
||||
FundingProjectPage,
|
||||
ProjectType,
|
||||
ProjectsFilteringProperties,
|
||||
ProjectsSortBy,
|
||||
SortDirection,
|
||||
@@ -262,20 +265,15 @@ class BundProjectsSearchClient(ProjectsSearchClient):
|
||||
)
|
||||
response = await self.make_search_request(query)
|
||||
return self.response_to_bund_project_page(response, page, size)
|
||||
|
||||
async def get_bund_project_by_id(self, project_id: str) -> Optional[BundProjectDetails]:
|
||||
|
||||
query= {
|
||||
"query": {
|
||||
"term": {
|
||||
"Förderkennzeichen.keyword": {
|
||||
"value": project_id
|
||||
}
|
||||
}
|
||||
},
|
||||
"_source":True
|
||||
}
|
||||
|
||||
async def get_bund_project_by_id(
|
||||
self, project_id: str
|
||||
) -> Optional[BundProjectDetails]:
|
||||
|
||||
query = {
|
||||
"query": {"term": {"Förderkennzeichen.keyword": {"value": project_id}}},
|
||||
"_source": True,
|
||||
}
|
||||
|
||||
response = await self.make_search_request(query)
|
||||
hits = response.get("hits", {}).get("hits", [])
|
||||
@@ -797,11 +795,10 @@ class DfgProjectsSearchClient(ProjectsSearchClient):
|
||||
response = await self.make_search_request(query)
|
||||
return self.response_to_dfg_project_page(response, page, size)
|
||||
|
||||
async def get_dfg_project_by_id(self, project_id: str) -> Optional[DfgProjectDetails]:
|
||||
query = {
|
||||
"query": {"ids": {"values": [project_id]}},
|
||||
"_source": True
|
||||
}
|
||||
async def get_dfg_project_by_id(
|
||||
self, project_id: str
|
||||
) -> Optional[DfgProjectDetails]:
|
||||
query = {"query": {"ids": {"values": [project_id]}}, "_source": True}
|
||||
|
||||
response = await self.make_search_request(query)
|
||||
hits = response.get("hits", {}).get("hits", [])
|
||||
@@ -811,3 +808,133 @@ class DfgProjectsSearchClient(ProjectsSearchClient):
|
||||
details = DfgProjectDetails.from_elastic_hit(hit=hit)
|
||||
return details
|
||||
return None
|
||||
|
||||
|
||||
class CompleteProjectsSearchClient(ProjectsSearchClient):
|
||||
def __init__(self):
|
||||
if not settings.elasticsearch_inse_url:
|
||||
raise ValueError("Elasticsearch INSE URL is missing in settings.")
|
||||
if not settings.elasticsearch_inse_api_key:
|
||||
raise ValueError("Elasticsearch INSE API key is missing in settings.")
|
||||
super().__init__(
|
||||
base_url=settings.elasticsearch_inse_url,
|
||||
index="cordis_eu_*_projects,projects_bund_v1,projects_dfg_all",
|
||||
api_key=settings.elasticsearch_inse_api_key,
|
||||
)
|
||||
|
||||
def _build_projects_search_body(
|
||||
self,
|
||||
page: int,
|
||||
size: int,
|
||||
title: Optional[str] = None,
|
||||
sort_by: ProjectsSortBy = ProjectsSortBy.TITLE,
|
||||
sort_direction: SortDirection = SortDirection.ASC,
|
||||
) -> Dict[str, Any]:
|
||||
if sort_by != ProjectsSortBy.TITLE:
|
||||
raise ValueError("Currently only sorting by title is supported.")
|
||||
|
||||
query: Dict[str, Any] = {
|
||||
"size": size,
|
||||
"from": page * size,
|
||||
"sort": [
|
||||
{
|
||||
"title.keyword": {
|
||||
"order": sort_direction,
|
||||
"missing": "_last",
|
||||
"unmapped_type": "keyword",
|
||||
}
|
||||
},
|
||||
{
|
||||
"Thema.keyword": {
|
||||
"order": sort_direction,
|
||||
"missing": "_last",
|
||||
"unmapped_type": "keyword",
|
||||
}
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
if title and len(title.strip()) > 0:
|
||||
title = f"*{title.strip()}*"
|
||||
query["query"] = {
|
||||
"bool": {
|
||||
"should": [
|
||||
{
|
||||
"wildcard": {
|
||||
"title.keyword": {
|
||||
"value": title,
|
||||
"case_insensitive": True,
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"wildcard": {
|
||||
"Thema.keyword": {
|
||||
"value": title,
|
||||
"case_insensitive": True,
|
||||
}
|
||||
}
|
||||
},
|
||||
],
|
||||
"minimum_should_match": 1,
|
||||
}
|
||||
}
|
||||
|
||||
return query
|
||||
|
||||
def _project_type_to_index(self, project_type: ProjectType) -> str:
|
||||
if project_type == ProjectType.BUND:
|
||||
return "projects_bund_v1"
|
||||
elif project_type == ProjectType.EU:
|
||||
return "cordis_eu_*_projects"
|
||||
elif project_type == ProjectType.DFG:
|
||||
return "projects_dfg_all"
|
||||
else:
|
||||
raise ValueError(f"Unsupported project type: {project_type}")
|
||||
|
||||
def _hit_to_funding_project(self, hit: Dict[str, Any]) -> FundingProject:
|
||||
if hit.get("_index", "").startswith("cordis_eu_") and hit.get(
|
||||
"_index", ""
|
||||
).endswith("_projects"):
|
||||
return FundingProject.from_cordis_projects_hit(hit=hit)
|
||||
elif hit.get("_index") == "projects_bund_v1":
|
||||
return FundingProject.from_bund_projects_hit(hit=hit)
|
||||
elif hit.get("_index") == "projects_dfg_all":
|
||||
return FundingProject.from_dfg_projects_hit(hit=hit)
|
||||
else:
|
||||
raise ValueError(
|
||||
"The provided hit does not belong to a recognized project index."
|
||||
)
|
||||
|
||||
def _response_to_funding_project_page(
|
||||
self, response: Dict[str, Any], page: int, size: int
|
||||
) -> FundingProjectPage:
|
||||
hits = response.get("hits", {}).get("hits", [])
|
||||
projects = [self._hit_to_funding_project(hit=hit) for hit in hits]
|
||||
total = response.get("hits", {}).get("total", {}).get("value", 0)
|
||||
return FundingProjectPage(elements=projects, total=total, page=page, size=size)
|
||||
|
||||
async def search_projects(
|
||||
self,
|
||||
page: int,
|
||||
size: int,
|
||||
selected_project_types: Optional[Set[ProjectType]] = None,
|
||||
title: Optional[str] = None,
|
||||
sort_by: ProjectsSortBy = ProjectsSortBy.TITLE,
|
||||
sort_direction: SortDirection = SortDirection.ASC,
|
||||
):
|
||||
body = self._build_projects_search_body(
|
||||
page=page,
|
||||
size=size,
|
||||
title=title,
|
||||
sort_by=sort_by,
|
||||
sort_direction=sort_direction,
|
||||
)
|
||||
if not selected_project_types:
|
||||
selected_project_types = {ProjectType.BUND, ProjectType.EU, ProjectType.DFG}
|
||||
index = ",".join(
|
||||
self._project_type_to_index(pt) for pt in selected_project_types
|
||||
)
|
||||
|
||||
projects_response = await self.make_search_request(body, index=index)
|
||||
return self._response_to_funding_project_page(projects_response, page, size)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from functools import lru_cache
|
||||
import logging
|
||||
from typing import Annotated, Optional
|
||||
from typing import Annotated, Optional, Set
|
||||
|
||||
from fastapi import APIRouter, Body, Depends, Path, Query, status
|
||||
|
||||
@@ -8,8 +8,12 @@ from inse.projects.model import (
|
||||
BundProjectPage,
|
||||
CordisEuProjectPage,
|
||||
DfgProjectPage,
|
||||
FundingProjectPage,
|
||||
InstitutionFunderSummary,
|
||||
ProjectType,
|
||||
ProjectsFilteringProperties,
|
||||
ProjectsSortBy,
|
||||
SortDirection,
|
||||
)
|
||||
from inse.models.dfg_project_details import DfgProjectDetails
|
||||
from inse.models.bund_project_details import BundProjectDetails
|
||||
@@ -17,6 +21,7 @@ from inse.tags import Tags
|
||||
from inse.projects import service as projects_service
|
||||
from inse.projects.projects_search_client import (
|
||||
BundProjectsSearchClient,
|
||||
CompleteProjectsSearchClient,
|
||||
DfgProjectsSearchClient,
|
||||
EuProjectsSearchClient,
|
||||
)
|
||||
@@ -45,6 +50,11 @@ def get_dfg_search_client() -> DfgProjectsSearchClient:
|
||||
return DfgProjectsSearchClient()
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_complete_projects_search_client() -> CompleteProjectsSearchClient:
|
||||
return CompleteProjectsSearchClient()
|
||||
|
||||
|
||||
@router.post(
|
||||
"/institution/bund/search",
|
||||
summary="Get bund projects.",
|
||||
@@ -272,3 +282,49 @@ async def get_dfg_projects(
|
||||
sort_by=sort_by,
|
||||
sort_direction=sort_direction,
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/search",
|
||||
summary="Search projects across all funders.",
|
||||
description="Returns a page of projects across all funders based on the provided pagination parameters and optional institution filter.",
|
||||
operation_id="searchProjects",
|
||||
responses={
|
||||
status.HTTP_200_OK: {
|
||||
"description": "Successful Response",
|
||||
"model": FundingProjectPage,
|
||||
},
|
||||
},
|
||||
response_model_by_alias=False,
|
||||
)
|
||||
async def search_projects(
|
||||
complete_projects_search_client: Annotated[
|
||||
CompleteProjectsSearchClient, Depends(get_complete_projects_search_client)
|
||||
],
|
||||
page: Annotated[int, Query(description="The page number.", ge=0)] = 0,
|
||||
size: Annotated[int, Query(description="The page size.", ge=1)] = 10,
|
||||
selected_project_types: Annotated[
|
||||
Optional[Set[ProjectType]],
|
||||
Query(
|
||||
description="The set of project types to filter by (e.g., 'bund', 'eu', 'dfg'). If not provided, projects of all types will be included."
|
||||
),
|
||||
] = None,
|
||||
title: Annotated[
|
||||
Optional[str], Query(description="The title to filter by.")
|
||||
] = None,
|
||||
sort_by: Annotated[
|
||||
ProjectsSortBy, Query(description="The field to sort by.")
|
||||
] = ProjectsSortBy.TITLE,
|
||||
sort_direction: Annotated[
|
||||
SortDirection, Query(description="The sort direction (asc or desc).")
|
||||
] = SortDirection.ASC,
|
||||
) -> FundingProjectPage:
|
||||
return await projects_service.search_projects(
|
||||
projects_search_client=complete_projects_search_client,
|
||||
page=page,
|
||||
size=size,
|
||||
selected_project_types=selected_project_types,
|
||||
title=title,
|
||||
sort_by=sort_by,
|
||||
sort_direction=sort_direction,
|
||||
)
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import datetime
|
||||
import logging
|
||||
from typing import Any, Dict, List, Optional
|
||||
from typing import Any, Dict, List, Optional, Set
|
||||
|
||||
from inse.projects.projects_search_client import (
|
||||
BundProjectsSearchClient,
|
||||
CompleteProjectsSearchClient,
|
||||
DfgProjectsSearchClient,
|
||||
EuProjectsSearchClient,
|
||||
)
|
||||
@@ -12,9 +13,12 @@ from inse.projects.model import (
|
||||
CordisEuProjectPage,
|
||||
DfgProjectPage,
|
||||
EuProjectPage,
|
||||
FundingProjectPage,
|
||||
InstitutionFunderSummary,
|
||||
ProjectType,
|
||||
ProjectsFilteringProperties,
|
||||
ProjectsSortBy,
|
||||
SortDirection,
|
||||
)
|
||||
from inse.models.dfg_project_details import DfgProjectDetails
|
||||
from inse.models.bund_project_details import BundProjectDetails
|
||||
@@ -27,6 +31,25 @@ from inse.persons.logic import get_author_name_by_id
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def search_projects(
|
||||
projects_search_client: CompleteProjectsSearchClient,
|
||||
page: int,
|
||||
size: int,
|
||||
sort_by: ProjectsSortBy,
|
||||
sort_direction: SortDirection,
|
||||
selected_project_types: Optional[Set[ProjectType]] = None,
|
||||
title: Optional[str] = None,
|
||||
) -> FundingProjectPage:
|
||||
return await projects_search_client.search_projects(
|
||||
page=page,
|
||||
size=size,
|
||||
selected_project_types=selected_project_types,
|
||||
title=title,
|
||||
sort_by=sort_by,
|
||||
sort_direction=sort_direction,
|
||||
)
|
||||
|
||||
|
||||
async def search_bund_projects(
|
||||
bund_search_client: BundProjectsSearchClient,
|
||||
institutions_search_client: InstitutionsSearchClient,
|
||||
@@ -335,20 +358,20 @@ async def get_single_dfg_project(
|
||||
project_id: str,
|
||||
) -> DfgProjectDetails:
|
||||
logger.debug(f"Fetching single DFG project for id={project_id}")
|
||||
|
||||
|
||||
project = await dfg_search_client.get_dfg_project_by_id(project_id)
|
||||
if not project:
|
||||
raise NotFoundException(f"DFG project with id {project_id} not found")
|
||||
return project
|
||||
|
||||
|
||||
async def get_single_bund_project(
|
||||
bund_search_client: BundProjectsSearchClient,
|
||||
project_id: str,
|
||||
) -> BundProjectDetails:
|
||||
logger.debug(f"Fetching single BUND project for id={project_id}")
|
||||
|
||||
|
||||
project = await bund_search_client.get_bund_project_by_id(project_id)
|
||||
if not project:
|
||||
raise NotFoundException(f"BUND project with id {project_id} not found")
|
||||
return project
|
||||
|
||||
|
||||
@@ -22,6 +22,11 @@ GET https://inse.nes.uni-due.de/elastic/cordis_eu_*_organizations/_mapping
|
||||
Authorization: ApiKey bG1NSWc1NEJPZ3FnTGZCZXRSSEg6VnJXRFd5SnpSTTNWc1VPT01FMEhMZw==
|
||||
Content-Type: application/json
|
||||
|
||||
###
|
||||
GET https://inse.nes.uni-due.de/elastic/cordis_eu_*_projects/_mapping
|
||||
Authorization: ApiKey bG1NSWc1NEJPZ3FnTGZCZXRSSEg6VnJXRFd5SnpSTTNWc1VPT01FMEhMZw==
|
||||
Content-Type: application/json
|
||||
|
||||
###
|
||||
GET https://inse.nes.uni-due.de/elastic/cordis_eu_*_projects/_search
|
||||
Authorization: ApiKey bG1NSWc1NEJPZ3FnTGZCZXRSSEg6VnJXRFd5SnpSTTNWc1VPT01FMEhMZw==
|
||||
@@ -514,6 +519,37 @@ Content-Type: application/json
|
||||
# }
|
||||
# }
|
||||
|
||||
###
|
||||
GET https://inse.nes.uni-due.de/elastic/projects_dfg_all/_search
|
||||
Authorization: ApiKey bG1NSWc1NEJPZ3FnTGZCZXRSSEg6VnJXRFd5SnpSTTNWc1VPT01FMEhMZw==
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
"should": [
|
||||
{
|
||||
"wildcard": {
|
||||
"title.keyword": {
|
||||
"value": "*generic*",
|
||||
"case_insensitive": true
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"wildcard": {
|
||||
"Thema.keyword": {
|
||||
"value": "*generic*",
|
||||
"case_insensitive": true
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
###
|
||||
GET https://inse.nes.uni-due.de/elastic/projects_dfg_all/_mapping
|
||||
Authorization: ApiKey bG1NSWc1NEJPZ3FnTGZCZXRSSEg6VnJXRFd5SnpSTTNWc1VPT01FMEhMZw==
|
||||
|
||||
@@ -63,6 +63,8 @@ model/filterInformation.ts
|
||||
model/filterProperties.ts
|
||||
model/funderByAuthor.ts
|
||||
model/fundersByAuthorResponse.ts
|
||||
model/fundingProject.ts
|
||||
model/fundingProjectPage.ts
|
||||
model/fwci.ts
|
||||
model/groupByResult.ts
|
||||
model/hTTPValidationError.ts
|
||||
|
||||
@@ -27,11 +27,19 @@ import { DfgProjectDetails } from '../model/dfgProjectDetails';
|
||||
// @ts-ignore
|
||||
import { DfgProjectPage } from '../model/dfgProjectPage';
|
||||
// @ts-ignore
|
||||
import { FundingProjectPage } from '../model/fundingProjectPage';
|
||||
// @ts-ignore
|
||||
import { HTTPValidationError } from '../model/hTTPValidationError';
|
||||
// @ts-ignore
|
||||
import { InstitutionFunderSummary } from '../model/institutionFunderSummary';
|
||||
// @ts-ignore
|
||||
import { ProjectType } from '../model/projectType';
|
||||
// @ts-ignore
|
||||
import { ProjectsFilteringProperties } from '../model/projectsFilteringProperties';
|
||||
// @ts-ignore
|
||||
import { ProjectsSortBy } from '../model/projectsSortBy';
|
||||
// @ts-ignore
|
||||
import { SortDirection } from '../model/sortDirection';
|
||||
|
||||
// @ts-ignore
|
||||
import { BASE_PATH, COLLECTION_FORMATS } from '../variables';
|
||||
@@ -491,4 +499,81 @@ export class ProjectsService extends BaseService {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search projects across all funders.
|
||||
* Returns a page of projects across all funders based on the provided pagination parameters and optional institution filter.
|
||||
* @endpoint get /api/projects/search
|
||||
* @param page The page number.
|
||||
* @param size The page size.
|
||||
* @param selectedProjectTypes The set of project types to filter by (e.g., \'bund\', \'eu\', \'dfg\'). If not provided, projects of all types will be included.
|
||||
* @param title The title to filter by.
|
||||
* @param sortBy The field to sort by.
|
||||
* @param sortDirection The sort direction (asc or desc).
|
||||
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
|
||||
* @param reportProgress flag to report request and response progress.
|
||||
*/
|
||||
public searchProjects(page?: number, size?: number, selectedProjectTypes?: Set<ProjectType>, title?: string, sortBy?: ProjectsSortBy, sortDirection?: SortDirection, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<FundingProjectPage>;
|
||||
public searchProjects(page?: number, size?: number, selectedProjectTypes?: Set<ProjectType>, title?: string, sortBy?: ProjectsSortBy, sortDirection?: SortDirection, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<HttpResponse<FundingProjectPage>>;
|
||||
public searchProjects(page?: number, size?: number, selectedProjectTypes?: Set<ProjectType>, title?: string, sortBy?: ProjectsSortBy, sortDirection?: SortDirection, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<HttpEvent<FundingProjectPage>>;
|
||||
public searchProjects(page?: number, size?: number, selectedProjectTypes?: Set<ProjectType>, title?: string, sortBy?: ProjectsSortBy, sortDirection?: SortDirection, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<any> {
|
||||
|
||||
let localVarQueryParameters = new HttpParams({encoder: this.encoder});
|
||||
localVarQueryParameters = this.addToHttpParams(localVarQueryParameters,
|
||||
<any>page, 'page');
|
||||
localVarQueryParameters = this.addToHttpParams(localVarQueryParameters,
|
||||
<any>size, 'size');
|
||||
if (selectedProjectTypes) {
|
||||
selectedProjectTypes.forEach((element) => {
|
||||
localVarQueryParameters = this.addToHttpParams(localVarQueryParameters,
|
||||
<any>element, 'selected_project_types');
|
||||
})
|
||||
}
|
||||
localVarQueryParameters = this.addToHttpParams(localVarQueryParameters,
|
||||
<any>title, 'title');
|
||||
localVarQueryParameters = this.addToHttpParams(localVarQueryParameters,
|
||||
<any>sortBy, 'sort_by');
|
||||
localVarQueryParameters = this.addToHttpParams(localVarQueryParameters,
|
||||
<any>sortDirection, 'sort_direction');
|
||||
|
||||
let localVarHeaders = this.defaultHeaders;
|
||||
|
||||
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
||||
'application/json'
|
||||
]);
|
||||
if (localVarHttpHeaderAcceptSelected !== undefined) {
|
||||
localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected);
|
||||
}
|
||||
|
||||
const localVarHttpContext: HttpContext = options?.context ?? new HttpContext();
|
||||
|
||||
const localVarTransferCache: boolean = options?.transferCache ?? true;
|
||||
|
||||
|
||||
let responseType_: 'text' | 'json' | 'blob' = 'json';
|
||||
if (localVarHttpHeaderAcceptSelected) {
|
||||
if (localVarHttpHeaderAcceptSelected.startsWith('text')) {
|
||||
responseType_ = 'text';
|
||||
} else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) {
|
||||
responseType_ = 'json';
|
||||
} else {
|
||||
responseType_ = 'blob';
|
||||
}
|
||||
}
|
||||
|
||||
let localVarPath = `/api/projects/search`;
|
||||
const { basePath, withCredentials } = this.configuration;
|
||||
return this.httpClient.request<FundingProjectPage>('get', `${basePath}${localVarPath}`,
|
||||
{
|
||||
context: localVarHttpContext,
|
||||
params: localVarQueryParameters,
|
||||
responseType: <any>responseType_,
|
||||
...(withCredentials ? { withCredentials } : {}),
|
||||
headers: localVarHeaders,
|
||||
observe: observe,
|
||||
...(localVarTransferCache !== undefined ? { transferCache: localVarTransferCache } : {}),
|
||||
reportProgress: reportProgress
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Innovation Search Engine API
|
||||
*
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
import { ProjectType } from './projectType';
|
||||
|
||||
|
||||
export interface FundingProject {
|
||||
/**
|
||||
* The type of the project.
|
||||
*/
|
||||
type: ProjectType;
|
||||
/**
|
||||
* The unique identifier of the project.
|
||||
*/
|
||||
id: string;
|
||||
title?: string | null;
|
||||
start_date?: string | null;
|
||||
end_date?: string | null;
|
||||
funding_amount?: number | null;
|
||||
}
|
||||
export namespace FundingProject {
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Innovation Search Engine API
|
||||
*
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
import { FundingProject } from './fundingProject';
|
||||
|
||||
|
||||
export interface FundingProjectPage {
|
||||
/**
|
||||
* The current page number.
|
||||
*/
|
||||
page?: number;
|
||||
/**
|
||||
* The requested page size.
|
||||
*/
|
||||
size?: number;
|
||||
/**
|
||||
* The total number of items.
|
||||
*/
|
||||
total?: number;
|
||||
/**
|
||||
* The funding projects on this page.
|
||||
*/
|
||||
elements?: Array<FundingProject>;
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@ export * from './filterInformation';
|
||||
export * from './filterProperties';
|
||||
export * from './funderByAuthor';
|
||||
export * from './fundersByAuthorResponse';
|
||||
export * from './fundingProject';
|
||||
export * from './fundingProjectPage';
|
||||
export * from './fwci';
|
||||
export * from './groupByResult';
|
||||
export * from './hTTPValidationError';
|
||||
|
||||
@@ -13,6 +13,7 @@ import { dfgSingleProjectResolver } from './resolvers/dfg-single-project-resolve
|
||||
import { bundSingleProjectResolver } from './resolvers/bund-single-project-resolver';
|
||||
import { cordisEuProjectPageResolver } from './resolvers/cordis-eu-project-page.resolver';
|
||||
import { cordisEuProjectsFundingResolver } from './resolvers/cordis-eu-projects-funding.resolver';
|
||||
import { fundingProjectPageResolver } from './resolvers/funding-project-page.resolver';
|
||||
|
||||
export const routes: Routes = [
|
||||
{
|
||||
@@ -101,7 +102,7 @@ export const routes: Routes = [
|
||||
dfgSingleProject: dfgSingleProjectResolver,
|
||||
},
|
||||
},
|
||||
{
|
||||
{
|
||||
path: 'projects/bund/:id',
|
||||
canActivate: [userGuard],
|
||||
pathMatch: 'full',
|
||||
@@ -278,6 +279,31 @@ export const routes: Routes = [
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: 'projects',
|
||||
canActivate: [userGuard],
|
||||
loadComponent: () =>
|
||||
import('./modules/projects/projects.component').then(
|
||||
(mod) => mod.ProjectsComponent,
|
||||
),
|
||||
resolve: {
|
||||
fundingProjectPage: fundingProjectPageResolver,
|
||||
},
|
||||
runGuardsAndResolvers: (from, to) => {
|
||||
const keys = [
|
||||
'search',
|
||||
'page',
|
||||
'size',
|
||||
'selected_project_types',
|
||||
'sort_by',
|
||||
'sorting_order',
|
||||
];
|
||||
|
||||
return keys.some(
|
||||
(key) => from.queryParamMap.get(key) !== to.queryParamMap.get(key),
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'error',
|
||||
loadComponent: () =>
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
<div class="content">
|
||||
<h1>Passende Projekte finden</h1>
|
||||
|
||||
<mat-divider />
|
||||
|
||||
<div style="padding: 0 1rem">
|
||||
<mat-form-field style="width: 100%">
|
||||
<mat-label>Suche nach Namen</mat-label>
|
||||
<input
|
||||
matInput
|
||||
type="search"
|
||||
[debounceTime]="300"
|
||||
[(debouncedValue)]="urlSearchTerm"
|
||||
(debouncedValueChange)="handleSearchTermChange($event)" />
|
||||
<mat-icon matPrefix>search</mat-icon>
|
||||
<button matIconButton matSuffix (click)="clearSearchTerm()">
|
||||
<mat-icon>clear</mat-icon>
|
||||
</button>
|
||||
</mat-form-field>
|
||||
|
||||
<div
|
||||
style="
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
">
|
||||
<mat-chip-listbox
|
||||
[value]="urlChips()"
|
||||
(change)="handleChipBoxChange($event)"
|
||||
multiple>
|
||||
<mat-chip-option value="eu">EU</mat-chip-option>
|
||||
<mat-chip-option value="bund">BUND</mat-chip-option>
|
||||
<mat-chip-option value="dfg">DFG</mat-chip-option>
|
||||
</mat-chip-listbox>
|
||||
|
||||
<div class="sorting">
|
||||
<select (change)="handleSortFieldChange($event)" [value]="urlSortBy()">
|
||||
<option value="title">Name</option>
|
||||
</select>
|
||||
|
||||
<select
|
||||
(change)="handleSortOrderChange($event)"
|
||||
[value]="urlSortingOrder()">
|
||||
<option value="desc">Absteigend</option>
|
||||
<option value="asc">Aufsteigend</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<mat-divider />
|
||||
|
||||
@let fundingProjectPageValue = fundingProjectPage();
|
||||
|
||||
@if (
|
||||
fundingProjectPageValue.elements &&
|
||||
fundingProjectPageValue.elements.length > 0
|
||||
) {
|
||||
<div class="cards">
|
||||
@for (fundingProject of fundingProjectPageValue.elements; track $index) {
|
||||
<mat-card
|
||||
class="card"
|
||||
appearance="outlined"
|
||||
[routerLink]="getDetaiLink(fundingProject)">
|
||||
<mat-card-header>
|
||||
<mat-card-title>{{ fundingProject.title }}</mat-card-title>
|
||||
<mat-card-subtitle>{{
|
||||
fundingProject.type | uppercase
|
||||
}}</mat-card-subtitle>
|
||||
</mat-card-header>
|
||||
|
||||
<mat-card-content class="card-content">
|
||||
<mat-divider />
|
||||
<div class="card-metadata">
|
||||
<span
|
||||
>Von {{ fundingProject.start_date | date }} bis
|
||||
{{ fundingProject.end_date | date }}</span
|
||||
>
|
||||
</div>
|
||||
<mat-divider />
|
||||
</mat-card-content>
|
||||
|
||||
<mat-card-footer>
|
||||
<mat-card-actions>
|
||||
<a
|
||||
mat-button
|
||||
[routerLink]="getDetaiLink(fundingProject)"
|
||||
(click)="$event.stopPropagation()">
|
||||
<mat-icon>info</mat-icon>
|
||||
Übersicht
|
||||
</a>
|
||||
</mat-card-actions>
|
||||
</mat-card-footer>
|
||||
</mat-card>
|
||||
}
|
||||
</div>
|
||||
} @else {
|
||||
<div class="no-results">
|
||||
<p>Keine passenden Projekte gefunden.</p>
|
||||
</div>
|
||||
}
|
||||
|
||||
<mat-divider />
|
||||
|
||||
<mat-paginator
|
||||
[length]="fundingProjectPageValue.total"
|
||||
[pageSize]="fundingProjectPageValue.size"
|
||||
[pageSizeOptions]="[10, 20, 50]"
|
||||
[pageIndex]="fundingProjectPageValue.page"
|
||||
(page)="handlePageChange($event)">
|
||||
</mat-paginator>
|
||||
</div>
|
||||
@@ -0,0 +1,99 @@
|
||||
.content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.sorting {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.sorting select {
|
||||
padding: 0.75rem;
|
||||
border: 1px solid var(--sg-border);
|
||||
border-radius: var(--sg-radius-sm);
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.sorting select:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.cards {
|
||||
display: grid;
|
||||
gap: 1.5rem;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
padding: 0 1rem;
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.cards {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.cards {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
mat-paginator {
|
||||
background-color: var(--sg-background);
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 0.5rem;
|
||||
background-color: var(--sg-background);
|
||||
transition: transform 0.3s ease;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.card:hover {
|
||||
cursor: pointer;
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
.card-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: flex-end;
|
||||
gap: 0.5rem;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.card-metadata {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.2rem;
|
||||
font-size: 0.9rem;
|
||||
color: var(--sg-text-secondary);
|
||||
}
|
||||
|
||||
mat-card-actions {
|
||||
padding-top: 0.5rem;
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
mat-card-actions a {
|
||||
width: 100%;
|
||||
text-decoration: none;
|
||||
border: 1px solid var(--sg-border);
|
||||
border-radius: var(--sg-radius-sm);
|
||||
}
|
||||
|
||||
.no-results {
|
||||
text-align: center;
|
||||
padding: 2rem;
|
||||
color: var(--sg-text-secondary);
|
||||
}
|
||||
|
||||
.mat-mdc-standard-chip {
|
||||
border-radius: var(--sg-radius-sm);
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
import { Component, effect, input, signal } from '@angular/core';
|
||||
import { FundingProject, FundingProjectPage, ProjectType } from '../../api';
|
||||
import { MatDividerModule } from '@angular/material/divider';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { DebounceDirective } from '../../directives/debounce.directive';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { ActivatedRoute, Router, RouterModule } from '@angular/router';
|
||||
import { MatPaginator, PageEvent } from '@angular/material/paginator';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { DatePipe, UpperCasePipe } from '@angular/common';
|
||||
import { MatChipListboxChange, MatChipsModule } from '@angular/material/chips';
|
||||
|
||||
@Component({
|
||||
selector: 'app-projects',
|
||||
imports: [
|
||||
MatDividerModule,
|
||||
MatFormFieldModule,
|
||||
DebounceDirective,
|
||||
MatIconModule,
|
||||
MatCardModule,
|
||||
RouterModule,
|
||||
MatPaginator,
|
||||
MatInputModule,
|
||||
MatButtonModule,
|
||||
UpperCasePipe,
|
||||
DatePipe,
|
||||
MatChipsModule,
|
||||
],
|
||||
templateUrl: './projects.component.html',
|
||||
styleUrl: './projects.component.scss',
|
||||
})
|
||||
export class ProjectsComponent {
|
||||
fundingProjectPage = input.required<FundingProjectPage>();
|
||||
|
||||
urlSearchTerm = signal<string>('');
|
||||
urlSortBy = signal<string>('relevance');
|
||||
urlSortingOrder = signal<string>('desc');
|
||||
urlChips = signal<ProjectType[]>(['eu', 'bund', 'dfg']);
|
||||
|
||||
constructor(
|
||||
private readonly activatedRoute: ActivatedRoute,
|
||||
private readonly router: Router,
|
||||
) {
|
||||
this.activatedRoute.queryParams
|
||||
.pipe(takeUntilDestroyed())
|
||||
.subscribe((params) => {
|
||||
this.urlSearchTerm.set(params['search'] || '');
|
||||
this.urlSortBy.set(params['sort_by'] || 'relevance');
|
||||
this.urlSortingOrder.set(params['sorting_order'] || 'desc');
|
||||
this.urlChips.set(
|
||||
(params['selected_project_types'] || 'eu,bund,dfg').split(','),
|
||||
);
|
||||
});
|
||||
|
||||
effect(() => {
|
||||
const searchTerm = this.urlSearchTerm();
|
||||
this.router.navigate([], {
|
||||
queryParams: { search: searchTerm },
|
||||
queryParamsHandling: 'merge',
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
handleSearchTermChange(newTerm: string): void {
|
||||
this.router.navigate([], {
|
||||
queryParams: { search: newTerm },
|
||||
queryParamsHandling: 'merge',
|
||||
});
|
||||
}
|
||||
|
||||
clearSearchTerm(): void {
|
||||
this.router.navigate([], {
|
||||
queryParams: { search: null },
|
||||
queryParamsHandling: 'merge',
|
||||
});
|
||||
}
|
||||
|
||||
handlePageChange(event: PageEvent): void {
|
||||
this.router.navigate([], {
|
||||
queryParams: { page: event.pageIndex, size: event.pageSize },
|
||||
queryParamsHandling: 'merge',
|
||||
});
|
||||
}
|
||||
|
||||
handleSortFieldChange(event: Event): void {
|
||||
const selectElement = event.target as HTMLSelectElement;
|
||||
const sortField = selectElement.value;
|
||||
this.router.navigate([], {
|
||||
queryParams: { sort_by: sortField },
|
||||
queryParamsHandling: 'merge',
|
||||
});
|
||||
}
|
||||
|
||||
handleSortOrderChange(event: Event): void {
|
||||
const selectElement = event.target as HTMLSelectElement;
|
||||
const sortOrder = selectElement.value;
|
||||
this.router.navigate([], {
|
||||
queryParams: { sorting_order: sortOrder },
|
||||
queryParamsHandling: 'merge',
|
||||
});
|
||||
}
|
||||
|
||||
handleChipBoxChange(change: MatChipListboxChange): void {
|
||||
const selectedValues = change.value as string[];
|
||||
|
||||
this.router.navigate([], {
|
||||
queryParams: {
|
||||
selected_project_types: selectedValues.length
|
||||
? selectedValues.join(',')
|
||||
: null,
|
||||
},
|
||||
queryParamsHandling: 'merge',
|
||||
});
|
||||
}
|
||||
|
||||
getDetaiLink(fundingProject: FundingProject): string | null {
|
||||
if (fundingProject.type === 'bund') {
|
||||
return '/projects/bund/' + fundingProject.id;
|
||||
} else if (fundingProject.type === 'dfg') {
|
||||
return '/projects/dfg/' + fundingProject.id;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { ResolveFn } from '@angular/router';
|
||||
import {
|
||||
FundingProjectPage,
|
||||
ProjectsService,
|
||||
ProjectsSortBy,
|
||||
ProjectType,
|
||||
SortDirection,
|
||||
} from '../api';
|
||||
import { inject } from '@angular/core';
|
||||
|
||||
export const fundingProjectPageResolver: ResolveFn<FundingProjectPage> = (
|
||||
route,
|
||||
state,
|
||||
) => {
|
||||
const page = Number(route.queryParamMap.get('page') || '0');
|
||||
const size = Number(route.queryParamMap.get('size') || '10');
|
||||
const sortBy = (route.queryParamMap.get('sort_by') ??
|
||||
'title') as ProjectsSortBy;
|
||||
const sortOrder = (route.queryParamMap.get('sorting_order') ??
|
||||
'asc') as SortDirection;
|
||||
const title = route.queryParamMap.get('search') ?? undefined;
|
||||
const selectedProjectTypes = route.queryParamMap.get('selected_project_types')
|
||||
? new Set(
|
||||
route.queryParamMap
|
||||
.get('selected_project_types')!
|
||||
.split(',') as ProjectType[],
|
||||
)
|
||||
: undefined;
|
||||
return inject(ProjectsService).searchProjects(
|
||||
page,
|
||||
size,
|
||||
selectedProjectTypes,
|
||||
title,
|
||||
sortBy,
|
||||
sortOrder,
|
||||
);
|
||||
};
|
||||
@@ -59,6 +59,20 @@ export class AppMenuComponent {
|
||||
sorting_order: 'desc',
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Projekte',
|
||||
icon: 'work',
|
||||
route: '/projects',
|
||||
disabled: false,
|
||||
queryParams: {
|
||||
search: '',
|
||||
page: 0,
|
||||
size: 10,
|
||||
selected_project_types: 'eu,bund,dfg',
|
||||
sort_by: 'title',
|
||||
sorting_order: 'asc',
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
constructor(
|
||||
|
||||
Reference in New Issue
Block a user