From 0d2c7f93bea6b4cd16931a6ce9bed792363436ba Mon Sep 17 00:00:00 2001 From: louis-19041904 Date: Mon, 29 Jun 2026 22:38:31 +0200 Subject: [PATCH] filter topic chips use same topic color --- .../person-publications.component.ts | 61 ++++++++++++++++++- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/webapp/src/app/modules/person-publications/person-publications.component.ts b/webapp/src/app/modules/person-publications/person-publications.component.ts index 2a65d1dd..e55918ff 100644 --- a/webapp/src/app/modules/person-publications/person-publications.component.ts +++ b/webapp/src/app/modules/person-publications/person-publications.component.ts @@ -66,6 +66,10 @@ interface TopicAutocompleteOption { works_count?: number | null; entity_type?: string | null; external_id?: string | null; + field_id?: string | null; + field_name?: string | null; + domain_id?: string | null; + domain_name?: string | null; } interface TopicAutocompleteResponse { @@ -154,6 +158,8 @@ export class PersonPublicationsComponent implements OnInit { institutionNames: 'publicationInstitutionName', topicIds: 'publicationTopicId', topicNames: 'publicationTopicName', + topicFields: 'publicationTopicField', + topicDomains: 'publicationTopicDomain', } as const; readonly typeOptions = [ @@ -283,6 +289,8 @@ export class PersonPublicationsComponent implements OnInit { [this.queryParamKeys.institutionNames]: null, [this.queryParamKeys.topicIds]: null, [this.queryParamKeys.topicNames]: null, + [this.queryParamKeys.topicFields]: null, + [this.queryParamKeys.topicDomains]: null, }); } @@ -316,13 +324,26 @@ export class PersonPublicationsComponent implements OnInit { const topic = event.option.value as TopicAutocompleteOption; if (!topic.id) return; if (!this.selectedTopics.some((item) => item.id === topic.id)) { - this.selectedTopics = [...this.selectedTopics, topic]; + // Das Autocomplete liefert die Hierarchie nur im hint ("Feld · Subfeld + // · Domain"); für die Chip-Farbe das Fachgebiet daraus ableiten. + const enrichedTopic: TopicAutocompleteOption = { + ...topic, + field_name: topic.field_name ?? this.fieldNameFromHint(topic.hint), + }; + this.selectedTopics = [...this.selectedTopics, enrichedTopic]; this.applyFilters(); } this.topicSearchControl.setValue('', { emitEvent: false }); this.topicOptions = []; } + private fieldNameFromHint( + hint: string | null | undefined, + ): string | undefined { + const fieldName = (hint ?? '').split('·')[0]?.trim(); + return fieldName || undefined; + } + removeTopic(topic: TopicAutocompleteOption): void { this.selectedTopics = this.selectedTopics.filter( (item) => item.id !== topic.id, @@ -361,7 +382,14 @@ export class PersonPublicationsComponent implements OnInit { } getSelectedTopicColor(topic: TopicAutocompleteOption): string { - return topicHierarchyColor({ id: topic.id, name: topic.display_name }); + return topicHierarchyColor({ + id: topic.id, + name: topic.display_name, + field_id: topic.field_id, + field_name: topic.field_name, + domain_id: topic.domain_id, + domain_name: topic.domain_name, + }); } isTopicActive(topic: WorkTopic): boolean { @@ -375,7 +403,14 @@ export class PersonPublicationsComponent implements OnInit { if (this.selectedTopics.some((item) => item.id === topic.id)) return; this.selectedTopics = [ ...this.selectedTopics, - { id: topic.id, display_name: topic.display_name ?? topic.id }, + { + id: topic.id, + display_name: topic.display_name ?? topic.id, + field_id: topic.field?.id, + field_name: topic.field?.display_name, + domain_id: topic.domain?.id, + domain_name: topic.domain?.display_name, + }, ]; this.applyFilters(); } @@ -520,6 +555,14 @@ export class PersonPublicationsComponent implements OnInit { const topicNames = this.selectedTopics .map((topic) => topic.display_name) .filter((name): name is string => !!name); + // Index-aligned mit topicIds, damit die Hierarchie-Farbe nach einem + // Reload erhalten bleibt (leerer String = keine Angabe). + const topicFields = this.selectedTopics.map( + (topic) => topic.field_name ?? '', + ); + const topicDomains = this.selectedTopics.map( + (topic) => topic.domain_name ?? '', + ); void this.router.navigate([], { relativeTo: this.route, @@ -541,6 +584,14 @@ export class PersonPublicationsComponent implements OnInit { : null, [this.queryParamKeys.topicIds]: topicIds.length ? topicIds : null, [this.queryParamKeys.topicNames]: topicNames.length ? topicNames : null, + [this.queryParamKeys.topicFields]: topicFields.some((field) => field) + ? topicFields + : null, + [this.queryParamKeys.topicDomains]: topicDomains.some( + (domain) => domain, + ) + ? topicDomains + : null, ...overrides, }, queryParamsHandling: 'merge', @@ -558,6 +609,8 @@ export class PersonPublicationsComponent implements OnInit { ); const topicIds = queryParams.getAll(this.queryParamKeys.topicIds); const topicNames = queryParams.getAll(this.queryParamKeys.topicNames); + const topicFields = queryParams.getAll(this.queryParamKeys.topicFields); + const topicDomains = queryParams.getAll(this.queryParamKeys.topicDomains); return { pageIndex: @@ -585,6 +638,8 @@ export class PersonPublicationsComponent implements OnInit { topics: topicIds.filter(Boolean).map((id, index) => ({ id, display_name: topicNames[index] || id, + field_name: topicFields[index] || undefined, + domain_name: topicDomains[index] || undefined, })), }; }