From 6b6a5c7cffc35f59c92eec306fad1855ef0c56b8 Mon Sep 17 00:00:00 2001 From: genja Date: Tue, 17 Nov 2026 21:25:51 +0100 Subject: [PATCH] added organization badge to person profile --- .../app/modules/person/person.component.html | 74 ++++++++++++++----- .../app/modules/person/person.component.scss | 49 ++++++++++++ .../app/modules/person/person.component.ts | 74 ++++++++++++++++++- webapp/src/app/resolvers/person.resolver.ts | 15 +++- 4 files changed, 190 insertions(+), 22 deletions(-) diff --git a/webapp/src/app/modules/person/person.component.html b/webapp/src/app/modules/person/person.component.html index 27f9bec5..2fafa6f6 100644 --- a/webapp/src/app/modules/person/person.component.html +++ b/webapp/src/app/modules/person/person.component.html @@ -29,27 +29,61 @@ }} - @if (resolvedInstitution(); as inst) { + @if (resolvedInstitution() || verifiedOrganizations().length > 0) {
- - @if (secondaryInstitutions().length > 0) { - + @if (resolvedInstitution(); as inst) { + + @if (secondaryInstitutions().length > 0) { + + } + } + @for (org of verifiedOrganizations(); track $index) { + @if (canOpenOrganizationHierarchy(org)) { + + } @else { + + {{ VERIFIED_ICON }} + {{ org.org_name }} + + } }
} diff --git a/webapp/src/app/modules/person/person.component.scss b/webapp/src/app/modules/person/person.component.scss index 538226ca..d5a38c0f 100644 --- a/webapp/src/app/modules/person/person.component.scss +++ b/webapp/src/app/modules/person/person.component.scss @@ -146,6 +146,55 @@ font-size: 13px; } +.verified-org-chip { + display: inline-flex; + align-items: center; + gap: 6px; + min-height: 24px; + max-width: 100%; + padding: 2px 10px; + border: 1px solid var(--sg-border); + border-radius: 999px; + background: var(--sg-surface-muted); + color: var(--sg-text); + font-size: 13px; + font-weight: 600; + line-height: 1.2; + text-decoration: none; + transition: + border-color 0.15s, + background 0.15s; + + span { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + } + + mat-icon { + flex: 0 0 auto; + width: 16px; + height: 16px; + font-size: 16px; + color: var(--sg-success); + } + + &[type='button'] { + cursor: pointer; + } + + &[type='button']:hover, + &[type='button']:focus-visible { + border-color: var(--sg-success); + background: var(--sg-primary-soft); + outline: none; + } + + &.static { + cursor: default; + } +} + .stats-line { display: flex; align-items: center; diff --git a/webapp/src/app/modules/person/person.component.ts b/webapp/src/app/modules/person/person.component.ts index c096b160..f69feef5 100644 --- a/webapp/src/app/modules/person/person.component.ts +++ b/webapp/src/app/modules/person/person.component.ts @@ -39,12 +39,17 @@ import { CareerStageChipComponent } from '../../shared/ui/career-stage-chip/care 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 { + DehydratedInstitution, + VerifiedOrganization, + WorksService, +} from '../../api'; import { LoadingComponent } from '../../shared/ui/loading/loading.component'; import { PersonBioResolved } from '../../resolvers/person-bio.resolver'; import { PersonDataResolved } from '../../resolvers/person.resolver'; import { BookmarkService } from '../../shared/services/bookmark.service'; import { AuthorAffiliationService } from '../../shared/services/author-affiliation.service'; +import { CredentialService } from '../../shared/services/credential.service'; import { collaborationGraphQueryParamKeys } from '../../resolvers/collaboration-graph.resolver'; import { workQueryParamKeys } from '../../resolvers/work-page.resolver'; import { @@ -73,6 +78,16 @@ import { } from '../../shared/ui/icons'; import { PageContainerComponent } from '../../shared/ui/page-container/page-container.component'; +/** Accepts raw and full-URL OpenAlex IDs, e.g. `I123` or `.../I123`. */ +const normalizeInstitutionId = ( + value: string | null | undefined, +): string => + (value ?? '') + .trim() + .replace(/^https:\/\/openalex\.org\//i, '') + .replace(/\/+$/, '') + .toUpperCase(); + @Component({ selector: 'app-person', imports: [ @@ -116,6 +131,7 @@ export class PersonComponent { private readonly destroyRef = inject(DestroyRef); readonly bookmarkService = inject(BookmarkService); private readonly authorAffiliationService = inject(AuthorAffiliationService); + private readonly credentialService = inject(CredentialService); canFetchGdprRelevantData = input.required(); @@ -206,6 +222,33 @@ export class PersonComponent { .subscribe(); } + canOpenOrganizationHierarchy(organization: VerifiedOrganization): boolean { + return ( + this.canOpenVerifiedOrganizationHierarchy() && + !!organization.org_uri && + (organization.org_hierarchy_path?.length ?? 0) > 0 + ); + } + + openOrganizationHierarchy(organization: VerifiedOrganization): void { + if (!this.canOpenOrganizationHierarchy(organization)) return; + void this.router.navigate(['/hierarchy'], { + queryParams: { + orgFocus: organization.org_uri, + orgFocusPath: JSON.stringify(organization.org_hierarchy_path ?? []), + hierarchyExpanded: true, + organizationExpanded: false, + orgUrl: null, + orgName: null, + orgExpanded: null, + orgSelectionCategory: null, + orgSelectionIndex: null, + classifiedCategory: null, + classifiedPage: null, + }, + }); + } + readonly personBio = toSignal( combineLatest([this.activatedRoute.data, toObservable(this.person)]).pipe( switchMap(([data, person]) => { @@ -249,6 +292,35 @@ export class PersonComponent { readonly secondaryInstitutions = computed(() => this.authorAffiliationService.resolveSecondaryInstitutions(this.person()), ); + readonly verifiedOrganizationData = toSignal( + this.activatedRoute.data.pipe( + switchMap((data) => { + const resolved = data['personData'] as PersonDataResolved | undefined; + return resolved?.verifiedOrganizations$ ?? of(null); + }), + ), + { initialValue: null }, + ); + readonly verifiedOrganizations = computed( + () => this.verifiedOrganizationData()?.organizations ?? [], + ); + /** + * Verified organizations come from one institution's OrgMiner data. Only + * users of that institution have a hierarchy where the nodes can be found. + */ + readonly canOpenVerifiedOrganizationHierarchy = computed(() => { + const userInstitutionId = normalizeInstitutionId( + this.credentialService.effectiveInstitutionId(), + ); + const dataInstitutionId = normalizeInstitutionId( + this.verifiedOrganizationData()?.institution_id, + ); + return ( + !!userInstitutionId && + !!dataInstitutionId && + userInstitutionId === dataInstitutionId + ); + }); readonly worksCount = computed(() => this.person()?.works_count ?? null); readonly citedByCount = computed(() => this.person()?.cited_by_count ?? null); readonly h_index = computed( diff --git a/webapp/src/app/resolvers/person.resolver.ts b/webapp/src/app/resolvers/person.resolver.ts index 56dcbfbc..4b2e5268 100644 --- a/webapp/src/app/resolvers/person.resolver.ts +++ b/webapp/src/app/resolvers/person.resolver.ts @@ -4,6 +4,7 @@ import { CompanyConnectionsService, CustomAuthorsListResponse, PersonsService, + VerifiedOrganizationsResponse, } from '../api'; import { Observable, @@ -20,6 +21,7 @@ import { toObservable } from '@angular/core/rxjs-interop'; export interface PersonDataResolved { personData$: Observable; companyConnectionsAvailable$: Observable; + verifiedOrganizations$: Observable; } export const personResolver: ResolveFn = (route, state) => { @@ -38,6 +40,7 @@ export const personResolver: ResolveFn = (route, state) => { return { personData$: of(null), companyConnectionsAvailable$: of(false), + verifiedOrganizations$: of(null), }; } @@ -51,6 +54,16 @@ export const personResolver: ResolveFn = (route, state) => { shareReplay(1), ); + const verifiedOrganizations$ = personsService + .getVerifiedOrganizations(authorId) + .pipe( + catchError((err) => { + console.error('Failed to load verified organizations:', err); + return of(null); + }), + shareReplay(1), + ); + const companyConnectionsAvailable$ = toObservable( credentialService.effectiveInstitutionId, ).pipe( @@ -76,5 +89,5 @@ export const personResolver: ResolveFn = (route, state) => { shareReplay({ bufferSize: 1, refCount: true }), ); - return { personData$, companyConnectionsAvailable$ }; + return { personData$, companyConnectionsAvailable$, verifiedOrganizations$ }; };