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';
7 selector: 'eg-marc-html',
8 // view is generated from MARC HTML
9 template: '<ng-template></ng-template>'
11 export class MarcHtmlComponent implements OnInit {
16 @Input() set recordId(id: number) {
18 // Only force new data collection when recordId()
19 // is invoked after ngInit() has already run.
26 @Input() set recordType(rtype: string) {
31 private elm: ElementRef,
32 private net: NetService,
33 private auth: AuthService
42 if (!this.recId) { return; }
44 let service = 'open-ils.search';
45 let method = 'open-ils.search.biblio.record.html';
46 const params: any[] = [this.recId];
48 switch (this.recType) {
51 method = 'open-ils.search.authority.to_html';
54 case 'vandelay-authority':
55 params.unshift(this.auth.token());
56 service = 'open-ils.vandelay';
57 method = 'open-ils.vandelay.queued_authority_record.html';
61 params.unshift(this.auth.token());
62 service = 'open-ils.vandelay';
63 method = 'open-ils.vandelay.queued_bib_record.html';
67 this.net.requestWithParamList(service, method, params)
68 .toPromise().then(html => this.injectHtml(html));
71 injectHtml(html: string) {
73 // Remove embedded labels and actions.
75 /<button onclick="window.print(.*?)<\/button>/, '');
77 html = html.replace(/<title>(.*?)<\/title>/, '');
79 // remove reference to nonexistant CSS file
80 html = html.replace(/<link(.*?)\/>/, '');
82 // there shouldn't be any, but while we're at it,
83 // kill any embedded script tags
84 html = html.replace(/<script(.*?)<\/script>/, '');
86 this.elm.nativeElement.innerHTML = html;