From 13b2fb3350a1428da00575c52b8c89abdba93d2a Mon Sep 17 00:00:00 2001 From: genja Date: Wed, 8 Jul 2026 03:19:43 +0200 Subject: [PATCH 1/9] added new routes for keywords search components --- webapp/src/app/app.routes.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/webapp/src/app/app.routes.ts b/webapp/src/app/app.routes.ts index d6c48f5c..162b35da 100644 --- a/webapp/src/app/app.routes.ts +++ b/webapp/src/app/app.routes.ts @@ -24,7 +24,9 @@ import { accountViewerGuard } from './shared/guards/account-viewer.guard'; import { accountsPageResolver } from './resolvers/accounts-page.resolver'; import { accountsOrganizationResolver } from './resolvers/accounts-organizations.resolver'; import { organizationsOrganizationsResolver } from './resolvers/organizations-organizations.resolver'; - +import { KeywordsToPersonsResultsComponent } from './modules/keywords-search/search-results/persons-results/persons-results.component'; +import { KeywordsToProjectsResultsComponent } from './modules/keywords-search/search-results/projects-results/projects-results.component'; +import { KeywordsToPatentsResultsComponent } from './modules/keywords-search/search-results/patents-results/patents-results.component'; export const routes: Routes = [ { path: '', @@ -103,6 +105,19 @@ export const routes: Routes = [ (mod) => mod.KeywordsSearchComponent, ), }, + { + path: 'keywords/search-results', + loadComponent: () => + import('./modules/keywords-search/search-results/search-results.component').then( + (mod) => mod.KeywordsSearchResultsComponent, + ), + children: [ + { path: '', pathMatch: 'full', redirectTo: 'persons' }, + { path: 'persons', component: KeywordsToPersonsResultsComponent }, + { path: 'projects', component: KeywordsToProjectsResultsComponent }, + { path: 'patents', component: KeywordsToPatentsResultsComponent }, + ], + }, { path: 'news', canActivate: [userGuard], -- 2.56.1 From 3e115619a622298e7c05382796634cd86c0fe301 Mon Sep 17 00:00:00 2001 From: genja Date: Wed, 8 Jul 2026 03:25:37 +0200 Subject: [PATCH 2/9] added topic mapping toggle --- .../keywords-search.component.html | 47 ++++++----- .../keywords-search.component.scss | 82 ++++++++++++++++--- 2 files changed, 98 insertions(+), 31 deletions(-) diff --git a/webapp/src/app/modules/keywords-search/keywords-search.component.html b/webapp/src/app/modules/keywords-search/keywords-search.component.html index a46bb8b3..496e4154 100644 --- a/webapp/src/app/modules/keywords-search/keywords-search.component.html +++ b/webapp/src/app/modules/keywords-search/keywords-search.component.html @@ -99,9 +99,17 @@ Alle auswählen } +
- text_fields Extrahierte Keywords - - account_tree - Topic Mapping - + @if (topicMappingSearch()) { + + account_tree + Topic Mapping + + }
- + + Topic Mapping +
@@ -366,8 +374,8 @@ @if (keywordsExist()) { - -
+ +
+ +
+ @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(); + } +} -- 2.56.1 From 2bfb877e7765b20bbfb60d5e4889d292893d4c1e Mon Sep 17 00:00:00 2001 From: genja Date: Wed, 8 Jul 2026 03:28:16 +0200 Subject: [PATCH 5/9] created a template for patents results for keyword search --- .../patents-results.component.html | 31 +++++ .../patents-results.component.scss | 29 +++++ .../patents-results.component.ts | 112 ++++++++++++++++++ 3 files changed, 172 insertions(+) create mode 100644 webapp/src/app/modules/keywords-search/search-results/patents-results/patents-results.component.html create mode 100644 webapp/src/app/modules/keywords-search/search-results/patents-results/patents-results.component.scss create mode 100644 webapp/src/app/modules/keywords-search/search-results/patents-results/patents-results.component.ts diff --git a/webapp/src/app/modules/keywords-search/search-results/patents-results/patents-results.component.html b/webapp/src/app/modules/keywords-search/search-results/patents-results/patents-results.component.html new file mode 100644 index 00000000..e5f4062b --- /dev/null +++ b/webapp/src/app/modules/keywords-search/search-results/patents-results/patents-results.component.html @@ -0,0 +1,31 @@ +
+ + + groups +

Patentenliste

+

+ Die aktuelle Gewichtung ist unter normalized verfügbar. +

