LP#1775466 Catalog paging and format repairs
authorBill Erickson <berickxx@gmail.com>
Wed, 25 Jul 2018 19:33:09 +0000 (15:33 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 5 Sep 2018 14:05:23 +0000 (10:05 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/util/pager.ts
Open-ILS/src/eg2/src/app/staff/catalog/result/pagination.component.html
Open-ILS/src/eg2/src/app/staff/catalog/result/pagination.component.ts
Open-ILS/src/eg2/src/app/staff/catalog/result/record.component.html

index b352fdb..8926b17 100644 (file)
@@ -72,6 +72,29 @@ export class Pager {
         return pages;
     }
 
+    // Returns a list of pages numbers with @pivot at the center
+    // or as close to center as possible.
+    // @pivot is 1-based for consistency with page numbers.
+    // pageRange(25, 10) => [21,22,...29,30]
+    pageRange(pivot: number, size: number): number[] {
+
+        const diff = Math.floor(size / 2);
+        let start = pivot <= diff ? 1 : pivot - diff + 1;
+
+        const pcount = this.pageCount();
+
+        if (start + size > pcount) {
+            start = pcount - size + 1;
+            if (start < 1) { start = 1 };
+        }
+
+        if (start + size > pcount) {
+            size = pcount;
+        }
+
+        return this.pageList().slice(start - 1, start - 1 + size);
+    }
+
     pageList(): number[] {
         const list = [];
         for (let i = 1; i <= this.pageCount(); i++) {
index 55b63dd..7cdda00 100644 (file)
@@ -13,7 +13,7 @@ unnecessary given we have to track paging externally anyway.
     </a>
   </li>
   <li class="page-item" 
-    *ngFor="let page of searchContext.pager.pageList()"
+    *ngFor="let page of currentPageList()"
     [ngClass]="{active : searchContext.pager.currentPage() == page}">
     <a class="page-link" (click)="setPage(page)">
       {{page}} <span class="sr-only" i18n>(current)</span></a>
index 3522bf5..15214b5 100644 (file)
@@ -12,15 +12,25 @@ export class ResultPaginationComponent implements OnInit {
 
     searchContext: CatalogSearchContext;
 
+    // Maximum number of jump-to-page buttons displayed.
+    @Input() numPages: number;
+
     constructor(
         private cat: CatalogService,
         private staffCat: StaffCatalogService
-    ) {}
+    ) {
+        this.numPages = 10;
+    }
 
     ngOnInit() {
         this.searchContext = this.staffCat.searchContext;
     }
 
+    currentPageList(): number[] {
+        const pgr = this.searchContext.pager;
+        return pgr.pageRange(pgr.currentPage(), this.numPages);
+    }
+
     nextPage(): void {
         this.searchContext.pager.increment();
         this.staffCat.search();
index c30f46f..54ad3db 100644 (file)
@@ -40,7 +40,7 @@
         <div class="row pt-2">
           <div class="col-lg-12">
             <!-- only shows the first icon format -->
-            <span *ngIf="summary.attributes.icon_format[0]">
+            <span *ngIf="summary.attributes.icon_format && summary.attributes.icon_format[0]">
               <img class="pr-1"
                 src="/images/format_icons/icon_format/{{summary.attributes.icon_format[0]}}.png"/>
               <span>{{iconFormatLabel(summary.attributes.icon_format[0])}}</span>