1 import {Component, Input, ViewEncapsulation} from '@angular/core';
2 import {BibRecordSummary} from '@eg/share/catalog/bib-record.service';
4 /* Display content from a bib summary display field. If highlight
5 * data is avaialble, it will be used in lieu of the plan display string.
7 * <eg-bib-display-field field="title" [summary]="summary"
8 * [usePlaceholder]="true"></eg-bib-display-field>
11 // non-collapsing space
12 const PAD_SPACE = ' '; // U+2007
15 selector: 'eg-bib-display-field',
16 templateUrl: 'bib-display-field.component.html',
17 styleUrls: ['bib-display-field.component.css'],
18 encapsulation: ViewEncapsulation.None // required for search highlighting
20 export class BibDisplayFieldComponent {
22 @Input() summary: BibRecordSummary;
23 @Input() field: string; // display field name
25 // Used to join multi fields
26 @Input() joiner: string;
28 // If true, replace empty values with a non-collapsing space.
29 @Input() usePlaceholder: boolean;
31 // If provided, turn the display value into a link
32 @Input() routerLink: string;
34 // Returns an array of display values which may either be
35 // plain string values or strings with embedded HTML markup
36 // for search results highlighting.
37 getDisplayStrings(): string[] {
38 const replacement = this.usePlaceholder ? PAD_SPACE : '';
40 if (!this.summary) { return [replacement]; }
42 const scrunch = (value) => {
43 if (Array.isArray(value)) {
46 return [value || replacement];
51 this.summary.displayHighlights[this.field] ||
52 this.summary.display[this.field]