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';
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) {
// Only force new data collection when recordId()
// is invoked after ngInit() has already run.
if (this.initDone) {
- this.copyGrid.reload();
+ this.holdsGrid.reload();
}
}
ngOnInit() {
this.initDone = true;
+ this.pickupLib = this.staffCat.searchContext.searchOrg;
this.gridDataSource.getRows = (pager: Pager, sort: any[]) => {
// sorting not currently supported
};
}
+ 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,
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;
}
}