From aca10c6242f2afe152d366bd8af5774285c2be50 Mon Sep 17 00:00:00 2001 From: Olli Mannevaara Date: Wed, 25 Oct 2023 17:20:34 +0300 Subject: [PATCH] Add total count to the new search. Improve the presentation of the new search. --- .../publications2.component.html | 236 +++++++++++------- .../publications2/publications2.component.ts | 12 +- .../components/results/results.component.html | 4 - .../search-bar2/search-bar2.component.html | 9 +- .../search-bar2/search-bar2.component.ts | 10 +- .../portal/services/publication2.service.ts | 9 + .../pagination/pagination.component.ts | 8 +- 7 files changed, 181 insertions(+), 107 deletions(-) diff --git a/src/app/portal/components/results/publications2/publications2.component.html b/src/app/portal/components/results/publications2/publications2.component.html index c773fb26c..ebcb27408 100644 --- a/src/app/portal/components/results/publications2/publications2.component.html +++ b/src/app/portal/components/results/publications2/publications2.component.html @@ -1,125 +1,177 @@ -
- - - +
+
-
- - -
+
+ -
-
Keywords: {{keywords}}
-
Search Parameters: {{searchParams$ | async | json}}
-
-
- - -
+ +
+ + + -
-
-
- + + - - - + +
+ {{tab}} +
+
- + +
+ {{tab}} +
+
+
+
- +
+
+

Julkaisut - {{total$ | async}}

