diff --git a/service/src/main/inse/dashboard/model.py b/service/src/main/inse/dashboard/model.py index 82759df4..e6ee4b3d 100644 --- a/service/src/main/inse/dashboard/model.py +++ b/service/src/main/inse/dashboard/model.py @@ -34,6 +34,14 @@ class BmbfProjectStatusStatistics(BaseModel): completed: int +class DfgProjectStatusStatistics(BaseModel): + institution_id: str + organization_name: str + ongoing: int + upcoming: int + completed: int + + class DfgProjectTopic(BaseModel): id: str name: str diff --git a/service/src/main/inse/dashboard/router.py b/service/src/main/inse/dashboard/router.py index 611e3a4e..e265fcb1 100644 --- a/service/src/main/inse/dashboard/router.py +++ b/service/src/main/inse/dashboard/router.py @@ -12,6 +12,7 @@ from .model import ( BmbfProjectStatusStatistics, DashboardStatisticValue, DashboardStatistics, + DfgProjectStatusStatistics, DfgProjectTopics, EuProjectStatusStatistics, TopAuthorStatistics, @@ -22,6 +23,7 @@ from .service import ( get_dashboard_bmbf_project_statuses, get_dashboard_bmbf_projects, get_dashboard_dfg_projects, + get_dashboard_dfg_project_statuses, get_dashboard_dfg_topics, get_dashboard_eu_projects, get_dashboard_eu_project_statuses, @@ -210,6 +212,26 @@ async def dashboard_dfg_projects( ) +@router.get( + "/projects/dfg/status", + operation_id="getDashboardDfgProjectStatuses", + response_model=DfgProjectStatusStatistics, +) +async def dashboard_dfg_project_statuses( + from_year: int | None = Query(default=None, ge=1900, le=2100), + to_year: int | None = Query(default=None, ge=1900, le=2100), + session: Session = Depends(get_session), + access_token: AccessToken = auth_service.CurrentUserAccessTokenPayloadDep, +) -> DfgProjectStatusStatistics: + organization = get_dashboard_organization(session, access_token) + return await get_dashboard_dfg_project_statuses( + organization.openalex_institution_id, + organization.name, + from_year=from_year, + to_year=to_year, + ) + + @router.get( "/projects/dfg/topics", operation_id="getDashboardDfgProjectTopics", diff --git a/service/src/main/inse/dashboard/service.py b/service/src/main/inse/dashboard/service.py index d855b91a..6c2b52f9 100644 --- a/service/src/main/inse/dashboard/service.py +++ b/service/src/main/inse/dashboard/service.py @@ -25,6 +25,7 @@ from .model import ( DashboardStatisticValue, DashboardStatistics, DfgProjectTopic, + DfgProjectStatusStatistics, DfgProjectTopics, EuProjectStatusStatistics, TopAuthor, @@ -495,6 +496,108 @@ async def get_dashboard_dfg_projects( ) +async def get_dashboard_dfg_project_statuses( + institution_id: str, + organization_name: str, + from_year: int | None = None, + to_year: int | None = None, +) -> DfgProjectStatusStatistics: + normalized_id = _normalize_institution_id(institution_id) + period = _dashboard_period(from_year, to_year) + project_ids = await _get_dfg_project_ids_for_institution( + normalized_id, + ) + if not project_ids: + return DfgProjectStatusStatistics( + institution_id=normalized_id, + organization_name=organization_name, + ongoing=0, + upcoming=0, + completed=0, + ) + + selected_project_filters: list[dict[str, Any]] = [ + { + "terms": { + "projects.project_id": [ + int(project_id) for project_id in project_ids + ] + } + } + ] + if period_filter := _project_overlap_filter( + "projects.funding_start", + "projects.funding_end", + period, + missing_end_is_ongoing=True, + ): + selected_project_filters.append(period_filter) + + response = await elasticsearch.search( + index=ESIndex.DFG_INSTITUTES_V2, + body={ + "size": 0, + "aggs": { + "projects_nested": { + "nested": {"path": "projects"}, + "aggs": { + "selected_projects": { + "filter": ( + selected_project_filters[0] + if len(selected_project_filters) == 1 + else {"bool": {"filter": selected_project_filters}} + ), + "aggs": { + "ongoing": { + "filter": { + "match_phrase": { + "projects.status_de": "laufend" + } + }, + "aggs": { + "projects": { + "cardinality": { + "field": "projects.project_id" + } + } + }, + }, + "completed": { + "filter": { + "match_phrase": { + "projects.status_de": "abgeschlossen" + } + }, + "aggs": { + "projects": { + "cardinality": { + "field": "projects.project_id" + } + } + }, + }, + }, + } + }, + } + }, + }, + cluster=ESCluster.INSE, + ) + aggregations = ( + response.get("aggregations", {}) + .get("projects_nested", {}) + .get("selected_projects", {}) + ) + return DfgProjectStatusStatistics( + institution_id=normalized_id, + organization_name=organization_name, + ongoing=_project_status_count(aggregations, "ongoing"), + upcoming=0, + completed=_project_status_count(aggregations, "completed"), + ) + + async def get_dashboard_dfg_topics( institution_id: str, organization_name: str, diff --git a/service/src/main/inse/dashboard/test_service.py b/service/src/main/inse/dashboard/test_service.py index 182c0162..82120462 100644 --- a/service/src/main/inse/dashboard/test_service.py +++ b/service/src/main/inse/dashboard/test_service.py @@ -14,6 +14,7 @@ from inse.authors.institution_membership_query import ( from inse.dashboard.service import ( get_dashboard_bmbf_project_statuses, get_dashboard_organization, + get_dashboard_dfg_project_statuses, get_dashboard_dfg_topics, get_dashboard_eu_project_statuses, get_dashboard_patents, @@ -227,6 +228,102 @@ async def test_dashboard_bmbf_project_statuses_uses_funding_dates(): } +@pytest.mark.anyio +async def test_dashboard_dfg_project_statuses_uses_nested_status_de(): + with patch( + "inse.dashboard.service._get_dfg_project_ids_for_institution", + new=AsyncMock(return_value=["123", "456"]), + ) as project_ids, patch( + "inse.dashboard.service.elasticsearch.search", + new=AsyncMock( + return_value={ + "aggregations": { + "projects_nested": { + "selected_projects": { + "ongoing": {"projects": {"value": 1}}, + "completed": {"projects": {"value": 1}}, + } + } + } + } + ), + ) as search: + result = await get_dashboard_dfg_project_statuses( + ORG_INSTITUTION_ID, + "Example Org", + from_year=2020, + to_year=2024, + ) + + project_ids.assert_awaited_once_with( + ORG_INSTITUTION_ID, + ) + assert result.model_dump() == { + "institution_id": ORG_INSTITUTION_ID, + "organization_name": "Example Org", + "ongoing": 1, + "upcoming": 0, + "completed": 1, + } + call = search.await_args + assert call.kwargs["index"] == ESIndex.DFG_INSTITUTES_V2 + selected = call.kwargs["body"]["aggs"]["projects_nested"]["aggs"][ + "selected_projects" + ] + assert selected["filter"] == { + "bool": { + "filter": [ + {"terms": {"projects.project_id": [123, 456]}}, + { + "bool": { + "filter": [ + { + "range": { + "projects.funding_start": {"lte": 2024} + } + }, + { + "bool": { + "should": [ + { + "range": { + "projects.funding_end": { + "gte": 2020 + } + } + }, + { + "bool": { + "must_not": { + "exists": { + "field": "projects.funding_end" + } + } + } + }, + ], + "minimum_should_match": 1, + } + }, + ] + } + }, + ] + } + } + assert selected["aggs"]["ongoing"]["filter"] == { + "match_phrase": {"projects.status_de": "laufend"} + } + assert selected["aggs"]["completed"]["filter"] == { + "match_phrase": {"projects.status_de": "abgeschlossen"} + } + assert all( + selected["aggs"][status]["aggs"]["projects"]["cardinality"]["field"] + == "projects.project_id" + for status in ("ongoing", "completed") + ) + + @pytest.mark.anyio async def test_dashboard_statistics_counts_organization_data_and_all_projects(): async def search(**kwargs): diff --git a/service/src/main/inse/topics/v2/service.py b/service/src/main/inse/topics/v2/service.py index 2538b860..b73379d8 100644 --- a/service/src/main/inse/topics/v2/service.py +++ b/service/src/main/inse/topics/v2/service.py @@ -74,7 +74,27 @@ async def search_topics( query = None if search_term: - query = {"match_phrase_prefix": {"display_name": search_term}} + search_terms = [ + term.strip() for term in search_term.split(",") if term.strip() + ] + if len(search_terms) == 1: + query = { + "match_phrase_prefix": {"display_name": search_terms[0]} + } + elif search_terms: + query = { + "bool": { + "should": [ + { + "match_phrase_prefix": { + "display_name": search_term + } + } + for search_term in search_terms + ], + "minimum_should_match": 1, + } + } return await _search_topics( page=page, diff --git a/service/src/main/inse/topics/v2/test_service.py b/service/src/main/inse/topics/v2/test_service.py new file mode 100644 index 00000000..02d97a0a --- /dev/null +++ b/service/src/main/inse/topics/v2/test_service.py @@ -0,0 +1,41 @@ +from unittest.mock import AsyncMock, patch + +import pytest + +from inse.topics.v2.service import search_topics + + +@pytest.fixture +def anyio_backend(): + return "asyncio" + + +@pytest.mark.anyio +async def test_search_topics_treats_comma_separated_terms_as_alternatives(): + with patch( + "inse.topics.v2.service.elasticsearch.search", + new=AsyncMock( + return_value={ + "hits": {"hits": [], "total": {"value": 0}} + } + ), + ) as search: + await search_topics("Artificial Intelligence, Machine Learning") + + assert search.await_args.kwargs["query"] == { + "bool": { + "should": [ + { + "match_phrase_prefix": { + "display_name": "Artificial Intelligence" + } + }, + { + "match_phrase_prefix": { + "display_name": "Machine Learning" + } + }, + ], + "minimum_should_match": 1, + } + } diff --git a/webapp/src/app/app.routes.ts b/webapp/src/app/app.routes.ts index 35393b5c..1a63d1a6 100644 --- a/webapp/src/app/app.routes.ts +++ b/webapp/src/app/app.routes.ts @@ -758,9 +758,14 @@ export const routes: Routes = [ topicPage: topicPageResolver, }, runGuardsAndResolvers: (from, to) => { - return Object.values(topicQueryParamKeys).some( - (key) => from.queryParamMap.get(key) !== to.queryParamMap.get(key), - ); + return Object.values(topicQueryParamKeys).some((key) => { + const fromValues = from.queryParamMap.getAll(key); + const toValues = to.queryParamMap.getAll(key); + return ( + fromValues.length !== toValues.length || + fromValues.some((value, index) => value !== toValues[index]) + ); + }); }, }, { diff --git a/webapp/src/app/modules/dashboard/dashboard-statistics.service.ts b/webapp/src/app/modules/dashboard/dashboard-statistics.service.ts index 79a5e80d..89af4d00 100644 --- a/webapp/src/app/modules/dashboard/dashboard-statistics.service.ts +++ b/webapp/src/app/modules/dashboard/dashboard-statistics.service.ts @@ -44,6 +44,14 @@ export interface BmbfProjectStatusStatistics { completed: number; } +export interface DfgProjectStatusStatistics { + institution_id: string; + organization_name: string; + ongoing: number; + upcoming: number; + completed: number; +} + export interface DfgProjectTopic { id: string; name: string; @@ -149,6 +157,15 @@ export class DashboardStatisticsService { ); } + getDfgProjectStatuses( + period: DashboardPeriodBounds = {}, + ): Observable { + return this.httpClient.get( + `${this.apiConfiguration?.basePath ?? ''}/api/dashboard/projects/dfg/status`, + { params: this.periodParams(period) }, + ); + } + getBmbfProjectCount( period: DashboardPeriodBounds = {}, ): Observable { diff --git a/webapp/src/app/modules/dashboard/dashboard.component.html b/webapp/src/app/modules/dashboard/dashboard.component.html index 21a02f91..e4ec19bb 100644 --- a/webapp/src/app/modules/dashboard/dashboard.component.html +++ b/webapp/src/app/modules/dashboard/dashboard.component.html @@ -165,20 +165,22 @@ @if ( euProjectStatusesLoading || bmbfProjectStatusesLoading || + dfgProjectStatusesLoading || euProjectStatusesError || bmbfProjectStatusesError || - (euProjectStatuses && bmbfProjectStatuses) + dfgProjectStatusesError || + (euProjectStatuses && bmbfProjectStatuses && dfgProjectStatuses) ) {

Projektstatus nach Fördergeber

- Laufende, kommende und abgeschlossene EU- und Bund-Projekte Ihrer - Organisation. + Laufende, kommende und abgeschlossene EU-, Bund- und DFG-Projekte + Ihrer Organisation.

- @if (euProjectStatuses && bmbfProjectStatuses) { + @if (euProjectStatuses && bmbfProjectStatuses && dfgProjectStatuses) {
EU: @@ -196,11 +198,23 @@ bmbfProjectStatuses.completed | number }} + + DFG: + {{ + dfgProjectStatuses.ongoing + + dfgProjectStatuses.upcoming + + dfgProjectStatuses.completed | number + }} +
}
- @if (euProjectStatusesLoading || bmbfProjectStatusesLoading) { + @if ( + euProjectStatusesLoading || + bmbfProjectStatusesLoading || + dfgProjectStatusesLoading + ) {
- } @else if (euProjectStatusesError || bmbfProjectStatusesError) { + } @else if ( + euProjectStatusesError || + bmbfProjectStatusesError || + dfgProjectStatusesError + ) {

- Der Status der EU- und Bund-Projekte konnte nicht geladen werden. + Der Status der EU-, Bund- und DFG-Projekte konnte nicht geladen + werden.

- } @else if (euProjectStatuses && bmbfProjectStatuses) { + } @else if ( + euProjectStatuses && bmbfProjectStatuses && dfgProjectStatuses + ) { + [bmbfStatuses]="bmbfProjectStatuses" + [dfgStatuses]="dfgProjectStatuses"> }
} diff --git a/webapp/src/app/modules/dashboard/dashboard.component.ts b/webapp/src/app/modules/dashboard/dashboard.component.ts index 204895cc..fed48f09 100644 --- a/webapp/src/app/modules/dashboard/dashboard.component.ts +++ b/webapp/src/app/modules/dashboard/dashboard.component.ts @@ -23,6 +23,7 @@ import { DashboardStatisticValue, DashboardStatistics, DashboardStatisticsService, + DfgProjectStatusStatistics, DfgProjectTopics, EuProjectStatusStatistics, TopAuthor, @@ -101,6 +102,9 @@ export class DashboardComponent implements OnInit { bmbfProjectStatuses?: BmbfProjectStatusStatistics; bmbfProjectStatusesLoading = false; bmbfProjectStatusesError = false; + dfgProjectStatuses?: DfgProjectStatusStatistics; + dfgProjectStatusesLoading = false; + dfgProjectStatusesError = false; readonly topicTreemapMinYear = 1900; readonly topicTreemapMaxYear = new Date().getFullYear(); dashboardPeriodMode: DashboardPeriodMode = 'all_time'; @@ -125,6 +129,7 @@ export class DashboardComponent implements OnInit { this.loadDfgProjectTopics(); this.loadEuProjectStatuses(); this.loadBmbfProjectStatuses(); + this.loadDfgProjectStatuses(); } private loadStatistics(): void { @@ -281,12 +286,17 @@ export class DashboardComponent implements OnInit { } onTopicTreemapTopicSelect(topic: TopicTreemapTopicSelect): void { + const period = this.selectedPeriodBounds(); this.dialog.open( TopicWordCloudDialogComponent, { width: '85vw', maxWidth: '92vw', - data: topic, + data: { + ...topic, + fromYear: period.fromYear, + toYear: period.toYear, + }, }, ); } @@ -368,6 +378,7 @@ export class DashboardComponent implements OnInit { this.loadDfgProjectTopics(); this.loadEuProjectStatuses(); this.loadBmbfProjectStatuses(); + this.loadDfgProjectStatuses(); } private loadStatistic( @@ -479,6 +490,22 @@ export class DashboardComponent implements OnInit { }); } + private loadDfgProjectStatuses(): void { + this.dfgProjectStatusesLoading = true; + this.dfgProjectStatusesError = false; + this.statisticsService + .getDfgProjectStatuses(this.selectedPeriodBounds()) + .pipe(finalize(() => (this.dfgProjectStatusesLoading = false))) + .subscribe({ + next: (statuses) => { + this.dfgProjectStatuses = statuses; + }, + error: () => { + this.dfgProjectStatusesError = true; + }, + }); + } + private loadTopicTreemap(): void { if (this.dashboardFromYear > this.dashboardToYear) { this.topicTreemapLoading = false; diff --git a/webapp/src/app/modules/dashboard/eu-project-status-chart/eu-project-status-chart.component.ts b/webapp/src/app/modules/dashboard/eu-project-status-chart/eu-project-status-chart.component.ts index 7725cf65..d151b221 100644 --- a/webapp/src/app/modules/dashboard/eu-project-status-chart/eu-project-status-chart.component.ts +++ b/webapp/src/app/modules/dashboard/eu-project-status-chart/eu-project-status-chart.component.ts @@ -4,6 +4,7 @@ import { NgxEchartsDirective } from 'ngx-echarts'; import { BmbfProjectStatusStatistics, + DfgProjectStatusStatistics, EuProjectStatusStatistics, } from '../dashboard-statistics.service'; @@ -16,6 +17,7 @@ import { export class EuProjectStatusChartComponent implements OnChanges { @Input({ required: true }) statuses!: EuProjectStatusStatistics; @Input({ required: true }) bmbfStatuses!: BmbfProjectStatusStatistics; + @Input({ required: true }) dfgStatuses!: DfgProjectStatusStatistics; options: EChartsOption = {}; @@ -23,12 +25,20 @@ export class EuProjectStatusChartComponent implements OnChanges { const values = [ { name: 'Laufend', - data: [this.statuses?.ongoing ?? 0, this.bmbfStatuses?.ongoing ?? 0], + data: [ + this.statuses?.ongoing ?? 0, + this.bmbfStatuses?.ongoing ?? 0, + this.dfgStatuses?.ongoing ?? 0, + ], color: '#2563eb', }, { name: 'Kommend', - data: [this.statuses?.upcoming ?? 0, this.bmbfStatuses?.upcoming ?? 0], + data: [ + this.statuses?.upcoming ?? 0, + this.bmbfStatuses?.upcoming ?? 0, + this.dfgStatuses?.upcoming ?? 0, + ], color: '#f59e0b', }, { @@ -36,6 +46,7 @@ export class EuProjectStatusChartComponent implements OnChanges { data: [ this.statuses?.completed ?? 0, this.bmbfStatuses?.completed ?? 0, + this.dfgStatuses?.completed ?? 0, ], color: '#64748b', }, @@ -69,7 +80,7 @@ export class EuProjectStatusChartComponent implements OnChanges { }, yAxis: { type: 'category', - data: ['EU-Projekte', 'Bund-Projekte'], + data: ['EU-Projekte', 'Bund-Projekte', 'DFG-Projekte'], axisTick: { show: false }, axisLine: { show: false }, axisLabel: { color: '#334155', fontWeight: 600 }, diff --git a/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.html b/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.html index cc7613ee..1433163c 100644 --- a/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.html +++ b/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.html @@ -91,16 +91,100 @@ Die Keywords konnten nicht geladen werden. } @else if (words.length) { +
+
+ + + Keyword-Auswahl + Klicken Sie auf Begriffe in der Wordcloud, um sie + auszuwählen. + +
+ +
+ @for (word of selectedWords(); track word.id) { + + } @empty { + Noch nichts ausgewählt + } +
+ +
+ @if (selectedWordIds.size) { + + } + + + Suche in Keywords + + + + Suche in Themen + +
+
+
@for (word of words; track word.id) { - + [title]="word.name + ': ' + word.count + ' Publikationen'" + (click)="toggleWord(word)"> {{ word.name }} - + }
} @else { diff --git a/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.scss b/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.scss index 5c110e84..76d9a95e 100644 --- a/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.scss +++ b/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.scss @@ -187,6 +187,113 @@ mat-dialog-content { font-weight: 700; } +.keyword-toolbar { + display: grid; + grid-template-columns: auto minmax(160px, 1fr) auto; + align-items: center; + gap: 14px; + padding: 10px 14px; + border-bottom: 1px solid #e8edf5; + background: #f8faff; +} + +.keyword-toolbar-label { + display: flex; + align-items: center; + gap: 8px; + color: #334155; + + > mat-icon { + width: 19px; + height: 19px; + color: #7255d9; + font-size: 19px; + } + + > span { + display: flex; + flex-direction: column; + gap: 1px; + } + + strong { + font-size: 0.75rem; + } + + small { + color: var(--sg-text-muted, #64708f); + font-size: 0.6875rem; + } +} + +.keyword-selection { + display: flex; + min-width: 0; + flex-wrap: wrap; + align-items: center; + gap: 6px; +} + +.keyword-chip { + display: inline-flex; + min-height: 28px; + align-items: center; + gap: 4px; + padding: 4px 7px 4px 9px; + border: 1px solid #c9bafa; + border-radius: 999px; + background: #f6f0ff; + color: #6347c8; + cursor: pointer; + font: inherit; + font-size: 0.6875rem; + font-weight: 600; + + mat-icon { + width: 14px; + height: 14px; + font-size: 14px; + } + + &:hover { + border-color: #a992ef; + background: #eee7ff; + } +} + +.keyword-selection-empty { + color: var(--sg-text-soft, #8a95b3); + font-size: 0.75rem; + font-style: italic; +} + +.keyword-clear { + white-space: nowrap; +} + +.keyword-toolbar-actions { + display: flex; + align-items: center; + justify-content: flex-end; + gap: 4px; + white-space: nowrap; +} + +.keyword-search { + mat-icon { + margin-right: 5px; + } +} + +.keyword-search--secondary { + background: #ffffff; +} + +.keyword-search--disabled { + pointer-events: none; + opacity: 0.45; +} + .word-cloud-chart { display: flex; min-height: 280px; @@ -211,9 +318,13 @@ mat-dialog-content { } .word-cloud-word { + appearance: none; padding: 3px 5px; + border: 1px solid transparent; border-radius: 6px; - cursor: help; + background: transparent; + cursor: pointer; + font-family: inherit; line-height: 1.1; text-align: center; transition: @@ -224,6 +335,18 @@ mat-dialog-content { background: rgba(241, 243, 247, 0.9); transform: translateY(-2px); } + + &:focus-visible { + outline: 3px solid rgba(114, 85, 217, 0.25); + outline-offset: 2px; + } +} + +.word-cloud-word--selected { + border-color: currentColor; + background: #ffffff; + box-shadow: 0 2px 8px rgba(51, 65, 85, 0.16); + transform: translateY(-2px); } .word-cloud-state { @@ -303,6 +426,20 @@ mat-dialog-content { gap: 10px 14px; padding: 24px 18px; } + + .keyword-toolbar { + grid-template-columns: 1fr auto; + } + + .keyword-toolbar-actions { + grid-column: 2; + grid-row: 1; + } + + .keyword-selection { + grid-column: 1 / -1; + grid-row: 2; + } } @media (prefers-reduced-motion: reduce) { diff --git a/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.ts b/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.ts index 9cbf52d2..50191ed8 100644 --- a/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.ts +++ b/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.ts @@ -1,9 +1,14 @@ import { CommonModule } from '@angular/common'; import { Component, DestroyRef, inject } from '@angular/core'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; -import { MAT_DIALOG_DATA, MatDialogModule } from '@angular/material/dialog'; +import { + MAT_DIALOG_DATA, + MatDialogModule, + MatDialogRef, +} from '@angular/material/dialog'; import { MatIconModule } from '@angular/material/icon'; import { MatButtonModule } from '@angular/material/button'; +import { RouterLink } from '@angular/router'; import { DashboardStatisticsService, @@ -28,16 +33,26 @@ interface DisplayWord extends TopicWordCloudWord { @Component({ selector: 'app-topic-wordcloud-dialog', standalone: true, - imports: [CommonModule, MatButtonModule, MatDialogModule, MatIconModule], + imports: [ + CommonModule, + MatButtonModule, + MatDialogModule, + MatIconModule, + RouterLink, + ], templateUrl: './topic-wordcloud-dialog.component.html', styleUrl: './topic-wordcloud-dialog.component.scss', }) export class TopicWordCloudDialogComponent { readonly data = inject(MAT_DIALOG_DATA); + private readonly dialogRef = inject( + MatDialogRef, + ); private readonly statisticsService = inject(DashboardStatisticsService); private readonly destroyRef = inject(DestroyRef); words: DisplayWord[] = []; + selectedWordIds = new Set(); loading = true; loadFailed = false; @@ -74,6 +89,42 @@ export class TopicWordCloudDialogComponent { }); } + toggleWord(word: DisplayWord): void { + const selected = new Set(this.selectedWordIds); + if (selected.has(word.id)) { + selected.delete(word.id); + } else { + selected.add(word.id); + } + this.selectedWordIds = selected; + } + + isWordSelected(word: DisplayWord): boolean { + return this.selectedWordIds.has(word.id); + } + + selectedWords(): DisplayWord[] { + return this.words.filter((word) => this.selectedWordIds.has(word.id)); + } + + selectedWordsQuery(): string { + return this.selectedWordNames().join(', '); + } + + selectedWordNames(): string[] { + return this.selectedWords().map((word) => word.name); + } + + clearSelection(): void { + this.selectedWordIds = new Set(); + } + + closeForSearchNavigation(): void { + if (this.selectedWordIds.size) { + this.dialogRef.close(); + } + } + private buildWords(words: TopicWordCloudWord[]): DisplayWord[] { if (!words.length) return []; const values = words.map((word) => word.count); diff --git a/webapp/src/app/modules/topics/topics.component.ts b/webapp/src/app/modules/topics/topics.component.ts index 1e017d27..c8e809f8 100644 --- a/webapp/src/app/modules/topics/topics.component.ts +++ b/webapp/src/app/modules/topics/topics.component.ts @@ -24,6 +24,7 @@ export class TopicsComponent { id: 'query', queryParamKey: topicQueryParamKeys.query, icon: 'search', + removable: true, }, ]; diff --git a/webapp/src/app/resolvers/topic-page.resolver.ts b/webapp/src/app/resolvers/topic-page.resolver.ts index 42122955..208d54f7 100644 --- a/webapp/src/app/resolvers/topic-page.resolver.ts +++ b/webapp/src/app/resolvers/topic-page.resolver.ts @@ -16,7 +16,13 @@ export const topicQueryParamKeys = { } as const; export const topicPageResolver: ResolveFn = (route, state) => { - const query = route.queryParamMap.get(topicQueryParamKeys.query) || undefined; + const query = + route.queryParamMap + .getAll(topicQueryParamKeys.query) + .flatMap((value) => value.split(',')) + .map((value) => value.trim()) + .filter(Boolean) + .join(', ') || undefined; const page = Number(route.queryParamMap.get(topicQueryParamKeys.page) ?? '0'); const size = Number( route.queryParamMap.get(topicQueryParamKeys.size) ?? '10',