From 1369a2bf29a3fdd9a6aa48b3b27a0f3d8d65b3f9 Mon Sep 17 00:00:00 2001 From: Khuder Khalti Date: Sat, 15 Aug 2026 20:43:52 +0200 Subject: [PATCH] refactor(patents, person-funding): reuse shared app-card-search/app-data-table component --- .../modules/patents/patents.component.html | 166 ++++++++---------- .../modules/patents/patents.component.scss | 2 - .../app/modules/patents/patents.component.ts | 102 ++++------- .../person-funding.component.html | 128 ++++---------- .../person-funding.component.scss | 74 +++----- .../person-funding.component.ts | 65 ++++++- 6 files changed, 234 insertions(+), 303 deletions(-) diff --git a/webapp/src/app/modules/patents/patents.component.html b/webapp/src/app/modules/patents/patents.component.html index 76bac5ac..a018cef8 100644 --- a/webapp/src/app/modules/patents/patents.component.html +++ b/webapp/src/app/modules/patents/patents.component.html @@ -3,42 +3,6 @@ -
- - Suche nach Titel oder Patent-Nr. - - search - - - -
- - EPO - USPTO - - - -
-
- - - @if (loading) { } - } @else if (patents.length === 0) { -
-

Keine Patente gefunden.

-
} @else { -
- @for ( - patent of patents; - track patent.patent_id + (patent.publication_date ?? '') - ) { - - - {{ - patent.title ?? patent.patent_id - }} - - {{ patent.source }} - - - - - - - - - - - - - - } -
+ + + +
+ + EPO + USPTO + + + +
+
+ + +
+

Keine Patente gefunden.

+
+
+ + + + + {{ + patent.title ?? patent.patent_id + }} + + {{ patent.source }} + + + + + + + + + + + + + + } - - - - diff --git a/webapp/src/app/modules/patents/patents.component.scss b/webapp/src/app/modules/patents/patents.component.scss index 67227c82..87fa2142 100644 --- a/webapp/src/app/modules/patents/patents.component.scss +++ b/webapp/src/app/modules/patents/patents.component.scss @@ -76,14 +76,12 @@ mat-paginator { padding: 0.5rem; background-color: var(--sg-card-bg); border: 1px solid var(--sg-border); - transition: transform 0.3s ease; display: flex; flex-direction: column; gap: 0.5rem; &:hover { cursor: pointer; - transform: scale(1.03); } mat-card-title { diff --git a/webapp/src/app/modules/patents/patents.component.ts b/webapp/src/app/modules/patents/patents.component.ts index abd3d722..07b7045f 100644 --- a/webapp/src/app/modules/patents/patents.component.ts +++ b/webapp/src/app/modules/patents/patents.component.ts @@ -1,16 +1,12 @@ -import { Component, OnInit, inject } from '@angular/core'; +import { Component, DestroyRef, inject } from '@angular/core'; import { CommonModule } from '@angular/common'; import { ActivatedRoute, Router, RouterModule } from '@angular/router'; import { MatIconModule } from '@angular/material/icon'; import { MatButtonModule } from '@angular/material/button'; import { MatCardModule } from '@angular/material/card'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { MatInputModule } from '@angular/material/input'; -import { MatPaginatorModule, PageEvent } from '@angular/material/paginator'; import { MatChipListboxChange, MatChipsModule } from '@angular/material/chips'; import { MatDividerModule } from '@angular/material/divider'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; -import { debounceTime, distinctUntilChanged, Subject } from 'rxjs'; import { PatentsService } from '../../api/api/patents.service'; import { PatentEntry } from '../../api/model/patentEntry'; import { IpcClassification } from '../../api'; @@ -22,6 +18,10 @@ import { classificationSectionColor, topicHierarchyColor, } from '../../resolvers/utils/topic-colors'; +import { + CardSearchComponent, + Page, +} from '../../shared/ui/card-search/card-search.component'; type PatentSource = 'EPO' | 'USPTO'; @@ -48,32 +48,30 @@ const MIN_YEAR = 1978; MatIconModule, MatButtonModule, MatCardModule, - MatFormFieldModule, - MatInputModule, - MatPaginatorModule, MatChipsModule, MatDividerModule, TopicChipComponent, LoadingComponent, YearRangeSliderComponent, + CardSearchComponent, ], templateUrl: './patents.component.html', styleUrl: './patents.component.scss', }) -export class PatentsComponent implements OnInit { +export class PatentsComponent { private router = inject(Router); private route = inject(ActivatedRoute); private patentsApi = inject(PatentsService); + private destroyRef = inject(DestroyRef); patents: PatentEntry[] = []; total = 0; - page = 0; + pageIndex = 0; pageSize = 10; loading = true; error = false; - searchTerm = ''; selectedSources: PatentSource[] = ['EPO', 'USPTO']; sortDirection: string = 'asc'; @@ -83,49 +81,45 @@ export class PatentsComponent implements OnInit { selectedStartYear = MIN_YEAR; selectedEndYear = new Date().getFullYear(); - private searchSubject = new Subject(); - showDetail = false; selectedPatent: PatentEntry | null = null; readonly expandedClassificationKeys = new Set(); constructor() { - this.searchSubject - .pipe(debounceTime(300), distinctUntilChanged(), takeUntilDestroyed()) - .subscribe((term) => { - this.searchTerm = term; - this.page = 0; - this.loadPatents(); - this.updateQueryParams(); + this.route.queryParams + .pipe(takeUntilDestroyed(this.destroyRef)) + .subscribe((qp) => { + this.pageIndex = parseInt(qp['page'] ?? '0', 10) || 0; + this.pageSize = parseInt(qp['size'] ?? '10', 10) || 10; + const sourcesParam = qp['sources']; + this.selectedSources = ((sourcesParam ?? 'EPO,USPTO') as string) + .split(',') + .filter((s): s is PatentSource => s === 'EPO' || s === 'USPTO'); + const d = qp['sort_direction']; + this.sortDirection = d === 'asc' || d === 'desc' ? d : 'asc'; + const sy = parseInt(qp['year_from'] ?? '', 10); + const ey = parseInt(qp['year_to'] ?? '', 10); + this.selectedStartYear = isNaN(sy) ? this.minYear : sy; + this.selectedEndYear = isNaN(ey) ? this.maxYear : ey; + + this.loadPatents(qp['search'] ?? ''); }); } - ngOnInit(): void { - const qp = this.route.snapshot.queryParamMap; - this.searchTerm = qp.get('search') ?? ''; - this.page = parseInt(qp.get('page') ?? '0', 10); - this.pageSize = parseInt(qp.get('size') ?? '10', 10); - const sourcesParam = qp.get('sources'); - this.selectedSources = (sourcesParam ?? 'EPO,USPTO') - .split(',') - .filter((s): s is PatentSource => s === 'EPO' || s === 'USPTO'); - const d = qp.get('sort_direction'); - if (d === 'asc' || d === 'desc') this.sortDirection = d; - const sy = parseInt(qp.get('year_from') ?? '', 10); - const ey = parseInt(qp.get('year_to') ?? '', 10); - if (!isNaN(sy)) this.selectedStartYear = sy; - if (!isNaN(ey)) this.selectedEndYear = ey; - - this.loadPatents(); + cardSearchPage(): Page { + return { + page: this.pageIndex, + size: this.pageSize, + total: this.total, + elements: this.patents, + }; } onYearRangeChange(): void { - this.page = 0; - this.loadPatents(); this.updateQueryParams(); } - private loadPatents(): void { + private loadPatents(searchTerm: string): void { if (this.selectedSources.length === 0) { this.patents = []; this.total = 0; @@ -141,9 +135,9 @@ export class PatentsComponent implements OnInit { this.patentsApi .getAllPatents( - this.page, + this.pageIndex, this.pageSize, - this.searchTerm || undefined, + searchTerm || undefined, source, 'date', this.sortDirection, @@ -163,37 +157,16 @@ export class PatentsComponent implements OnInit { }); } - onSearchInput(event: Event): void { - this.searchSubject.next((event.target as HTMLInputElement).value); - } - - clearSearch(): void { - this.searchTerm = ''; - this.page = 0; - this.loadPatents(); - this.updateQueryParams(); - } - handleSourceChipChange(change: MatChipListboxChange): void { const selected = change.value as PatentSource[]; // Deselecting every chip resets back to "all sources", mirroring the // project-type filter's behavior instead of showing an empty state. this.selectedSources = selected.length ? selected : ['EPO', 'USPTO']; - this.page = 0; - this.loadPatents(); this.updateQueryParams(); } setSortDirection(direction: string): void { this.sortDirection = direction; - this.loadPatents(); - this.updateQueryParams(); - } - - handlePageChange(event: PageEvent): void { - this.page = event.pageIndex; - this.pageSize = event.pageSize; - this.loadPatents(); this.updateQueryParams(); } @@ -217,8 +190,7 @@ export class PatentsComponent implements OnInit { this.router.navigate([], { relativeTo: this.route, queryParams: { - search: this.searchTerm || null, - page: this.page, + page: 0, size: this.pageSize, sources: this.selectedSources.length ? this.selectedSources.join(',') diff --git a/webapp/src/app/modules/person-funding/person-funding.component.html b/webapp/src/app/modules/person-funding/person-funding.component.html index 70bec121..4a1f7a3e 100644 --- a/webapp/src/app/modules/person-funding/person-funding.component.html +++ b/webapp/src/app/modules/person-funding/person-funding.component.html @@ -44,95 +44,45 @@ - - - - - - - - - - - - @for (funder of getPagedFunders(); track funder.funder_id) { - - - - - - - - } - -
- Förderer - @if (sortColumn === 'name') { - {{ - sortDirection === 'asc' ? 'arrow_upward' : 'arrow_downward' - }} - } - - Publikationen - @if (sortColumn === 'publications') { - {{ - sortDirection === 'asc' ? 'arrow_upward' : 'arrow_downward' - }} - } - - Erstautor - @if (sortColumn === 'first') { - {{ - sortDirection === 'asc' ? 'arrow_upward' : 'arrow_downward' - }} - } - - Mitautor - @if (sortColumn === 'middle') { - {{ - sortDirection === 'asc' ? 'arrow_upward' : 'arrow_downward' - }} - } - - Letztautor - @if (sortColumn === 'last') { - {{ - sortDirection === 'asc' ? 'arrow_upward' : 'arrow_downward' - }} - } -
{{ funder.funder_name }}{{ getPublicationCount(funder) }} - {{ funder.author_position_count.first || 0 }} - - {{ funder.author_position_count.middle || 0 }} - - {{ funder.author_position_count.last || 0 }} -
+ + + + + + + + {{ getPublicationCount(funder) }} + + + + {{ + funder.author_position_count.first || 0 + }} + + + + {{ + funder.author_position_count.middle || 0 + }} + + + + {{ + funder.author_position_count.last || 0 + }} + + >('nameTmp'); + countTmp = viewChild.required>('countTmp'); + firstTmp = viewChild.required>('firstTmp'); + middleTmp = viewChild.required>('middleTmp'); + lastTmp = viewChild.required>('lastTmp'); + + columns(): GenericColumn[] { + return [ + { + id: 'name', + header: 'Förderer', + type: 'accessor', + accessorKey: 'funder_name', + cellTemplate: this.nameTmp(), + }, + { + id: 'publications', + header: 'Publikationen', + type: 'accessor', + accessorKey: 'publication_count', + cellTemplate: this.countTmp(), + }, + { + id: 'first', + header: 'Erstautor', + type: 'display', + cellTemplate: this.firstTmp(), + }, + { + id: 'middle', + header: 'Mitautor', + type: 'display', + cellTemplate: this.middleTmp(), + }, + { + id: 'last', + header: 'Letztautor', + type: 'display', + cellTemplate: this.lastTmp(), + }, + ]; + } + + isSelectedFunder(funder: any): boolean { + return this.selectedFunder === funder; + } + + onSortChange(sort: Sort): void { + if (!sort.direction || !this.isValidSortColumn(sort.active)) { + return; + } + this.sortColumn = sort.active; + this.sortDirection = sort.direction; + this.applyFilter(); + this.updateQueryParams(); + } + ngOnInit(): void { this.route.parent?.paramMap.subscribe((params) => { const authorId = params.get('id') ?? ''; -- 2.56.1