From 9aa242d73b32eeb2bdc90ad313fe67d22d1f6233 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 10 Jul 2018 12:46:28 -0400 Subject: [PATCH] LP#1775466 Marc html view genericized Signed-off-by: Bill Erickson --- .../src/app/share/catalog/marc-html.component.ts | 88 ++++++++++++++++++++++ .../eg2/src/app/staff/catalog/catalog.module.ts | 6 +- .../staff/catalog/record/marc-view.component.ts | 63 ---------------- .../app/staff/catalog/record/record.component.html | 2 +- Open-ILS/src/eg2/src/app/staff/common.module.ts | 10 ++- 5 files changed, 98 insertions(+), 71 deletions(-) create mode 100644 Open-ILS/src/eg2/src/app/share/catalog/marc-html.component.ts delete mode 100644 Open-ILS/src/eg2/src/app/staff/catalog/record/marc-view.component.ts 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( + /