From 3b16f8d8fc36bcd18ee144f57547c921d1b14c96 Mon Sep 17 00:00:00 2001 From: Steven Tischer Date: Sat, 20 Jun 2026 20:31:13 +0200 Subject: [PATCH] extract latest institution from affiliations if last_known_institutions is null --- .../person-card/person-card.component.ts | 24 +++++++++++++++---- .../app/modules/person/person.component.ts | 21 +++++++++------- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/webapp/src/app/modules/person-card/person-card.component.ts b/webapp/src/app/modules/person-card/person-card.component.ts index 89f0440c..6502b9c5 100644 --- a/webapp/src/app/modules/person-card/person-card.component.ts +++ b/webapp/src/app/modules/person-card/person-card.component.ts @@ -36,11 +36,25 @@ export class PersonCardComponent { } institution(person: CustomAuthor): DehydratedInstitution | undefined { - return ( - person.last_known_institutions?.[0] || - person.affiliations?.[person.affiliations.length - 1]?.institution || - undefined - ); + if (person.last_known_institutions?.[0]) { + return person.last_known_institutions[0]; + } + + const affiliations = person.affiliations ?? []; + let newestInstitution: DehydratedInstitution | undefined = + affiliations[0]?.institution ?? undefined; + let newestYear = -1; + + for (const affiliation of affiliations) { + for (const jahr of affiliation.years ?? []) { + if (jahr > newestYear) { + newestYear = jahr; + newestInstitution = affiliation.institution ?? undefined; + } + } + } + + return newestInstitution; } topics(person: CustomAuthor): WorkTopic[] { diff --git a/webapp/src/app/modules/person/person.component.ts b/webapp/src/app/modules/person/person.component.ts index a74be3fe..13b866bd 100644 --- a/webapp/src/app/modules/person/person.component.ts +++ b/webapp/src/app/modules/person/person.component.ts @@ -119,15 +119,20 @@ export class PersonComponent { () => this.person()?.affiliations?.[0] ?? null, ); readonly lastAffiliation = computed(() => { - let lastAffiliation: number | undefined = 0; - if (this.person()?.affiliations?.length != undefined) { - lastAffiliation = this.person()?.affiliations?.length; + const affiliations = this.person()?.affiliations ?? []; + let newestAffiliation = affiliations[0] ?? null; + let newestYear = -1; + + for (const affiliation of affiliations) { + for (const jahr of affiliation.years ?? []) { + if (jahr > newestYear) { + newestYear = jahr; + newestAffiliation = affiliation; + } + } } - return ( - (lastAffiliation - ? this.person()?.affiliations?.[lastAffiliation - 1] - : this.person()?.affiliations?.[0]) ?? null - ); + + return newestAffiliation; }); readonly institution = computed( () => -- 2.56.1