[#5352] Fix broken pagination if totalItems is missing (#5473)

* [#5352] Fix broken pagination if totalItems is missing. This happens when a search query is executed against Solr and not the DB

* fix lint issues

Co-authored-by: Arik Sidney Guggenheim <ariksidney@outlook.com>
This commit is contained in:
Eugenio Romano
2020-02-21 12:12:28 +00:00
committed by GitHub
parent b7de48c821
commit feebaebd6c
3 changed files with 51 additions and 11 deletions

View File

@@ -27,6 +27,7 @@ import { Subject } from 'rxjs';
import { PaginationModel } from '../models/pagination.model';
import { UserPreferencesService, UserPreferenceValues } from '../services/user-preferences.service';
import { takeUntil } from 'rxjs/operators';
import { TranslateService } from '@ngx-translate/core';
@Component({
selector: 'adf-pagination',
@@ -85,7 +86,7 @@ export class PaginationComponent implements OnInit, OnDestroy, PaginationCompone
private onDestroy$ = new Subject<boolean>();
constructor(private cdr: ChangeDetectorRef, private userPreferencesService: UserPreferencesService) {
constructor(private cdr: ChangeDetectorRef, private userPreferencesService: UserPreferencesService, private translate: TranslateService) {
}
ngOnInit() {
@@ -133,6 +134,9 @@ export class PaginationComponent implements OnInit, OnDestroy, PaginationCompone
}
get isLastPage(): boolean {
if (!this.pagination.totalItems && this.pagination.hasMoreItems) {
return false;
}
return this.current === this.lastPage;
}
@@ -161,7 +165,11 @@ export class PaginationComponent implements OnInit, OnDestroy, PaginationCompone
const { skipCount, maxItems, totalItems } = this.pagination;
const { isLastPage } = this;
const start = totalItems ? skipCount + 1 : 0;
let start = 0;
if (totalItems || totalItems !== 0) {
start = skipCount + 1;
}
const end = isLastPage ? totalItems : skipCount + maxItems;
return [start, end];
@@ -173,6 +181,18 @@ export class PaginationComponent implements OnInit, OnDestroy, PaginationCompone
.map((_, index) => (index + 1));
}
get itemRangeText(): string {
const rangeString = this.range.join('-');
let translation = this.translate.instant('CORE.PAGINATION.ITEMS_RANGE', {
range: rangeString,
total: this.pagination.totalItems
});
if (!this.pagination.totalItems) {
translation = translation.substr(0, translation.indexOf(rangeString) + rangeString.length);
}
return translation;
}
goNext() {
if (this.hasItems) {
const maxItems = this.pagination.maxItems;