LP1882828: Fix issues with displaying cataloged resources in Pull List
authorJane Sandberg <sandbej@linnbenton.edu>
Wed, 19 Aug 2020 23:22:43 +0000 (16:22 -0700)
committerGalen Charlton <gmc@equinoxinitiative.org>
Thu, 24 Sep 2020 16:23:27 +0000 (12:23 -0400)
I had mistakenly used switchMap, when I should have used mergeMap. This
led to erroneously canceled subscriptions, leaving rows out of the pull
list.

This commit also uses getRows, rather than manually setting the
GridDataSource's data.

Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Signed-off-by: Terran McCanna <tmccanna@georgialibraries.org>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/eg2/src/app/staff/booking/pull-list.component.html
Open-ILS/src/eg2/src/app/staff/booking/pull-list.component.ts

index 296d2a1..ef66c83 100644 (file)
@@ -9,7 +9,7 @@
         <label for="ou" class="input-group-text" i18n>Library:</label>
       </div>
       <eg-org-select domId="ou" [applyDefault]="true"
-        (onChange)="fillGrid($event.id())"
+        (onChange)="handleOrgChange($event)"
         [disableOrgs]="disableOrgs()" [hideOrgs]="disableOrgs()">
       </eg-org-select>
     </div>
@@ -24,7 +24,7 @@
   </div>
 </form>
 <eg-grid [dataSource]="dataSource" [useLocalSort]="true" #pullList
-  [sortable]="true" persistKey="booking.pull_list">
+  [disablePaging]="true" [sortable]="true" persistKey="booking.pull_list">
   <eg-grid-toolbar-action label="Cancel Selected" i18n-label (onClick)="cancelSelected($event)" [disableOnRows]="noSelectedRows"></eg-grid-toolbar-action>
   <eg-grid-toolbar-action label="View Item Status" i18n-label (onClick)="viewItemStatus($event)" [disableOnRows]="notOneCatalogedItemSelected"></eg-grid-toolbar-action>
   <eg-grid-toolbar-action label="View Reservations for This Resource" i18n-label (onClick)="viewByResource($event)" [disableOnRows]="notOneResourceSelected"></eg-grid-toolbar-action>
@@ -43,5 +43,5 @@
 </eg-grid>
 
 <eg-cancel-reservation-dialog #confirmCancelReservationDialog
-  (onSuccessfulCancel)="fillGrid()">
+  (onSuccessfulCancel)="pullList.reload()">
 </eg-cancel-reservation-dialog>
index e48c765..ae4685d 100644 (file)
@@ -1,7 +1,7 @@
 import {Component, OnInit, ViewChild} from '@angular/core';
 import {FormControl, FormGroup, Validators} from '@angular/forms';
-import {from, Observable, of} from 'rxjs';
-import {switchMap} from 'rxjs/operators';
+import {Observable, of, from} from 'rxjs';
+import {switchMap, mergeMap} from 'rxjs/operators';
 import {AuthService} from '@eg/core/auth.service';
 import {GridDataSource} from '@eg/share/grid/grid';
 import {IdlObject} from '@eg/core/idl.service';
@@ -10,6 +10,8 @@ import {OrgService} from '@eg/core/org.service';
 import {PcrudService} from '@eg/core/pcrud.service';
 import {ReservationActionsService} from './reservation-actions.service';
 import {CancelReservationDialogComponent} from './cancel-reservation-dialog.component';
+import {GridComponent} from '@eg/share/grid/grid.component';
+import {Pager} from '@eg/share/util/pager';
 
 // The data that comes from the API, along with some fleshing
 interface PullListRow {
@@ -29,10 +31,14 @@ export class PullListComponent implements OnInit {
     @ViewChild('confirmCancelReservationDialog', { static: true })
         private cancelReservationDialog: CancelReservationDialogComponent;
 
-    public dataSource: GridDataSource;
+    @ViewChild('pullList') private pullList: GridComponent;
+
+    public dataSource: GridDataSource = new GridDataSource();
 
     public disableOrgs: () => number[];
-    public fillGrid: (orgId?: number) => void;
+    public handleOrgChange: (org: IdlObject) => void;
+
+    currentOrg: number;
     pullListCriteria: FormGroup;
 
     constructor(
@@ -45,9 +51,9 @@ export class PullListComponent implements OnInit {
 
 
     ngOnInit() {
-        this.dataSource = new GridDataSource();
 
         const defaultDaysHence = 5;
+        this.currentOrg = this.auth.user().ws_ou();
 
         this.pullListCriteria = new FormGroup({
             'daysHence': new FormControl(defaultDaysHence, [
@@ -55,22 +61,25 @@ export class PullListComponent implements OnInit {
                 Validators.min(1)])
         });
 
-        this.pullListCriteria.valueChanges.subscribe(() => this.fillGrid() );
+        this.pullListCriteria.valueChanges.subscribe(() => this.pullList.reload() );
 
         this.disableOrgs = () => this.org.filterList( { canHaveVolumes : false }, true);
 
-        this.fillGrid = (orgId = this.auth.user().ws_ou()) => {
-            this.dataSource.data = [];
+        this.handleOrgChange = (org: IdlObject) => {
+            this.currentOrg = org.id();
+            this.pullList.reload();
+        };
+
+        this.dataSource.getRows = (pager: Pager) => {
             const numberOfSecondsInADay = 86400;
-            this.net.request(
+            return this.net.request(
                 'open-ils.booking', 'open-ils.booking.reservations.get_pull_list',
                 this.auth.token(), null,
                 (this.daysHence.value * numberOfSecondsInADay),
-                orgId
-            ).pipe(switchMap((resources) => from(resources)),
-                switchMap((resource: PullListRow) => this.fleshResource(resource))
-            )
-            .subscribe((resource) => this.dataSource.data.push(resource));
+                this.currentOrg
+            ).pipe(switchMap(arr => from(arr)), // Change the array we got into a stream
+            mergeMap(resource => this.fleshResource$(resource)) // Add info for cataloged resources
+            );
         };
     }
 
@@ -92,7 +101,7 @@ export class PullListComponent implements OnInit {
         this.cancelReservationDialog.open(rows.map(row => row['reservations'][0].id()));
     }
 
-    fleshResource = (resource: PullListRow): Observable<PullListRow> => {
+    fleshResource$ = (resource: any): Observable<PullListRow> => {
         if ('t' === resource['target_resource_type'].catalog_item()) {
             return this.pcrud.search('acp', {
                 'barcode': resource['current_resource'].barcode()
@@ -100,7 +109,7 @@ export class PullListComponent implements OnInit {
                     limit: 1,
                     flesh: 1,
                     flesh_fields: {'acp' : ['call_number', 'location' ]}
-            }).pipe(switchMap((acp) => {
+            }).pipe(mergeMap((acp) => {
                 resource['call_number'] = acp.call_number().label();
                 resource['call_number_sortkey'] = acp.call_number().label_sortkey();
                 resource['shelving_location'] = acp.location().name();