91 lines
3.1 KiB
TypeScript
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';
|
|
}
|
|
}
|