LP1821382 Angular holdings maintenance continued.
[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 {OrgService} from '@eg/core/org.service';
3 import {BibRecordService, BibRecordSummary
4     } from '@eg/share/catalog/bib-record.service';
5 import {ServerStoreService} from '@eg/core/server-store.service';
6
7 @Component({
8   selector: 'eg-bib-summary',
9   templateUrl: 'bib-summary.component.html',
10   styles: ['.eg-bib-summary .card-header {padding: .25rem .5rem}']
11 })
12 export class BibSummaryComponent implements OnInit {
13
14     initDone = false;
15
16     // True / false if the display is vertically expanded
17     private _exp: boolean;
18     set expand(e: boolean) {
19         this._exp = e;
20         if (this.initDone) {
21             this.saveExpandState();
22         }
23     }
24     get expand(): boolean { return this._exp; }
25
26     // If provided, the record will be fetched by the component.
27     @Input() recordId: number;
28
29     // Otherwise, we'll use the provided bib summary object.
30     summary: BibRecordSummary;
31     @Input() set bibSummary(s: any) {
32         this.summary = s;
33         if (this.initDone && this.summary) {
34             this.summary.getBibCallNumber();
35         }
36     }
37
38     constructor(
39         private bib: BibRecordService,
40         private org: OrgService,
41         private store: ServerStoreService
42     ) {}
43
44     ngOnInit() {
45
46         if (this.summary) {
47             this.summary.getBibCallNumber();
48         } else {
49             if (this.recordId) {
50                 this.loadSummary();
51             }
52         }
53
54         this.store.getItem('eg.cat.record.summary.collapse')
55         .then(value => this.expand = !value)
56         .then(() => this.initDone = true);
57     }
58
59     saveExpandState() {
60         this.store.setItem('eg.cat.record.summary.collapse', !this.expand);
61     }
62
63     loadSummary(): void {
64         this.bib.getBibSummary(this.recordId).toPromise()
65         .then(summary => {
66             summary.getBibCallNumber();
67             this.bib.fleshBibUsers([summary.record]);
68             this.summary = summary;
69             console.log(this.summary.display);
70         });
71     }
72
73     orgName(orgId: number): string {
74         if (orgId) {
75             return this.org.get(orgId).shortname();
76         }
77     }
78
79 }
80
81