Merge pull request 'refactor(patents): extract shared app-patent-table component built on app-data-table, used by person/institution/keywords patent views' (#277) from ts-136-patent-to-researchers-v2 into dev
LocationBasedServices/smartguide/pipeline/head This commit looks good

Reviewed-on: #277
This commit was merged in pull request #277.
This commit is contained in:
2026-08-13 22:06:21 +02:00
13 changed files with 580 additions and 979 deletions
@@ -57,193 +57,20 @@
[value]="sortColumn"
(selectionChange)="setSort($event.value)">
<mat-select-trigger>Sortieren nach</mat-select-trigger>
<mat-option value="year">Jahr</mat-option>
<mat-option value="publication_year">Jahr</mat-option>
<mat-option value="title">Titel</mat-option>
<mat-option value="source">Quelle</mat-option>
<mat-option value="matchType">Match-Typ</mat-option>
<mat-option value="match_type">Match-Typ</mat-option>
</mat-select>
</mat-form-field>
</div>
<table>
<thead>
<tr>
<th>Patent</th>
<th
class="sortable"
[class.sort-active]="sortColumn === 'source'"
(click)="setSort('source')">
Quelle
@if (sortColumn === 'source') {
<mat-icon class="sort-icon">{{
sortDirection === 'asc' ? 'arrow_upward' : 'arrow_downward'
}}</mat-icon>
}
</th>
<th
class="sortable"
[class.sort-active]="sortColumn === 'year'"
(click)="setSort('year')">
Jahr
@if (sortColumn === 'year') {
<mat-icon class="sort-icon">{{
sortDirection === 'asc' ? 'arrow_upward' : 'arrow_downward'
}}</mat-icon>
}
</th>
<th>Erfinder</th>
<th>Applicant/Assignee</th>
<th
class="sortable"
[class.sort-active]="sortColumn === 'matchType'"
(click)="setSort('matchType')">
Match-Typ
@if (sortColumn === 'matchType') {
<mat-icon class="sort-icon">{{
sortDirection === 'asc' ? 'arrow_upward' : 'arrow_downward'
}}</mat-icon>
}
</th>
<th>Personen</th>
</tr>
</thead>
<tbody>
@for (
patent of getPagedPatents();
track trackPatent($index, patent)
) {
<tr
[class.selected]="selectedPatent === patent"
(click)="selectPatent(patent)">
<td class="patent-title">
{{ patent.title ?? patent.patent_id }}
</td>
<td>
<span
class="source-badge source-badge--{{
patent.source.toLowerCase()
}}">
{{ patent.source }}
</span>
</td>
<td>
@if (patent.publication_year) {
<span class="year-badge">{{
patent.publication_year
}}</span>
} @else {
<span>-</span>
}
</td>
<td class="patent-people">
@if (patent.inventors && patent.inventors.length) {
<div class="person-chips">
@for (
inventor of patent.inventors.slice(0, 2);
track inventor
) {
<span class="person-chip">
<mat-icon>person</mat-icon>
{{ inventor }}
</span>
}
@if (patent.inventors.length > 2) {
<span class="person-chip-row">
<span class="person-chip">
<mat-icon>person</mat-icon>
{{ patent.inventors[2] }}
</span>
@if (patent.inventors.length > 3) {
<span class="person-chip person-chip--more"
>+{{ patent.inventors.length - 3 }}</span
>
}
</span>
}
</div>
} @else {
<span>-</span>
}
</td>
<td class="patent-people">
@if (patent.assignees && patent.assignees.length) {
<div class="person-chips">
@for (
assignee of patent.assignees.slice(0, 2);
track assignee
) {
<span class="person-chip">
<mat-icon>{{
isAssigneeLikelyPerson(assignee, patent)
? 'person'
: 'apartment'
}}</mat-icon>
{{ assignee }}
</span>
}
@if (patent.assignees.length > 2) {
<span class="person-chip-row">
<span class="person-chip">
<mat-icon>{{
isAssigneeLikelyPerson(
patent.assignees[2],
patent
)
? 'person'
: 'apartment'
}}</mat-icon>
{{ patent.assignees[2] }}
</span>
@if (patent.assignees.length > 3) {
<span class="person-chip person-chip--more"
>+{{ patent.assignees.length - 3 }}</span
>
}
</span>
}
</div>
} @else {
<span>-</span>
}
</td>
<td>
<span
class="match-badge match-badge--{{ patent.match_type }}">
{{ getMatchTypeLabel(patent) }}
</span>
</td>
<td>
<div class="cell-authors">
@if (
patent.matched_authors && patent.matched_authors.length
) {
@for (
author of patent.matched_authors.slice(0, 2);
track author.openalex_author_id
) {
<a
class="author-link"
[routerLink]="[
'/person',
author.openalex_author_id,
]"
[appComponentTooltip]="AuthorTooltipComponent"
[tooltipInputs]="{
authorId: author.openalex_author_id,
}"
(click)="$event.stopPropagation()">
{{ author.author_name }}
</a>
}
} @else {
<span>-</span>
}
</div>
</td>
</tr>
}
</tbody>
</table>
<app-patent-table
[patents]="getPagedPatents()"
[selectedPatent]="selectedPatent"
[showMatchType]="true"
(selectPatent)="selectPatent($event)"
(handleSortChange)="onSortChange($event)" />
<app-query-param-paginator
[total]="totalPatents"
@@ -57,134 +57,6 @@ app-query-param-paginator {
margin-bottom: 18px;
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);
&.sortable {
display: table-cell;
cursor: pointer;
-webkit-user-select: none;
user-select: none;
}
.sort-icon {
vertical-align: middle;
margin-left: 2px;
width: 14px;
height: 14px;
font-size: 14px;
}
}
tr {
cursor: pointer;
color: var(--sg-text);
transition: background-color 0.15s ease;
&:hover td {
background: var(--sg-surface-soft);
}
&.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;
}
.patent-title {
color: var(--sg-text);
font-weight: 600;
max-width: 320px;
white-space: normal;
word-break: break-word;
}
.patent-people {
max-width: 220px;
}
.cell-authors {
display: flex;
flex-direction: column;
gap: 4px;
min-width: 120px;
}
}
}
.year-badge {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 26px;
padding: 2px 10px;
border-radius: 999px;
border: 1px solid var(--sg-border);
color: var(--sg-text);
font-size: 0.8rem;
font-weight: 600;
}
.person-chips {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 4px;
}
.person-chip-row {
display: flex;
flex-direction: row;
align-items: center;
flex-wrap: wrap;
gap: 4px;
}
.person-chip {
display: inline-flex;
align-items: center;
gap: 4px;
max-width: 100%;
padding: 2px 8px;
border: 1px solid var(--sg-border);
border-radius: var(--sg-radius-sm);
background: var(--sg-surface-soft);
color: var(--sg-text);
font-size: 0.75rem;
line-height: 1.4;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
mat-icon {
flex-shrink: 0;
width: 14px;
height: 14px;
font-size: 14px;
color: var(--sg-text-soft);
}
&--more {
color: var(--sg-text-muted);
font-weight: 600;
}
}
.match-badge {
@@ -4,6 +4,7 @@ import { ActivatedRoute, Router, RouterLink } from '@angular/router';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatSelectModule } from '@angular/material/select';
import { MatIconModule } from '@angular/material/icon';
import { Sort } from '@angular/material/sort';
import { PatentsService } from '../../api/api/patents.service';
import { OrgPatentEntry } from '../../api/model/orgPatentEntry';
import {
@@ -15,8 +16,9 @@ import { PageEvent } from '@angular/material/paginator';
import { QueryParamPaginatorComponent } from '../../shared/ui/query-param-paginator/query-param-paginator.component';
import { ComponentTooltipDirective } from '../../directives/component-tooltip.directive';
import { AppAuthorTooltipComponent } from '../../shared/ui/app-author-tooltip/app-author-tooltip.component';
import { PatentTableComponent } from '../../shared/ui/patent-table/patent-table.component';
type SortColumn = 'title' | 'year' | 'source' | 'matchType';
type SortColumn = 'title' | 'publication_year' | 'source' | 'match_type';
type SortDirection = 'asc' | 'desc';
type SourceFilter = 'all' | 'EPO' | 'USPTO';
type OrgPatentMatchTypeFilter = 'all' | 'institution' | 'name' | 'both';
@@ -32,6 +34,7 @@ type OrgPatentMatchTypeFilter = 'all' | 'institution' | 'name' | 'both';
MatIconModule,
QueryParamPaginatorComponent,
ComponentTooltipDirective,
PatentTableComponent,
],
templateUrl: './institution-patents.component.html',
styleUrl: './institution-patents.component.scss',
@@ -53,7 +56,7 @@ export class InstitutionPatentsComponent implements OnInit {
activeFilter: SourceFilter = 'all';
activeMatchType: OrgPatentMatchTypeFilter = 'all';
sortColumn: SortColumn = 'year';
sortColumn: SortColumn = 'publication_year';
sortDirection: SortDirection = 'desc';
pageIndex = 0;
@@ -111,12 +114,22 @@ export class InstitutionPatentsComponent implements OnInit {
this.reloadPatents();
}
onSortChange(sort: Sort): void {
if (!sort.direction || !this.isValidSortColumn(sort.active)) {
return;
}
this.sortColumn = sort.active;
this.sortDirection = sort.direction;
this.filteredPatents = this.sortPatents(this.patents);
this.updateQueryParams();
}
setSort(column: SortColumn): void {
if (this.sortColumn === column) {
this.sortDirection = this.sortDirection === 'asc' ? 'desc' : 'asc';
} else {
this.sortColumn = column;
this.sortDirection = column === 'year' ? 'desc' : 'asc';
this.sortDirection = column === 'publication_year' ? 'desc' : 'asc';
}
this.filteredPatents = this.sortPatents(this.patents);
this.updateQueryParams();
@@ -186,14 +199,14 @@ export class InstitutionPatentsComponent implements OnInit {
const direction = this.sortDirection === 'asc' ? 1 : -1;
return [...patents].sort((a, b) => {
switch (this.sortColumn) {
case 'year': {
case 'publication_year': {
const yearA = a.publication_date ?? String(a.publication_year ?? '');
const yearB = b.publication_date ?? String(b.publication_year ?? '');
return direction * yearA.localeCompare(yearB);
}
case 'source':
return direction * a.source.localeCompare(b.source);
case 'matchType':
case 'match_type':
return direction * a.match_type.localeCompare(b.match_type);
default:
return (
@@ -239,9 +252,9 @@ export class InstitutionPatentsComponent implements OnInit {
private isValidSortColumn(value: string | null): value is SortColumn {
return (
value === 'title' ||
value === 'year' ||
value === 'publication_year' ||
value === 'source' ||
value === 'matchType'
value === 'match_type'
);
}
@@ -288,15 +301,6 @@ export class InstitutionPatentsComponent implements OnInit {
return this.patents.filter((p) => p.match_type === 'both').length;
}
trackPatent(_index: number, patent: OrgPatentEntry): string {
return [
patent.source,
patent.patent_id,
patent.publication_date ?? '',
patent.kind ?? patent.application_type ?? '',
].join('|');
}
getAbstractPreview(abstract: string | null | undefined): string | null {
if (!abstract?.trim()) {
return null;
@@ -324,50 +328,4 @@ export class InstitutionPatentsComponent implements OnInit {
return patent.match_type;
}
}
private static readonly ORG_SUFFIX_PATTERN =
/\b(Inc|Ltd|LLC|LLP|GmbH|Corp(oration)?|Co|KG|AG|SE|S\.?A\.?|N\.?V\.?|B\.?V\.?|PLC|Universit(y|ät|é)|Institut(e)?|Foundation|Laborator(y|ies)|Labs?|Group|Holdings?|Company|Gesellschaft)\b\.?/i;
private static readonly PERSON_SUFFIX_PATTERN =
/\b(Dr|Prof|PhD|Ph\.D|M\.D|Jr|Sr)\b\.?/i;
private normalizeNameForComparison(name: string): string {
return name
.normalize('NFD')
.replace(/[̀-ͯ]/g, '')
.replace(/[.,]/g, '')
.toUpperCase()
.split(/\s+/)
.filter(Boolean)
.sort()
.join(' ');
}
isAssigneeLikelyPerson(assignee: string, patent: OrgPatentEntry): boolean {
if (InstitutionPatentsComponent.ORG_SUFFIX_PATTERN.test(assignee)) {
return false;
}
const normalizedAssignee = this.normalizeNameForComparison(
assignee.replace(InstitutionPatentsComponent.PERSON_SUFFIX_PATTERN, ''),
);
const matchesInventor = (patent.inventors ?? []).some(
(inventor) =>
this.normalizeNameForComparison(inventor) === normalizedAssignee,
);
if (matchesInventor) {
return true;
}
return InstitutionPatentsComponent.PERSON_SUFFIX_PATTERN.test(assignee);
}
getMatchedAuthorsPreview(patent: OrgPatentEntry): string {
if (!patent.matched_authors?.length) {
return '-';
}
return patent.matched_authors
.slice(0, 2)
.map((author) => author.author_name)
.join(', ');
}
}
@@ -34,147 +34,18 @@
[value]="sortColumn()"
(selectionChange)="setSort($event.value)">
<mat-select-trigger>Sortieren nach</mat-select-trigger>
<mat-option value="year">Jahr</mat-option>
<mat-option value="publication_year">Jahr</mat-option>
<mat-option value="title">Titel</mat-option>
<mat-option value="source">Quelle</mat-option>
</mat-select>
</mat-form-field>
</div>
<table>
<thead>
<tr>
<th>Patent</th>
<th
class="sortable"
[class.sort-active]="sortColumn() === 'source'"
(click)="setSort('source')">
Quelle
@if (sortColumn() === 'source') {
<mat-icon class="sort-icon">{{
sortDirection() === 'asc'
? 'arrow_upward'
: 'arrow_downward'
}}</mat-icon>
}
</th>
<th
class="sortable"
[class.sort-active]="sortColumn() === 'year'"
(click)="setSort('year')">
Jahr
@if (sortColumn() === 'year') {
<mat-icon class="sort-icon">{{
sortDirection() === 'asc'
? 'arrow_upward'
: 'arrow_downward'
}}</mat-icon>
}
</th>
<th>Erfinder</th>
<th>Anmelder</th>
</tr>
</thead>
<tbody>
@for (item of getPagedMatches(); track trackMatch($index, item)) {
<tr
[class.selected]="selectedMatch() === item"
(click)="selectMatch(item)">
<td class="patent-title">
{{ item.patent.title ?? item.patent.patent_id }}
</td>
<td>
<span
class="source-badge source-badge--{{
item.patent.source.toLowerCase()
}}">
{{ item.patent.source }}
</span>
</td>
<td>
@if (item.patent.publication_year) {
<span class="year-badge">{{
item.patent.publication_year
}}</span>
} @else {
<span>-</span>
}
</td>
<td class="patent-people">
@if (item.patent.inventors && item.patent.inventors.length) {
<div class="person-chips">
@for (
inventor of item.patent.inventors.slice(0, 2);
track inventor
) {
<span class="person-chip">
<mat-icon>person</mat-icon>
{{ inventor }}
</span>
}
@if (item.patent.inventors.length > 2) {
<span class="person-chip-row">
<span class="person-chip">
<mat-icon>person</mat-icon>
{{ item.patent.inventors[2] }}
</span>
@if (item.patent.inventors.length > 3) {
<span class="person-chip person-chip--more"
>+{{ item.patent.inventors.length - 3 }}</span
>
}
</span>
}
</div>
} @else {
<span>-</span>
}
</td>
<td class="patent-people">
@if (item.patent.assignees && item.patent.assignees.length) {
<div class="person-chips">
@for (
assignee of item.patent.assignees.slice(0, 2);
track assignee
) {
<span class="person-chip">
<mat-icon>{{
isAssigneeLikelyPerson(assignee, item.patent)
? 'person'
: 'apartment'
}}</mat-icon>
{{ assignee }}
</span>
}
@if (item.patent.assignees.length > 2) {
<span class="person-chip-row">
<span class="person-chip">
<mat-icon>{{
isAssigneeLikelyPerson(
item.patent.assignees[2],
item.patent
)
? 'person'
: 'apartment'
}}</mat-icon>
{{ item.patent.assignees[2] }}
</span>
@if (item.patent.assignees.length > 3) {
<span class="person-chip person-chip--more"
>+{{ item.patent.assignees.length - 3 }}</span
>
}
</span>
}
</div>
} @else {
<span>-</span>
}
</td>
</tr>
}
</tbody>
</table>
<app-patent-table
[patents]="getPagedPatents()"
[selectedPatent]="selectedPatent()"
(selectPatent)="selectPatentFromTable($event)"
(handleSortChange)="onSortChange($event)" />
<app-query-param-paginator
[total]="filteredMatches().length"
@@ -88,126 +88,6 @@ app-query-param-paginator {
margin-bottom: 18px;
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);
&.sortable {
display: table-cell;
cursor: pointer;
-webkit-user-select: none;
user-select: none;
}
.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;
}
.patent-title {
color: var(--sg-text);
font-weight: 600;
max-width: 400px;
white-space: normal;
word-break: break-word;
}
.patent-people {
max-width: 220px;
}
}
}
.year-badge {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 26px;
padding: 2px 10px;
border-radius: 999px;
border: 1px solid var(--sg-border);
color: var(--sg-text);
font-size: 0.8rem;
font-weight: 600;
}
.person-chips {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 4px;
}
.person-chip-row {
display: flex;
flex-direction: row;
align-items: center;
flex-wrap: wrap;
gap: 4px;
}
.person-chip {
display: inline-flex;
align-items: center;
gap: 4px;
max-width: 100%;
padding: 2px 8px;
border: 1px solid var(--sg-border);
border-radius: var(--sg-radius-sm);
background: var(--sg-surface-soft);
color: var(--sg-text);
font-size: 0.75rem;
line-height: 1.4;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
mat-icon {
flex-shrink: 0;
width: 14px;
height: 14px;
font-size: 14px;
color: var(--sg-text-soft);
}
&--more {
color: var(--sg-text-muted);
font-weight: 600;
}
}
.source-badge {
@@ -4,6 +4,7 @@ import { MatFormFieldModule } from '@angular/material/form-field';
import { MatIconModule } from '@angular/material/icon';
import { MatSelectModule } from '@angular/material/select';
import { PageEvent } from '@angular/material/paginator';
import { Sort } from '@angular/material/sort';
import { ActivatedRoute, Router } from '@angular/router';
import { PatentEntry } from '../../../api/model/patentEntry';
import { KeywordPatentMatch } from '../../../api/model/keywordPatentMatch';
@@ -14,11 +15,16 @@ import {
getPublicationStageLabel,
} from '../../patent-detail/patent-detail.utils';
import { KeywordPatentMappingStatus } from '../../../api';
import { PatentTableComponent } from '../../../shared/ui/patent-table/patent-table.component';
type SourceFilter = 'all' | 'EPO' | 'USPTO';
type SortColumn = 'title' | 'year' | 'source';
type SortColumn = 'title' | 'publication_year' | 'source';
type SortDirection = 'asc' | 'desc';
function isValidSortColumn(value: string | null): value is SortColumn {
return value === 'title' || value === 'publication_year' || value === 'source';
}
@Component({
selector: 'app-keywords-patents',
imports: [
@@ -27,6 +33,7 @@ type SortDirection = 'asc' | 'desc';
MatSelectModule,
LoadingComponent,
QueryParamPaginatorComponent,
PatentTableComponent,
],
templateUrl: './keywords-patents.component.html',
styleUrl: './keywords-patents.component.scss',
@@ -45,7 +52,7 @@ export class KeywordsPatentsComponent {
readonly reload = output<void>();
activeFilter = signal<SourceFilter>('all');
sortColumn = signal<SortColumn>('year');
sortColumn = signal<SortColumn>('publication_year');
sortDirection = signal<SortDirection>('desc');
selectedMatch = signal<KeywordPatentMatch | null>(null);
@@ -68,6 +75,8 @@ export class KeywordsPatentsComponent {
return this.sortMatches(items);
});
readonly selectedPatent = computed(() => this.selectedMatch()?.patent ?? null);
emptyMessage(): string {
switch (this.mappingStatus()) {
case 'search_error':
@@ -82,57 +91,42 @@ export class KeywordsPatentsComponent {
return this.filteredMatches().slice(start, start + this.pageSize());
}
getPagedPatents(): PatentEntry[] {
return this.getPagedMatches().map((item) => item.patent);
}
setFilter(filter: SourceFilter): void {
this.activeFilter.set(filter);
this.selectedMatch.set(null);
this.resetPage();
}
onSortChange(sort: Sort): void {
if (!sort.direction || !isValidSortColumn(sort.active)) {
return;
}
this.sortColumn.set(sort.active);
this.sortDirection.set(sort.direction);
this.selectedMatch.set(null);
this.resetPage();
}
setSort(column: SortColumn): void {
if (this.sortColumn() === column) {
this.sortDirection.set(this.sortDirection() === 'asc' ? 'desc' : 'asc');
} else {
this.sortColumn.set(column);
this.sortDirection.set(column === 'year' ? 'desc' : 'asc');
this.sortDirection.set(column === 'publication_year' ? 'desc' : 'asc');
}
this.selectedMatch.set(null);
this.resetPage();
}
isAssigneeLikelyPerson(assignee: string, patent: PatentEntry): boolean {
if (KeywordsPatentsComponent.ORG_SUFFIX_PATTERN.test(assignee)) {
return false;
selectPatentFromTable(patent: PatentEntry): void {
const match = this.matches().find((item) => item.patent === patent);
if (match) {
this.selectMatch(match);
}
const normalizedAssignee = this.normalizeNameForComparison(
assignee.replace(KeywordsPatentsComponent.PERSON_SUFFIX_PATTERN, ''),
);
const matchesInventor = (patent.inventors ?? []).some(
(inventor) =>
this.normalizeNameForComparison(inventor) === normalizedAssignee,
);
if (matchesInventor) {
return true;
}
return KeywordsPatentsComponent.PERSON_SUFFIX_PATTERN.test(assignee);
}
private static readonly ORG_SUFFIX_PATTERN =
/\b(Inc|Ltd|LLC|LLP|GmbH|Corp(oration)?|Co|KG|AG|SE|S\.?A\.?|N\.?V\.?|B\.?V\.?|PLC|Universit(y|ät|é)|Institut(e)?|Foundation|Laborator(y|ies)|Labs?|Group|Holdings?|Company|Gesellschaft)\b\.?/i;
private static readonly PERSON_SUFFIX_PATTERN =
/\b(Dr|Prof|PhD|Ph\.D|M\.D|Jr|Sr)\b\.?/i;
private normalizeNameForComparison(name: string): string {
return name
.normalize('NFD')
.replace(/[̀-ͯ]/g, '')
.replace(/[.,]/g, '')
.toUpperCase()
.split(/\s+/)
.filter(Boolean)
.sort()
.join(' ');
}
onPatentPageChange(_event: PageEvent): void {
@@ -186,23 +180,12 @@ export class KeywordsPatentsComponent {
return `${text.slice(0, 160).trimEnd()}…`;
}
trackMatch(_index: number, item: KeywordPatentMatch): string {
const patent = item.patent;
return [
patent.source,
patent.patent_id,
patent.publication_date ?? '',
patent.kind ?? patent.application_type ?? '',
item.match_score,
].join('|');
}
private sortMatches(items: KeywordPatentMatch[]): KeywordPatentMatch[] {
const column = this.sortColumn();
const direction = this.sortDirection() === 'asc' ? 1 : -1;
return [...items].sort((a, b) => {
switch (column) {
case 'year': {
case 'publication_year': {
const yearA =
a.patent.publication_date ??
String(a.patent.publication_year ?? '');
@@ -122,6 +122,52 @@ export function getDescriptionPreview(text: string | null): string {
return `${text.slice(0, DESCRIPTION_PREVIEW_LENGTH).trimEnd()}…`;
}
const ORG_SUFFIX_PATTERN =
/\b(Inc|Ltd|LLC|LLP|GmbH|Corp(oration)?|Co|KG|AG|SE|S\.?A\.?|N\.?V\.?|B\.?V\.?|PLC|Universit(y|ät|é)|Institut(e)?|Foundation|Laborator(y|ies)|Labs?|Group|Holdings?|Company|Gesellschaft)\b\.?/i;
const PERSON_SUFFIX_PATTERN = /\b(Dr|Prof|PhD|Ph\.D|M\.D|Jr|Sr)\b\.?/i;
function normalizeNameForComparison(name: string): string {
return name
.normalize('NFD')
.replace(/[̀-ͯ]/g, '')
.replace(/[.,]/g, '')
.toUpperCase()
.split(/\s+/)
.filter(Boolean)
.sort()
.join(' ');
}
export function isAssigneeLikelyPerson(
assignee: string,
inventors: string[] | undefined,
): boolean {
if (ORG_SUFFIX_PATTERN.test(assignee)) {
return false;
}
const normalizedAssignee = normalizeNameForComparison(
assignee.replace(PERSON_SUFFIX_PATTERN, ''),
);
const matchesInventor = (inventors ?? []).some(
(inventor) => normalizeNameForComparison(inventor) === normalizedAssignee,
);
if (matchesInventor) {
return true;
}
return PERSON_SUFFIX_PATTERN.test(assignee);
}
export function trackPatentEntry(patent: PatentEntry): string {
return [
patent.source,
patent.patent_id,
patent.publication_date ?? '',
patent.kind ?? patent.application_type ?? '',
].join('|');
}
export function patentExternalLinks(
patent: PatentEntry,
): { label: string; url: string }[] {
@@ -34,146 +34,18 @@
[value]="sortColumn"
(selectionChange)="setSort($event.value)">
<mat-select-trigger>Sortieren nach</mat-select-trigger>
<mat-option value="year">Jahr</mat-option>
<mat-option value="publication_year">Jahr</mat-option>
<mat-option value="title">Titel</mat-option>
<mat-option value="source">Quelle</mat-option>
</mat-select>
</mat-form-field>
</div>
<table>
<thead>
<tr>
<th>Patent</th>
<th
class="sortable"
[class.sort-active]="sortColumn === 'source'"
(click)="setSort('source')">
Quelle
@if (sortColumn === 'source') {
<mat-icon class="sort-icon">{{
sortDirection === 'asc' ? 'arrow_upward' : 'arrow_downward'
}}</mat-icon>
}
</th>
<th
class="sortable"
[class.sort-active]="sortColumn === 'year'"
(click)="setSort('year')">
Jahr
@if (sortColumn === 'year') {
<mat-icon class="sort-icon">{{
sortDirection === 'asc' ? 'arrow_upward' : 'arrow_downward'
}}</mat-icon>
}
</th>
<th>Erfinder</th>
<th>Anmelder</th>
</tr>
</thead>
<tbody>
@for (
patent of getPagedPatents();
track trackPatent($index, patent)
) {
<tr
[class.selected]="selectedPatent === patent"
(click)="selectPatent(patent)">
<td class="patent-title">
{{ patent.title ?? patent.patent_id }}
</td>
<td>
<span
class="source-badge source-badge--{{
patent.source.toLowerCase()
}}">
{{ patent.source }}
</span>
</td>
<td>
@if (patent.publication_year) {
<span class="year-badge">{{
patent.publication_year
}}</span>
} @else {
<span>-</span>
}
</td>
<td class="patent-people">
@if (patent.inventors && patent.inventors.length) {
<div class="person-chips">
@for (
inventor of patent.inventors.slice(0, 2);
track inventor
) {
<span class="person-chip">
<mat-icon>person</mat-icon>
{{ inventor }}
</span>
}
@if (patent.inventors.length > 2) {
<span class="person-chip-row">
<span class="person-chip">
<mat-icon>person</mat-icon>
{{ patent.inventors[2] }}
</span>
@if (patent.inventors.length > 3) {
<span class="person-chip person-chip--more"
>+{{ patent.inventors.length - 3 }}</span
>
}
</span>
}
</div>
} @else {
<span>-</span>
}
</td>
<td class="patent-people">
@if (patent.assignees && patent.assignees.length) {
<div class="person-chips">
@for (
assignee of patent.assignees.slice(0, 2);
track assignee
) {
<span class="person-chip">
<mat-icon>{{
isAssigneeLikelyPerson(assignee, patent)
? 'person'
: 'apartment'
}}</mat-icon>
{{ assignee }}
</span>
}
@if (patent.assignees.length > 2) {
<span class="person-chip-row">
<span class="person-chip">
<mat-icon>{{
isAssigneeLikelyPerson(
patent.assignees[2],
patent
)
? 'person'
: 'apartment'
}}</mat-icon>
{{ patent.assignees[2] }}
</span>
@if (patent.assignees.length > 3) {
<span class="person-chip person-chip--more"
>+{{ patent.assignees.length - 3 }}</span
>
}
</span>
}
</div>
} @else {
<span>-</span>
}
</td>
</tr>
}
</tbody>
</table>
<app-patent-table
[patents]="getPagedPatents()"
[selectedPatent]="selectedPatent"
(selectPatent)="selectPatent($event)"
(handleSortChange)="onSortChange($event)" />
<app-query-param-paginator
[total]="filteredPatents.length"
@@ -41,127 +41,6 @@ app-query-param-paginator {
margin-bottom: 18px;
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);
&.sortable {
display: table-cell;
cursor: pointer;
-webkit-user-select: none;
user-select: none;
}
.sort-icon {
vertical-align: middle;
margin-left: 2px;
width: 14px;
height: 14px;
font-size: 14px;
}
}
tr {
cursor: pointer;
color: var(--sg-text);
transition: background-color 0.15s ease;
&:hover td {
background: var(--sg-surface-soft);
}
&.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;
}
.patent-title {
color: var(--sg-text);
font-weight: 600;
max-width: 320px;
white-space: normal;
word-break: break-word;
}
.patent-people {
max-width: 260px;
}
}
}
.year-badge {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 26px;
padding: 2px 10px;
border-radius: 999px;
border: 1px solid var(--sg-border);
color: var(--sg-text);
font-size: 0.8rem;
font-weight: 600;
}
.person-chips {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 4px;
}
.person-chip-row {
display: flex;
flex-direction: row;
align-items: center;
flex-wrap: wrap;
gap: 4px;
}
.person-chip {
display: inline-flex;
align-items: center;
gap: 4px;
max-width: 100%;
padding: 2px 8px;
border: 1px solid var(--sg-border);
border-radius: var(--sg-radius-sm);
background: var(--sg-surface-soft);
color: var(--sg-text);
font-size: 0.75rem;
line-height: 1.4;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
mat-icon {
flex-shrink: 0;
width: 14px;
height: 14px;
font-size: 14px;
color: var(--sg-text-soft);
}
&--more {
color: var(--sg-text-muted);
font-weight: 600;
}
}
.match-badges {
@@ -6,6 +6,7 @@ import { finalize, of, switchMap } from 'rxjs';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatSelectModule } from '@angular/material/select';
import { MatIconModule } from '@angular/material/icon';
import { Sort } from '@angular/material/sort';
import { PatentEntry } from '../../api/model/patentEntry';
import { PersonPatentsResolved } from '../../resolvers/person-patents.resolver';
import {
@@ -15,8 +16,9 @@ import {
import { LoadingComponent } from '../../shared/ui/loading/loading.component';
import { PageEvent } from '@angular/material/paginator';
import { QueryParamPaginatorComponent } from '../../shared/ui/query-param-paginator/query-param-paginator.component';
import { PatentTableComponent } from '../../shared/ui/patent-table/patent-table.component';
type SortColumn = 'title' | 'year' | 'source';
type SortColumn = 'title' | 'publication_year' | 'source';
type SortDirection = 'asc' | 'desc';
type SourceFilter = 'all' | 'EPO' | 'USPTO';
@@ -29,6 +31,7 @@ type SourceFilter = 'all' | 'EPO' | 'USPTO';
MatSelectModule,
MatIconModule,
QueryParamPaginatorComponent,
PatentTableComponent,
],
templateUrl: './person-patents.component.html',
styleUrl: './person-patents.component.scss',
@@ -47,7 +50,7 @@ export class PersonPatentsComponent {
error = false;
activeFilter: SourceFilter = 'all';
sortColumn: SortColumn = 'year';
sortColumn: SortColumn = 'publication_year';
sortDirection: SortDirection = 'desc';
pageIndex = 0;
@@ -119,12 +122,22 @@ export class PersonPatentsComponent {
this.pageSize = event.pageSize;
}
onSortChange(sort: Sort): void {
if (!sort.direction || !this.isValidSortColumn(sort.active)) {
return;
}
this.sortColumn = sort.active;
this.sortDirection = sort.direction;
this.applyFilter();
this.updateQueryParams();
}
setSort(column: SortColumn): void {
if (this.sortColumn === column) {
this.sortDirection = this.sortDirection === 'asc' ? 'desc' : 'asc';
} else {
this.sortColumn = column;
this.sortDirection = column === 'year' ? 'desc' : 'asc';
this.sortDirection = column === 'publication_year' ? 'desc' : 'asc';
}
this.applyFilter();
this.updateQueryParams();
@@ -154,7 +167,7 @@ export class PersonPatentsComponent {
const direction = this.sortDirection === 'asc' ? 1 : -1;
return [...patents].sort((a, b) => {
switch (this.sortColumn) {
case 'year': {
case 'publication_year': {
const yearA = a.publication_date ?? String(a.publication_year ?? '');
const yearB = b.publication_date ?? String(b.publication_year ?? '');
return direction * yearA.localeCompare(yearB);
@@ -202,7 +215,9 @@ export class PersonPatentsComponent {
}
private isValidSortColumn(value: string | null): value is SortColumn {
return value === 'title' || value === 'year' || value === 'source';
return (
value === 'title' || value === 'publication_year' || value === 'source'
);
}
private isValidSortDirection(value: string | null): value is SortDirection {
@@ -214,42 +229,6 @@ export class PersonPatentsComponent {
return this.filteredPatents.slice(start, start + this.pageSize);
}
private static readonly ORG_SUFFIX_PATTERN =
/\b(Inc|Ltd|LLC|LLP|GmbH|Corp(oration)?|Co|KG|AG|SE|S\.?A\.?|N\.?V\.?|B\.?V\.?|PLC|Universit(y|ät|é)|Institut(e)?|Foundation|Laborator(y|ies)|Labs?|Group|Holdings?|Company|Gesellschaft)\b\.?/i;
private static readonly PERSON_SUFFIX_PATTERN =
/\b(Dr|Prof|PhD|Ph\.D|M\.D|Jr|Sr)\b\.?/i;
private normalizeNameForComparison(name: string): string {
return name
.normalize('NFD')
.replace(/[̀-ͯ]/g, '')
.replace(/[.,]/g, '')
.toUpperCase()
.split(/\s+/)
.filter(Boolean)
.sort()
.join(' ');
}
isAssigneeLikelyPerson(assignee: string, patent: PatentEntry): boolean {
if (PersonPatentsComponent.ORG_SUFFIX_PATTERN.test(assignee)) {
return false;
}
const normalizedAssignee = this.normalizeNameForComparison(
assignee.replace(PersonPatentsComponent.PERSON_SUFFIX_PATTERN, ''),
);
const matchesInventor = (patent.inventors ?? []).some(
(inventor) =>
this.normalizeNameForComparison(inventor) === normalizedAssignee,
);
if (matchesInventor) {
return true;
}
return PersonPatentsComponent.PERSON_SUFFIX_PATTERN.test(assignee);
}
formatDate(date: string | null | undefined): string {
return formatPatentDate(date);
}
@@ -262,15 +241,6 @@ export class PersonPatentsComponent {
return this.patents.filter((p) => p.source === 'USPTO').length;
}
trackPatent(_index: number, patent: PatentEntry): string {
return [
patent.source,
patent.patent_id,
patent.publication_date ?? '',
patent.kind ?? patent.application_type ?? '',
].join('|');
}
getAbstractPreview(abstract: string | null | undefined): string | null {
if (!abstract?.trim()) {
return null;