+
-
- +
+ Näytetään tulokset 1 - 10 / 777912 - -
- - {{yearFilter.year}} - ({{yearFilter.count}}) -
-
-
+ - -
+ tulosta / sivu -
- - - - -
- - {{organizationFilter.name}} - ({{organizationFilter.count}}) -
-
-
+ Mitä julkaisutietoja palvelu sisältää? +
+
+ + + +
+
+
+
+ +
+
+ +
+ +
+
+ {{yearFilter.year}} +
+ +
+ ({{yearFilter.count}}) +
+
+ + +
+
+
+ +
+ +
+ +
+
+ +
+ +
+
+ {{organizationFilter.name}} +
+ +
+ ({{organizationFilter.count}}) +
+
+
+
+
+
-
-
-
+
+
- - + + - - -
-
{{yearFilter.year}}
- -
+ + +
+
{{yearFilter.year}}
+ +
+
-
-
+
- - - publicationName +
+ + + Julkaisun nimi + - -
-
-
+ +
+
+ - - authorsText + + + Tekijät + - -
-
-
+ +
+
+
- - publisherName + + + Julkaisukanava + - -
-
-
+ +
+
+
- - publicationYear + + + Julkaisuvuosi + - -
-
-
+ +
+
+
- - -
+ + + -
- +
+ +
diff --git a/src/app/portal/components/results/publications2/publications2.component.ts b/src/app/portal/components/results/publications2/publications2.component.ts index 07d47017e..ef3df9e4e 100644 --- a/src/app/portal/components/results/publications2/publications2.component.ts +++ b/src/app/portal/components/results/publications2/publications2.component.ts @@ -12,13 +12,15 @@ import { } from '@portal/services/publication2.service'; import { map, take } from 'rxjs/operators'; import { SharedModule } from '@shared/shared.module'; +import { SearchBar2Component } from '@portal/search-bar2/search-bar2.component'; @Component({ selector: 'app-publications2', templateUrl: './publications2.component.html', styleUrls: ['./publications2.component.scss'], imports: [CdkTableModule, FormsModule, AsyncPipe, JsonPipe, NgForOf, NgIf, - SharedModule // TODO not good? + SharedModule, FormsModule, //TODO not good? + SearchBar2Component, ], standalone: true }) @@ -27,7 +29,6 @@ export class Publications2Component implements OnDestroy { router = inject(Router); publications2Service = inject(Publication2Service); - // input and pagination inputs keywords = ""; page = 1; size = 10; @@ -43,7 +44,6 @@ export class Publications2Component implements OnDestroy { // TODO joka kerta uusi HTTP? organizationNames$ = this.publications2Service.getOrganizationNames(); - yearAdditions$ = this.aggregations$.pipe( map(aggs => getYearAdditions(aggs).map((bucket: any) => ({ year: bucket.key.toString(), count: bucket.doc_count })) ?? []), map(aggs => aggs.sort((a, b) => b.year - a.year)) @@ -79,6 +79,8 @@ export class Publications2Component implements OnDestroy { this.size = parseInt(searchParams.size?.[0] ?? "10"); }); + total$ = this.publications2Service.getTotal(); + ngOnDestroy() { this.searchParamsSubscription.unsubscribe(); } @@ -141,7 +143,11 @@ export class Publications2Component implements OnDestroy { }); } + public num = 0; + setPageSize(size: number) { + console.log(size); + this.router.navigate([], { relativeTo: this.route, queryParams: { size }, queryParamsHandling: 'merge' diff --git a/src/app/portal/components/results/results.component.html b/src/app/portal/components/results/results.component.html index d7031a138..2882283a1 100644 --- a/src/app/portal/components/results/results.component.html +++ b/src/app/portal/components/results/results.component.html @@ -8,10 +8,6 @@

-
- -
-
- + + -
diff --git a/src/app/portal/search-bar2/search-bar2.component.ts b/src/app/portal/search-bar2/search-bar2.component.ts index a59b944be..3df1cfd4b 100644 --- a/src/app/portal/search-bar2/search-bar2.component.ts +++ b/src/app/portal/search-bar2/search-bar2.component.ts @@ -1,4 +1,4 @@ -import { Component, inject } from '@angular/core'; +import { Component, EventEmitter, inject, Input, Output } from '@angular/core'; import { CommonModule } from '@angular/common'; import { MatRippleModule } from '@angular/material/core'; import { FormsModule } from '@angular/forms'; @@ -15,8 +15,12 @@ export class SearchBar2Component { route = inject(ActivatedRoute); router = inject(Router) - /* Input/Output for keywords; Keep the keyword management in the parent? */ - /* Can be changed later easily */ + // two-way "value" binding that's a string; basically text input + @Input() value = ""; + @Output() valueChange = new EventEmitter(); + + // search is pressed output + @Output() search = new EventEmitter(); public keywords = this.route.snapshot.queryParams.q ?? ""; diff --git a/src/app/portal/services/publication2.service.ts b/src/app/portal/services/publication2.service.ts index 35f56abe3..7de4e05a2 100644 --- a/src/app/portal/services/publication2.service.ts +++ b/src/app/portal/services/publication2.service.ts @@ -64,6 +64,10 @@ export class Publication2Service { shareReplay({ bufferSize: 1, refCount: true }) ); + resultsTotal$ = this.searchResults$.pipe( + map((data) => data.hits.total.value) + ); + publicationSearch$: Observable = this.searchResults$.pipe( map((data) => parsePublicationSearch(data)), map((publicationSearch: PublicationSearch) => this.createHighlightedPublications(publicationSearch)) @@ -77,6 +81,10 @@ export class Publication2Service { return this.publicationSearch$; } + getTotal() { + return this.resultsTotal$; + } + getAggregations() { return this.publicationAggregations$; } @@ -96,6 +104,7 @@ export class Publication2Service { return this.http.post('https://researchfi-api-qa.rahtiapp.fi/portalapi/publication/_search?', { from: from, size: size, + track_total_hits: true, query: { bool: { must: { diff --git a/src/app/shared/components/pagination/pagination.component.ts b/src/app/shared/components/pagination/pagination.component.ts index db7740f7d..182ad63bb 100644 --- a/src/app/shared/components/pagination/pagination.component.ts +++ b/src/app/shared/components/pagination/pagination.component.ts @@ -26,7 +26,7 @@ import { map } from 'rxjs/operators'; export class PaginationComponent implements OnInit { @Input() page: number = 1; @Input() pageSize: number = 10; - @Input() total: any; + @Input() total: number = 0; fromPage: number; // Used for HTML rendering @@ -88,6 +88,8 @@ function countTotalPages(totalDocuments, pageSize): number { } function generatePages(currentPage: number, range: 5 | 9, results: number, pageSize: number): number[] { + console.log(currentPage, range, results, pageSize); + let output: number[] = []; const maxPage = countTotalPages(results, pageSize); const i = currentPage; @@ -100,8 +102,8 @@ function generatePages(currentPage: number, range: 5 | 9, results: number, pageS output = [i-4, i-3, i-2, i-1, i, i+1, i+2, i+3, i+4]; } - let min = Math.min(...output); - let max = Math.max(...output); + const min = Math.min(...output); + const max = Math.max(...output); if (min < 1) { const increment = 1 - output[0];