import {IdlObject} from '@eg/core/idl.service';
import {OrgService} from '@eg/core/org.service';
import {NetService} from '@eg/core/net.service';
+import {PcrudService} from '@eg/core/pcrud.service';
import {AuthService} from '@eg/core/auth.service';
import {PatronService} from '@eg/staff/share/patron/patron.service';
import {PatronManagerService} from './patron.service';
import {AudioService} from '@eg/share/util/audio.service';
import {CopyAlertsDialogComponent
} from '@eg/staff/share/holdings/copy-alerts-dialog.component';
-import {CircGridComponent} from '@eg/staff/share/circ/grid.component';
+import {CircGridComponent, CircGridEntry} from '@eg/staff/share/circ/grid.component';
@Component({
templateUrl: 'items.component.html',
loading = false;
mainList: number[] = [];
altList: number[] = [];
- noncatDataSource: GridDataSource = new GridDataSource();
+
+ displayLost: number; // 1 | 2 | 5 | 6;
+ displayLongOverdue: number;
+ displayClaimsReturned: number;
+ fetchCheckedIn = true;
+ displayAltList = true;
@ViewChild('checkoutsGrid') private checkoutsGrid: CircGridComponent;
+ @ViewChild('otherGrid') private otherGrid: CircGridComponent;
+ @ViewChild('nonCatGrid') private nonCatGrid: CircGridComponent;
constructor(
private org: OrgService,
private net: NetService,
+ private pcrud: PcrudService,
private auth: AuthService,
public circ: CircService,
private audio: AudioService,
) {}
ngOnInit() {
+ this.load();
}
ngAfterViewInit() {
- setTimeout(() => this.loadTab(this.itemsTab));
+ }
+
+ load(): Promise<any> {
+ this.loading = true;
+ return this.applyDisplaySettings()
+ .then(_ => this.loadTab(this.itemsTab));
}
tabChange(evt: NgbNavChangeEvent) {
this.loading = true;
let promise;
if (name === 'checkouts') {
- promise = this.loadCheckoutsGrid();
+ promise = this.loadMainGrid();
+ } else if (name === 'other') {
+ promise = this.loadAltGrid();
+ } else {
+ promise = this.loadNonCatGrid();
}
promise.then(_ => this.loading = false);
}
- loadCheckoutsGrid(): Promise<any> {
+ applyDisplaySettings() {
+ return this.serverStore.getItemBatch([
+ 'ui.circ.items_out.lost',
+ 'ui.circ.items_out.longoverdue',
+ 'ui.circ.items_out.claimsreturned'
+ ]).then(sets => {
+
+ this.displayLost =
+ Number(sets['ui.circ.items_out.lost']) || 2;
+ this.displayLongOverdue =
+ Number(sets['ui.circ.items_out.longoverdue']) || 2;
+ this.displayClaimsReturned =
+ Number(sets['ui.circ.items_out.claimsreturned']) || 2;
+
+ if (this.displayLost & 4 &&
+ this.displayLongOverdue & 4 &&
+ this.displayClaimsReturned & 4) {
+
+ // all special types are configured to be hidden once
+ // checked in, so there's no need to fetch checked-in circs.
+ this.fetchCheckedIn = false;
+
+ if (this.displayLost & 1 &&
+ this.displayLongOverdue & 1 &&
+ this.displayClaimsReturned & 1) {
+ // additionally, if all types are configured to display
+ // in the main list while checked out, nothing will
+ // ever appear in the alternate list, so we can hide
+ // the alternate list from the UI.
+ this.displayAltList = false;
+ }
+ }
+ });
+ }
+
+ // Determine which grid ('checkouts' or 'other') a circ should appear in.
+ promoteCircs(list: number[], displayCode: number, xactOpen?: boolean) {
+ if (xactOpen) {
+ if (1 & displayCode) { // bitflag 1 == top list
+ this.mainList = this.mainList.concat(list);
+ } else {
+ this.altList = this.altList.concat(list);
+ }
+ } else {
+ if (4 & displayCode) return; // bitflag 4 == hide on checkin
+ this.altList = this.altList.concat(list);
+ }
+ }
+
+ getCircIds(): Promise<any> {
this.mainList = [];
this.altList = [];
this.auth.token(), this.patronId
).toPromise().then(checkouts => {
this.mainList = checkouts.overdue.concat(checkouts.out);
-
- // TODO promise_circs, etc.
+ this.promoteCircs(checkouts.lost, this.displayLost, true);
+ this.promoteCircs(checkouts.long_overdue, this.displayLongOverdue, true);
+ this.promoteCircs(checkouts.claims_returned, this.displayClaimsReturned, true);
});
- // TODO: fetch checked in
+ if (!this.fetchCheckedIn) { return promise; }
return promise.then(_ => {
- this.checkoutsGrid.load(this.mainList)
- .subscribe(null, null, () => this.checkoutsGrid.reloadGrid());
+ return this.net.request(
+ 'open-ils.actor',
+ 'open-ils.actor.user.checked_in_with_fines.authoritative',
+ this.auth.token(), this.patronId
+ ).toPromise().then(checkouts => {
+ this.promoteCircs(checkouts.lost, this.displayLost);
+ this.promoteCircs(checkouts.long_overdue, this.displayLongOverdue);
+ this.promoteCircs(checkouts.claims_returned, this.displayClaimsReturned);
+ });
});
}
- /*
- function get_circ_ids() {
- $scope.main_list = [];
- $scope.alt_list = [];
+ loadMainGrid(): Promise<any> {
+ return this.getCircIds()
+ .then(_ => this.checkoutsGrid.load(this.mainList).toPromise())
+ .then(_ => this.checkoutsGrid.reloadGrid());
+ }
- // we can fetch these in parallel
- var promise1 = egCore.net.request(
- 'open-ils.actor',
- 'open-ils.actor.user.checked_out.authoritative',
- egCore.auth.token(), $scope.patron_id
- ).then(function(outs) {
- $scope.main_list = outs.overdue.concat(outs.out);
- promote_circs(outs.lost, display_lost, true);
- promote_circs(outs.long_overdue, display_lo, true);
- promote_circs(outs.claims_returned, display_cr, true);
- });
+ loadAltGrid(): Promise<any> {
+ return this.getCircIds()
+ .then(_ => this.otherGrid.load(this.altList).toPromise())
+ .then(_ => this.otherGrid.reloadGrid());
+ }
- // only fetched checked-in-with-bills circs if configured to display
- var promise2 = !fetch_checked_in ? $q.when() : egCore.net.request(
- 'open-ils.actor',
- 'open-ils.actor.user.checked_in_with_fines.authoritative',
- egCore.auth.token(), $scope.patron_id
- ).then(function(outs) {
- promote_circs(outs.lost, display_lost);
- promote_circs(outs.long_overdue, display_lo);
- promote_circs(outs.claims_returned, display_cr);
- });
+ loadNonCatGrid(): Promise<any> {
- return $q.all([promise1, promise2]);
- }
- */
+ return this.net.request(
+ 'open-ils.circ',
+ 'open-ils.circ.open_non_cataloged_circulation.user.batch.authoritative',
+ this.auth.token(), this.patronId)
+
+ .pipe(tap(circ => {
+ const entry: CircGridEntry = {
+ title: circ.item_type().name(),
+ dueDate: circ.duedate()
+ };
+ this.nonCatGrid.appendGridEntry(entry);
+ })).toPromise()
+
+ .then(_ => this.nonCatGrid.reloadGrid());
+ }
}