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';
10 selector: 'eg-bib-summary',
11 templateUrl: 'bib-summary.component.html',
12 styleUrls: ['bib-summary.component.css']
14 export class BibSummaryComponent implements OnInit {
20 // True / false if the display is vertically expanded
21 private _exp: boolean;
22 set expand(e: boolean) {
25 this.saveExpandState();
28 get expand(): boolean { return this._exp; }
30 // If provided, the record will be fetched by the component.
31 @Input() recordId: number;
33 // Otherwise, we'll use the provided bib summary object.
34 summary: BibRecordSummary;
35 @Input() set bibSummary(s: any) {
37 if (this.initDone && this.summary) {
38 this.summary.getBibCallNumber();
39 this.loadCourseInformation(this.summary.record.id());
44 private bib: BibRecordService,
45 private org: OrgService,
46 private store: ServerStoreService,
47 private cat: CatalogService,
48 private course: CourseService
53 this.store.getItem('eg.cat.record.summary.collapse')
54 .then(value => this.expand = !value)
55 .then(_ => this.cat.fetchCcvms())
58 return this.loadCourseInformation(this.summary.record.id())
59 .then(__ => this.summary.getBibCallNumber());
62 return this.loadSummary();
65 }).then(_ => this.initDone = true);
69 this.store.setItem('eg.cat.record.summary.collapse', !this.expand);
72 loadSummary(): Promise<any> {
73 return this.loadCourseInformation(this.recordId)
75 return this.bib.getBibSummary(this.recordId).toPromise()
77 this.summary = summary;
78 return summary.getBibCallNumber();
83 loadCourseInformation(recordId): Promise<any> {
84 return this.org.settings('circ.course_materials_opt_in')
86 if (setting['circ.course_materials_opt_in']) {
87 this.course.fetchCoursesForRecord(recordId).then(courseList => {
89 this.courses = courseList;
90 this.hasCourse = true;
97 orgName(orgId: number): string {
99 return this.org.get(orgId).shortname();
103 iconFormatLabel(code: string): string {
104 return this.cat.iconFormatLabel(code);