]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/catalog/marc-html.component.ts
LP#1775466 Angular(6) base application
[Evergreen.git] / Open-ILS / src / eg2 / src / app / share / catalog / marc-html.component.ts
1 import {Component, OnInit, Input, ElementRef} 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
6 @Component({
7   selector: 'eg-marc-html',
8   // view is generated from MARC HTML
9   template: '<ng-template></ng-template>'
10 })
11 export class MarcHtmlComponent implements OnInit {
12
13     recId: number;
14     initDone = false;
15
16     @Input() set recordId(id: number) {
17         this.recId = id;
18         // Only force new data collection when recordId()
19         // is invoked after ngInit() has already run.
20         if (this.initDone) {
21             this.collectData();
22         }
23     }
24
25     recType: string;
26     @Input() set recordType(rtype: string) {
27         this.recType = rtype;
28     }
29
30     constructor(
31         private elm: ElementRef,
32         private net: NetService,
33         private auth: AuthService
34     ) {}
35
36     ngOnInit() {
37         this.initDone = true;
38         this.collectData();
39     }
40
41     collectData() {
42         if (!this.recId) { return; }
43
44         let service = 'open-ils.search';
45         let method = 'open-ils.search.biblio.record.html';
46         const params: any[] = [this.recId];
47
48         switch (this.recType) {
49
50             case 'authority':
51                 method = 'open-ils.search.authority.to_html';
52                 break;
53
54             case 'vandelay-authority':
55                 params.unshift(this.auth.token());
56                 service = 'open-ils.vandelay';
57                 method = 'open-ils.vandelay.queued_authority_record.html';
58                 break;
59
60             case 'vandelay-bib':
61                 params.unshift(this.auth.token());
62                 service = 'open-ils.vandelay';
63                 method = 'open-ils.vandelay.queued_bib_record.html';
64                 break;
65         }
66
67         this.net.requestWithParamList(service, method, params)
68         .toPromise().then(html => this.injectHtml(html));
69     }
70
71     injectHtml(html: string) {
72
73         // Remove embedded labels and actions.
74         html = html.replace(
75             /<button onclick="window.print(.*?)<\/button>/, '');
76
77         html = html.replace(/<title>(.*?)<\/title>/, '');
78
79         // remove reference to nonexistant CSS file
80         html = html.replace(/<link(.*?)\/>/, '');
81
82         // there shouldn't be any, but while we're at it,
83         // kill any embedded script tags
84         html = html.replace(/<script(.*?)<\/script>/, '');
85
86         this.elm.nativeElement.innerHTML = html;
87     }
88 }
89
90