Merge pull request 'refactor(patents, person-funding): reuse shared app-card-search/app-data-table component' (#280) from ts-136-patent-to-researchers-v2 into dev
LocationBasedServices/smartguide/pipeline/head This commit looks good

Reviewed-on: #280
This commit was merged in pull request #280.
This commit is contained in:
2026-08-15 20:47:59 +02:00
6 changed files with 234 additions and 303 deletions
@@ -3,42 +3,6 @@
<mat-divider />
<div class="search-and-filter">
<mat-form-field style="width: 100%">
<mat-label>Suche nach Titel oder Patent-Nr.</mat-label>
<input
matInput
type="search"
[value]="searchTerm"
(input)="onSearchInput($event)" />
<mat-icon matPrefix>search</mat-icon>
<button matIconButton matSuffix (click)="clearSearch()">
<mat-icon>clear</mat-icon>
</button>
</mat-form-field>
<div class="filter-row">
<mat-chip-listbox
[value]="selectedSources"
multiple
(change)="handleSourceChipChange($event)">
<mat-chip-option value="EPO">EPO</mat-chip-option>
<mat-chip-option value="USPTO">USPTO</mat-chip-option>
</mat-chip-listbox>
<app-year-range-slider
class="patent-year-filter"
[minYear]="minYear"
[maxYear]="maxYear"
[(startYear)]="selectedStartYear"
[(endYear)]="selectedEndYear"
(startYearChange)="onYearRangeChange()"
(endYearChange)="onYearRangeChange()" />
</div>
</div>
<mat-divider />
@if (loading) {
<app-loading
text="Patentdaten werden geladen..."
@@ -295,62 +259,80 @@
</div>
}
</div>
} @else if (patents.length === 0) {
<div class="no-results">
<p>Keine Patente gefunden.</p>
</div>
} @else {
<div class="cards">
@for (
patent of patents;
track patent.patent_id + (patent.publication_date ?? '')
) {
<mat-card
class="card"
appearance="outlined"
(click)="selectPatent(patent)">
<mat-card-header>
<mat-card-title>{{
patent.title ?? patent.patent_id
}}</mat-card-title>
<mat-card-subtitle>
<span
class="source-badge source-badge--{{
patent.source.toLowerCase()
}}"
>{{ patent.source }}</span
>
</mat-card-subtitle>
</mat-card-header>
<mat-card-content class="card-content">
<mat-divider />
<div class="card-metadata">
<span>{{ patent.patent_id }}</span>
<span>{{ formatDate(patent.publication_date ?? '') }}</span>
</div>
<mat-divider />
</mat-card-content>
<mat-card-footer>
<mat-card-actions>
<button
mat-button
(click)="selectPatent(patent); $event.stopPropagation()">
<mat-icon>info</mat-icon>
Übersicht
</button>
</mat-card-actions>
</mat-card-footer>
</mat-card>
}
</div>
<app-card-search
[page]="cardSearchPage()"
[cardTmp]="cardTmp"
[additionalFiltersTmp]="filtersTmp"
[noResultsTmp]="noResultsTmp"
[cardMinWidth]="500"
searchLabel="Suche nach Titel oder Patent-Nr." />
<ng-template #filtersTmp>
<div class="filter-row">
<mat-chip-listbox
[value]="selectedSources"
multiple
(change)="handleSourceChipChange($event)">
<mat-chip-option value="EPO">EPO</mat-chip-option>
<mat-chip-option value="USPTO">USPTO</mat-chip-option>
</mat-chip-listbox>
<app-year-range-slider
class="patent-year-filter"
[minYear]="minYear"
[maxYear]="maxYear"
[(startYear)]="selectedStartYear"
[(endYear)]="selectedEndYear"
(startYearChange)="onYearRangeChange()"
(endYearChange)="onYearRangeChange()" />
</div>
</ng-template>
<ng-template #noResultsTmp>
<div class="no-results">
<p>Keine Patente gefunden.</p>
</div>
</ng-template>
<ng-template #cardTmp let-patent>
<mat-card
class="card"
appearance="outlined"
(click)="selectPatent(patent)">
<mat-card-header>
<mat-card-title>{{
patent.title ?? patent.patent_id
}}</mat-card-title>
<mat-card-subtitle>
<span
class="source-badge source-badge--{{
patent.source.toLowerCase()
}}"
>{{ patent.source }}</span
>
</mat-card-subtitle>
</mat-card-header>
<mat-card-content class="card-content">
<mat-divider />
<div class="card-metadata">
<span>{{ patent.patent_id }}</span>
<span>{{ formatDate(patent.publication_date ?? '') }}</span>
</div>
<mat-divider />
</mat-card-content>
<mat-card-footer>
<mat-card-actions>
<button
mat-button
type="button"
(click)="selectPatent(patent); $event.stopPropagation()">
<mat-icon>info</mat-icon>
Übersicht
</button>
</mat-card-actions>
</mat-card-footer>
</mat-card>
</ng-template>
}
<mat-divider />
<mat-paginator
[length]="total"
[pageSize]="pageSize"
[pageIndex]="page"
[pageSizeOptions]="[10, 25, 50]"
(page)="handlePageChange($event)" />
</div>
@@ -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 {
@@ -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<string>();
showDetail = false;
selectedPatent: PatentEntry | null = null;
readonly expandedClassificationKeys = new Set<string>();
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(',')
@@ -44,95 +44,45 @@
</mat-select>
</mat-form-field>
</div>
<table>
<thead>
<tr>
<th
class="sortable"
[class.sort-active]="sortColumn === 'name'"
(click)="setSort('name')">
Förderer
@if (sortColumn === 'name') {
<mat-icon class="sort-icon">{{
sortDirection === 'asc' ? 'arrow_upward' : 'arrow_downward'
}}</mat-icon>
}
</th>
<th
class="text-center sortable"
[class.sort-active]="sortColumn === 'publications'"
(click)="setSort('publications')">
Publikationen
@if (sortColumn === 'publications') {
<mat-icon class="sort-icon">{{
sortDirection === 'asc' ? 'arrow_upward' : 'arrow_downward'
}}</mat-icon>
}
</th>
<th
class="text-center sortable"
[class.sort-active]="sortColumn === 'first'"
(click)="setSort('first')">
Erstautor
@if (sortColumn === 'first') {
<mat-icon class="sort-icon">{{
sortDirection === 'asc' ? 'arrow_upward' : 'arrow_downward'
}}</mat-icon>
}
</th>
<th
class="text-center sortable"
[class.sort-active]="sortColumn === 'middle'"
(click)="setSort('middle')">
Mitautor
@if (sortColumn === 'middle') {
<mat-icon class="sort-icon">{{
sortDirection === 'asc' ? 'arrow_upward' : 'arrow_downward'
}}</mat-icon>
}
</th>
<th
class="text-center sortable"
[class.sort-active]="sortColumn === 'last'"
(click)="setSort('last')">
Letztautor
@if (sortColumn === 'last') {
<mat-icon class="sort-icon">{{
sortDirection === 'asc' ? 'arrow_upward' : 'arrow_downward'
}}</mat-icon>
}
</th>
</tr>
</thead>
<tbody>
@for (funder of getPagedFunders(); track funder.funder_id) {
<tr
[class.selected]="selectedFunder === funder"
(click)="selectFunder(funder)">
<td class="funder-name">{{ funder.funder_name }}</td>
<td class="text-center">{{ getPublicationCount(funder) }}</td>
<td class="text-center">
<span
class="position-count-badge position-count-badge--first"
>{{ funder.author_position_count.first || 0 }}</span
>
</td>
<td class="text-center">
<span
class="position-count-badge position-count-badge--middle"
>{{ funder.author_position_count.middle || 0 }}</span
>
</td>
<td class="text-center">
<span
class="position-count-badge position-count-badge--last"
>{{ funder.author_position_count.last || 0 }}</span
>
</td>
</tr>
}
</tbody>
</table>
<app-data-table
[columns]="columns()"
[data]="getPagedFunders()"
queryParamSortKey="sortBy"
queryParamSortDirectionKey="sortDir"
(handleSortChange)="onSortChange($event)" />
<ng-template #nameTmp let-funder>
<button
type="button"
class="funder-name-btn"
[class.selected]="isSelectedFunder(funder)"
(click)="selectFunder(funder)">
{{ funder.funder_name }}
</button>
</ng-template>
<ng-template #countTmp let-funder>
{{ getPublicationCount(funder) }}
</ng-template>
<ng-template #firstTmp let-funder>
<span class="position-count-badge position-count-badge--first">{{
funder.author_position_count.first || 0
}}</span>
</ng-template>
<ng-template #middleTmp let-funder>
<span class="position-count-badge position-count-badge--middle">{{
funder.author_position_count.middle || 0
}}</span>
</ng-template>
<ng-template #lastTmp let-funder>
<span class="position-count-badge position-count-badge--last">{{
funder.author_position_count.last || 0
}}</span>
</ng-template>
<app-query-param-paginator
[total]="filteredFunders.length"
queryParamPageKey="funderPage"
@@ -37,63 +37,29 @@ app-query-param-paginator {
flex-wrap: wrap;
}
table {
width: 100%;
border-collapse: collapse;
}
th {
text-align: left;
padding: 12px 16px;
border-bottom: 1px solid var(--sg-border);
font-size: 12px;
font-weight: 700;
color: var(--sg-text-muted);
.funder-name-btn {
padding: 0;
border: 0;
background: none;
color: var(--sg-text);
font-weight: 600;
font-size: 13px;
cursor: pointer;
&.sortable {
display: table-cell;
cursor: pointer;
-webkit-user-select: none;
user-select: none;
}
&:hover,
&.selected {
color: var(--sg-blue-highlight);
}
}
.sort-icon {
vertical-align: middle;
margin-left: 2px;
width: 14px;
height: 14px;
font-size: 14px;
}
}
tr {
cursor: pointer;
transition: background-color 0.15s ease;
&:hover td {
background: rgba(16, 26, 61, 0.04);
}
&.selected td {
background: var(--sg-primary-soft);
}
}
td {
padding: 12px 16px;
border-bottom: 1px solid var(--sg-border);
color: var(--sg-text);
font-size: 13px;
transition: background-color 0.15s ease;
}
.funder-name {
color: var(--sg-text);
font-weight: 600;
}
.text-center {
text-align: center;
}
::ng-deep {
.mat-column-publications,
.mat-column-first,
.mat-column-middle,
.mat-column-last {
text-align: center;
}
}
@@ -1,4 +1,4 @@
import { Component, OnInit, inject } from '@angular/core';
import { Component, OnInit, TemplateRef, inject, viewChild } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ActivatedRoute, RouterLink } from '@angular/router';
import { Router } from '@angular/router';
@@ -6,9 +6,14 @@ import { MatFormFieldModule } from '@angular/material/form-field';
import { MatSelectModule } from '@angular/material/select';
import { MatIconModule } from '@angular/material/icon';
import { PageEvent } from '@angular/material/paginator';
import { Sort } from '@angular/material/sort';
import { FundingService } from '../../api';
import { LoadingComponent } from '../../shared/ui/loading/loading.component';
import { QueryParamPaginatorComponent } from '../../shared/ui/query-param-paginator/query-param-paginator.component';
import {
DataTableComponent,
GenericColumn,
} from '../../shared/ui/data-table/data-table.component';
type SortColumn = 'name' | 'publications' | 'first' | 'middle' | 'last';
type SortDirection = 'asc' | 'desc';
@@ -32,6 +37,7 @@ type FundingPublicationDetail = {
MatIconModule,
LoadingComponent,
QueryParamPaginatorComponent,
DataTableComponent,
],
templateUrl: './person-funding.component.html',
styleUrl: './person-funding.component.scss',
@@ -59,6 +65,63 @@ export class PersonFundingComponent implements OnInit {
loading = true;
error = false;
nameTmp = viewChild.required<TemplateRef<any>>('nameTmp');
countTmp = viewChild.required<TemplateRef<any>>('countTmp');
firstTmp = viewChild.required<TemplateRef<any>>('firstTmp');
middleTmp = viewChild.required<TemplateRef<any>>('middleTmp');
lastTmp = viewChild.required<TemplateRef<any>>('lastTmp');
columns(): GenericColumn<any>[] {
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') ?? '';