From 7f3d2ac581dac1a25bd691790b562905f1170e90 Mon Sep 17 00:00:00 2001 From: Lotte Hofstede Date: Fri, 25 Aug 2017 15:01:32 +0200 Subject: [PATCH] 44024: pagination fixes and translation --- resources/i18n/en.json | 9 +++++++++ src/app/search-page/search-page.component.html | 2 +- src/app/search-page/search-page.component.ts | 17 +++++++++-------- .../search-results.component.html | 1 + .../search-results/search-results.compontent.ts | 11 +---------- .../shared/pagination/pagination.component.ts | 11 +++++++---- .../search-form/search-form.component.html | 10 +++++----- .../shared/search-form/search-form.component.ts | 4 +--- 8 files changed, 34 insertions(+), 31 deletions(-) diff --git a/resources/i18n/en.json b/resources/i18n/en.json index 9714640287..c605d76961 100644 --- a/resources/i18n/en.json +++ b/resources/i18n/en.json @@ -69,5 +69,14 @@ "head": "Communities in DSpace", "help": "Select a community to browse its collections." } + }, + "search": { + "form": { + "search": "Search", + "search_dspace": "Search DSpace" + }, + "results": { + "title": "Search Results" + } } } diff --git a/src/app/search-page/search-page.component.html b/src/app/search-page/search-page.component.html index 97eb9360dd..45b7e70ed1 100644 --- a/src/app/search-page/search-page.component.html +++ b/src/app/search-page/search-page.component.html @@ -1,4 +1,4 @@
- +
diff --git a/src/app/search-page/search-page.component.ts b/src/app/search-page/search-page.component.ts index e601ab4d8c..bfabd1c0c6 100644 --- a/src/app/search-page/search-page.component.ts +++ b/src/app/search-page/search-page.component.ts @@ -6,6 +6,7 @@ import { SearchResult } from '../search/search-result.model'; import { DSpaceObject } from '../core/shared/dspace-object.model'; import { SortOptions } from '../core/cache/models/sort-options.model'; import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model'; +import { SearchOptions } from '../search/search-options.model'; /** * This component renders a simple item page. @@ -20,11 +21,12 @@ import { PaginationComponentOptions } from '../shared/pagination/pagination-comp }) export class SearchPageComponent implements OnInit, OnDestroy { private sub; - private query: string; + query: string; private scope: string; private page: number; - private results: RemoteData>>; + results: RemoteData>>; private currentParams = {}; + searchOptions: SearchOptions; constructor(private service: SearchService, private route: ActivatedRoute, @@ -40,13 +42,12 @@ export class SearchPageComponent implements OnInit, OnDestroy { this.scope = params.scope; this.page = +params.page || 1; const pagination: PaginationComponentOptions = new PaginationComponentOptions(); - pagination.id = 'results-pagination'; + pagination.id = 'search-results-pagination'; pagination.currentPage = this.page; - pagination.pageSize = +params.pageSize; - this.results = this.service.search(this.query, this.scope, { - pagination: pagination, - sort: new SortOptions(params.sortField, params.sortDirection) - }); + pagination.pageSize = +params.pageSize || 10; + const sort: SortOptions = new SortOptions(params.sortField, params.sortDirection); + this.searchOptions = {pagination: pagination, sort: sort}; + this.results = this.service.search(this.query, this.scope, this.searchOptions); } ); } diff --git a/src/app/search-page/search-results/search-results.component.html b/src/app/search-page/search-results/search-results.component.html index 2f17c9a730..7d769dbeb0 100644 --- a/src/app/search-page/search-results/search-results.component.html +++ b/src/app/search-page/search-results/search-results.component.html @@ -1,2 +1,3 @@ +

{{ 'search.results.title' | translate }}

