Added network table for institutions

This commit is contained in:
Mats Paul Tončik
2026-06-05 14:23:55 +02:00
parent e107657318
commit f76d63a76c
9 changed files with 246 additions and 24 deletions
@@ -142,6 +142,10 @@ export class PersonNetworkCollaboratorsComponent implements AfterViewInit {
}
});
Object.values(allAuthors).forEach((author) => {
author.works.sort((a, b) => a.title.localeCompare(b.title));
});
return new MatTableDataSource(
Object.values(allAuthors).filter(
(author) =>
@@ -13,7 +13,6 @@ import {
import { CanvasRenderer } from 'echarts/renderers';
import { GraphChart } from 'echarts/charts';
import { MatIconModule } from '@angular/material/icon';
import { ActivatedRoute, Router } from '@angular/router';
echarts.use([
GridComponent,
CanvasRenderer,
@@ -22,7 +21,7 @@ echarts.use([
LegendComponent,
]);
export type NodeCategory = 'author' | 'collaborator' | 'work';
export type NodeCategory = 'author' | 'collaborator' | 'work' | 'institution';
export interface NodeClickEvent {
id: string;
@@ -0,0 +1,45 @@
<div class="table">
<table mat-table [dataSource]="dataSource" [trackBy]="trackBy" matSort>
<ng-container matColumnDef="id">
<th mat-header-cell *matHeaderCellDef mat-sort-header>ID</th>
<td mat-cell *matCellDef="let element">{{ element.id }}</td>
</ng-container>
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Titel</th>
<td mat-cell *matCellDef="let element">
{{ element.name }}
</td>
</ng-container>
<ng-container matColumnDef="collaborators">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Mitwirkende</th>
<td mat-cell *matCellDef="let element">
{{ element.collaborators.length }}
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
<tr
mat-row
*matRowDef="let row; columns: displayedColumns"
class="element-row"
[cdkDetailRow]="row"
[cdkDetailRowTpl]="tpl"
></tr>
</table>
</div>
<ng-template #tpl let-element>
<tr class="detail-row">
<td [attr.colspan]="displayedColumns.length">
<ul>
@for (collaborator of element.collaborators; track $index) {
<li>
{{ collaborator.name }}
(<a [routerLink]="['/person', collaborator.id]">{{ collaborator.id }}</a
>)
</li>
}
</ul>
</td>
</tr>
</ng-template>
@@ -0,0 +1,29 @@
.table {
overflow: auto;
width: 100%;
max-height: 100%;
}
.mat-mdc-table {
background-color: var(--sg-background);
}
.element-row {
position: relative;
}
.element-row:not(.expanded) {
cursor: pointer;
}
.element-row:not(.expanded):hover {
background: #f5f5f5;
}
.element-row.expanded {
border-bottom-color: transparent;
}
.detail-row {
width: 100%;
}
@@ -0,0 +1,126 @@
import {
AfterViewInit,
Component,
effect,
input,
ViewChild,
} from '@angular/core';
import { CollaborationNetwork } from '../../api';
import { MatTableDataSource, MatTableModule } from '@angular/material/table';
import { MatSort, MatSortModule } from '@angular/material/sort';
import { MatIconModule } from '@angular/material/icon';
import { RouterModule } from '@angular/router';
import { CdkDetailRowDirective } from '../../directives/cdk-detail-row.directive';
import { MatButtonModule } from '@angular/material/button';
type Collaborator = {
id: string;
name: string;
};
type Institution = {
id: string;
name: string;
collaborators: Collaborator[];
};
@Component({
selector: 'app-person-network-institutions',
imports: [
MatTableModule,
MatIconModule,
MatSortModule,
RouterModule,
CdkDetailRowDirective,
MatButtonModule,
],
templateUrl: './person-network-institutions.component.html',
styleUrl: './person-network-institutions.component.scss',
})
export class PersonNetworkInstitutionsComponent implements AfterViewInit {
collaborationNetwork = input.required<CollaborationNetwork>();
searchTerm = input.required<string>();
displayedColumns: string[] = ['id', 'name', 'collaborators'];
dataSource = new MatTableDataSource<Institution>();
trackBy = (index: number, item: Institution) => item.id;
@ViewChild(MatSort) sort!: MatSort;
constructor() {
effect(() => {
const collaborationNetwork = this.collaborationNetwork();
if (!collaborationNetwork) {
return;
}
this.dataSource = this.buildInstitutionsDataSource(collaborationNetwork);
this.dataSource.sortingDataAccessor = (item, property) => {
if (property === 'collaborators') {
return item.collaborators.length;
}
return (item as any)[property];
};
if (this.sort) {
this.dataSource.sort = this.sort;
this.setDefaultSort();
}
});
effect(() => {
const searchTerm = this.searchTerm().toLowerCase();
this.dataSource.filter = searchTerm;
});
}
ngAfterViewInit() {
if (this.sort) {
this.dataSource.sort = this.sort;
}
}
private setDefaultSort(): void {
this.sort.active = 'name';
this.sort.direction = 'asc';
this.sort.sortChange.emit({ active: 'name', direction: 'asc' });
}
buildInstitutionsDataSource(
collaborationNetwork: CollaborationNetwork,
): MatTableDataSource<Institution> {
const institutionsMap: Record<string, Institution> = {};
for (const node of collaborationNetwork.nodes) {
if (node.category === 'institution') {
institutionsMap[node.raw_id] = {
id: node.raw_id,
name: node.display_name,
collaborators: [],
};
}
}
for (const edge of collaborationNetwork.edges) {
if (edge.raw_target_id in institutionsMap) {
const institution = institutionsMap[edge.raw_target_id];
institution.collaborators.push({
id: edge.raw_source_id,
name:
collaborationNetwork.nodes.find(
(node) => node.raw_id === edge.raw_source_id,
)?.display_name || 'Unbekannt',
});
}
}
for (const institution of Object.values(institutionsMap)) {
institution.collaborators.sort((a, b) =>
a.name.localeCompare(b.name, 'de', { sensitivity: 'base' }),
);
}
return new MatTableDataSource(Object.values(institutionsMap));
}
}
@@ -16,18 +16,6 @@
{{ element.collaborators.length }}
</td>
</ng-container>
<ng-container matColumnDef="actions">
<th mat-header-cell *matHeaderCellDef></th>
<td mat-cell *matCellDef="let element">
<button
mat-icon-button
color="primary"
[routerLink]="['/work', element.id]"
>
<mat-icon>open_in_new</mat-icon>
</button>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
<tr
@@ -43,7 +43,7 @@ export class PersonNetworkPublicationsComponent implements AfterViewInit {
collaborationNetwork = input.required<CollaborationNetwork>();
searchTerm = input.required<string>();
displayedColumns: string[] = ['id', 'title', 'contributors', 'actions'];
displayedColumns: string[] = ['id', 'title', 'contributors'];
dataSource = new MatTableDataSource<Work>();
@@ -134,6 +134,10 @@ export class PersonNetworkPublicationsComponent implements AfterViewInit {
}
});
Object.values(allWorks).forEach((work) => {
work.collaborators.sort((a, b) => a.name.localeCompare(b.name));
});
return new MatTableDataSource(
Object.values(allWorks).filter((work) => work.collaborators.length > 0),
);
@@ -27,6 +27,9 @@
<mat-button-toggle value="publications"
>Publikationen</mat-button-toggle
>
<mat-button-toggle value="institutions">
Institutionen
</mat-button-toggle>
</mat-button-toggle-group>
<button mat-stroked-button type="button" (click)="openFilterDialog()">
<mat-icon>filter_alt</mat-icon>
@@ -34,18 +37,17 @@
</button>
</div>
<mat-form-field style="width: 100%">
<mat-label>{{
this.displayedTable() === "collaborators"
? "Suche Kollaborierende nach Name oder ID"
: "Suche Publikationen nach Titel oder ID"
}}</mat-label>
<mat-label>{{ this.searchTermLabel() }}</mat-label>
<input
matInput
#input
appearance="outline"
formControlName="searchTerm"
/>
<mat-icon matSuffix>search</mat-icon>
<mat-icon matPrefix>search</mat-icon>
<button matIconButton matSuffix (click)="clearSearch()">
<mat-icon>clear</mat-icon>
</button>
</mat-form-field>
</form>
@@ -61,6 +63,11 @@
[collaborationNetwork]="collaborationNetwork"
[searchTerm]="searchTerm()"
/>
} @else if (this.displayedTable() === "institutions") {
<app-person-network-institutions
[collaborationNetwork]="collaborationNetwork"
[searchTerm]="searchTerm()"
/>
}
</mat-card-content>
</mat-card>
@@ -36,6 +36,7 @@ import { MatExpansionModule } from '@angular/material/expansion';
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
import { PersonNetworkFilterDialogComponent } from '../person-network-filter-dialog/person-network-filter-dialog.component';
import { PersonNetworkInfoCardComponent } from '../person-network-info-card/person-network-info-card.component';
import { PersonNetworkInstitutionsComponent } from '../person-network-institutions/person-network-institutions.component';
@Component({
selector: 'app-person-network',
@@ -62,6 +63,7 @@ import { PersonNetworkInfoCardComponent } from '../person-network-info-card/pers
MatExpansionModule,
MatDialogModule,
PersonNetworkInfoCardComponent,
PersonNetworkInstitutionsComponent,
],
templateUrl: './person-network.component.html',
styleUrl: './person-network.component.scss',
@@ -88,18 +90,32 @@ export class PersonNetworkComponent implements OnInit {
publications = signal(0);
connections = signal(0);
searchTermLabel = computed(() => {
const displayedTable = this.displayedTable();
switch (displayedTable) {
case 'collaborators':
return 'Suche Kollaborierende nach Name oder ID';
case 'publications':
return 'Suche Publikationen nach Titel oder ID';
case 'institutions':
return 'Suche Institutionen nach Name oder ID';
default:
return 'Suchbegriff';
}
});
private readonly categoryTableMap: Record<NodeCategory, string> = {
author: 'collaborators',
collaborator: 'collaborators',
work: 'publications',
institution: 'institutions',
};
latestNodeId = signal<string | null>(null);
handleNodeClick = ({ id, name, category }: NodeClickEvent): void => {
if (this.latestNodeId() === id) {
this.latestNodeId.set(null);
this.filterForm.patchValue({ searchTerm: '' });
this.clearSearch();
return;
}
@@ -111,6 +127,11 @@ export class PersonNetworkComponent implements OnInit {
});
};
clearSearch() {
this.latestNodeId.set(null);
this.filterForm.patchValue({ searchTerm: '' });
}
readonly summaryCards = computed(() => [
{
icon: 'person',
@@ -175,7 +196,6 @@ export class PersonNetworkComponent implements OnInit {
});
dialogRef.afterClosed().subscribe((result) => {
console.log('Dialog result:', result);
if (result) {
this.filterForm.setValue({
searchTerm: this.filterForm.get('searchTerm')?.value || '',