]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/share/bib-summary/bib-summary.component.ts
78d2653c4725d03d3586e65a6a640a473ece62e1
[working/Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / share / bib-summary / bib-summary.component.ts
1 import {Component, OnInit, Input} from '@angular/core';
2 import {NetService} from '@eg/core/net.service';
3 import {OrgService} from '@eg/core/org.service';
4 import {PcrudService} from '@eg/core/pcrud.service';
5 import {CatalogService} from '@eg/share/catalog/catalog.service';
6 import {BibRecordService, BibRecordSummary} from '@eg/share/catalog/bib-record.service';
7
8 @Component({
9   selector: 'eg-bib-summary',
10   templateUrl: 'bib-summary.component.html',
11   styles: ['.eg-bib-summary .card-header {padding: .25rem .5rem}']
12 })
13 export class BibSummaryComponent implements OnInit {
14
15     initDone = false;
16     expandDisplay = true;
17
18     // If provided, the record will be fetched by the component.
19     @Input() recordId: number;
20
21     // Otherwise, we'll use the provided bib summary object.
22     summary: BibRecordSummary;
23     @Input() set bibSummary(s: any) {
24         this.summary = s;
25         if (this.initDone && this.summary) {
26             this.summary.getBibCallNumber();
27         }
28     }
29
30     constructor(
31         private bib: BibRecordService,
32         private cat: CatalogService,
33         private net: NetService,
34         private org: OrgService,
35         private pcrud: PcrudService
36     ) {}
37
38     ngOnInit() {
39         this.initDone = true;
40         if (this.summary) {
41             this.summary.getBibCallNumber();
42         } else {
43             if (this.recordId) {
44                 this.loadSummary();
45             }
46         }
47     }
48
49     loadSummary(): void {
50         this.bib.getBibSummary(this.recordId).toPromise()
51         .then(summary => {
52             summary.getBibCallNumber();
53             this.bib.fleshBibUsers([summary.record]);
54             this.summary = summary;
55             console.log(this.summary.display);
56         });
57     }
58
59     orgName(orgId: number): string {
60         if (orgId) {
61             return this.org.get(orgId).shortname();
62         }
63     }
64
65 }
66
67