]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/catalog/bib-display-field.component.ts
LP1615805 No inputs after submit in patron search (AngularJS)
[Evergreen.git] / Open-ILS / src / eg2 / src / app / share / catalog / bib-display-field.component.ts
1 import {Component, OnInit, Input, ViewEncapsulation} from '@angular/core';
2 import {NetService} from '@eg/core/net.service';
3 import {OrgService} from '@eg/core/org.service';
4 import {AuthService} from '@eg/core/auth.service';
5 import {BibRecordService, BibRecordSummary
6     } from '@eg/share/catalog/bib-record.service';
7
8 /* Display content from a bib summary display field.  If highlight
9  * data is avaialble, it will be used in lieu of the plan display string.
10  *
11  * <eg-bib-display-field field="title" [summary]="summary"
12  *  [usePlaceholder]="true"></eg-bib-display-field>
13  */
14
15 // non-collapsing space
16 const PAD_SPACE = ' '; // U+2007
17
18 @Component({
19   selector: 'eg-bib-display-field',
20   templateUrl: 'bib-display-field.component.html',
21   styleUrls: ['bib-display-field.component.css'],
22   encapsulation: ViewEncapsulation.None // required for search highlighting
23 })
24 export class BibDisplayFieldComponent implements OnInit {
25
26     @Input() summary: BibRecordSummary;
27     @Input() field: string; // display field name
28
29     // Used to join multi fields
30     @Input() joiner: string;
31
32     // If true, replace empty values with a non-collapsing space.
33     @Input() usePlaceholder: boolean;
34
35     constructor() {}
36
37     ngOnInit() {}
38
39     // Returns an array of display values which may either be
40     // plain string values or strings with embedded HTML markup
41     // for search results highlighting.
42     getDisplayStrings(): string[] {
43         const replacement = this.usePlaceholder ? PAD_SPACE : '';
44
45         if (!this.summary) { return [replacement]; }
46
47         const scrunch = (value) => {
48             if (Array.isArray(value)) {
49                 return value;
50             } else {
51                 return [value || replacement];
52             }
53         };
54
55         return scrunch(
56             this.summary.displayHighlights[this.field] ||
57             this.summary.display[this.field]
58         );
59     }
60 }
61
62