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
LocationBasedServices/smartguide/pipeline/head This commit looks good
Reviewed-on: #277
This commit was merged in pull request #277.
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
<app-data-table
|
||||
[columns]="columns()"
|
||||
[data]="patents()"
|
||||
[queryParamSortKey]="queryParamSortKey()"
|
||||
[queryParamSortDirectionKey]="queryParamSortDirectionKey()"
|
||||
(handleSortChange)="handleSortChange.emit($event)" />
|
||||
|
||||
<ng-template #titleTmp let-patent>
|
||||
<button
|
||||
type="button"
|
||||
class="patent-title-btn"
|
||||
[class.selected]="isSelected(patent)"
|
||||
(click)="selectPatent.emit(patent)">
|
||||
@if (isSelected(patent)) {
|
||||
<mat-icon class="patent-title-btn__icon">chevron_right</mat-icon>
|
||||
}
|
||||
<span>{{ patent.title ?? patent.patent_id }}</span>
|
||||
</button>
|
||||
</ng-template>
|
||||
|
||||
<ng-template #sourceTmp let-patent>
|
||||
<app-chip
|
||||
variant="outlined"
|
||||
[color]="patent.source === 'EPO' ? 'success' : 'info'">
|
||||
{{ patent.source }}
|
||||
</app-chip>
|
||||
</ng-template>
|
||||
|
||||
<ng-template #yearTmp let-patent>
|
||||
@if (patent.publication_year) {
|
||||
<span class="year-badge">{{ patent.publication_year }}</span>
|
||||
} @else {
|
||||
<span class="empty-text">-</span>
|
||||
}
|
||||
</ng-template>
|
||||
|
||||
<ng-template #inventorsTmp let-patent>
|
||||
@let expanded = isInventorsExpanded(patent);
|
||||
@let visibleInventors =
|
||||
expanded ? patent.inventors : (patent.inventors ?? []).slice(0, 3);
|
||||
<div class="person-chips">
|
||||
@for (inventor of visibleInventors; track inventor) {
|
||||
<span class="person-chip">
|
||||
<mat-icon>person</mat-icon>
|
||||
{{ inventor }}
|
||||
</span>
|
||||
} @empty {
|
||||
<span class="empty-text">-</span>
|
||||
}
|
||||
@if ((patent.inventors ?? []).length > 3) {
|
||||
<button
|
||||
type="button"
|
||||
class="patent-chip-more"
|
||||
[attr.aria-expanded]="expanded"
|
||||
(click)="toggleInventorsExpansion(patent)">
|
||||
{{ expanded ? 'weniger' : '+' + (patent.inventors!.length - 3) }}
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</ng-template>
|
||||
|
||||
<ng-template #assigneesTmp let-patent>
|
||||
@let expanded = isAssigneesExpanded(patent);
|
||||
@let visibleAssignees =
|
||||
expanded ? patent.assignees : (patent.assignees ?? []).slice(0, 3);
|
||||
<div class="person-chips">
|
||||
@for (assignee of visibleAssignees; track assignee) {
|
||||
<span class="person-chip">
|
||||
<mat-icon>{{
|
||||
isAssigneeLikelyPerson(assignee, patent) ? 'person' : 'apartment'
|
||||
}}</mat-icon>
|
||||
{{ assignee }}
|
||||
</span>
|
||||
} @empty {
|
||||
<span class="empty-text">-</span>
|
||||
}
|
||||
@if ((patent.assignees ?? []).length > 3) {
|
||||
<button
|
||||
type="button"
|
||||
class="patent-chip-more"
|
||||
[attr.aria-expanded]="expanded"
|
||||
(click)="toggleAssigneesExpansion(patent)">
|
||||
{{ expanded ? 'weniger' : '+' + (patent.assignees!.length - 3) }}
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</ng-template>
|
||||
|
||||
<ng-template #matchTypeTmp let-patent>
|
||||
<span class="match-badge match-badge--{{ patent.match_type }}">
|
||||
{{ getMatchTypeLabel(patent.match_type) }}
|
||||
</span>
|
||||
</ng-template>
|
||||
|
||||
<ng-template #matchedAuthorsTmp let-patent>
|
||||
<div class="cell-authors">
|
||||
@if (patent.matched_authors && patent.matched_authors.length) {
|
||||
@for (
|
||||
author of patent.matched_authors.slice(0, 3);
|
||||
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 class="empty-text">-</span>
|
||||
}
|
||||
</div>
|
||||
</ng-template>
|
||||
|
||||
<ng-template #actionsTmp let-patent>
|
||||
<a
|
||||
mat-icon-button
|
||||
color="primary"
|
||||
[routerLink]="['/patent', patent.patent_id]"
|
||||
matTooltip="Patentdetails anzeigen">
|
||||
<mat-icon>open_in_new</mat-icon>
|
||||
</a>
|
||||
</ng-template>
|
||||
@@ -0,0 +1,149 @@
|
||||
:host {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
color: var(--sg-text-muted);
|
||||
}
|
||||
|
||||
.patent-title-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: none;
|
||||
color: var(--sg-text);
|
||||
font-weight: 600;
|
||||
font-size: 13px;
|
||||
text-align: left;
|
||||
white-space: normal;
|
||||
word-break: break-word;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
color: var(--sg-blue-highlight);
|
||||
}
|
||||
|
||||
&.selected {
|
||||
color: var(--sg-blue-highlight);
|
||||
}
|
||||
|
||||
&__icon {
|
||||
flex-shrink: 0;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
.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;
|
||||
max-width: 240px;
|
||||
}
|
||||
|
||||
.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);
|
||||
}
|
||||
}
|
||||
|
||||
.match-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 3px 10px;
|
||||
border-radius: 999px;
|
||||
font-size: 0.72rem;
|
||||
font-weight: 700;
|
||||
|
||||
&--institution {
|
||||
background: var(--sg-primary-soft);
|
||||
color: var(--sg-primary);
|
||||
border: 1px solid var(--sg-border);
|
||||
}
|
||||
|
||||
&--name {
|
||||
background: var(--sg-warning-soft);
|
||||
color: var(--sg-warning);
|
||||
border: 1px solid var(--sg-border);
|
||||
}
|
||||
|
||||
&--both {
|
||||
background: var(--sg-success-soft);
|
||||
color: var(--sg-success);
|
||||
border: 1px solid var(--sg-border);
|
||||
}
|
||||
}
|
||||
|
||||
.patent-chip-more {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
min-height: 24px;
|
||||
padding: 3px 8px;
|
||||
border: 1px solid var(--sg-border);
|
||||
border-radius: var(--sg-radius-sm);
|
||||
background: var(--sg-surface);
|
||||
color: var(--sg-text-muted);
|
||||
font-family: inherit;
|
||||
font-size: 11px;
|
||||
line-height: 1.2;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
background: var(--sg-surface-soft);
|
||||
color: var(--sg-text);
|
||||
}
|
||||
}
|
||||
|
||||
.cell-authors {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
min-width: 120px;
|
||||
}
|
||||
|
||||
.author-link {
|
||||
color: var(--sg-blue-highlight);
|
||||
text-decoration: none;
|
||||
font-size: 0.82rem;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
import { Component, TemplateRef, input, output, signal, viewChild } from '@angular/core';
|
||||
import { RouterModule } from '@angular/router';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import { Sort } from '@angular/material/sort';
|
||||
import { PatentEntry } from '../../../api/model/patentEntry';
|
||||
import { MatchedAuthor } from '../../../api/model/matchedAuthor';
|
||||
import { DataTableComponent, GenericColumn } from '../data-table/data-table.component';
|
||||
import { ChipComponent } from '../chip/chip.component';
|
||||
import { ComponentTooltipDirective } from '../../../directives/component-tooltip.directive';
|
||||
import { AppAuthorTooltipComponent } from '../app-author-tooltip/app-author-tooltip.component';
|
||||
import { isAssigneeLikelyPerson } from '../../../modules/patent-detail/patent-detail.utils';
|
||||
|
||||
export interface PatentTableEntry extends PatentEntry {
|
||||
match_type?: string;
|
||||
matched_authors?: MatchedAuthor[];
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-patent-table',
|
||||
imports: [
|
||||
RouterModule,
|
||||
MatIconModule,
|
||||
MatButtonModule,
|
||||
MatTooltipModule,
|
||||
DataTableComponent,
|
||||
ChipComponent,
|
||||
ComponentTooltipDirective,
|
||||
],
|
||||
templateUrl: './patent-table.component.html',
|
||||
styleUrl: './patent-table.component.scss',
|
||||
})
|
||||
export class PatentTableComponent<T extends PatentTableEntry = PatentTableEntry> {
|
||||
readonly AuthorTooltipComponent = AppAuthorTooltipComponent;
|
||||
|
||||
patents = input.required<T[]>();
|
||||
selectedPatent = input<T | null>(null);
|
||||
showMatchType = input<boolean>(false);
|
||||
|
||||
queryParamSortKey = input<string>('sortBy');
|
||||
queryParamSortDirectionKey = input<string>('sortDir');
|
||||
|
||||
selectPatent = output<T>();
|
||||
handleSortChange = output<Sort>();
|
||||
|
||||
titleTmp = viewChild.required<TemplateRef<any>>('titleTmp');
|
||||
sourceTmp = viewChild.required<TemplateRef<any>>('sourceTmp');
|
||||
yearTmp = viewChild.required<TemplateRef<any>>('yearTmp');
|
||||
inventorsTmp = viewChild.required<TemplateRef<any>>('inventorsTmp');
|
||||
assigneesTmp = viewChild.required<TemplateRef<any>>('assigneesTmp');
|
||||
matchTypeTmp = viewChild.required<TemplateRef<any>>('matchTypeTmp');
|
||||
matchedAuthorsTmp = viewChild.required<TemplateRef<any>>('matchedAuthorsTmp');
|
||||
actionsTmp = viewChild.required<TemplateRef<any>>('actionsTmp');
|
||||
|
||||
columns(): GenericColumn<T>[] {
|
||||
const baseColumns: GenericColumn<T>[] = [
|
||||
{
|
||||
id: 'title',
|
||||
header: 'Patent',
|
||||
type: 'accessor',
|
||||
accessorKey: 'title' as keyof T,
|
||||
cellTemplate: this.titleTmp(),
|
||||
},
|
||||
{
|
||||
id: 'source',
|
||||
header: 'Quelle',
|
||||
type: 'accessor',
|
||||
accessorKey: 'source' as keyof T,
|
||||
cellTemplate: this.sourceTmp(),
|
||||
},
|
||||
{
|
||||
id: 'publication_year',
|
||||
header: 'Jahr',
|
||||
type: 'accessor',
|
||||
accessorKey: 'publication_year' as keyof T,
|
||||
cellTemplate: this.yearTmp(),
|
||||
},
|
||||
{
|
||||
id: 'inventors',
|
||||
header: 'Erfinder',
|
||||
type: 'display',
|
||||
cellTemplate: this.inventorsTmp(),
|
||||
},
|
||||
{
|
||||
id: 'assignees',
|
||||
header: 'Anmelder',
|
||||
type: 'display',
|
||||
cellTemplate: this.assigneesTmp(),
|
||||
},
|
||||
];
|
||||
|
||||
if (this.showMatchType()) {
|
||||
baseColumns.push(
|
||||
{
|
||||
id: 'match_type',
|
||||
header: 'Match-Typ',
|
||||
type: 'display',
|
||||
cellTemplate: this.matchTypeTmp(),
|
||||
},
|
||||
{
|
||||
id: 'matched_authors',
|
||||
header: 'Personen',
|
||||
type: 'display',
|
||||
cellTemplate: this.matchedAuthorsTmp(),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
baseColumns.push({
|
||||
id: 'actions',
|
||||
header: '',
|
||||
type: 'display',
|
||||
cellTemplate: this.actionsTmp(),
|
||||
});
|
||||
|
||||
return baseColumns;
|
||||
}
|
||||
|
||||
private readonly expandedInventorsIds = signal<Set<string>>(new Set());
|
||||
private readonly expandedAssigneesIds = signal<Set<string>>(new Set());
|
||||
|
||||
isInventorsExpanded(patent: T): boolean {
|
||||
return this.expandedInventorsIds().has(patent.patent_id);
|
||||
}
|
||||
|
||||
toggleInventorsExpansion(patent: T): void {
|
||||
this.expandedInventorsIds.update((ids) => toggleId(ids, patent.patent_id));
|
||||
}
|
||||
|
||||
isAssigneesExpanded(patent: T): boolean {
|
||||
return this.expandedAssigneesIds().has(patent.patent_id);
|
||||
}
|
||||
|
||||
toggleAssigneesExpansion(patent: T): void {
|
||||
this.expandedAssigneesIds.update((ids) => toggleId(ids, patent.patent_id));
|
||||
}
|
||||
|
||||
isSelected(patent: T): boolean {
|
||||
return this.selectedPatent() === patent;
|
||||
}
|
||||
|
||||
isAssigneeLikelyPerson(assignee: string, patent: T): boolean {
|
||||
return isAssigneeLikelyPerson(assignee, patent.inventors);
|
||||
}
|
||||
|
||||
getMatchTypeLabel(matchType: string | undefined): string {
|
||||
switch (matchType) {
|
||||
case 'institution':
|
||||
return 'Institution';
|
||||
case 'name':
|
||||
return 'Name';
|
||||
case 'both':
|
||||
return 'Beides';
|
||||
default:
|
||||
return matchType ?? '-';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function toggleId(ids: Set<string>, id: string): Set<string> {
|
||||
const next = new Set(ids);
|
||||
if (next.has(id)) {
|
||||
next.delete(id);
|
||||
} else {
|
||||
next.add(id);
|
||||
}
|
||||
return next;
|
||||
}
|
||||
Reference in New Issue
Block a user