From a2a4798ba7ab5be134c5045bc4af7933bed6678a Mon Sep 17 00:00:00 2001 From: Kazgatari <56477241+Kazgatari@users.noreply.github.com> Date: Sat, 29 Aug 2026 22:05:16 +0200 Subject: [PATCH] corrected service and added icon to institution chip (additional active institutions) --- .../person-card/person-card.component.html | 17 ++- .../person-card/person-card.component.scss | 43 ++++++ .../person-card/person-card.component.ts | 15 ++ .../app/modules/person/person.component.html | 42 +++--- .../app/modules/person/person.component.scss | 50 ++++--- .../app/modules/person/person.component.ts | 24 ++-- .../services/author-affiliation.service.ts | 135 ++++++++++++------ ...on-institution-tooltip-list.component.html | 25 ++++ ...on-institution-tooltip-list.component.scss | 60 ++++++++ ...rson-institution-tooltip-list.component.ts | 27 ++++ 10 files changed, 349 insertions(+), 89 deletions(-) create mode 100644 webapp/src/app/shared/ui/person-institution-tooltip-list/person-institution-tooltip-list.component.html create mode 100644 webapp/src/app/shared/ui/person-institution-tooltip-list/person-institution-tooltip-list.component.scss create mode 100644 webapp/src/app/shared/ui/person-institution-tooltip-list/person-institution-tooltip-list.component.ts diff --git a/webapp/src/app/modules/person-card/person-card.component.html b/webapp/src/app/modules/person-card/person-card.component.html index 1f8906ee..59970d53 100644 --- a/webapp/src/app/modules/person-card/person-card.component.html +++ b/webapp/src/app/modules/person-card/person-card.component.html @@ -50,7 +50,7 @@
@if (institution(); as inst) { -
+
+ @if (secondaryInstitutions().length > 0) { + + }
} diff --git a/webapp/src/app/modules/person-card/person-card.component.scss b/webapp/src/app/modules/person-card/person-card.component.scss index da6232db..77372825 100644 --- a/webapp/src/app/modules/person-card/person-card.component.scss +++ b/webapp/src/app/modules/person-card/person-card.component.scss @@ -168,6 +168,49 @@ justify-content: space-between; } +.institution-row { + display: flex; + align-items: center; + gap: 6px; + flex-wrap: wrap; +} + +.more-institutions-btn { + display: inline-flex; + align-items: center; + gap: 2px; + padding: 2px 6px; + height: 24px; + border: 1px dashed var(--sg-border-strong, rgba(0, 0, 0, 0.2)); + border-radius: 999px; + background: var(--sg-surface-muted, transparent); + color: var(--sg-text-muted); + font-size: 11px; + font-weight: 600; + cursor: pointer; + transition: all 0.15s ease; + + .more-info-icon { + font-size: 14px; + width: 14px; + height: 14px; + } + + .count-text { + font-size: 10px; + font-weight: 700; + line-height: 1; + } + + &:hover, + &:focus-visible { + border-color: var(--sg-primary); + background: var(--sg-primary-soft); + color: var(--sg-primary); + outline: none; + } +} + .topic-row { display: flex; flex-wrap: wrap; 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 b2f87016..9ea2b649 100644 --- a/webapp/src/app/modules/person-card/person-card.component.ts +++ b/webapp/src/app/modules/person-card/person-card.component.ts @@ -9,10 +9,13 @@ import { TopicChipComponent } from '../../shared/ui/topic-chip/topic-chip.compon import { AppInstitutionChipComponent } from '../../shared/ui/app-institution-chip/app-institution-chip.component'; import { CareerStageChipComponent } from '../../shared/ui/career-stage-chip/career-stage-chip.component'; import { topicHierarchyColor } from '../../resolvers/utils/topic-colors'; +import { ComponentTooltipDirective } from '../../directives/component-tooltip.directive'; +import { PersonInstitutionTooltipListComponent } from '../../shared/ui/person-institution-tooltip-list/person-institution-tooltip-list.component'; import { AuthorAffiliationService } from '../../shared/services/author-affiliation.service'; import { BOOKMARK_BORDER_ICON, BOOKMARK_ICON, + MORE_INFO_ICON, NETWORK_ICON, OVERVIEW_ICON, PUBLICATION_ICON, @@ -30,6 +33,7 @@ import { TopicChipComponent, AppInstitutionChipComponent, CareerStageChipComponent, + ComponentTooltipDirective, ], templateUrl: './person-card.component.html', styleUrl: './person-card.component.scss', @@ -40,6 +44,10 @@ export class PersonCardComponent { readonly OVERVIEW_ICON = OVERVIEW_ICON; readonly PUBLICATION_ICON = PUBLICATION_ICON; readonly NETWORK_ICON = NETWORK_ICON; + readonly MORE_INFO_ICON = MORE_INFO_ICON; + + readonly PersonInstitutionTooltipListComponent = + PersonInstitutionTooltipListComponent; private readonly authorAffiliationService = inject(AuthorAffiliationService); @@ -70,6 +78,13 @@ export class PersonCardComponent { ); }); + secondaryInstitutions = computed(() => { + return this.authorAffiliationService.resolveSecondaryInstitutions( + this.person(), + this.activeInstitutionId(), + ); + }); + isInstitutionActive = computed(() => { const active = this.normalizeInstitutionId(this.activeInstitutionId()); if (!active) return false; diff --git a/webapp/src/app/modules/person/person.component.html b/webapp/src/app/modules/person/person.component.html index 7cda808d..4e84caa0 100644 --- a/webapp/src/app/modules/person/person.component.html +++ b/webapp/src/app/modules/person/person.component.html @@ -28,24 +28,30 @@ }}
-
- {{ INSTITUTION_ICON }} - @if (institutionId(); as institutionId) { - - {{ institution() }} - - } @else { -

{{ institution() }}

- } - @if (countryCode(); as countryCode) { - - - {{ countryCode }} - - } -
+ @if (resolvedInstitution(); as inst) { +
+ + @if (secondaryInstitutions().length > 0) { + + } +
+ } @if ( worksCount() !== null || citedByCount() !== null || h_index() !== null ) { diff --git a/webapp/src/app/modules/person/person.component.scss b/webapp/src/app/modules/person/person.component.scss index ab068a7d..d3cb6da0 100644 --- a/webapp/src/app/modules/person/person.component.scss +++ b/webapp/src/app/modules/person/person.component.scss @@ -99,31 +99,45 @@ .institution-line { display: flex; align-items: center; - gap: 6px; + gap: 8px; margin: 10px 0 0; + flex-wrap: wrap; } -.institution-icon { - width: 16px; - height: 16px; - font-size: 16px; +.more-institutions-btn { + display: inline-flex; + align-items: center; + gap: 3px; + padding: 3px 8px; + height: 28px; + border: 1px dashed var(--sg-border-strong, rgba(0, 0, 0, 0.2)); + border-radius: 999px; + background: var(--sg-surface-muted, transparent); color: var(--sg-text-muted); -} - -.institution-name, -.institution-link { - margin: 0; - color: var(--sg-text); + font-size: 12px; font-weight: 600; - font-size: 14px; -} + cursor: pointer; + transition: all 0.15s ease; -.institution-link { - text-decoration: none; -} + .more-info-icon { + font-size: 16px; + width: 16px; + height: 16px; + } -.institution-link:hover { - text-decoration: underline; + .count-text { + font-size: 11px; + font-weight: 700; + line-height: 1; + } + + &:hover, + &:focus-visible { + border-color: var(--sg-primary); + background: var(--sg-primary-soft); + color: var(--sg-primary); + outline: none; + } } .profile-main > span { diff --git a/webapp/src/app/modules/person/person.component.ts b/webapp/src/app/modules/person/person.component.ts index f6c9d7e6..e2b7853d 100644 --- a/webapp/src/app/modules/person/person.component.ts +++ b/webapp/src/app/modules/person/person.component.ts @@ -35,9 +35,11 @@ import { } from 'rxjs'; import { PersonInterestingComponent } from '../person-interesting/person-interesting.component'; -import { CountryFlagComponent } from '../../shared/ui/country-flag/country-flag.component'; import { CareerStageChipComponent } from '../../shared/ui/career-stage-chip/career-stage-chip.component'; -import { WorksService } from '../../api'; +import { AppInstitutionChipComponent } from '../../shared/ui/app-institution-chip/app-institution-chip.component'; +import { ComponentTooltipDirective } from '../../directives/component-tooltip.directive'; +import { PersonInstitutionTooltipListComponent } from '../../shared/ui/person-institution-tooltip-list/person-institution-tooltip-list.component'; +import { DehydratedInstitution, WorksService } from '../../api'; import { LoadingComponent } from '../../shared/ui/loading/loading.component'; import { PersonBioResolved } from '../../resolvers/person-bio.resolver'; import { PersonDataResolved } from '../../resolvers/person.resolver'; @@ -58,6 +60,7 @@ import { DESCRIPTION_ICON, FUNDING_ICON, INSTITUTION_ICON, + MORE_INFO_ICON, NETWORK_ICON, NEWS_ICON, OVERVIEW_ICON, @@ -80,9 +83,10 @@ import { RouterOutlet, RouterModule, LoadingComponent, - CountryFlagComponent, CareerStageChipComponent, LinkTabNavBarComponent, + AppInstitutionChipComponent, + ComponentTooltipDirective, ], templateUrl: './person.component.html', styleUrl: './person.component.scss', @@ -98,6 +102,10 @@ export class PersonComponent { readonly DESCRIPTION_ICON = DESCRIPTION_ICON; readonly PERSON_ICON = PERSON_ICON; readonly AI_GENERATED_ICON = AI_GENERATED_ICON; + readonly MORE_INFO_ICON = MORE_INFO_ICON; + + readonly PersonInstitutionTooltipListComponent = + PersonInstitutionTooltipListComponent; private readonly router = inject(Router); private readonly activatedRoute = inject(ActivatedRoute); @@ -236,14 +244,8 @@ export class PersonComponent { readonly resolvedInstitution = computed(() => this.authorAffiliationService.resolveInstitution(this.person()), ); - readonly institution = computed( - () => this.resolvedInstitution()?.display_name ?? 'Unbekannte Institution', - ); - readonly countryCode = computed( - () => this.resolvedInstitution()?.country_code ?? null, - ); - readonly institutionId = computed( - () => this.resolvedInstitution()?.id?.split('/').pop() ?? null, + readonly secondaryInstitutions = computed(() => + this.authorAffiliationService.resolveSecondaryInstitutions(this.person()), ); readonly worksCount = computed(() => this.person()?.works_count ?? null); readonly citedByCount = computed(() => this.person()?.cited_by_count ?? null); diff --git a/webapp/src/app/shared/services/author-affiliation.service.ts b/webapp/src/app/shared/services/author-affiliation.service.ts index 1dc67326..1103bd12 100644 --- a/webapp/src/app/shared/services/author-affiliation.service.ts +++ b/webapp/src/app/shared/services/author-affiliation.service.ts @@ -11,53 +11,106 @@ import { }) export class AuthorAffiliationService { /** - * Resolves the primary institution for an author based on: - * 1. Active search filter match (if filtering by an institution) - * 2. Most recent publication affiliation (highest year in affiliations.years) - * 3. Fallback to last_known_institutions[0] if affiliations are empty + * Resolves the full list of candidate institutions for an author by taking the + * union of: + * 1. The most recent publication affiliations (matching the author's maximum publication year) + * 2. The author's last known institutions (last_known_institutions) + * + * If an activeInstitutionId filter is supplied and matches one of the candidates, + * that institution is prioritized at index 0. + */ + resolveAllInstitutions( + author: Author | CustomAuthor | null | undefined, + activeInstitutionId?: string | null, + ): DehydratedInstitution[] { + if (!author) { + return []; + } + + const affiliations = author.affiliations ?? []; + const lastKnown = author.last_known_institutions ?? []; + + // Find the maximum publication year across all affiliations + let maxGlobalYear = -1; + for (const aff of affiliations) { + for (const year of aff.years ?? []) { + if (year > maxGlobalYear) { + maxGlobalYear = year; + } + } + } + + const candidatesMap = new Map(); + const cleanActiveId = this.normalizeId(activeInstitutionId); + + // 1. Collect most recent affiliations (matching maxGlobalYear, or all if maxGlobalYear <= 0) + for (const aff of affiliations) { + if (!aff.institution || !aff.institution.id) continue; + const years = aff.years ?? []; + const isMostRecent = maxGlobalYear <= 0 || years.includes(maxGlobalYear); + + if (isMostRecent) { + const normId = this.normalizeId(aff.institution.id); + if (normId && !candidatesMap.has(normId)) { + candidatesMap.set(normId, aff.institution); + } + } + } + + // 2. Union with last_known_institutions (deduplicating by normalized ID) + for (const inst of lastKnown) { + if (!inst || !inst.id) continue; + const normId = this.normalizeId(inst.id); + if (normId && !candidatesMap.has(normId)) { + candidatesMap.set(normId, inst); + } + } + + // Fallback: If no recent affiliations and no lastKnown institutions were found, use any affiliation institution + if (candidatesMap.size === 0) { + for (const aff of affiliations) { + if (!aff.institution || !aff.institution.id) continue; + const normId = this.normalizeId(aff.institution.id); + if (normId && !candidatesMap.has(normId)) { + candidatesMap.set(normId, aff.institution); + } + } + } + + const allCandidates = Array.from(candidatesMap.values()); + + // 3. If activeInstitutionId is set and matches a candidate, prioritize it at index 0 + if (cleanActiveId) { + const matchIndex = allCandidates.findIndex( + (inst) => this.normalizeId(inst.id) === cleanActiveId, + ); + if (matchIndex > 0) { + const [matched] = allCandidates.splice(matchIndex, 1); + allCandidates.unshift(matched); + } + } + + return allCandidates; + } + + /** + * Resolves the primary institution for an author. */ resolveInstitution( author: Author | CustomAuthor | null | undefined, activeInstitutionId?: string | null, ): DehydratedInstitution | undefined { - if (!author) { - return undefined; - } + return this.resolveAllInstitutions(author, activeInstitutionId)[0]; + } - const affiliations = author.affiliations ?? []; - - // 1. If an active institution filter is present, prioritize the matching affiliation - if (activeInstitutionId) { - const cleanActiveId = this.normalizeId(activeInstitutionId); - if (cleanActiveId) { - const matchedAffiliation = affiliations.find((aff) => { - const affId = this.normalizeId(aff.institution?.id); - return affId === cleanActiveId; - }); - if (matchedAffiliation?.institution) { - return matchedAffiliation.institution; - } - - const matchedLastKnown = (author.last_known_institutions ?? []).find( - (inst) => { - const instId = this.normalizeId(inst.id); - return instId === cleanActiveId; - }, - ); - if (matchedLastKnown) { - return matchedLastKnown; - } - } - } - - // 2. Otherwise, find the newest affiliation by highest publication year - const latestAffiliation = this.getLatestAffiliation(author); - if (latestAffiliation?.institution) { - return latestAffiliation.institution; - } - - // 3. Fallback to last_known_institutions if affiliations have no valid institution - return author.last_known_institutions?.[0] ?? undefined; + /** + * Resolves any secondary/alternative candidate institutions (excluding the primary one). + */ + resolveSecondaryInstitutions( + author: Author | CustomAuthor | null | undefined, + activeInstitutionId?: string | null, + ): DehydratedInstitution[] { + return this.resolveAllInstitutions(author, activeInstitutionId).slice(1); } /** diff --git a/webapp/src/app/shared/ui/person-institution-tooltip-list/person-institution-tooltip-list.component.html b/webapp/src/app/shared/ui/person-institution-tooltip-list/person-institution-tooltip-list.component.html new file mode 100644 index 00000000..9032fafa --- /dev/null +++ b/webapp/src/app/shared/ui/person-institution-tooltip-list/person-institution-tooltip-list.component.html @@ -0,0 +1,25 @@ + +
+ {{ INSTITUTION_ICON }} +

{{ title() }}

+ {{ institutions().length }} +
+ + + + +
+ @for ( + inst of institutions(); + track inst.id ?? inst.display_name ?? $index + ) { + + } +
+
+
diff --git a/webapp/src/app/shared/ui/person-institution-tooltip-list/person-institution-tooltip-list.component.scss b/webapp/src/app/shared/ui/person-institution-tooltip-list/person-institution-tooltip-list.component.scss new file mode 100644 index 00000000..5ba7d4a9 --- /dev/null +++ b/webapp/src/app/shared/ui/person-institution-tooltip-list/person-institution-tooltip-list.component.scss @@ -0,0 +1,60 @@ +:host { + display: block; +} + +.institution-tooltip-card { + background: var(--sg-surface); + border: 1px solid var(--sg-border); + border-radius: var(--sg-radius-md, 12px); + box-shadow: var(--sg-shadow-lg, 0 10px 25px -5px rgba(0, 0, 0, 0.15)); + padding: 0; + overflow: hidden; + min-width: 260px; + max-width: 440px; +} + +.tooltip-header { + display: flex; + align-items: center; + gap: 8px; + padding: 10px 14px; + background: var(--sg-surface-muted, rgba(0, 0, 0, 0.02)); + + .header-icon { + font-size: 18px; + width: 18px; + height: 18px; + color: var(--sg-primary); + } + + .header-title { + font-size: 13px; + font-weight: 600; + color: var(--sg-text); + margin: 0; + flex: 1; + } + + .count-badge { + display: inline-flex; + align-items: center; + justify-content: center; + padding: 1px 7px; + font-size: 11px; + font-weight: 700; + border-radius: 999px; + background: var(--sg-primary-soft, rgba(59, 130, 246, 0.12)); + color: var(--sg-primary); + } +} + +.tooltip-content { + padding: 12px 14px; +} + +.chips-container { + display: flex; + flex-direction: column; + gap: 8px; + align-items: flex-start; +} diff --git a/webapp/src/app/shared/ui/person-institution-tooltip-list/person-institution-tooltip-list.component.ts b/webapp/src/app/shared/ui/person-institution-tooltip-list/person-institution-tooltip-list.component.ts new file mode 100644 index 00000000..435732d7 --- /dev/null +++ b/webapp/src/app/shared/ui/person-institution-tooltip-list/person-institution-tooltip-list.component.ts @@ -0,0 +1,27 @@ +import { Component, input, output } from '@angular/core'; +import { MatCardModule } from '@angular/material/card'; +import { MatIconModule } from '@angular/material/icon'; +import { MatDividerModule } from '@angular/material/divider'; +import { DehydratedInstitution, Institution } from '../../../api'; +import { AppInstitutionChipComponent } from '../app-institution-chip/app-institution-chip.component'; +import { INSTITUTION_ICON } from '../icons'; + +@Component({ + selector: 'app-person-institution-tooltip-list', + standalone: true, + imports: [ + MatCardModule, + MatIconModule, + MatDividerModule, + AppInstitutionChipComponent, + ], + templateUrl: './person-institution-tooltip-list.component.html', + styleUrl: './person-institution-tooltip-list.component.scss', +}) +export class PersonInstitutionTooltipListComponent { + readonly INSTITUTION_ICON = INSTITUTION_ICON; + + institutions = input([]); + title = input('Weitere Institutionen'); + handleChipClick = output(); +}