Files
smartguide/webapp/src/app/modules/institutions/institutions.component.ts
T
khaltiandClaude Sonnet 5 970486d860
LocationBasedServices/smartguide/pipeline/head This commit looks good
LocationBasedServices/smartguide/pipeline/pr-dev There was a failure building this commit
feat(institutions): only show the Patente tab/action once org_patents actually has indexed data for that institution
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-17 17:24:41 +02:00

91 lines
3.1 KiB
TypeScript

import { Component, computed, effect, inject, input } from '@angular/core';
import { Institution, InstitutionPage } from '../../api';
import { PatentsService } from '../../api/api/patents.service';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { RouterModule } from '@angular/router';
import { MatIconModule } from '@angular/material/icon';
import { MatDividerModule } from '@angular/material/divider';
import { SelectorOption } from '../../shared/ui/query-param-selector/query-param-selector.component';
import {
Page,
CardSearchComponent,
} from '../../shared/ui/card-search/card-search.component';
@Component({
selector: 'app-institutions',
imports: [
MatButtonModule,
MatCardModule,
MatIconModule,
MatDividerModule,
RouterModule,
CardSearchComponent,
],
templateUrl: './institutions.component.html',
styleUrl: './institutions.component.scss',
})
export class InstitutionsComponent {
private readonly patentsApi = inject(PatentsService);
institutionPage = input.required<InstitutionPage>();
page = computed<Page>(() => ({
page: this.institutionPage().page || 0,
size: this.institutionPage().size || 10,
total: this.institutionPage().total || 0,
elements: this.institutionPage().elements || [],
}));
// The "Patente" action only makes sense once org_patents has been indexed
// for that institution (currently a manual, per-institution process), so
// it's hidden by default and only shown once a cheap count check confirms
// there is actually data behind it.
private readonly patentsAvailable = new Map<string, boolean>();
constructor() {
effect(() => {
for (const institution of this.page().elements) {
const id = this.extractInstitutionId(institution);
if (!id || this.patentsAvailable.has(id)) continue;
this.patentsAvailable.set(id, false);
this.patentsApi.getOrgPatentsByInstitution(id, undefined, 0, 0).subscribe({
next: (result) => {
this.patentsAvailable.set(id, (result.patent_count ?? 0) > 0);
},
});
}
});
}
hasPatents(institution: Institution): boolean {
return this.patentsAvailable.get(this.extractInstitutionId(institution)) ?? false;
}
sortingOptions: SelectorOption[] = [
{ value: 'relevance', display_name: 'Relevanz' },
{ value: 'name', display_name: 'Name' },
{ value: 'works_count', display_name: 'Anzahl Publikationen' },
{ value: 'citations_count', display_name: 'Anzahl Zitationen' },
];
sortingDirectionOptions: SelectorOption[] = [
{ value: 'asc', display_name: 'Aufsteigend' },
{ value: 'desc', display_name: 'Absteigend' },
];
extractInstitutionId(institution: Institution): string {
return institution.id?.split('/').pop() ?? '';
}
getDisplayName(institution: Institution): string {
const primary = institution.display_name?.trim();
if (primary && primary.length > 0) return primary;
const alt = institution.display_name_alternatives?.[0]?.trim();
if (alt && alt.length > 0) return alt;
return 'Unbekannte Institution';
}
}