]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/catalog/bib-display-field.component.ts
LP1915464 follow-up: use spaces, not tabs; remove extra comma
[working/Evergreen.git] / Open-ILS / src / eg2 / src / app / share / catalog / bib-display-field.component.ts
1 import {Component, Input, ViewEncapsulation} from '@angular/core';
2 import {BibRecordSummary} from '@eg/share/catalog/bib-record.service';
3
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.
6  *
7  * <eg-bib-display-field field="title" [summary]="summary"
8  *  [usePlaceholder]="true"></eg-bib-display-field>
9  */
10
11 // non-collapsing space
12 const PAD_SPACE = ' '; // U+2007
13
14 @Component({
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
19 })
20 export class BibDisplayFieldComponent {
21
22     @Input() summary: BibRecordSummary;
23     @Input() field: string; // display field name
24
25     // Used to join multi fields
26     @Input() joiner: string;
27
28     // If true, replace empty values with a non-collapsing space.
29     @Input() usePlaceholder: boolean;
30
31     // If provided, turn the display value into a link
32     @Input() routerLink: string;
33
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 : '';
39
40         if (!this.summary) { return [replacement]; }
41
42         const scrunch = (value) => {
43             if (Array.isArray(value)) {
44                 return value;
45             } else {
46                 return [value || replacement];
47             }
48         };
49
50         return scrunch(
51             this.summary.displayHighlights[this.field] ||
52             this.summary.display[this.field]
53         );
54     }
55 }
56
57