From 48e33e7fe555fd9293b3904be2588f21236dfa35 Mon Sep 17 00:00:00 2001 From: genja Date: Wed, 8 Jul 2026 03:27:29 +0200 Subject: [PATCH] added search-results parent component --- .../search-results-state.service.ts | 44 ++++ .../search-results.component.html | 77 +++++++ .../search-results.component.scss | 209 ++++++++++++++++++ .../search-results.component.ts | 191 ++++++++++++++++ 4 files changed, 521 insertions(+) create mode 100644 webapp/src/app/modules/keywords-search/search-results/search-results-state.service.ts create mode 100644 webapp/src/app/modules/keywords-search/search-results/search-results.component.html create mode 100644 webapp/src/app/modules/keywords-search/search-results/search-results.component.scss create mode 100644 webapp/src/app/modules/keywords-search/search-results/search-results.component.ts diff --git a/webapp/src/app/modules/keywords-search/search-results/search-results-state.service.ts b/webapp/src/app/modules/keywords-search/search-results/search-results-state.service.ts new file mode 100644 index 00000000..b5b91234 --- /dev/null +++ b/webapp/src/app/modules/keywords-search/search-results/search-results-state.service.ts @@ -0,0 +1,44 @@ +import { Injectable, computed, signal } from '@angular/core'; +import { KeywordEntryWithTopic } from '../../../api/model/keywordEntryWithTopic'; + +export interface SearchResultsPayload { + extractedKeywords: KeywordEntryWithTopic[]; + manualKeywords: KeywordEntryWithTopic[]; + keywords: string[]; + options: { + softSearch: boolean; + }; +} + +/** + * Provided at the parent route (KeywordsSearchResultsComponent) so it's + * created once when entering /search-results and destroyed when leaving it. + * Child routes (persons/projects/patents) inject it read-only to build + * their own search requests without re-deriving the keyword state. + */ +@Injectable() +export class SearchResultsStateService { + private readonly _payload = signal(null); + + readonly payload = this._payload.asReadonly(); + + readonly hasValidSearch = computed(() => { + const payload = this._payload(); + return !!payload && payload.keywords.length > 0; + }); + + readonly keywords = computed(() => this._payload()?.keywords ?? []); + readonly softSearch = computed( + () => this._payload()?.options.softSearch ?? false, + ); + readonly extractedKeywords = computed( + () => this._payload()?.extractedKeywords ?? [], + ); + readonly manualKeywords = computed( + () => this._payload()?.manualKeywords ?? [], + ); + + setPayload(payload: SearchResultsPayload): void { + this._payload.set(payload); + } +} diff --git a/webapp/src/app/modules/keywords-search/search-results/search-results.component.html b/webapp/src/app/modules/keywords-search/search-results/search-results.component.html new file mode 100644 index 00000000..982210b6 --- /dev/null +++ b/webapp/src/app/modules/keywords-search/search-results/search-results.component.html @@ -0,0 +1,77 @@ +
+
+ +
+ @if (state.hasValidSearch()) { + + +
+
+ Suchprofil + {{ selectedKeywordCount() }} Keywords +
+ + account_tree + {{ state.softSearch() ? 'Topic Mapping' : 'Keyword Matching' }} + +
+ +
+ @for (entry of selectedKeywordEntries(); track getEntryTrack(entry)) { + + } + @for (keyword of missingKeywordLabels(); track keyword) { + + } +
+
+
+ + + + + + + } @else { + + + manage_search +

Keine Suchdaten

+

Starte eine neue Suche, um Ergebnisse zu sehen.

+ +
+
+ } +
diff --git a/webapp/src/app/modules/keywords-search/search-results/search-results.component.scss b/webapp/src/app/modules/keywords-search/search-results/search-results.component.scss new file mode 100644 index 00000000..b1d2a7ee --- /dev/null +++ b/webapp/src/app/modules/keywords-search/search-results/search-results.component.scss @@ -0,0 +1,209 @@ +/* ============================================================ + DESIGN TOKENS + ============================================================ */ +$phone: 599px; +$tablet: 900px; +$touch-target: 44px; + +/* ============================================================ + SEARCH RESULTS PAGE (parent shell) + ============================================================ */ +.search-results-page { + display: flex; + flex-direction: column; + gap: 0.75rem; + padding: 0.75rem 1rem; +} + +.page-header { + display: flex; + align-items: flex-start; + gap: 0.75rem; + + h1 { + margin: 0; + font-size: clamp(1.2rem, 2vw, 1.6rem); + font-weight: 650; + color: var(--sg-text-primary); + } + + p { + margin: 0.2rem 0 0; + color: var(--sg-text-secondary); + font-size: 0.9rem; + } +} + +/* ============================================================ + KEYWORD SUMMARY CARD + ============================================================ */ +.summary-card { + background: var(--sg-surface, #ffffff); + border: 1px solid var(--sg-divider, rgba(0, 0, 0, 0.12)); + box-shadow: none; + + .mat-mdc-card-content { + padding: 0.75rem; + } +} + +.summary-header { + display: flex; + align-items: flex-start; + justify-content: space-between; + gap: 0.5rem; + margin-bottom: 0.5rem; +} + +.summary-label { + display: block; + font-size: 0.75rem; + font-weight: 600; + text-transform: uppercase; + letter-spacing: 0.03em; + color: var(--sg-text-secondary); +} + +.summary-count { + display: block; + margin-top: 0.15rem; + font-size: 0.95rem; + font-weight: 650; + color: var(--sg-text-primary); +} + +.mode-badge { + display: inline-flex; + align-items: center; + gap: 0.25rem; + border-radius: 999px; + padding: 0.25rem 0.5rem; + background: var(--sg-background-muted, #f4f5f7); + color: var(--sg-text-secondary); + font-size: 0.75rem; + font-weight: 500; + + mat-icon { + font-size: 16px; + width: 16px; + height: 16px; + } +} + +.keyword-stack { + display: flex; + flex-wrap: wrap; + gap: 0.6rem; + + ::ng-deep app-topic-chip .topic-chip__count { + display: none; + } +} + +/* ============================================================ + CHILD ROUTE NAV + ============================================================ */ +.result-nav { + display: flex; + gap: 0.25rem; + border-bottom: 1px solid var(--sg-divider, rgba(0, 0, 0, 0.12)); +} + +.result-nav__link { + display: inline-flex; + align-items: center; + gap: 0.35rem; + padding: 0.5rem 0.85rem; + border-radius: 6px 6px 0 0; + color: var(--sg-text-secondary); + text-decoration: none; + font-size: 0.85rem; + font-weight: 500; + border-bottom: 2px solid transparent; + transition: + color 0.15s ease, + border-color 0.15s ease; + + mat-icon { + font-size: 18px; + width: 18px; + height: 18px; + } + + &:hover { + color: var(--sg-text-primary); + } + + &--active { + color: var(--sg-text-primary); + border-bottom-color: var(--sg-primary, currentColor); + } +} + +/* ============================================================ + EMPTY STATE + ============================================================ */ +.empty-card { + background: var(--sg-surface, #ffffff); + border: 1px solid var(--sg-divider, rgba(0, 0, 0, 0.12)); + box-shadow: none; +} + +.empty-state { + min-height: 240px; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + gap: 0.5rem; + text-align: center; + color: var(--sg-text-secondary); + + mat-icon { + font-size: 48px; + width: 48px; + height: 48px; + opacity: 0.65; + } + + h2 { + margin: 0; + color: var(--sg-text-primary); + font-size: 1.1rem; + } + + p { + margin: 0; + max-width: 480px; + line-height: 1.4; + } + + button { + margin-top: 0.5rem; + min-height: $touch-target; + } +} + +/* ============================================================ + PHONE + ============================================================ */ +@media (max-width: $phone) { + .search-results-page { + padding: 0.5rem; + } + + .summary-header { + flex-direction: column; + align-items: flex-start; + gap: 0.3rem; + } + + .mode-badge { + width: 100%; + justify-content: center; + } + + .result-nav { + overflow-x: auto; + } +} diff --git a/webapp/src/app/modules/keywords-search/search-results/search-results.component.ts b/webapp/src/app/modules/keywords-search/search-results/search-results.component.ts new file mode 100644 index 00000000..f935571b --- /dev/null +++ b/webapp/src/app/modules/keywords-search/search-results/search-results.component.ts @@ -0,0 +1,191 @@ +import { Component, computed, inject } from '@angular/core'; +import { + Router, + RouterLink, + RouterLinkActive, + RouterOutlet, +} from '@angular/router'; + +import { MatButtonModule } from '@angular/material/button'; +import { MatCardModule } from '@angular/material/card'; +import { MatIconModule } from '@angular/material/icon'; + +import { KeywordEntryWithTopic } from '../../../api/model/keywordEntryWithTopic'; +import { Topic } from '../../../api/model/topic'; +import { TopicChipComponent } from '../../../shared/ui/topic-chip/topic-chip.component'; +import { + topicHierarchyColor, + TopicHierarchyColorInput, +} from '../../../resolvers/utils/topic-colors'; +import { MatTabsModule } from '@angular/material/tabs'; +import { + SearchResultsPayload, + SearchResultsStateService, +} from './search-results-state.service'; + +@Component({ + selector: 'app-keywords-search-results', + standalone: true, + imports: [ + RouterLink, + RouterLinkActive, + RouterOutlet, + MatButtonModule, + MatCardModule, + MatIconModule, + TopicChipComponent, + MatTabsModule, + ], + // Scoped to this component's route subtree: created on entering /results, + // destroyed on leaving it entirely — survives switching persons/projects/patents. + providers: [SearchResultsStateService], + templateUrl: './search-results.component.html', + styleUrl: './search-results.component.scss', +}) +export class KeywordsSearchResultsComponent { + private readonly router = inject(Router); + + protected readonly state = inject(SearchResultsStateService); + + protected readonly childRoutes = [ + { path: 'persons', label: 'Personen', icon: 'groups' }, + { path: 'projects', label: 'Projekte', icon: 'account_tree' }, + { path: 'patents', label: 'Patente', icon: 'workspace_premium' }, + ]; + + readonly selectedKeywordCount = computed(() => this.state.keywords().length); + + readonly selectedKeywordEntries = computed(() => { + const payload = this.state.payload(); + if (!payload) return []; + + const allEntries = [ + ...(payload.extractedKeywords ?? []), + ...(payload.manualKeywords ?? []), + ]; + + const entryByKeyword = new Map(); + + for (const entry of allEntries) { + entryByKeyword.set( + this.normalizeKeyword(this.getKeywordLabel(entry)), + entry, + ); + } + + const result: KeywordEntryWithTopic[] = []; + const seen = new Set(); + + for (const keyword of payload.keywords) { + const normalized = this.normalizeKeyword(keyword); + const entry = entryByKeyword.get(normalized); + + if (!entry || seen.has(normalized)) continue; + + seen.add(normalized); + result.push(entry); + } + + return result; + }); + + readonly missingKeywordLabels = computed(() => { + const payload = this.state.payload(); + if (!payload) return []; + + const entryKeywordSet = new Set( + this.selectedKeywordEntries().map((entry) => + this.normalizeKeyword(this.getKeywordLabel(entry)), + ), + ); + + return payload.keywords.filter( + (keyword) => !entryKeywordSet.has(this.normalizeKeyword(keyword)), + ); + }); + + constructor() { + const navigationState = + this.router.currentNavigation()?.extras.state ?? window.history.state; + + const restoredPayload = this.parsePayload(navigationState); + + if (restoredPayload) { + this.state.setPayload(restoredPayload); + } + } + + goBackToSearch(): void { + void this.router.navigate(['/keywords']); + } + + getChipLabel(keyword: KeywordEntryWithTopic): string { + return keyword.llm_keyword?.keyword ?? ''; + } + + getChipDescription(item: KeywordEntryWithTopic): string | null { + return this.getTopic(item)?.description ?? null; + } + + getChipSubfieldName(item: KeywordEntryWithTopic): string | null { + return this.getTopic(item)?.subfield?.display_name ?? null; + } + + getChipFieldName(item: KeywordEntryWithTopic): string | null { + return this.getTopic(item)?.field?.display_name ?? null; + } + + getChipDomainName(item: KeywordEntryWithTopic): string | null { + return this.getTopic(item)?.domain?.display_name ?? null; + } + + getChipCount(item: KeywordEntryWithTopic): number | null { + return this.getTopic(item)?.works_count ?? null; + } + + getTopicColor(topic: Topic | undefined | null): string { + const topicInput: TopicHierarchyColorInput = { + id: topic?.id ?? null, + name: topic?.display_name ?? null, + field_id: topic?.field?.id ?? null, + field_name: topic?.field?.display_name ?? null, + domain_id: topic?.domain?.id ?? null, + domain_name: topic?.domain?.display_name ?? null, + }; + + return topicHierarchyColor(topicInput); + } + + getEntryTrack(entry: KeywordEntryWithTopic): string { + return this.getKeywordLabel(entry); + } + + private parsePayload(value: unknown): SearchResultsPayload | null { + if (!value || typeof value !== 'object') return null; + + const maybePayload = value as Partial; + + if (!Array.isArray(maybePayload.keywords)) return null; + + return { + extractedKeywords: maybePayload.extractedKeywords ?? [], + manualKeywords: maybePayload.manualKeywords ?? [], + keywords: maybePayload.keywords ?? [], + options: { + softSearch: maybePayload.options?.softSearch ?? false, + }, + }; + } + + private getKeywordLabel(item: KeywordEntryWithTopic): string { + return item.llm_keyword.keyword; + } + + private getTopic(item: KeywordEntryWithTopic): Topic | null { + return item.topic_mapping?.topic ?? null; + } + + private normalizeKeyword(value: string): string { + return value.trim().toLowerCase(); + } +}