From 5633b412d4a874c4d9ff3385e2b2330d0a34157d Mon Sep 17 00:00:00 2001 From: Khuder Khalti Date: Thu, 13 Aug 2026 22:01:53 +0200 Subject: [PATCH] refactor(patents): extract shared app-patent-table component built on app-data-table, used by person/institution/keywords patent views --- .../institution-patents.component.html | 189 +----------------- .../institution-patents.component.scss | 128 ------------ .../institution-patents.component.ts | 82 ++------ .../keywords-patents.component.html | 141 +------------ .../keywords-patents.component.scss | 120 ----------- .../keywords-patents.component.ts | 79 +++----- .../patent-detail/patent-detail.utils.ts | 46 +++++ .../person-patents.component.html | 140 +------------ .../person-patents.component.scss | 121 ----------- .../person-patents.component.ts | 70 ++----- .../patent-table/patent-table.component.html | 125 ++++++++++++ .../patent-table/patent-table.component.scss | 149 ++++++++++++++ .../ui/patent-table/patent-table.component.ts | 169 ++++++++++++++++ 13 files changed, 580 insertions(+), 979 deletions(-) create mode 100644 webapp/src/app/shared/ui/patent-table/patent-table.component.html create mode 100644 webapp/src/app/shared/ui/patent-table/patent-table.component.scss create mode 100644 webapp/src/app/shared/ui/patent-table/patent-table.component.ts diff --git a/webapp/src/app/modules/institution-patents/institution-patents.component.html b/webapp/src/app/modules/institution-patents/institution-patents.component.html index fbb05df2..e6b144f0 100644 --- a/webapp/src/app/modules/institution-patents/institution-patents.component.html +++ b/webapp/src/app/modules/institution-patents/institution-patents.component.html @@ -57,193 +57,20 @@ [value]="sortColumn" (selectionChange)="setSort($event.value)"> Sortieren nach - Jahr + Jahr Titel Quelle - Match-Typ + Match-Typ - - - - - - - - - - - - - - @for ( - patent of getPagedPatents(); - track trackPatent($index, patent) - ) { - - - - - - - - - - } - -
Patent - Quelle - @if (sortColumn === 'source') { - {{ - sortDirection === 'asc' ? 'arrow_upward' : 'arrow_downward' - }} - } - - Jahr - @if (sortColumn === 'year') { - {{ - sortDirection === 'asc' ? 'arrow_upward' : 'arrow_downward' - }} - } - ErfinderApplicant/Assignee - Match-Typ - @if (sortColumn === 'matchType') { - {{ - sortDirection === 'asc' ? 'arrow_upward' : 'arrow_downward' - }} - } - Personen
- {{ patent.title ?? patent.patent_id }} - - - {{ patent.source }} - - - @if (patent.publication_year) { - {{ - patent.publication_year - }} - } @else { - - - } - - @if (patent.inventors && patent.inventors.length) { -
- @for ( - inventor of patent.inventors.slice(0, 2); - track inventor - ) { - - person - {{ inventor }} - - } - @if (patent.inventors.length > 2) { - - - person - {{ patent.inventors[2] }} - - @if (patent.inventors.length > 3) { - +{{ patent.inventors.length - 3 }} - } - - } -
- } @else { - - - } -
- @if (patent.assignees && patent.assignees.length) { -
- @for ( - assignee of patent.assignees.slice(0, 2); - track assignee - ) { - - {{ - isAssigneeLikelyPerson(assignee, patent) - ? 'person' - : 'apartment' - }} - {{ assignee }} - - } - @if (patent.assignees.length > 2) { - - - {{ - isAssigneeLikelyPerson( - patent.assignees[2], - patent - ) - ? 'person' - : 'apartment' - }} - {{ patent.assignees[2] }} - - @if (patent.assignees.length > 3) { - +{{ patent.assignees.length - 3 }} - } - - } -
- } @else { - - - } -
- - {{ getMatchTypeLabel(patent) }} - - -
- @if ( - patent.matched_authors && patent.matched_authors.length - ) { - @for ( - author of patent.matched_authors.slice(0, 2); - track author.openalex_author_id - ) { - - {{ author.author_name }} - - } - } @else { - - - } -
-
+ { 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(', '); - } } diff --git a/webapp/src/app/modules/keywords-search/keywords-patents/keywords-patents.component.html b/webapp/src/app/modules/keywords-search/keywords-patents/keywords-patents.component.html index 838a42ad..3bce037a 100644 --- a/webapp/src/app/modules/keywords-search/keywords-patents/keywords-patents.component.html +++ b/webapp/src/app/modules/keywords-search/keywords-patents/keywords-patents.component.html @@ -34,147 +34,18 @@ [value]="sortColumn()" (selectionChange)="setSort($event.value)"> Sortieren nach - Jahr + Jahr Titel Quelle - - - - - - - - - - - - @for (item of getPagedMatches(); track trackMatch($index, item)) { - - - - - - - - } - -
Patent - Quelle - @if (sortColumn() === 'source') { - {{ - sortDirection() === 'asc' - ? 'arrow_upward' - : 'arrow_downward' - }} - } - - Jahr - @if (sortColumn() === 'year') { - {{ - sortDirection() === 'asc' - ? 'arrow_upward' - : 'arrow_downward' - }} - } - ErfinderAnmelder
- {{ item.patent.title ?? item.patent.patent_id }} - - - {{ item.patent.source }} - - - @if (item.patent.publication_year) { - {{ - item.patent.publication_year - }} - } @else { - - - } - - @if (item.patent.inventors && item.patent.inventors.length) { -
- @for ( - inventor of item.patent.inventors.slice(0, 2); - track inventor - ) { - - person - {{ inventor }} - - } - @if (item.patent.inventors.length > 2) { - - - person - {{ item.patent.inventors[2] }} - - @if (item.patent.inventors.length > 3) { - +{{ item.patent.inventors.length - 3 }} - } - - } -
- } @else { - - - } -
- @if (item.patent.assignees && item.patent.assignees.length) { -
- @for ( - assignee of item.patent.assignees.slice(0, 2); - track assignee - ) { - - {{ - isAssigneeLikelyPerson(assignee, item.patent) - ? 'person' - : 'apartment' - }} - {{ assignee }} - - } - @if (item.patent.assignees.length > 2) { - - - {{ - isAssigneeLikelyPerson( - item.patent.assignees[2], - item.patent - ) - ? 'person' - : 'apartment' - }} - {{ item.patent.assignees[2] }} - - @if (item.patent.assignees.length > 3) { - +{{ item.patent.assignees.length - 3 }} - } - - } -
- } @else { - - - } -
+ (); activeFilter = signal('all'); - sortColumn = signal('year'); + sortColumn = signal('publication_year'); sortDirection = signal('desc'); selectedMatch = signal(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 ?? ''); diff --git a/webapp/src/app/modules/patent-detail/patent-detail.utils.ts b/webapp/src/app/modules/patent-detail/patent-detail.utils.ts index bc74fecd..11757964 100644 --- a/webapp/src/app/modules/patent-detail/patent-detail.utils.ts +++ b/webapp/src/app/modules/patent-detail/patent-detail.utils.ts @@ -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 }[] { diff --git a/webapp/src/app/modules/person-patents/person-patents.component.html b/webapp/src/app/modules/person-patents/person-patents.component.html index b32185a7..ba80b808 100644 --- a/webapp/src/app/modules/person-patents/person-patents.component.html +++ b/webapp/src/app/modules/person-patents/person-patents.component.html @@ -34,146 +34,18 @@ [value]="sortColumn" (selectionChange)="setSort($event.value)"> Sortieren nach - Jahr + Jahr Titel Quelle - - - - - - - - - - - - @for ( - patent of getPagedPatents(); - track trackPatent($index, patent) - ) { - - - - - - - - } - -
Patent - Quelle - @if (sortColumn === 'source') { - {{ - sortDirection === 'asc' ? 'arrow_upward' : 'arrow_downward' - }} - } - - Jahr - @if (sortColumn === 'year') { - {{ - sortDirection === 'asc' ? 'arrow_upward' : 'arrow_downward' - }} - } - ErfinderAnmelder
- {{ patent.title ?? patent.patent_id }} - - - {{ patent.source }} - - - @if (patent.publication_year) { - {{ - patent.publication_year - }} - } @else { - - - } - - @if (patent.inventors && patent.inventors.length) { -
- @for ( - inventor of patent.inventors.slice(0, 2); - track inventor - ) { - - person - {{ inventor }} - - } - @if (patent.inventors.length > 2) { - - - person - {{ patent.inventors[2] }} - - @if (patent.inventors.length > 3) { - +{{ patent.inventors.length - 3 }} - } - - } -
- } @else { - - - } -
- @if (patent.assignees && patent.assignees.length) { -
- @for ( - assignee of patent.assignees.slice(0, 2); - track assignee - ) { - - {{ - isAssigneeLikelyPerson(assignee, patent) - ? 'person' - : 'apartment' - }} - {{ assignee }} - - } - @if (patent.assignees.length > 2) { - - - {{ - isAssigneeLikelyPerson( - patent.assignees[2], - patent - ) - ? 'person' - : 'apartment' - }} - {{ patent.assignees[2] }} - - @if (patent.assignees.length > 3) { - +{{ patent.assignees.length - 3 }} - } - - } -
- } @else { - - - } -
+ { 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; diff --git a/webapp/src/app/shared/ui/patent-table/patent-table.component.html b/webapp/src/app/shared/ui/patent-table/patent-table.component.html new file mode 100644 index 00000000..0a6fcdae --- /dev/null +++ b/webapp/src/app/shared/ui/patent-table/patent-table.component.html @@ -0,0 +1,125 @@ + + + + + + + + + {{ patent.source }} + + + + + @if (patent.publication_year) { + {{ patent.publication_year }} + } @else { + - + } + + + + @let expanded = isInventorsExpanded(patent); + @let visibleInventors = + expanded ? patent.inventors : (patent.inventors ?? []).slice(0, 3); +
+ @for (inventor of visibleInventors; track inventor) { + + person + {{ inventor }} + + } @empty { + - + } + @if ((patent.inventors ?? []).length > 3) { + + } +
+
+ + + @let expanded = isAssigneesExpanded(patent); + @let visibleAssignees = + expanded ? patent.assignees : (patent.assignees ?? []).slice(0, 3); +
+ @for (assignee of visibleAssignees; track assignee) { + + {{ + isAssigneeLikelyPerson(assignee, patent) ? 'person' : 'apartment' + }} + {{ assignee }} + + } @empty { + - + } + @if ((patent.assignees ?? []).length > 3) { + + } +
+
+ + + + {{ getMatchTypeLabel(patent.match_type) }} + + + + +
+ @if (patent.matched_authors && patent.matched_authors.length) { + @for ( + author of patent.matched_authors.slice(0, 3); + track author.openalex_author_id + ) { + + {{ author.author_name }} + + } + } @else { + - + } +
+
+ + + + open_in_new + + diff --git a/webapp/src/app/shared/ui/patent-table/patent-table.component.scss b/webapp/src/app/shared/ui/patent-table/patent-table.component.scss new file mode 100644 index 00000000..76b50023 --- /dev/null +++ b/webapp/src/app/shared/ui/patent-table/patent-table.component.scss @@ -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; + } +} diff --git a/webapp/src/app/shared/ui/patent-table/patent-table.component.ts b/webapp/src/app/shared/ui/patent-table/patent-table.component.ts new file mode 100644 index 00000000..44b4d0df --- /dev/null +++ b/webapp/src/app/shared/ui/patent-table/patent-table.component.ts @@ -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 { + readonly AuthorTooltipComponent = AppAuthorTooltipComponent; + + patents = input.required(); + selectedPatent = input(null); + showMatchType = input(false); + + queryParamSortKey = input('sortBy'); + queryParamSortDirectionKey = input('sortDir'); + + selectPatent = output(); + handleSortChange = output(); + + titleTmp = viewChild.required>('titleTmp'); + sourceTmp = viewChild.required>('sourceTmp'); + yearTmp = viewChild.required>('yearTmp'); + inventorsTmp = viewChild.required>('inventorsTmp'); + assigneesTmp = viewChild.required>('assigneesTmp'); + matchTypeTmp = viewChild.required>('matchTypeTmp'); + matchedAuthorsTmp = viewChild.required>('matchedAuthorsTmp'); + actionsTmp = viewChild.required>('actionsTmp'); + + columns(): GenericColumn[] { + const baseColumns: GenericColumn[] = [ + { + 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>(new Set()); + private readonly expandedAssigneesIds = signal>(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, id: string): Set { + const next = new Set(ids); + if (next.has(id)) { + next.delete(id); + } else { + next.add(id); + } + return next; +} -- 2.56.1