<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>
</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>
</eg-grid>
<eg-cancel-reservation-dialog #confirmCancelReservationDialog
- (onSuccessfulCancel)="fillGrid()">
+ (onSuccessfulCancel)="pullList.reload()">
</eg-cancel-reservation-dialog>
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';
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 {
@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(
ngOnInit() {
- this.dataSource = new GridDataSource();
const defaultDaysHence = 5;
+ this.currentOrg = this.auth.user().ws_ou();
this.pullListCriteria = new FormGroup({
'daysHence': new FormControl(defaultDaysHence, [
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
+ );
};
}
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()
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();