1
|
import {Component, Input, Output, EventEmitter} from '@angular/core';
|
2
|
import {Observable} from 'rxjs/Observable';
|
3
|
import {ErrorCodes} from '../../utils/properties/openaireProperties';
|
4
|
|
5
|
@Component({
|
6
|
selector: 'search-paging',
|
7
|
template: `
|
8
|
<div class= "searchPaging uk-panel uk-margin-top uk-grid uk-margin-bottom">
|
9
|
<div class="uk-h6 uk-width-1-1@s uk-width-1-2@m" *ngIf="results && searchUtils.totalResults > 0">
|
10
|
{{searchUtils.totalResults}} {{type}}, page {{searchUtils.page}} of {{(totalPages(searchUtils.totalResults))}}
|
11
|
</div>
|
12
|
<div class="uk-h6 uk-width-1-1@s uk-width-1-2@m" *ngIf="!loadPaging && oldTotalResults > 0 && searchUtils.status == errorCodes.LOADING">
|
13
|
{{oldTotalResults}} {{type}}, page {{searchUtils.page}} of {{(totalPages(oldTotalResults))}}
|
14
|
</div>
|
15
|
<div class="float-children-right-at-medium margin-small-top-at-small uk-width-1-1@s uk-width-1-2@m" *ngIf="results && searchUtils.totalResults > searchUtils.size">
|
16
|
<paging [currentPage]="searchUtils.page" [totalResults]="searchUtils.totalResults" [baseUrl]="baseUrl" [size]="searchUtils.size" [parameterNames] = "parameterNames" [parameterValues] = "parameterValues" > </paging>
|
17
|
</div>
|
18
|
<div class="float-children-right-at-medium margin-small-top-at-small uk-width-1-1@s uk-width-1-2@m" *ngIf="!loadPaging && oldTotalResults > searchUtils.size && searchUtils.status == errorCodes.LOADING">
|
19
|
<paging [currentPage]="searchUtils.page" [totalResults]="oldTotalResults" [baseUrl]="baseUrl" [size]="searchUtils.size" [parameterNames] = "parameterNames" [parameterValues] = "parameterValues" > </paging>
|
20
|
</div>
|
21
|
</div>
|
22
|
`
|
23
|
})
|
24
|
|
25
|
export class SearchPagingComponent {
|
26
|
@Input() searchUtils;
|
27
|
@Input() results;
|
28
|
@Input() baseUrl;
|
29
|
@Input() type;
|
30
|
@Input() parameterNames:string[];
|
31
|
@Input() parameterValues:string[];
|
32
|
|
33
|
@Input() loadPaging: boolean = true;
|
34
|
@Input() oldTotalResults: number = 0;
|
35
|
|
36
|
public totalResults: number = 0;
|
37
|
public errorCodes:ErrorCodes = new ErrorCodes();
|
38
|
|
39
|
// @Input() totalResults:number = 0;
|
40
|
constructor () {}
|
41
|
|
42
|
ngOnInit() {
|
43
|
// this.totalResults = this.searchUtils.totalResults;
|
44
|
// if(!this.loadPaging && this.totalResults == 0) {
|
45
|
// this.totalResults = this.oldTotalResults;
|
46
|
// }
|
47
|
}
|
48
|
|
49
|
totalPages(totalResults: number): number {
|
50
|
let totalPages:any = totalResults/(this.searchUtils.size);
|
51
|
if(!(Number.isInteger(totalPages))) {
|
52
|
totalPages = (parseInt(totalPages, 10) + 1);
|
53
|
}
|
54
|
return totalPages;
|
55
|
}
|
56
|
|
57
|
|
58
|
}
|