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