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
54 this.summary.getBibCallNumber();
55 this.loadCourseInformation(this.summary.record.id());
62 this.store.getItem('eg.cat.record.summary.collapse')
63 .then(value => this.expand = !value)
64 .then(() => this.initDone = true);
68 this.store.setItem('eg.cat.record.summary.collapse', !this.expand);
72 this.loadCourseInformation(this.recordId);
73 this.bib.getBibSummary(this.recordId).toPromise()
75 summary.getBibCallNumber();
76 this.summary = summary;
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 this.courses = courseList;
85 this.hasCourse = true;
91 orgName(orgId: number): string {
93 return this.org.get(orgId).shortname();
97 iconFormatLabel(code: string): string {
98 return this.cat.iconFormatLabel(code);