42 lines
996 B
TypeScript
42 lines
996 B
TypeScript
import {Component, Input} from "@angular/core";
|
|
|
|
@Component({
|
|
selector: 'results-and-pages',
|
|
template: `
|
|
<h6 *ngIf="type" [ngClass]="customClasses">
|
|
<span>{{totalResults | number}}</span>
|
|
<span class="uk-text-meta uk-text-capitalize"> {{type}}, page </span>
|
|
<span>{{currentPage}}</span>
|
|
<span class="uk-text-meta"> of </span>
|
|
<span>{{getTotalPages() | number}}</span>
|
|
</h6>
|
|
`
|
|
})
|
|
|
|
export class ResultsAndPagesNumComponent {
|
|
@Input() type: string;
|
|
@Input() page: number = 1;
|
|
@Input() pageSize: number = 10;
|
|
@Input() totalResults: number = 0;
|
|
@Input() customClasses: string = "";
|
|
|
|
constructor() {}
|
|
|
|
get currentPage() {
|
|
if(this.page > this.getTotalPages()) {
|
|
return this.getTotalPages();
|
|
} else {
|
|
return this.page;
|
|
}
|
|
}
|
|
|
|
getTotalPages(){
|
|
let total: number;
|
|
let i= this.totalResults/this.pageSize;
|
|
let integerI=parseInt(''+i);
|
|
total = parseInt(''+((i==integerI)?i:i+1));
|
|
|
|
return total;
|
|
}
|
|
}
|