1 import {Component, OnInit, Input, Renderer2} from '@angular/core';
2 import {NetService} from '@eg/core/net.service';
3 import {IdlService} from '@eg/core/idl.service';
4 import {EventService} from '@eg/core/event.service';
5 import {ToastService} from '@eg/share/toast/toast.service';
6 import {AuthService} from '@eg/core/auth.service';
7 import {DialogComponent} from '@eg/share/dialog/dialog.component';
8 import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
11 * Dialog for adding bib records to new and existing record buckets.
15 selector: 'eg-record-bucket-dialog',
16 templateUrl: 'record-bucket-dialog.component.html'
19 export class RecordBucketDialogComponent
20 extends DialogComponent implements OnInit {
22 selectedBucket: number;
23 newBucketName: string;
24 newBucketDesc: string;
27 @Input() bucketType: string;
30 @Input() set recordId(id: number) {
34 // Add items from a (vandelay) bib queue to a bucket
36 @Input() set queueId(id: number) {
41 private modal: NgbModal, // required for passing to parent
42 private renderer: Renderer2,
43 private toast: ToastService,
44 private idl: IdlService,
45 private net: NetService,
46 private evt: EventService,
47 private auth: AuthService) {
48 super(modal); // required for subclassing
54 this.bucketType = 'vandelay_queue';
56 this.bucketType = 'staff_client';
59 this.onOpen$.subscribe(ok => {
60 // Reset data on dialog open
62 this.selectedBucket = null;
63 this.newBucketName = '';
64 this.newBucketDesc = '';
68 'open-ils.actor.container.retrieve_by_class.authoritative',
69 this.auth.token(), this.auth.user().id(),
70 'biblio', this.bucketType
71 ).subscribe(buckets => this.buckets = buckets);
76 this.addToBucket(this.selectedBucket);
79 // Create a new bucket then add the record
81 const bucket = this.idl.create('cbreb');
83 bucket.owner(this.auth.user().id());
84 bucket.name(this.newBucketName);
85 bucket.description(this.newBucketDesc);
86 bucket.btype(this.bucketType);
90 'open-ils.actor.container.create',
91 this.auth.token(), 'biblio', bucket
92 ).subscribe(bktId => {
93 const evt = this.evt.parse(bktId);
95 this.toast.danger(evt.desc);
97 // make it find-able to the queue-add method which
98 // requires the bucket name.
100 this.buckets.push(bucket);
102 this.addToBucket(bktId);
107 // Add the record to the selected existing bucket
108 addToBucket(id: number) {
110 this.addRecordToBucket(id);
111 } else if (this.qId) {
112 this.addQueueToBucket(id);
116 addRecordToBucket(bucketId: number) {
117 const item = this.idl.create('cbrebi');
118 item.bucket(bucketId);
119 item.target_biblio_record_entry(this.recId);
122 'open-ils.actor.container.item.create',
123 this.auth.token(), 'biblio', item
124 ).subscribe(resp => {
125 const evt = this.evt.parse(resp);
127 this.toast.danger(evt.toString());
134 addQueueToBucket(bucketId: number) {
135 const bucket = this.buckets.filter(b => b.id() === bucketId)[0];
136 if (!bucket) { return; }
140 'open-ils.vandelay.bib_queue.to_bucket',
141 this.auth.token(), this.qId, bucket.name()
142 ).toPromise().then(resp => {
143 const evt = this.evt.parse(resp);
145 this.toast.danger(evt.toString());