2020-11-07 13:14:39 +00:00
|
|
|
import { Component, Input } from '@angular/core';
|
|
|
|
import { Router } from '@angular/router';
|
2020-11-07 09:58:14 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-list-paginate',
|
|
|
|
templateUrl: './list-paginate.component.html',
|
|
|
|
styleUrls: ['./list-paginate.component.styl']
|
|
|
|
})
|
2020-11-07 13:14:39 +00:00
|
|
|
export class ListPaginateComponent {
|
2020-11-07 11:41:52 +00:00
|
|
|
@Input()
|
|
|
|
page: number;
|
|
|
|
|
|
|
|
@Input()
|
|
|
|
pages: number;
|
2020-11-07 09:58:14 +00:00
|
|
|
|
2020-11-07 13:14:39 +00:00
|
|
|
constructor(private router: Router) { }
|
2020-11-07 09:58:14 +00:00
|
|
|
|
2020-11-07 13:14:39 +00:00
|
|
|
public get pageNums(): number[] {
|
|
|
|
const starti = Math.min(Math.max(this.page - 2, 1), this.pages - 4);
|
|
|
|
return [...Array(5)].map((p, i) => starti + i);
|
2020-11-07 09:58:14 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 13:14:39 +00:00
|
|
|
public navigate(num: number): void {
|
|
|
|
this.router.navigate(['/list'], { queryParams: { page: Math.min(Math.max(num, 1), this.pages) }});
|
|
|
|
}
|
2020-11-07 09:58:14 +00:00
|
|
|
}
|