Experimental Signal based service injection
LocationBasedServices/smartguide/pipeline/head This commit looks good

This commit is contained in:
Kazgatari
2026-05-28 22:11:06 +02:00
parent 8ecf766aef
commit 011c14ee6a
10 changed files with 280 additions and 56 deletions
+2 -1
View File
@@ -152,7 +152,8 @@ def get_topics_from_cache(topic_names: List[str]) -> List[model.Topic]:
continue
topics.append(model.Topic(
id=data.get("topic_id", ""),
name=name,
display_name=name,
count=data.get("count", 1),
subfield=data.get("subfield", ""),
field=data.get("field", ""),
domain=data.get("domain", "")
+5 -1
View File
@@ -38,11 +38,15 @@ class ItemPage(Page[Item]):
class Topic(BaseModel):
id: str = Field(description="The openalex topic id.")
name: str = Field(description="The topic name.")
display_name: str = Field(description="The topic name.")
count: int = Field(description="The number of works associated with the topic.")
subfield: str = Field(description="The subfield of the topic.")
field: str = Field(description="The field of the topic.")
domain: str = Field(description="The domain of the topic.")
class TopicShare(Topic):
count: float = Field(description="Share value (0..1) for this topic.")
class PersonBio(BaseModel):
bio: str = Field(description="The generated biography.")
@@ -0,0 +1,12 @@
<aside class="interest-card">
<h3>Interessant für</h3>
<div class="interest-tags">
@if (tags.length > 0) {
@for (tag of tags; track tag.label) {
<span>{{ tag.label }}</span>
}
} @else {
<span class="interest-empty">Keine Themen gefunden</span>
}
</div>
</aside>
@@ -0,0 +1,38 @@
:host {
display: block;
}
.interest-card {
align-self: center;
padding: 24px 28px;
border-radius: var(--sg-radius-sm);
background: var(--sg-surface-muted);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}
.interest-card h3 {
margin: 0 0 18px;
font-size: 14px;
font-weight: 700;
}
.interest-tags {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
.interest-tags span {
padding: 9px 16px;
border: 1px solid #a8c0ff;
border-radius: 7px;
background: #ffffff;
color: var(--sg-primary);
font-size: 13px;
font-weight: 600;
}
.interest-tags .interest-empty {
border-style: dashed;
color: var(--sg-text-muted);
}
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { PersonInterestingComponent } from './person-interesting.component';
describe('PersonInterestingComponent', () => {
let component: PersonInterestingComponent;
let fixture: ComponentFixture<PersonInterestingComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [PersonInterestingComponent]
})
.compileComponents();
fixture = TestBed.createComponent(PersonInterestingComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,46 @@
import { Component, Input } from '@angular/core';
import { Topic } from '../../api';
interface InterestTag {
label: string;
score: number;
}
@Component({
selector: 'app-person-interesting',
imports: [],
templateUrl: './person-interesting.component.html',
styleUrl: './person-interesting.component.scss',
})
export class PersonInterestingComponent {
private _topics: Topic[] = [];
tags: InterestTag[] = [];
@Input()
set topics(value: Topic[] | null) {
this._topics = value ?? [];
this.tags = this.buildTags(this._topics);
}
get topics(): Topic[] {
return this._topics;
}
private buildTags(topics: Topic[]): InterestTag[] {
const grouped = new Map<string, number>();
for (const topic of topics) {
const label = (topic.subfield?.display_name ?? '').trim();
if (!label) continue;
const score = typeof topic.score === 'number' ? topic.score : 0;
grouped.set(label, (grouped.get(label) ?? 0) + score);
}
return Array.from(grouped.entries())
.map(([label, score]) => ({ label, score }))
.sort((a, b) => b.score - a.score)
.slice(0, 8);
}
}
@@ -1,41 +1,56 @@
<section class="person-hero">
<div class="profile-card">
<div class="profile-avatar">AB</div>
<div class="profile-avatar">{{ initials() }}</div>
<div class="profile-main">
<div class="name-line">
<span>Prof. Dr.</span>
<h1>Anna Becker</h1>
<span>Person</span>
<h1>{{ displayName() }}</h1>
</div>
<p>Universität Duisburg-Essen</p>
<span>Fakultät für Ingenieurwissenschaften</span>
<span>Lehrstuhl für Datenanalyse</span>
<p>{{ institution() }}</p>
@if (countryCode()) {
<span>{{ countryCode() }}</span>
}
@if (worksCount() !== null || citedByCount() !== null) {
<span>
@if (worksCount() !== null) {
{{ worksCount() }} Publikationen
}
@if (worksCount() !== null && citedByCount() !== null) {
·
}
@if (citedByCount() !== null) {
{{ citedByCount() }} Zitationen
}
</span>
}
</div>
<div class="profile-contact">
<div>
<mat-icon>mail</mat-icon>
<span>anna.becker@uni-due.de</span>
</div>
<div>
<mat-icon class="orcid">verified</mat-icon>
<span>0000-0002-1234-5678</span>
</div>
@if (openAlexId()) {
<div>
<mat-icon>person</mat-icon>
<span>{{ openAlexId() }}</span>
</div>
}
@if (orcid()) {
<div>
<mat-icon class="orcid">verified</mat-icon>
<a [href]="orcidUrl()" target="_blank" rel="noopener">{{ orcid() }}</a>
</div>
}
<div>
<mat-icon>language</mat-icon>
<a href="https://ude.de/anna-becker" target="_blank" rel="noopener">ude.de/anna-becker</a>
<a href="https://ude.de/anna-becker" target="_blank" rel="noopener">
ude.de/anna-becker
</a>
</div>
</div>
</div>
<aside class="interest-card">
<h3>Interessant für</h3>
<div class="interest-tags">
<span>KI & Machine Learning</span>
<span>Datenanalyse</span>
<span>Industrie 4.0</span>
<span>Nachhaltigkeit</span>
<span>Smart Systems</span>
</div>
</aside>
<app-person-interesting [topics]="topicsFull()"></app-person-interesting>
</section>
<nav class="person-tabs" mat-tab-nav-bar [tabPanel]="tabPanel">
@@ -97,35 +97,6 @@
font-weight: 600;
}
.interest-card {
align-self: center;
padding: 24px 28px;
border-radius: var(--sg-radius-sm);
background: var(--sg-surface-muted);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}
.interest-card h3 {
margin: 0 0 18px;
font-size: 14px;
font-weight: 700;
}
.interest-tags {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
.interest-tags span {
padding: 9px 16px;
border: 1px solid #a8c0ff;
border-radius: 7px;
background: #ffffff;
color: var(--sg-primary);
font-size: 13px;
font-weight: 600;
}
.person-tabs {
padding: 0 32px;
@@ -1,15 +1,57 @@
import { Component } from '@angular/core';
import { Component, OnDestroy, OnInit, computed, inject } from '@angular/core';
import { MatIconModule } from '@angular/material/icon';
import { MatTabsModule } from '@angular/material/tabs';
import { RouterModule, RouterOutlet } from '@angular/router';
import { ActivatedRoute, RouterModule, RouterOutlet } from '@angular/router';
import { Subscription } from 'rxjs';
import { Topic } from '../../api';
import { PersonStore } from '../../shared/services/person-store.service';
import { PersonInterestingComponent } from '../person-interesting/person-interesting.component';
@Component({
selector: 'app-person',
imports: [MatIconModule, MatTabsModule, RouterOutlet, RouterModule],
imports: [
MatIconModule,
MatTabsModule,
PersonInterestingComponent,
RouterOutlet,
RouterModule,
],
templateUrl: './person.component.html',
styleUrl: './person.component.scss',
})
export class PersonComponent {
export class PersonComponent implements OnInit, OnDestroy {
private route = inject(ActivatedRoute);
readonly personStore = inject(PersonStore);
private routeSub?: Subscription;
readonly person = computed(() => this.personStore.person());
readonly displayName = computed(
() => this.person()?.name ?? 'Unbekannte Person',
);
readonly initials = computed(() => this.buildInitials(this.displayName()));
readonly primaryAffiliation = computed(
() => this.person()?.affiliations?.[0] ?? null,
);
readonly institution = computed(
() => this.primaryAffiliation()?.institution ?? 'Unbekannte Institution',
);
readonly countryCode = computed(
() => this.primaryAffiliation()?.country_code ?? null,
);
readonly worksCount = computed(() => this.person()?.works_count ?? null);
readonly citedByCount = computed(() => this.person()?.cited_by_count ?? null);
readonly orcid = computed(() => this.getId('orcid'));
readonly orcidUrl = computed(() =>
this.orcid() ? `https://orcid.org/${this.orcid()}` : null,
);
readonly worksApiUrl = computed(() => this.person()?.works_api_url ?? null);
readonly openAlexId = computed(() => this.person()?.id ?? null);
readonly topicsFull = computed(
() => (this.personStore.person()?.topics_full ?? []) as Topic[],
);
links = [
{ label: 'Übersicht', path: 'overview', disabled: false },
{ label: 'Projekte', path: 'projects', disabled: true },
@@ -17,4 +59,38 @@ export class PersonComponent {
{ label: 'Netzwerk', path: 'network', disabled: false },
{ label: 'Gründungen', path: 'foundings', disabled: true },
];
ngOnInit(): void {
this.routeSub = this.route.paramMap.subscribe((params) => {
const authorId = params.get('id') ?? '';
this.personStore.loadPerson(authorId);
});
}
ngOnDestroy(): void {
this.routeSub?.unsubscribe();
}
private getId(key: string): string | null {
const ids = this.person()?.ids as Record<string, string> | undefined;
if (!ids) {
return null;
}
const value = ids[key];
return value ? String(value) : null;
}
private buildInitials(name: string): string {
const parts = name.trim().split(/\s+/).filter(Boolean);
if (parts.length === 0) {
return '??';
}
if (parts.length === 1) {
return parts[0].slice(0, 2).toUpperCase();
}
return `${parts[0][0]}${parts[1][0]}`.toUpperCase();
}
}
@@ -0,0 +1,38 @@
import { Injectable, computed, signal } from '@angular/core';
import { rxResource } from '@angular/core/rxjs-interop';
import { map, of } from 'rxjs';
import { Person, PersonsOpenApiService } from '../../api';
const PERSON_INCLUDE_TAGS = //hardcoded for now to get all values for the person page
'topics_full,topic_share,summary_stats,ids,last_known_institutions,' +
'sources,counts_by_year,works_api_url,dates,cited_by_count_boost';
@Injectable({ providedIn: 'root' })
export class PersonStore {
private readonly authorId = signal<string | null>(null);
private readonly personResource = rxResource<Person | null, string | null>({
params: () => this.authorId(),
stream: ({ params }) => {
if (!params) {
return of(null);
}
return this.personsApi.searchPersons(params, undefined, PERSON_INCLUDE_TAGS).pipe(
map((result) => result.persons?.[0] ?? null),
);
},
defaultValue: null,
});
readonly person = computed(() => this.personResource.value());
readonly loading = this.personResource.isLoading;
readonly error = this.personResource.error;
constructor(private personsApi: PersonsOpenApiService) {}
loadPerson(authorId: string): void {
this.authorId.set(authorId ? authorId : null);
}
}