+
+
+ + + + + + +
diff --git a/webapp/src/app/modules/keywords-search/search-results/patents-results/patents-results.component.scss b/webapp/src/app/modules/keywords-search/search-results/patents-results/patents-results.component.scss new file mode 100644 index 00000000..ffeea20d --- /dev/null +++ b/webapp/src/app/modules/keywords-search/search-results/patents-results/patents-results.component.scss @@ -0,0 +1,29 @@ +/* ============================================================ + RESULT LAYOUT + ============================================================ */ +.result-layout { + display: grid; + grid-template-columns: minmax(300px, 420px) 1fr; + grid-template-areas: 'summary results'; + gap: 0.75rem; + align-items: start; +} + +.search-summary-card { + grid-area: summary; +} + +.results-card { + grid-area: results; +} + +.search-summary-card, +.results-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; + } +} diff --git a/webapp/src/app/modules/keywords-search/search-results/patents-results/patents-results.component.ts b/webapp/src/app/modules/keywords-search/search-results/patents-results/patents-results.component.ts new file mode 100644 index 00000000..659c9064 --- /dev/null +++ b/webapp/src/app/modules/keywords-search/search-results/patents-results/patents-results.component.ts @@ -0,0 +1,112 @@ +import { Component, inject, signal } from '@angular/core'; + +import { MatCardModule } from '@angular/material/card'; +import { MatIconModule } from '@angular/material/icon'; + +import { + WeightMap, + WeightSliderOption, + WeightsSlidersComponent, + WeightsSlidersValue, +} from '../../../../shared/ui/weights-sliders/weights-sliders.component'; +import { SearchResultsStateService } from '../search-results-state.service'; + +@Component({ + selector: 'app-patents-results', + imports: [MatCardModule, MatIconModule, WeightsSlidersComponent], + templateUrl: './patents-results.component.html', + styleUrl: './patents-results.component.scss', +}) +export class KeywordsToPatentsResultsComponent { + // injects the state set by the parent route — no duplicate parsing here + private readonly state = inject(SearchResultsStateService); + + readonly defaultWeights: WeightMap = { + param1: 0.33, + param2: 0.33, + param3: 0.34, + }; + + readonly weightOptions: WeightSliderOption[] = [ + { + key: 'param1', + label: 'Parameter 1', + icon: 'workspace_premium', + description: 'Gewichtet Parameter 1.', + defaultValue: 0.5, + queryParamName: 'wParam1', + }, + { + key: 'param2', + label: 'Parameter 2', + icon: 'workspace_premium', + description: 'Gewichtet Parameter 2.', + defaultValue: 0.5, + queryParamName: 'wParam2', + }, + { + key: 'param3', + label: 'Parameter 3', + icon: 'workspace_premium', + description: 'Gewichtet Parameter 3.', + defaultValue: 0.5, + queryParamName: 'wParam3', + }, + ]; + + readonly currentWeights = signal({ + raw: this.defaultWeights, + normalized: { + param1: 0.33, + param2: 0.33, + param3: 0.34, + }, + rawSum: 2.5, + normalizedSum: 1, + valid: true, + }); + + readonly projects = signal([]); // placeholder until the results service lands + + private hasLoadedInitial = false; + + onWeightsChange(value: WeightsSlidersValue): void { + this.currentWeights.set(value); + + // fires once with the query-param-aware initial state — use it to load + if (!this.hasLoadedInitial) { + this.hasLoadedInitial = true; + this.loadprojects(); + } + } + + onApplyWeights(value: WeightsSlidersValue): void { + this.currentWeights.set(value); + this.loadprojects(); + } + + private loadprojects(): void { + const weights = this.currentWeights(); + + const requestPayload = { + manualKeywords: this.state.manualKeywords(), + extractedKeywords: this.state.extractedKeywords(), + keywords: this.state.keywords(), + softSearch: this.state.softSearch(), + weights: { + raw: weights.raw, + normalized: weights.normalized, + }, + }; + + console.log(requestPayload); + + /** + * TODO: + * this.projectsService.searchprojects(requestPayload).subscribe({ + * next: results => this.projects.set(results), + * error: error => console.error(error), + * }); + */ + } +} -- 2.56.1 From be72d28bdaf02b9cb9fc682630d0787db17c52a3 Mon Sep 17 00:00:00 2001 From: genja Date: Wed, 8 Jul 2026 03:29:04 +0200 Subject: [PATCH 6/9] created a template component for persons results for keyword search --- .../persons-results.component.html | 31 ++++ .../persons-results.component.scss | 29 ++++ .../persons-results.component.ts | 135 ++++++++++++++++++ 3 files changed, 195 insertions(+) create mode 100644 webapp/src/app/modules/keywords-search/search-results/persons-results/persons-results.component.html create mode 100644 webapp/src/app/modules/keywords-search/search-results/persons-results/persons-results.component.scss create mode 100644 webapp/src/app/modules/keywords-search/search-results/persons-results/persons-results.component.ts diff --git a/webapp/src/app/modules/keywords-search/search-results/persons-results/persons-results.component.html b/webapp/src/app/modules/keywords-search/search-results/persons-results/persons-results.component.html new file mode 100644 index 00000000..a97b0264 --- /dev/null +++ b/webapp/src/app/modules/keywords-search/search-results/persons-results/persons-results.component.html @@ -0,0 +1,31 @@ +
+ + + groups +

Personenliste

+

+ Die aktuelle Gewichtung ist unter normalized verfügbar. +

+
+
+ + + + + + +
diff --git a/webapp/src/app/modules/keywords-search/search-results/persons-results/persons-results.component.scss b/webapp/src/app/modules/keywords-search/search-results/persons-results/persons-results.component.scss new file mode 100644 index 00000000..ffeea20d --- /dev/null +++ b/webapp/src/app/modules/keywords-search/search-results/persons-results/persons-results.component.scss @@ -0,0 +1,29 @@ +/* ============================================================ + RESULT LAYOUT + ============================================================ */ +.result-layout { + display: grid; + grid-template-columns: minmax(300px, 420px) 1fr; + grid-template-areas: 'summary results'; + gap: 0.75rem; + align-items: start; +} + +.search-summary-card { + grid-area: summary; +} + +.results-card { + grid-area: results; +} + +.search-summary-card, +.results-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; + } +} diff --git a/webapp/src/app/modules/keywords-search/search-results/persons-results/persons-results.component.ts b/webapp/src/app/modules/keywords-search/search-results/persons-results/persons-results.component.ts new file mode 100644 index 00000000..533c28e7 --- /dev/null +++ b/webapp/src/app/modules/keywords-search/search-results/persons-results/persons-results.component.ts @@ -0,0 +1,135 @@ +import { Component, inject, signal } from '@angular/core'; + +import { MatCardModule } from '@angular/material/card'; +import { MatIconModule } from '@angular/material/icon'; + +import { + WeightMap, + WeightSliderOption, + WeightsSlidersComponent, + WeightsSlidersValue, +} from '../../../../shared/ui/weights-sliders/weights-sliders.component'; + +import { SearchResultsStateService } from '../search-results-state.service'; + +@Component({ + selector: 'app-persons-results', + standalone: true, + imports: [MatCardModule, MatIconModule, WeightsSlidersComponent], + templateUrl: './persons-results.component.html', + styleUrl: './persons-results.component.scss', +}) +export class KeywordsToPersonsResultsComponent { + // injects the state set by the parent route — no duplicate parsing here + private readonly state = inject(SearchResultsStateService); + + readonly defaultWeights: WeightMap = { + publications: 0.5, + citations: 0.5, + patents: 0.5, + projects: 0.5, + mediaVisibility: 0.5, + }; + + readonly weightOptions: WeightSliderOption[] = [ + { + key: 'publications', + label: 'Publikationen', + icon: 'article', + description: + 'Gewichtet die Anzahl und Relevanz wissenschaftlicher Arbeiten.', + defaultValue: 0.5, + queryParamName: 'wPublications', + }, + { + key: 'citations', + label: 'Zitationen', + icon: 'format_quote', + description: 'Gewichtet wissenschaftlichen Einfluss über Zitationen.', + defaultValue: 0.5, + queryParamName: 'wCitations', + }, + { + key: 'patents', + label: 'Patente', + icon: 'workspace_premium', + description: 'Gewichtet Innovations- und Transferleistung.', + defaultValue: 0.5, + queryParamName: 'wPatents', + }, + { + key: 'projects', + label: 'Projekte', + icon: 'account_tree', + description: 'Gewichtet Beteiligung an relevanten Forschungsprojekten.', + defaultValue: 0.5, + queryParamName: 'wProjects', + }, + { + key: 'mediaVisibility', + label: 'Medien-Sichtbarkeit', + icon: 'visibility', + description: 'Gewichtet öffentliche und mediale Sichtbarkeit.', + defaultValue: 0.5, + queryParamName: 'wMedia', + }, + ]; + + readonly currentWeights = signal({ + raw: this.defaultWeights, + normalized: { + publications: 0.2, + citations: 0.2, + patents: 0.2, + projects: 0.2, + mediaVisibility: 0.2, + }, + rawSum: 2.5, + normalizedSum: 1, + valid: true, + }); + + readonly persons = signal([]); // placeholder until the results service lands + + private hasLoadedInitial = false; + + onWeightsChange(value: WeightsSlidersValue): void { + this.currentWeights.set(value); + + // fires once with the query-param-aware initial state — use it to load + if (!this.hasLoadedInitial) { + this.hasLoadedInitial = true; + this.loadPersons(); + } + } + + onApplyWeights(value: WeightsSlidersValue): void { + this.currentWeights.set(value); + this.loadPersons(); + } + + private loadPersons(): void { + const weights = this.currentWeights(); + + const requestPayload = { + manualKeywords: this.state.manualKeywords(), + extractedKeywords: this.state.extractedKeywords(), + keywords: this.state.keywords(), + softSearch: this.state.softSearch(), + weights: { + raw: weights.raw, + normalized: weights.normalized, + }, + }; + + console.log(requestPayload); + + /** + * TODO: + * this.personsService.searchPersons(requestPayload).subscribe({ + * next: results => this.persons.set(results), + * error: error => console.error(error), + * }); + */ + } +} -- 2.56.1 From 134055b8b91156f84a8d562a7a25911f40ed2b28 Mon Sep 17 00:00:00 2001 From: genja Date: Wed, 8 Jul 2026 03:29:26 +0200 Subject: [PATCH 7/9] created a template for projects results for keyword search --- .../projects-results.component.html | 31 +++++ .../projects-results.component.scss | 29 +++++ .../projects-results.component.ts | 111 ++++++++++++++++++ 3 files changed, 171 insertions(+) create mode 100644 webapp/src/app/modules/keywords-search/search-results/projects-results/projects-results.component.html create mode 100644 webapp/src/app/modules/keywords-search/search-results/projects-results/projects-results.component.scss create mode 100644 webapp/src/app/modules/keywords-search/search-results/projects-results/projects-results.component.ts diff --git a/webapp/src/app/modules/keywords-search/search-results/projects-results/projects-results.component.html b/webapp/src/app/modules/keywords-search/search-results/projects-results/projects-results.component.html new file mode 100644 index 00000000..d365ed77 --- /dev/null +++ b/webapp/src/app/modules/keywords-search/search-results/projects-results/projects-results.component.html @@ -0,0 +1,31 @@ +
+ + + groups +

Projectsliste

+

+ Die aktuelle Gewichtung ist unter normalized verfügbar. +

+
+
+ + + + + + +
diff --git a/webapp/src/app/modules/keywords-search/search-results/projects-results/projects-results.component.scss b/webapp/src/app/modules/keywords-search/search-results/projects-results/projects-results.component.scss new file mode 100644 index 00000000..ffeea20d --- /dev/null +++ b/webapp/src/app/modules/keywords-search/search-results/projects-results/projects-results.component.scss @@ -0,0 +1,29 @@ +/* ============================================================ + RESULT LAYOUT + ============================================================ */ +.result-layout { + display: grid; + grid-template-columns: minmax(300px, 420px) 1fr; + grid-template-areas: 'summary results'; + gap: 0.75rem; + align-items: start; +} + +.search-summary-card { + grid-area: summary; +} + +.results-card { + grid-area: results; +} + +.search-summary-card, +.results-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; + } +} diff --git a/webapp/src/app/modules/keywords-search/search-results/projects-results/projects-results.component.ts b/webapp/src/app/modules/keywords-search/search-results/projects-results/projects-results.component.ts new file mode 100644 index 00000000..d09d09db --- /dev/null +++ b/webapp/src/app/modules/keywords-search/search-results/projects-results/projects-results.component.ts @@ -0,0 +1,111 @@ +import { Component, inject, signal } from '@angular/core'; + +import { MatCardModule } from '@angular/material/card'; +import { MatIconModule } from '@angular/material/icon'; + +import { + WeightMap, + WeightSliderOption, + WeightsSlidersComponent, + WeightsSlidersValue, +} from '../../../../shared/ui/weights-sliders/weights-sliders.component'; +import { SearchResultsStateService } from '../search-results-state.service'; +@Component({ + selector: 'app-projects-results', + imports: [MatCardModule, MatIconModule, WeightsSlidersComponent], + templateUrl: './projects-results.component.html', + styleUrl: './projects-results.component.scss', +}) +export class KeywordsToProjectsResultsComponent { + // injects the state set by the parent route — no duplicate parsing here + private readonly state = inject(SearchResultsStateService); + + readonly defaultWeights: WeightMap = { + param1: 0.33, + param2: 0.33, + param3: 0.34, + }; + + readonly weightOptions: WeightSliderOption[] = [ + { + key: 'param1', + label: 'Parameter 1', + icon: 'workspace_premium', + description: 'Gewichtet Parameter 1.', + defaultValue: 0.5, + queryParamName: 'wParam1', + }, + { + key: 'param2', + label: 'Parameter 2', + icon: 'workspace_premium', + description: 'Gewichtet Parameter 2.', + defaultValue: 0.5, + queryParamName: 'wParam2', + }, + { + key: 'param3', + label: 'Parameter 3', + icon: 'workspace_premium', + description: 'Gewichtet Parameter 3.', + defaultValue: 0.5, + queryParamName: 'wParam3', + }, + ]; + + readonly currentWeights = signal({ + raw: this.defaultWeights, + normalized: { + param1: 0.33, + param2: 0.33, + param3: 0.34, + }, + rawSum: 2.5, + normalizedSum: 1, + valid: true, + }); + + readonly projects = signal([]); // placeholder until the results service lands + + private hasLoadedInitial = false; + + onWeightsChange(value: WeightsSlidersValue): void { + this.currentWeights.set(value); + + // fires once with the query-param-aware initial state — use it to load + if (!this.hasLoadedInitial) { + this.hasLoadedInitial = true; + this.loadprojects(); + } + } + + onApplyWeights(value: WeightsSlidersValue): void { + this.currentWeights.set(value); + this.loadprojects(); + } + + private loadprojects(): void { + const weights = this.currentWeights(); + + const requestPayload = { + manualKeywords: this.state.manualKeywords(), + extractedKeywords: this.state.extractedKeywords(), + keywords: this.state.keywords(), + softSearch: this.state.softSearch(), + weights: { + raw: weights.raw, + normalized: weights.normalized, + }, + }; + + console.log(requestPayload); + + /** + * TODO: + * this.projectsService.searchprojects(requestPayload).subscribe({ + * next: results => this.projects.set(results), + * error: error => console.error(error), + * }); + */ + } +} -- 2.56.1 From a6d30dd8977d8888d4d0491fbc13fe7eb39f4d89 Mon Sep 17 00:00:00 2001 From: genja Date: Wed, 8 Jul 2026 03:30:55 +0200 Subject: [PATCH 8/9] added navigate event to keywords-search on keyword click --- .../app/modules/news-detail/news-detail.component.html | 7 +++++++ .../app/modules/news-detail/news-detail.component.scss | 9 +++++++++ .../app/modules/news-detail/news-detail.component.ts | 10 ++++++++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/webapp/src/app/modules/news-detail/news-detail.component.html b/webapp/src/app/modules/news-detail/news-detail.component.html index 1857d060..4580694d 100644 --- a/webapp/src/app/modules/news-detail/news-detail.component.html +++ b/webapp/src/app/modules/news-detail/news-detail.component.html @@ -215,6 +215,13 @@

Vorgeschlagen durch das Schlüsselwort im Text:

+ + } + + + +
+ @for (option of options; track option.key) { +
+
+ @if (option.icon) { + {{ option.icon }} + } + {{ option.label }} +
+ + + + + +
+ {{ formatRawWeightLabel(weightControl(option.key).value) }} +
+
+ } +
+ + + @if (!weightsState().valid) { +
+ warning + Mindestens ein Gewicht > 0 +
+ } + + + @if (showApplyButton) { +
+ +
+ } + + diff --git a/webapp/src/app/shared/ui/weights-sliders/weights-sliders.component.scss b/webapp/src/app/shared/ui/weights-sliders/weights-sliders.component.scss new file mode 100644 index 00000000..592c7b7b --- /dev/null +++ b/webapp/src/app/shared/ui/weights-sliders/weights-sliders.component.scss @@ -0,0 +1,215 @@ +/* weights-sliders.component.scss */ + +$phone: 599px; +$tablet: 900px; +$touch-target: 44px; + +/* ============================================================ + CARD + ============================================================ */ +::ng-deep .weights-card { + background: var(--sg-surface, #fff); + border: 1px solid var(--sg-divider, rgba(0, 0, 0, 0.12)); + box-shadow: none; + + mat-card-content.mat-mdc-card-content { + padding: 0.5rem 0.5rem 0.25rem; /* compact bottom */ + border: none; + } +} + +/* ============================================================ + HEADER + ============================================================ */ +.weights-header { + display: flex; + align-items: center; + justify-content: space-between; + gap: 0.4rem; + margin-bottom: 0.3rem; + + h2 { + margin: 0; + font-size: 0.85rem; + font-weight: 650; + color: var(--sg-text-primary); + } + + button { + min-height: $touch-target; + padding: 0.2rem 0.4rem; + font-size: 0.75rem; + line-height: 1.2; + } +} + +/* ============================================================ + SLIDERS + ============================================================ */ +.weight-list { + display: flex; + flex-direction: column; + gap: 0.2rem; + margin-top: 0.1rem; +} + +.weight-row { + display: grid; + grid-template-columns: 1fr 1fr 40px; + align-items: center; + gap: 0.2rem; + min-height: 34px; + font-size: 0.8rem; +} + +.weight-label { + display: flex; + align-items: center; + gap: 0.2rem; + color: var(--sg-text-primary); + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + + .icon-small { + font-size: 14px; + width: 14px; + height: 14px; + color: var(--sg-text-secondary); + } + + span { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + font-weight: 500; + } +} + +.weight-slider { + width: 100%; + height: 20px; /* reduced from 24px */ + margin: 0; +} + +.weight-value { + font-size: 0.75rem; + font-weight: 650; + color: var(--sg-text-secondary); + text-align: right; + font-variant-numeric: tabular-nums; +} + +/* ============================================================ + WARNING + ============================================================ */ +.weight-warning { + display: flex; + align-items: center; + gap: 0.2rem; + margin-top: 0.2rem; + padding: 0.2rem 0.3rem; + border-radius: 3px; + background: color-mix(in srgb, #ff9800 12%, #ffffff); + color: #8a5200; + font-size: 0.7rem; + font-weight: 500; + + mat-icon { + font-size: 14px; + width: 14px; + height: 14px; + } +} + +/* ============================================================ + ACTIONS + ============================================================ */ +.weight-actions { + display: flex; + justify-content: flex-end; + margin-top: 0.3rem; + + button { + min-height: $touch-target; + padding: 0.2rem 0.6rem; + font-size: 0.8rem; + } +} + +/* ============================================================ + TOOLTIP + ============================================================ */ +.tooltip-sm { + font-size: 0.75rem; + padding: 0.3rem 0.5rem; + max-width: 200px; + border-radius: 3px; + background: var(--sg-surface, #fff); + color: var(--sg-text-primary); + box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12); +} + +/* ============================================================ + TABLET & PHONE + ============================================================ */ +@media (max-width: $tablet) { + .weight-row { + grid-template-columns: 1fr 40px; + gap: 0.15rem; + padding: 0.1rem 0; + } + + .weight-label { + grid-column: 1 / -1; + font-size: 0.75rem; + } + + .weight-slider { + grid-column: 1 / 2; + } + + .weight-value { + grid-column: 2 / 3; + } + + .weight-actions { + position: sticky; + bottom: 0; + z-index: 5; + background: var(--sg-background, #fff); + padding: 0.4rem; + margin: 0.3rem -0.5rem -0.25rem -0.5rem; + box-shadow: 0 -2px 6px rgba(0, 0, 0, 0.06); + } +} + +@media (max-width: $phone) { + .weights-header { + flex-direction: column; + align-items: flex-start; + gap: 0.2rem; + } + + .weight-row { + gap: 0.1rem; + min-height: 30px; + } + + .weight-label { + font-size: 0.7rem; + } + + .weight-slider { + height: 18px; + } + + .weight-value { + font-size: 0.7rem; + } + + .weight-actions { + padding: 0.3rem; + margin: 0.2rem -0.4rem -0.2rem -0.4rem; + } +} diff --git a/webapp/src/app/shared/ui/weights-sliders/weights-sliders.component.ts b/webapp/src/app/shared/ui/weights-sliders/weights-sliders.component.ts new file mode 100644 index 00000000..436499ff --- /dev/null +++ b/webapp/src/app/shared/ui/weights-sliders/weights-sliders.component.ts @@ -0,0 +1,430 @@ +import { + Component, + DestroyRef, + EventEmitter, + Input, + OnChanges, + OnInit, + Output, + SimpleChanges, + inject, + signal, +} from '@angular/core'; +import { FormControl, FormRecord, ReactiveFormsModule } from '@angular/forms'; +import { ActivatedRoute, Router } from '@angular/router'; +import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; +import { debounceTime, skip } from 'rxjs'; + +import { MatButtonModule } from '@angular/material/button'; +import { MatCardModule } from '@angular/material/card'; +import { MatDividerModule } from '@angular/material/divider'; +import { MatIconModule } from '@angular/material/icon'; +import { MatSliderModule } from '@angular/material/slider'; +import { MatTooltipModule } from '@angular/material/tooltip'; + +export interface WeightSliderOption { + key: string; + label: string; + icon?: string; + description?: string; + + /** + * Optional default raw weight. + * Must be between 0 and 1. + */ + defaultValue?: number; + + /** + * Optional explicit query param name. + * If not set, queryParamPrefix + key is used. + */ + queryParamName?: string; +} + +export type WeightMap = Record; + +export interface WeightsSlidersValue { + raw: WeightMap; + normalized: WeightMap; + rawSum: number; + normalizedSum: number; + valid: boolean; +} + +@Component({ + selector: 'app-weights-sliders', + standalone: true, + imports: [ + ReactiveFormsModule, + MatButtonModule, + MatCardModule, + MatDividerModule, + MatIconModule, + MatSliderModule, + MatTooltipModule, + ], + templateUrl: './weights-sliders.component.html', + styleUrl: './weights-sliders.component.scss', +}) +export class WeightsSlidersComponent implements OnInit, OnChanges { + private readonly router = inject(Router); + private readonly route = inject(ActivatedRoute); + private readonly destroyRef = inject(DestroyRef); + @Input({ required: true }) options: WeightSliderOption[] = []; + + @Input() title = 'Suchgewichtung'; + + @Input() description = + 'Werte zwischen 0 und 1. Die normalisierte Gewichtung wird durch Sum-Normalisierung berechnet und ergibt zusammen 1.'; + + @Input() resetLabel = 'Ausgewogen'; + + @Input() applyLabel = 'Ergebnisse neu gewichten'; + + @Input() normalizedTitle = 'Normalisierte Gewichtung'; + + @Input() showApplyButton = true; + + @Input() showResetButton = true; + + @Input() showNormalizedPreview = true; + + @Input() showDescriptions = true; + + @Input() persistInQueryParams = true; + + /** + * If option.queryParamName is not set, the query param becomes: + * queryParamPrefix + option.key + * + * Example: + * queryParamPrefix = 'personW_' + * key = 'publications' + * query param = personW_publications + */ + @Input() queryParamPrefix = 'w_'; + + /** + * Initial raw values from parent. + * Example: + * { + * publications: 0.5, + * citations: 0.2 + * } + */ + @Input() initialWeights: Partial | null = null; + + /** + * If old values like 50 or 80 arrive, they can be converted to 0.5 / 0.8. + */ + @Input() convertPercentValues = true; + + @Input() min = 0; + + @Input() max = 1; + + @Input() step = 0.05; + + @Input() decimals = 2; + + @Input() normalizedDecimals = 3; + + @Output() weightsChange = new EventEmitter(); + + @Output() applyWeights = new EventEmitter(); + + readonly form = new FormRecord>({}); + + readonly weightsState = signal({ + raw: {}, + normalized: {}, + rawSum: 0, + normalizedSum: 0, + valid: false, + }); + + private initialized = false; + private isOwnNavigation = false; + + constructor() { + this.form.valueChanges + .pipe(debounceTime(250), takeUntilDestroyed(this.destroyRef)) + .subscribe(() => { + this.updateState({ + emit: true, + persist: this.persistInQueryParams, + }); + }); + } + + ngOnInit(): void { + this.rebuildForm(); + + if (this.persistInQueryParams) { + this.patchWeightsFromQueryParams(); + } + + this.updateState({ + emit: true, + persist: false, + }); + + this.initialized = true; + + if (this.persistInQueryParams) { + this.route.queryParamMap + .pipe(skip(1), takeUntilDestroyed(this.destroyRef)) + .subscribe(() => { + if (this.isOwnNavigation) { + this.isOwnNavigation = false; + return; + } + + this.patchWeightsFromQueryParams(); + + this.updateState({ + emit: true, + persist: false, + }); + }); + } + } + + ngOnChanges(changes: SimpleChanges): void { + if ( + changes['options'] || + changes['initialWeights'] || + changes['min'] || + changes['max'] + ) { + this.rebuildForm(); + + if (this.initialized) { + if (this.persistInQueryParams) { + this.patchWeightsFromQueryParams(); + } + + this.updateState({ + emit: true, + persist: false, + }); + } + } + } + + weightControl(key: string): FormControl { + const control = this.form.controls[key]; + + if (!control) { + throw new Error(`Weight control "${key}" does not exist.`); + } + + return control; + } + + formatRawWeightLabel = (value: number): string => { + return Number(value).toFixed(this.decimals); + }; + + formatNormalizedWeight(value: number): string { + return Number(value).toFixed(this.normalizedDecimals); + } + + resetWeights(): void { + const nextValues: WeightMap = {}; + + for (const option of this.options) { + nextValues[option.key] = this.sanitizeWeightValue( + option.defaultValue ?? 0.5, + ); + } + + this.form.setValue(nextValues); + } + + onApplyClick(): void { + const value = this.calculateValue(); + + this.updateState({ + emit: true, + persist: this.persistInQueryParams, + }); + + this.applyWeights.emit(value); + } + + normalizedEntries(): Array<{ + key: string; + label: string; + value: number; + }> { + const normalized = this.weightsState().normalized; + + return this.options.map((option) => ({ + key: option.key, + label: option.label, + value: normalized[option.key] ?? 0, + })); + } + + private rebuildForm(): void { + const wantedKeys = new Set(this.options.map((option) => option.key)); + + for (const existingKey of Object.keys(this.form.controls)) { + if (!wantedKeys.has(existingKey)) { + this.form.removeControl(existingKey); + } + } + + for (const option of this.options) { + const initialValue = this.resolveInitialValue(option); + + if (this.form.controls[option.key]) { + this.form.controls[option.key].setValue(initialValue, { + emitEvent: false, + }); + } else { + this.form.addControl( + option.key, + new FormControl(initialValue, { nonNullable: true }), + { emitEvent: false }, + ); + } + } + } + + private resolveInitialValue(option: WeightSliderOption): number { + const fromInput = this.initialWeights?.[option.key]; + + if (fromInput !== undefined && fromInput !== null) { + return this.sanitizeWeightValue(fromInput); + } + + return this.sanitizeWeightValue(option.defaultValue ?? 0.5); + } + + private patchWeightsFromQueryParams(): void { + const queryParams = this.route.snapshot.queryParamMap; + const patch: Record = {}; + + for (const option of this.options) { + const queryParamName = this.getQueryParamName(option); + const rawValue = queryParams.get(queryParamName); + + if (rawValue === null) continue; + + patch[option.key] = this.sanitizeWeightValue(rawValue); + } + + if (Object.keys(patch).length > 0) { + this.form.patchValue(patch, { emitEvent: false }); + } + } + + private updateState(config: { emit: boolean; persist: boolean }): void { + const value = this.calculateValue(); + + this.weightsState.set(value); + + if (config.persist) { + this.updateQueryParams(value.raw); + } + + if (config.emit) { + this.weightsChange.emit(value); + } + } + + private calculateValue(): WeightsSlidersValue { + const raw = this.getRawWeights(); + const rawSum = this.sumWeights(raw); + const normalized = this.sumNormalize(raw, rawSum); + const normalizedSum = this.sumWeights(normalized); + + return { + raw, + normalized, + rawSum, + normalizedSum, + valid: rawSum > 0, + }; + } + + private getRawWeights(): WeightMap { + const rawFormValue = this.form.getRawValue(); + const result: WeightMap = {}; + + for (const option of this.options) { + result[option.key] = this.sanitizeWeightValue(rawFormValue[option.key]); + } + + return result; + } + + private sumNormalize(raw: WeightMap, rawSum: number): WeightMap { + const normalized: WeightMap = {}; + + for (const option of this.options) { + if (rawSum <= 0 || !Number.isFinite(rawSum)) { + normalized[option.key] = 0; + } else { + normalized[option.key] = raw[option.key] / rawSum; + } + } + + return normalized; + } + + private sumWeights(weights: WeightMap): number { + return Object.values(weights).reduce((sum, value) => sum + value, 0); + } + + private updateQueryParams(rawWeights: WeightMap): void { + const queryParams: Record = {}; + + for (const option of this.options) { + const queryParamName = this.getQueryParamName(option); + const value = rawWeights[option.key] ?? 0; + + queryParams[queryParamName] = Number(value.toFixed(this.decimals)); + } + + this.isOwnNavigation = true; + + this.router + .navigate([], { + relativeTo: this.route, + queryParams, + queryParamsHandling: 'merge', + replaceUrl: true, + }) + .then((navigated) => { + if (!navigated) { + this.isOwnNavigation = false; + } + }); + } + + private getQueryParamName(option: WeightSliderOption): string { + return option.queryParamName ?? `${this.queryParamPrefix}${option.key}`; + } + + private sanitizeWeightValue(value: unknown): number { + const parsed = Number(value); + + if (!Number.isFinite(parsed)) { + return 0; + } + + let normalizedInput = parsed; + + if (this.convertPercentValues && this.max === 1 && parsed > 1) { + normalizedInput = parsed / 100; + } + + return Math.min( + this.max, + Math.max(this.min, Number(normalizedInput.toFixed(this.decimals))), + ); + } +} -- 2.56.1