1 import {Component, OnInit, Input, Output, ViewChild, EventEmitter} from '@angular/core';
2 import {tap} from 'rxjs/operators';
3 import {IdlObject} from '@eg/core/idl.service';
4 import {NetService} from '@eg/core/net.service';
5 import {PcrudService} from '@eg/core/pcrud.service';
6 import {OrgService} from '@eg/core/org.service';
7 import {AuthService} from '@eg/core/auth.service';
8 import {HoldNoteDialogComponent} from './note-dialog.component';
9 import {HoldNotifyDialogComponent} from './notify-dialog.component';
11 /** Hold details read-only view */
14 selector: 'eg-hold-detail',
15 templateUrl: 'detail.component.html'
17 export class HoldDetailComponent implements OnInit {
19 notes: IdlObject[] = [];
20 notifies: IdlObject[] = [];
22 private _holdId: number;
23 @Input() set holdId(id: number) {
24 if (this._holdId !== id) {
32 get holdId(): number {
36 hold: any; // wide hold reference
37 @Input() set wideHold(wh: any) {
45 // Display bib record summary along the top of the detail page.
46 @Input() showRecordSummary = false;
49 @Output() onShowList: EventEmitter<any>;
51 @ViewChild('noteDialog') noteDialog: HoldNoteDialogComponent;
52 @ViewChild('notifyDialog') notifyDialog: HoldNotifyDialogComponent;
55 private net: NetService,
56 private pcrud: PcrudService,
57 private org: OrgService,
58 private auth: AuthService,
60 this.onShowList = new EventEmitter<any>();
69 if (!this.holdId && !this.hold) { return; }
71 const promise = this.hold ? Promise.resolve(this.hold) :
74 'open-ils.circ.hold.wide_hash.stream',
75 this.auth.token(), {id: this.holdId}
78 return promise.then(wideHold => {
80 // avoid this.holdId = since it re-fires this fetch.
81 this._holdId = wideHold.id;
83 .then(_ => this.getNotes())
84 .then(_ => this.getNotifies());
87 getNotes(): Promise<any> {
89 return this.pcrud.search('ahrn', {hold: this.holdId})
90 .pipe(tap(note => this.notes.push(note))).toPromise();
93 getNotifies(): Promise<any> {
96 return this.pcrud.search('ahn', {hold: this.holdId}, {
98 flesh_fields: {ahn: ['notify_staff']},
99 order_by: {ahn: 'notify_time DESC'}
100 }).pipe(tap(notify => this.notifies.push(notify))).toPromise();
103 getOrgName(id: number) {
105 return this.org.get(id).shortname();
110 this.onShowList.emit();
113 deleteNote(note: IdlObject) {
114 this.pcrud.remove(note).toPromise()
115 .then(ok => { if (ok) { this.getNotes(); } });
119 this.noteDialog.open().subscribe(note => this.notes.unshift(note));
123 this.notifyDialog.open().subscribe(notify => this.getNotifies()); // fleshing