-
-<eg-staff-banner bannerText="Hold Details (#{{hold.id}})" i18n-bannerText>
-</eg-staff-banner>
-
<div class="row">
- <div class="col-lg-3">
+ <div class="col-lg-2">
<button (click)="showListView()" class="btn btn-info" i18n>List View</button>
</div>
+ <div class="col-lg-3 font-weight-bold" i18n><h4>Hold #{{holdId}}</h4></div>
</div>
<div class="well-table">
</div>
</div>
+<div class="row mt-2">
+ <div class="col-lg-12">
+ <ul ngbNav #detailNav="ngbNav" class="nav-tabs" [activeId]="detailTab">
+ <li ngbNavItem="notes">
+ <a ngbNavLink i18n>Notes</a>
+ <ng-template ngbNavContent>
+ <button class="btn btn-outline-dark mt-3" (click)="newNote()" i18n>New Note</button>
+ <div class="mt-3" *ngFor="let note of notes">
+ <div class="d-flex">
+ <div class="font-weight-bold">{{note.title()}}</div>
+ <div class="flex-1"></div>
+ <div>
+ <span *ngIf="note.slip() == 't'"
+ class="ml-2 badge badge-info">Print on Slip</span>
+ <span *ngIf="note.pub() == 't'"
+ class="ml-2 badge badge-warning">Patron Visible</span>
+ <span *ngIf="note.staff() == 't'"
+ class="ml-2 badge badge-info">Staff Create</span>
+ </div>
+ </div>
+ <div class="well-table">
+ <div class="well-row">
+ <div class="well-value">{{note.body()}}</div>
+ <div class="well-label-no-flex">
+ <button class="btn btn-warning"
+ (click)="deleteNote(note)" i18n>Delete</button>
+ </div>
+ </div>
+ </div>
+ </div>
+ </ng-template>
+ </li>
+ <li ngbNavItem="notifications">
+ <a ngbNavLink i18n>Staff Notifications</a>
+ <ng-template ngbNavContent>
+ NOTIFY
+ </ng-template>
+ </li>
+ </ul>
+ <div [ngbNavOutlet]="detailNav"></div>
+ </div>
+</div>
import {Component, OnInit, Input, Output, ViewChild, EventEmitter} from '@angular/core';
import {Observable, Observer, of} from 'rxjs';
+import {tap} from 'rxjs/operators';
+import {IdlObject} from '@eg/core/idl.service';
import {NetService} from '@eg/core/net.service';
+import {PcrudService} from '@eg/core/pcrud.service';
import {OrgService} from '@eg/core/org.service';
import {AuthService} from '@eg/core/auth.service';
templateUrl: 'detail.component.html'
})
export class HoldDetailComponent implements OnInit {
+ detailTab = 'notes';
+ notes: IdlObject[] = [];
+ notifies: IdlObject[] = [];
- _holdId: number;
+ private _holdId: number;
@Input() set holdId(id: number) {
- this._holdId = id;
- if (this.initDone) {
- this.fetchHold();
+ if (this._holdId !== id) {
+ this._holdId = id;
+ if (this.initDone) {
+ this.fetchHold();
+ }
}
}
+ get holdId(): number {
+ return this._holdId;
+ }
+
hold: any; // wide hold reference
@Input() set wideHold(wh: any) {
this.hold = wh;
}
+ get wideHold(): any {
+ return this.hold;
+ }
+
initDone: boolean;
@Output() onShowList: EventEmitter<any>;
constructor(
private net: NetService,
+ private pcrud: PcrudService,
private org: OrgService,
private auth: AuthService,
) {
}
fetchHold() {
- if (!this._holdId) { return; }
+ if (!this.holdId && !this.hold) { return; }
+
+ const promise = this.hold ? Promise.resolve(this.hold) :
+ this.net.request(
+ 'open-ils.circ',
+ 'open-ils.circ.hold.wide_hash.stream',
+ this.auth.token(), {id: this.holdId}
+ ).toPromise();
- this.net.request(
- 'open-ils.circ',
- 'open-ils.circ.hold.wide_hash.stream',
- this.auth.token(), {id: this._holdId}
- ).subscribe(wideHold => {
+ return promise.then(wideHold => {
this.hold = wideHold;
- });
+ // avoid this.holdId = since it re-fires this fetch.
+ this._holdId = wideHold.id;
+ })
+ .then(_ => this.getNotes())
+ .then(_ => this.getNotifies());
+ }
+
+ getNotes(): Promise<any> {
+ this.notes = [];
+ return this.pcrud.search('ahrn', {hold: this.holdId})
+ .pipe(tap(note => this.notes.push(note))).toPromise()
+ }
+
+ getNotifies(): Promise<any> {
+ this.notifies = [];
+
+ return this.pcrud.search('ahn',
+ {hold: this.holdId},
+ {order_by: {ahn: 'notify_time DESC'}}
+ ).pipe(tap(notify => this.notifies.push(notify))).toPromise();
}
getOrgName(id: number) {
showListView() {
this.onShowList.emit();
}
+
+ deleteNote(note: IdlObject) {
+ this.pcrud.remove(note).toPromise()
+ .then(ok => { if (ok) { this.getNotes(); } });
+ }
}