\ No newline at end of file diff --git a/src/app/search-page/search-results/search-results.compontent.ts b/src/app/search-page/search-results/search-results.compontent.ts index e39c0323c9..8ca741a68d 100644 --- a/src/app/search-page/search-results/search-results.compontent.ts +++ b/src/app/search-page/search-results/search-results.compontent.ts @@ -17,16 +17,7 @@ import { SearchOptions } from '../../search/search-options.model'; templateUrl: './search-results.component.html', }) -export class SearchResultsComponent implements OnInit { +export class SearchResultsComponent { @Input() searchResults: RemoteData>>; - @Input() searchConfig: SearchOptions; - - ngOnInit(): void { - this.searchConfig = new SearchOptions(); - this.searchConfig.pagination = new PaginationComponentOptions(); - this.searchConfig.pagination.id = 'search-results-pagination'; - this.searchConfig.sort = new SortOptions(); - } - } diff --git a/src/app/shared/pagination/pagination.component.ts b/src/app/shared/pagination/pagination.component.ts index c0b8e4abd6..5cdefd8eed 100644 --- a/src/app/shared/pagination/pagination.component.ts +++ b/src/app/shared/pagination/pagination.component.ts @@ -199,8 +199,8 @@ export class PaginationComponent implements OnDestroy, OnInit { this.sortDirection = this.sortOptions.direction; this.sortField = this.sortOptions.field; } + this.setShowingDetail(); })); - this.setShowingDetail(); } /** @@ -246,6 +246,7 @@ export class PaginationComponent implements OnDestroy, OnInit { */ public setPageSize(pageSize: number) { this.pageSize = pageSize; + this.doPageChange(1); this.updateRoute(); this.setShowingDetail(); this.pageSizeChange.emit(pageSize); @@ -259,6 +260,7 @@ export class PaginationComponent implements OnDestroy, OnInit { */ public setSortDirection(sortDirection: SortDirection) { this.sortDirection = sortDirection; + this.doPageChange(1); this.updateRoute(); this.setShowingDetail(); this.sortDirectionChange.emit(sortDirection); @@ -272,6 +274,7 @@ export class PaginationComponent implements OnDestroy, OnInit { */ public setSortField(field: string) { this.sortField = field; + this.doPageChange(1); this.updateRoute(); this.setShowingDetail(); this.sortFieldChange.emit(field); @@ -298,11 +301,11 @@ export class PaginationComponent implements OnDestroy, OnInit { private setShowingDetail() { let firstItem; let lastItem; - const lastPage = Math.round(this.collectionSize / this.pageSize); + const pageMax = this.pageSize * this.currentPage; firstItem = this.pageSize * (this.currentPage - 1) + 1; - if (this.currentPage !== lastPage) { - lastItem = this.pageSize * this.currentPage; + if (this.collectionSize > pageMax) { + lastItem = pageMax; } else { lastItem = this.collectionSize; } diff --git a/src/app/shared/search-form/search-form.component.html b/src/app/shared/search-form/search-form.component.html index e83554ad9b..d636d3227a 100644 --- a/src/app/shared/search-form/search-form.component.html +++ b/src/app/shared/search-form/search-form.component.html @@ -1,16 +1,16 @@
-
+ diff --git a/src/app/shared/search-form/search-form.component.ts b/src/app/shared/search-form/search-form.component.ts index c81ead2151..10e992a6ea 100644 --- a/src/app/shared/search-form/search-form.component.ts +++ b/src/app/shared/search-form/search-form.component.ts @@ -11,12 +11,10 @@ import { Component, OnInit, EventEmitter, Output, Input } from '@angular/core'; styleUrls: ['./search-form.component.scss'], templateUrl: './search-form.component.html', }) -export class SearchFormComponent implements OnInit { +export class SearchFormComponent { @Output() formSubmit: EventEmitter = new EventEmitter(); @Input() query: string; - ngOnInit(): void { } - onSubmit(form: any, scope?: string) { const data: any = Object.assign({}, form, { scope: scope }); this.formSubmit.emit(data);