LP1806087 Catalog holds display WIP
authorBill Erickson <berickxx@gmail.com>
Tue, 19 Feb 2019 01:53:19 +0000 (17:53 -0800)
committerBill Erickson <berickxx@gmail.com>
Tue, 19 Feb 2019 01:53:19 +0000 (17:53 -0800)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/catalog/record/holds.component.html
Open-ILS/src/eg2/src/app/staff/catalog/record/holds.component.ts

index ee778cf..59867a0 100644 (file)
@@ -4,6 +4,18 @@
 
 <div class='eg-holds w-100 mt-3'>
 
+  <div class="row">
+    <div class="col-lg-4">
+      <div class="input-group">
+        <div class="input-group-prepend">
+          <div class="input-group-text" i18n>Pickup Library</div>
+        </div>
+        <eg-org-select [initialOrg]="pickupLib" (onChange)="pickupLibChanged($event)">
+        </eg-org-select>
+      </div>
+    </div>
+  </div>
+
   <eg-grid #holdsGrid [dataSource]="gridDataSource" [sortable]="true"
     [multiSortable]="true" persistKey="cat.catalog.wide_holds" 
     >
index 769aec4..5c281b6 100644 (file)
@@ -1,5 +1,5 @@
 import {Component, OnInit, Input, ViewChild} from '@angular/core';
-import {Observable, of} from 'rxjs';
+import {Observable, Observer, of} from 'rxjs';
 import {map, filter} from 'rxjs/operators';
 import {IdlObject} from '@eg/core/idl.service';
 import {NetService} from '@eg/core/net.service';
@@ -22,7 +22,7 @@ export class HoldsComponent implements OnInit {
     gridDataSource: GridDataSource;
     pickupLib: IdlObject;
     holdsCount: number;
-    @ViewChild('holdsGrid') private copyGrid: GridComponent;
+    @ViewChild('holdsGrid') private holdsGrid: GridComponent;
     @ViewChild('progressDialog') private progressDialog: ProgressDialogComponent;
 
     @Input() set recordId(id: number) {
@@ -30,7 +30,7 @@ export class HoldsComponent implements OnInit {
         // Only force new data collection when recordId()
         // is invoked after ngInit() has already run.
         if (this.initDone) {
-            this.copyGrid.reload();
+            this.holdsGrid.reload();
         }
     }
 
@@ -45,6 +45,7 @@ export class HoldsComponent implements OnInit {
 
     ngOnInit() {
         this.initDone = true;
+        this.pickupLib = this.staffCat.searchContext.searchOrg;
 
         this.gridDataSource.getRows = (pager: Pager, sort: any[]) => {
             // sorting not currently supported
@@ -52,11 +53,15 @@ export class HoldsComponent implements OnInit {
         };
     }
 
+    pickupLibChanged(org: IdlObject) {
+        this.pickupLib = org;
+        this.holdsGrid.reload();
+    }
+
     fetchHolds(pager: Pager, sort: any[]): Observable<any> {
         if (!this.recId) { return of([]); }
 
-        const orgs =
-            this.org.descendants(this.staffCat.searchContext.searchOrg, true);
+        const orgs = this.org.descendants(this.pickupLib, true);
 
         const restrictions = {
             is_staff_request: true,
@@ -73,39 +78,43 @@ export class HoldsComponent implements OnInit {
             orderBy.push(subObj);
         });
 
+        let observer: Observer<any>;
+        const observable = new Observable(obs => observer = obs);
+
         this.progressDialog.open();
         this.progressDialog.update({value: 0, max: 1});
         let first = true;
         let loadCount = 0;
-        return this.net.request(
+        this.net.request(
             'open-ils.circ',
             'open-ils.circ.hold.wide_hash.stream',
             this.auth.token(), restrictions, orderBy, pager.limit, pager.offset
-        ).pipe(
+        ).subscribe(
+            holdData => {
 
-            filter(holdData => {
-                // First API response is the hold count.
-                if (first) {
+                if (first) { // First response is the hold count.
                     this.holdsCount = Number(holdData);
-                    return first = false;
-                }
-                return true;
-            }),
+                    first = false;
 
-            map(holdData => {
+                } else { // Subsequent responses are hold data blobs
 
-                this.progressDialog.update(
-                    {value: ++loadCount, max: this.holdsCount});
+                    this.progressDialog.update(
+                        {value: ++loadCount, max: this.holdsCount});
 
-                if (loadCount === this.holdsCount) {
-                    this.progressDialog.close();
+                    observer.next(holdData);
                 }
-
-                // Do we even need to modify anything?
-                // Probably not.
-                return holdData;
-            })
+            },
+            err => {
+                this.progressDialog.close();
+                observer.error(err);
+            },
+            ()  => {
+                this.progressDialog.close();
+                observer.complete();
+            }
         );
+
+        return observable;
     }
 }