corrected service and added icon to institution chip (additional active institutions)

This commit is contained in:
Kazgatari
2026-08-29 22:05:16 +02:00
parent 4280ac24b8
commit a2a4798ba7
10 changed files with 349 additions and 89 deletions
@@ -50,7 +50,7 @@
<div class="card-body">
@if (institution(); as inst) {
<div class="institution-row" style="margin-bottom: 8px">
<div class="institution-row">
<app-institution-chip
[institution]="inst"
size="mini"
@@ -58,6 +58,21 @@
[isClickable]="true"
[isSelected]="isInstitutionActive()"
(handleChipClick)="institutionClick.emit($event)" />
@if (secondaryInstitutions().length > 0) {
<button
type="button"
class="more-institutions-btn"
[appComponentTooltip]="PersonInstitutionTooltipListComponent"
[tooltipInputs]="{ institutions: secondaryInstitutions() }"
[attr.aria-label]="
secondaryInstitutions().length + ' weitere Institutionen'
">
<mat-icon class="more-info-icon">{{ MORE_INFO_ICON }}</mat-icon>
<span class="count-text"
>+{{ secondaryInstitutions().length }}</span
>
</button>
}
</div>
}
@@ -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;
@@ -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<DehydratedInstitution[]>(() => {
return this.authorAffiliationService.resolveSecondaryInstitutions(
this.person(),
this.activeInstitutionId(),
);
});
isInstitutionActive = computed<boolean>(() => {
const active = this.normalizeInstitutionId(this.activeInstitutionId());
if (!active) return false;
@@ -28,24 +28,30 @@
}}</mat-icon>
</button>
</div>
<div class="institution-line">
<mat-icon class="institution-icon">{{ INSTITUTION_ICON }}</mat-icon>
@if (institutionId(); as institutionId) {
<a
class="institution-link"
[routerLink]="['/institution', institutionId]">
{{ institution() }}
</a>
} @else {
<p class="institution-name">{{ institution() }}</p>
}
@if (countryCode(); as countryCode) {
<span class="institution-country">
<app-country-flag [countryCode]="countryCode" [rounded]="true" />
{{ countryCode }}
</span>
}
</div>
@if (resolvedInstitution(); as inst) {
<div class="institution-line">
<app-institution-chip
[institution]="inst"
size="normal"
[showIcon]="true"
[isClickable]="false" />
@if (secondaryInstitutions().length > 0) {
<button
type="button"
class="more-institutions-btn"
[appComponentTooltip]="PersonInstitutionTooltipListComponent"
[tooltipInputs]="{ institutions: secondaryInstitutions() }"
[attr.aria-label]="
secondaryInstitutions().length + ' weitere Institutionen'
">
<mat-icon class="more-info-icon">{{ MORE_INFO_ICON }}</mat-icon>
<span class="count-text"
>+{{ secondaryInstitutions().length }}</span
>
</button>
}
</div>
}
@if (
worksCount() !== null || citedByCount() !== null || h_index() !== null
) {
@@ -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 {
@@ -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<DehydratedInstitution[]>(() =>
this.authorAffiliationService.resolveSecondaryInstitutions(this.person()),
);
readonly worksCount = computed(() => this.person()?.works_count ?? null);
readonly citedByCount = computed(() => this.person()?.cited_by_count ?? null);
@@ -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<string, DehydratedInstitution>();
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);
}
/**
@@ -0,0 +1,25 @@
<mat-card appearance="outlined" class="institution-tooltip-card">
<div class="tooltip-header">
<mat-icon class="header-icon">{{ INSTITUTION_ICON }}</mat-icon>
<h4 class="header-title">{{ title() }}</h4>
<span class="count-badge">{{ institutions().length }}</span>
</div>
<mat-divider />
<mat-card-content class="tooltip-content">
<div class="chips-container">
@for (
inst of institutions();
track inst.id ?? inst.display_name ?? $index
) {
<app-institution-chip
[institution]="inst"
size="mini"
[showIcon]="true"
[isClickable]="true"
(handleChipClick)="handleChipClick.emit($event)" />
}
</div>
</mat-card-content>
</mat-card>
@@ -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;
}
@@ -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<DehydratedInstitution[] | Institution[]>([]);
title = input<string>('Weitere Institutionen');
handleChipClick = output<Institution | DehydratedInstitution>();
}