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