59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
import { Component, computed, input } from '@angular/core';
|
|
import { Topic } from '../../../api';
|
|
import { MatCardModule } from '@angular/material/card';
|
|
import { MatDividerModule } from '@angular/material/divider';
|
|
import { MatIconModule } from '@angular/material/icon';
|
|
import { RouterModule } from '@angular/router';
|
|
import { DecimalPipe } from '@angular/common';
|
|
import { MatButtonModule } from '@angular/material/button';
|
|
import { topicHierarchyColor } from '../../../resolvers/utils/topic-colors';
|
|
|
|
@Component({
|
|
host: {
|
|
'[style.--topic-color]': 'color()',
|
|
},
|
|
selector: 'app-topic-card',
|
|
imports: [
|
|
MatCardModule,
|
|
MatDividerModule,
|
|
MatIconModule,
|
|
MatButtonModule,
|
|
RouterModule,
|
|
DecimalPipe,
|
|
],
|
|
templateUrl: './app-topic-card.component.html',
|
|
styleUrl: './app-topic-card.component.scss',
|
|
})
|
|
export class AppTopicCardComponent {
|
|
topic = input.required<Topic>();
|
|
|
|
stripOpenAlexId(id: string | null | undefined): string | undefined {
|
|
if (!id) {
|
|
return undefined;
|
|
}
|
|
return id.replace('https://openalex.org/', '');
|
|
}
|
|
|
|
subtitle = computed(() => {
|
|
return `${this.topic().subfield?.display_name} - ${this.topic().field?.display_name} - ${this.topic().domain?.display_name}`;
|
|
});
|
|
|
|
description = computed(() => {
|
|
return this.topic().description || 'Keine Beschreibung verfügbar';
|
|
});
|
|
|
|
color = computed<string>(() => {
|
|
const topic = this.topic();
|
|
return topicHierarchyColor({
|
|
id: topic.id ?? undefined,
|
|
name: topic.display_name ?? undefined,
|
|
field_id: topic.field?.id ?? undefined,
|
|
field_name: topic.field?.display_name ?? undefined,
|
|
domain_id: topic.domain?.id ?? undefined,
|
|
domain_name: topic.domain?.display_name ?? undefined,
|
|
})
|
|
.replace('hsl(', '')
|
|
.replace(')', '');
|
|
});
|
|
}
|