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>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Component, OnInit, inject } from '@angular/core';
|
||||
import {
|
||||
ActivatedRoute,
|
||||
RouterLink,
|
||||
@@ -6,9 +6,12 @@ import {
|
||||
RouterLinkActive,
|
||||
} from '@angular/router';
|
||||
import { Institution } from '../../api';
|
||||
import { PatentsService } from '../../api/api/patents.service';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatTabsModule } from '@angular/material/tabs';
|
||||
|
||||
const PATENTS_LINK = { label: 'Patente', path: 'patents', disabled: false };
|
||||
|
||||
@Component({
|
||||
selector: 'app-institution',
|
||||
imports: [
|
||||
@@ -22,6 +25,8 @@ import { MatTabsModule } from '@angular/material/tabs';
|
||||
styleUrl: './institution.component.scss',
|
||||
})
|
||||
export class InstitutionComponent implements OnInit {
|
||||
private readonly patentsApi = inject(PatentsService);
|
||||
|
||||
institution!: Institution;
|
||||
|
||||
links = [
|
||||
@@ -40,7 +45,6 @@ export class InstitutionComponent implements OnInit {
|
||||
sort_direction: 'asc',
|
||||
},
|
||||
},
|
||||
{ label: 'Patente', path: 'patents', disabled: false },
|
||||
];
|
||||
|
||||
constructor(private readonly activatedRoute: ActivatedRoute) {}
|
||||
@@ -49,5 +53,19 @@ export class InstitutionComponent implements OnInit {
|
||||
this.activatedRoute.data.subscribe(({ institution }) => {
|
||||
this.institution = institution;
|
||||
});
|
||||
|
||||
const institutionId = this.activatedRoute.snapshot.paramMap.get('institutionId');
|
||||
if (!institutionId) return;
|
||||
|
||||
// The "Patente" tab only makes sense once org_patents has been indexed for
|
||||
// this institution (currently a manual, ~30-40 min-per-institution process),
|
||||
// so only show it once we know there is actually data behind it.
|
||||
this.patentsApi.getOrgPatentsByInstitution(institutionId, undefined, 0, 0).subscribe({
|
||||
next: (result) => {
|
||||
if ((result.patent_count ?? 0) > 0) {
|
||||
this.links = [...this.links, PATENTS_LINK];
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,17 +74,19 @@
|
||||
<mat-icon>work</mat-icon>
|
||||
Projekte
|
||||
</a>
|
||||
<a
|
||||
mat-button
|
||||
[routerLink]="[
|
||||
'/institution',
|
||||
extractInstitutionId(institution),
|
||||
'patents',
|
||||
]"
|
||||
(click)="$event.stopPropagation()">
|
||||
<mat-icon>verified</mat-icon>
|
||||
Patente
|
||||
</a>
|
||||
@if (hasPatents(institution)) {
|
||||
<a
|
||||
mat-button
|
||||
[routerLink]="[
|
||||
'/institution',
|
||||
extractInstitutionId(institution),
|
||||
'patents',
|
||||
]"
|
||||
(click)="$event.stopPropagation()">
|
||||
<mat-icon>verified</mat-icon>
|
||||
Patente
|
||||
</a>
|
||||
}
|
||||
</mat-card-actions>
|
||||
</mat-card-footer>
|
||||
</mat-card>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Component, computed, input } from '@angular/core';
|
||||
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';
|
||||
@@ -26,6 +27,8 @@ import {
|
||||
styleUrl: './institutions.component.scss',
|
||||
})
|
||||
export class InstitutionsComponent {
|
||||
private readonly patentsApi = inject(PatentsService);
|
||||
|
||||
institutionPage = input.required<InstitutionPage>();
|
||||
|
||||
page = computed<Page>(() => ({
|
||||
@@ -35,6 +38,31 @@ export class InstitutionsComponent {
|
||||
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' },
|
||||
|
||||
Reference in New Issue
Block a user