From: Bill Erickson Date: Tue, 10 Jul 2018 16:46:28 +0000 (-0400) Subject: LP#1775466 Marc html view genericized X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=ee882513c6ae6a2ee3351d8e3b259894d2fb13df;p=working%2FEvergreen.git LP#1775466 Marc html view genericized Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/eg2/src/app/share/catalog/marc-html.component.ts b/Open-ILS/src/eg2/src/app/share/catalog/marc-html.component.ts new file mode 100644 index 0000000000..a002e965c6 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/share/catalog/marc-html.component.ts @@ -0,0 +1,88 @@ +import {Component, OnInit, Input, ElementRef} from '@angular/core'; +import {NetService} from '@eg/core/net.service'; +import {OrgService} from '@eg/core/org.service'; +import {AuthService} from '@eg/core/auth.service'; + +@Component({ + selector: 'eg-marc-html', + // view is generated from MARC HTML + template: '' +}) +export class MarcHtmlComponent implements OnInit { + + recId: number; + initDone = false; + + @Input() set recordId(id: number) { + this.recId = id; + // Only force new data collection when recordId() + // is invoked after ngInit() has already run. + if (this.initDone) { + this.collectData(); + } + } + + recType: string; + @Input() set recordType(rtype: string) { + this.recType = rtype; + } + + constructor( + private elm: ElementRef, + private net: NetService, + private auth: AuthService + ) {} + + ngOnInit() { + this.initDone = true; + this.collectData(); + } + + collectData() { + if (!this.recId) { return; } + + let service = 'open-ils.search'; + let method = 'open-ils.search.biblio.record.html'; + + switch (this.recType) { + + case 'authority': + method = 'open-ils.search.authority.to_html'; + break; + + case 'vandelay-authority': + service = 'open-ils.vandelay'; + method = 'open-ils.vandelay.queued_authority_record.html'; + break; + + case 'vandelay-bib': + service = 'open-ils.vandelay'; + method = 'open-ils.vandelay.queued_bib_record.html'; + break; + } + + this.net.request( + service, method, this.auth.token(), this.recId + ).toPromise().then(html => this.injectHtml(html)); + } + + injectHtml(html: string) { + + // Remove embedded labels and actions. + html = html.replace( + /