]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/catalog/result/pagination.component.ts
LP1860044 Angular catalog search result highlights
[working/Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / catalog / result / pagination.component.ts
1 import {Component, OnInit, Input} from '@angular/core';
2 import {CatalogService} from '@eg/share/catalog/catalog.service';
3 import {CatalogSearchContext} from '@eg/share/catalog/search-context';
4 import {StaffCatalogService} from '../catalog.service';
5
6 @Component({
7   selector: 'eg-catalog-result-pagination',
8   styleUrls: ['pagination.component.css'],
9   templateUrl: 'pagination.component.html'
10 })
11 export class ResultPaginationComponent implements OnInit {
12
13     searchContext: CatalogSearchContext;
14
15     // Maximum number of jump-to-page buttons displayed.
16     @Input() numPages: number;
17
18     constructor(
19         private cat: CatalogService,
20         private staffCat: StaffCatalogService
21     ) {
22         this.numPages = 10;
23     }
24
25     ngOnInit() {
26         this.searchContext = this.staffCat.searchContext;
27     }
28
29     currentPageList(): number[] {
30         const pgr = this.searchContext.pager;
31         return pgr.pageRange(pgr.currentPage(), this.numPages);
32     }
33
34     nextPage(): void {
35         this.searchContext.pager.increment();
36         this.staffCat.search();
37     }
38
39     prevPage(): void {
40         this.searchContext.pager.decrement();
41         this.staffCat.search();
42     }
43
44     setPage(page: number): void {
45         if (this.searchContext.pager.currentPage() === page) { return; }
46         this.searchContext.pager.setPage(page);
47         this.staffCat.search();
48     }
49 }
50
51