From 26b23a766f0458b872ea16a63452a94aba960f7e Mon Sep 17 00:00:00 2001 From: Jane Sandberg Date: Wed, 19 Aug 2020 16:22:43 -0700 Subject: [PATCH] LP1882828: Fix issues with displaying cataloged resources in Pull List 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 Signed-off-by: Terran McCanna Signed-off-by: Galen Charlton --- .../src/app/staff/booking/pull-list.component.html | 6 ++-- .../src/app/staff/booking/pull-list.component.ts | 41 +++++++++++++--------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/booking/pull-list.component.html b/Open-ILS/src/eg2/src/app/staff/booking/pull-list.component.html index 296d2a1b5e..ef66c83e22 100644 --- a/Open-ILS/src/eg2/src/app/staff/booking/pull-list.component.html +++ b/Open-ILS/src/eg2/src/app/staff/booking/pull-list.component.html @@ -9,7 +9,7 @@ @@ -24,7 +24,7 @@ + [disablePaging]="true" [sortable]="true" persistKey="booking.pull_list"> @@ -43,5 +43,5 @@ + (onSuccessfulCancel)="pullList.reload()"> diff --git a/Open-ILS/src/eg2/src/app/staff/booking/pull-list.component.ts b/Open-ILS/src/eg2/src/app/staff/booking/pull-list.component.ts index e48c7650d1..ae4685da99 100644 --- a/Open-ILS/src/eg2/src/app/staff/booking/pull-list.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/booking/pull-list.component.ts @@ -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 => { + fleshResource$ = (resource: any): Observable => { 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(); -- 2.11.0