From 3276bf46a7facf1bc3adb4fddc44caf4a023edf9 Mon Sep 17 00:00:00 2001 From: genja Date: Thu, 13 Aug 2026 13:17:57 +0200 Subject: [PATCH] Move filtered subject to top of subject list --- .../bund-project-table.component.html | 2 +- .../bund-project-table.component.ts | 22 ++++++++-- .../dfg-project-table.component.html | 2 +- .../dfg-project-table.component.ts | 41 +++++++++++++++---- .../eu-project-table.component.html | 2 +- .../eu-project-table.component.ts | 35 +++++++++++++--- 6 files changed, 86 insertions(+), 18 deletions(-) diff --git a/webapp/src/app/shared/ui/bund-project-table/bund-project-table.component.html b/webapp/src/app/shared/ui/bund-project-table/bund-project-table.component.html index 51828b4c..cdaae4cd 100644 --- a/webapp/src/app/shared/ui/bund-project-table/bund-project-table.component.html +++ b/webapp/src/app/shared/ui/bund-project-table/bund-project-table.component.html @@ -82,7 +82,7 @@ - @let projectTopics = project.oa_topics ?? []; + @let projectTopics = getProjectTopics(project); @let isTopicsExpanded = isProjectTopicsExpanded(project); @let visibleTopics = isTopicsExpanded ? projectTopics : projectTopics.slice(0, 3); diff --git a/webapp/src/app/shared/ui/bund-project-table/bund-project-table.component.ts b/webapp/src/app/shared/ui/bund-project-table/bund-project-table.component.ts index 2a89e462..90a62735 100644 --- a/webapp/src/app/shared/ui/bund-project-table/bund-project-table.component.ts +++ b/webapp/src/app/shared/ui/bund-project-table/bund-project-table.component.ts @@ -102,6 +102,9 @@ export class BundProjectTableComponent implements OnInit { selectedTopicIdsQueryParams = computed(() => { return this.queryParamMap().getAll(this.queryParamKeys.topicId); }); + selectedTopicMatchesQueryParams = computed(() => { + return this.queryParamMap().get('topics')?.split(',') || []; + }); selectedFundingTypesQueryParams = computed(() => { return this.queryParamMap().getAll(this.queryParamKeys.funding_type); }); @@ -225,7 +228,19 @@ export class BundProjectTableComponent implements OnInit { getProjectInstitutions(project: BundProjectSummary): any[] { return project.institution ? [project.institution] : []; } - + getProjectTopics(project: BundProjectSummary): Topic[] { + const topics = (project as any).oa_topics ?? []; + const activeTopics = topics.filter((topic: Topic) => + this.isTopicActive(topic), + ); + return topics.sort((a: Topic, b: Topic) => + activeTopics.includes(a) && !activeTopics.includes(b) + ? -1 + : !activeTopics.includes(a) && activeTopics.includes(b) + ? 1 + : 0, + ); + } isInstitutionActive( institution_name: string | number | null | undefined, ): boolean { @@ -293,8 +308,9 @@ export class BundProjectTableComponent implements OnInit { isTopicActive(topic: Topic): boolean { return ( !!topic.id && - this.authorFilterEnabled() && - this.selectedTopicIdsQueryParams().includes(topic.id) + this.topicFilterEnabled() && + (this.selectedTopicIdsQueryParams().includes(topic.id) || + this.selectedTopicMatchesQueryParams().includes(topic.id)) ); } diff --git a/webapp/src/app/shared/ui/dfg-project-table/dfg-project-table.component.html b/webapp/src/app/shared/ui/dfg-project-table/dfg-project-table.component.html index 5f4d2e52..790baa53 100644 --- a/webapp/src/app/shared/ui/dfg-project-table/dfg-project-table.component.html +++ b/webapp/src/app/shared/ui/dfg-project-table/dfg-project-table.component.html @@ -130,7 +130,7 @@ - @let projectTopics = project.topics ?? []; + @let projectTopics = getProjectTopics(project); @let isTopicsExpanded = isProjectTopicsExpanded(project); @let visibleTopics = isTopicsExpanded ? projectTopics : projectTopics.slice(0, 3); diff --git a/webapp/src/app/shared/ui/dfg-project-table/dfg-project-table.component.ts b/webapp/src/app/shared/ui/dfg-project-table/dfg-project-table.component.ts index d0445497..d748e6c7 100644 --- a/webapp/src/app/shared/ui/dfg-project-table/dfg-project-table.component.ts +++ b/webapp/src/app/shared/ui/dfg-project-table/dfg-project-table.component.ts @@ -96,6 +96,9 @@ export class DfgProjectTableComponent implements OnInit { selectedTopicIdsQueryParams = computed(() => { return this.queryParamMap().getAll(this.queryParamKeys.topicId); }); + selectedTopicMatchesQueryParams = computed(() => { + return this.queryParamMap().get('topics')?.split(',') || []; + }); ngOnInit(): void { this.columns = [ @@ -159,7 +162,15 @@ export class DfgProjectTableComponent implements OnInit { ); } getProjectAuthors(project: DfgProjectSummary): DfgPersonSummary[] { - return project.persons?.filter((a): a is DfgPersonSummary => !!a) || []; + const selectedAuthorIds = this.selectedAuthorIdsQueryParams(); + const authors = project.persons || []; + return authors.sort((a, b) => { + const aActive = selectedAuthorIds.includes(String(a.person_id)); + const bActive = selectedAuthorIds.includes(String(b.person_id)); + if (aActive && !bActive) return -1; + if (!aActive && bActive) return 1; + return 0; + }); } toggleProjectAuthorsExpansion(project: DfgProjectSummary): void { @@ -230,7 +241,7 @@ export class DfgProjectTableComponent implements OnInit { getProjectInstitutions(project: DfgProjectSummary): any[] { const institutions = new Map(); - + const selectedInstitutionIds = this.selectedInstitutionIdsQueryParams(); for (const institution of project.institutions ?? []) { const id = this.getProjectInstitutionId(institution); if (!id) continue; @@ -239,9 +250,11 @@ export class DfgProjectTableComponent implements OnInit { } return Array.from(institutions.values()).sort((a, b) => - this.getProjectInstitutionName(a).localeCompare( - this.getProjectInstitutionName(b), - ), + selectedInstitutionIds.includes(this.getProjectInstitutionId(a) ?? '') + ? -1 + : selectedInstitutionIds.includes(this.getProjectInstitutionId(b) ?? '') + ? 1 + : 0, ); } @@ -320,8 +333,9 @@ export class DfgProjectTableComponent implements OnInit { isTopicActive(topic: Topic): boolean { return ( !!topic.id && - this.authorFilterEnabled() && - this.selectedTopicIdsQueryParams().includes(topic.id) + this.topicFilterEnabled() && + (this.selectedTopicIdsQueryParams().includes(topic.id) || + this.selectedTopicMatchesQueryParams().includes(topic.id)) ); } @@ -364,6 +378,19 @@ export class DfgProjectTableComponent implements OnInit { return this.expandedProjectTopicsId.includes(project.id); } + getProjectTopics(project: DfgProjectSummary): Topic[] { + const topics = (project as any).topics ?? []; + const activeTopics = topics.filter((topic: Topic) => + this.isTopicActive(topic), + ); + return topics.sort((a: Topic, b: Topic) => + activeTopics.includes(a) && !activeTopics.includes(b) + ? -1 + : !activeTopics.includes(a) && activeTopics.includes(b) + ? 1 + : 0, + ); + } expandedProjectClassificationsId: string[] = []; //classifications getProjectClassifications(project: DfgProjectSummary): any[] { diff --git a/webapp/src/app/shared/ui/eu-project-table/eu-project-table.component.html b/webapp/src/app/shared/ui/eu-project-table/eu-project-table.component.html index f0fd3563..4e4a2b50 100644 --- a/webapp/src/app/shared/ui/eu-project-table/eu-project-table.component.html +++ b/webapp/src/app/shared/ui/eu-project-table/eu-project-table.component.html @@ -116,7 +116,7 @@ @let visibleTopics = isExpanded ? projectTopics : projectTopics.slice(0, 3);
- @for (topic of visibleTopics; track topic.id ?? $index) { + @for (topic of visibleTopics; track $index) { { return this.queryParamMap().getAll(this.queryParamKeys.topicId); }); + selectedTopicMatchesQueryParams = computed(() => { + return this.queryParamMap().get('topics')?.split(',') || []; + }); selectedTypesQueryParams = computed(() => { return this.queryParamMap().getAll(this.queryParamKeys.projectType); }); @@ -238,7 +241,15 @@ export class EuProjectTableComponent { // ------------------------- getProjectAuthors(project: EuCordisProjectSummary): Author[] { - return project.authors?.elements ?? []; + const selectedAuthorIds = this.selectedAuthorIdsQueryParams(); + const authors = project.authors?.elements ?? []; + return authors.sort((a, b) => { + const aActive = selectedAuthorIds.includes(String(a.id)); + const bActive = selectedAuthorIds.includes(String(b.id)); + if (aActive && !bActive) return -1; + if (!aActive && bActive) return 1; + return 0; + }); } getAuthorTrackId(author: any, index: number): string { return String( @@ -334,7 +345,7 @@ export class EuProjectTableComponent { if (!Array.isArray(organizations)) { return []; } - + const selectedOrganizationIds = this.selectedOrganizationIdsQueryParams(); const byId = new Map(); for (const organization of organizations) { @@ -345,7 +356,11 @@ export class EuProjectTableComponent { } return Array.from(byId.values()).sort((a, b) => - this.getOrganizationName(a).localeCompare(this.getOrganizationName(b)), + selectedOrganizationIds.includes(this.getOrganizationId(a) ?? '') + ? -1 + : selectedOrganizationIds.includes(this.getOrganizationId(b) ?? '') + ? 1 + : 0, ); } @@ -427,7 +442,16 @@ export class EuProjectTableComponent { getProjectTopics(project: EuCordisProjectSummary): Topic[] { const topics = (project as any).topics ?? []; - return Array.isArray(topics) ? topics : []; + const activeTopics = topics.filter((topic: Topic) => + this.isTopicActive(topic), + ); + return topics.sort((a: Topic, b: Topic) => + activeTopics.includes(a) && !activeTopics.includes(b) + ? -1 + : !activeTopics.includes(a) && activeTopics.includes(b) + ? 1 + : 0, + ); } getWorkTopicColor(topic: Topic): string { @@ -445,7 +469,8 @@ export class EuProjectTableComponent { return ( !!topic.id && this.topicFilterEnabled() && - this.selectedTopicIdsQueryParams().includes(topic.id) + (this.selectedTopicIdsQueryParams().includes(topic.id) || + this.selectedTopicMatchesQueryParams().includes(topic.id)) ); }