LP#1775466 Marc html view genericized
authorBill Erickson <berickxx@gmail.com>
Tue, 10 Jul 2018 16:46:28 +0000 (12:46 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 11 Jul 2018 14:18:30 +0000 (10:18 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/catalog/marc-html.component.ts [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/catalog/catalog.module.ts
Open-ILS/src/eg2/src/app/staff/catalog/record/marc-view.component.ts [deleted file]
Open-ILS/src/eg2/src/app/staff/catalog/record/record.component.html
Open-ILS/src/eg2/src/app/staff/common.module.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 (file)
index 0000000..a002e96
--- /dev/null
@@ -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: '<ng-template></ng-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(
+            /<button onclick="window.print(.*?)<\/button>/, '');
+
+        html = html.replace(/<title>(.*?)<\/title>/, '');
+
+        // remove reference to nonexistant CSS file
+        html = html.replace(/<link(.*?)\/>/, '');
+
+        // there shouldn't be any, but while we're at it, 
+        // kill any embedded script tags
+        html = html.replace(/<script(.*?)<\/script>/, '');
+
+        this.elm.nativeElement.innerHTML = html;
+    }
+}
+
+
index b2aa894..ca8aa48 100644 (file)
@@ -18,8 +18,6 @@ import {ResultRecordComponent} from './result/record.component';
 import {StaffCatalogService} from './catalog.service';
 import {RecordPaginationComponent} from './record/pagination.component';
 import {RecordActionsComponent} from './record/actions.component';
-import {MarcViewComponent} from './record/marc-view.component';
-import {RecordBucketDialogComponent} from '@eg/staff/share/buckets/record-bucket-dialog.component';
 import {HoldingsService} from '@eg/staff/share/holdings.service';
 
 @NgModule({
@@ -34,9 +32,7 @@ import {HoldingsService} from '@eg/staff/share/holdings.service';
     ResultFacetsComponent,
     ResultPaginationComponent,
     RecordPaginationComponent,
-    RecordActionsComponent,
-    MarcViewComponent,
-    RecordBucketDialogComponent
+    RecordActionsComponent
   ],
   imports: [
     StaffCommonModule,
diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/record/marc-view.component.ts b/Open-ILS/src/eg2/src/app/staff/catalog/record/marc-view.component.ts
deleted file mode 100644 (file)
index ca6e415..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-import {Component, OnInit, Input, ElementRef} from '@angular/core';
-import {NetService} from '@eg/core/net.service';
-import {StaffCatalogService} from '../catalog.service';
-import {OrgService} from '@eg/core/org.service';
-
-@Component({
-  selector: 'eg-catalog-marc-view',
-  // bulk of display is generated from MARC HTML
-  template: '<div class="w-100"></div>'
-})
-export class MarcViewComponent 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();
-        }
-    }
-
-    constructor(
-        private elm: ElementRef,
-        private net: NetService,
-        private staffCat: StaffCatalogService
-    ) {}
-
-    ngOnInit() {
-        this.initDone = true;
-        this.collectData();
-    }
-
-    collectData() {
-        if (!this.recId) { return; }
-        this.fetchMarcHtml();
-    }
-
-    fetchMarcHtml() {
-        this.net.request(
-            'open-ils.search',
-            'open-ils.search.biblio.record.html',
-            this.recId, false
-
-        ).subscribe(html => {
-
-            // Remove those pesky non-i8n labels / actions.
-            // Note: for printing, use the browser print page
-            // option.  The end result is the same.
-            html = html.replace(
-                /<button onclick="window.print(.*?)<\/button>/, '');
-            html = html.replace(/<title>(.*?)<\/title>/, '');
-
-            // remove reference to nonexistant CSS file
-            html = html.replace(/<link(.*?)\/>/, '');
-            this.elm.nativeElement.innerHTML = html;
-        });
-    }
-}
-
-
index f2b1ee4..4c74316 100644 (file)
@@ -27,7 +27,7 @@
       </ngb-tab>
       <ngb-tab title="MARC View" i18n-title id="marc_view">
         <ng-template ngbTabContent>
-          <eg-catalog-marc-view [recordId]="recordId"></eg-catalog-marc-view>
+          <eg-marc-html [recordId]="recordId" recordType="bib"></eg-marc-html>
         </ng-template>
       </ngb-tab>
     </ngb-tabset>
index da3bc32..02bb078 100644 (file)
@@ -15,6 +15,8 @@ import {StringComponent} from '@eg/share/string/string.component';
 import {StringService} from '@eg/share/string/string.service';
 import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component';
 import {DateSelectComponent} from '@eg/share/date-select/date-select.component';
+import {RecordBucketDialogComponent} from '@eg/staff/share/buckets/record-bucket-dialog.component';
+import {MarcHtmlComponent} from '@eg/share/catalog/marc-html.component';
 
 /**
  * Imports the EG common modules and adds modules common to all staff UI's.
@@ -32,7 +34,9 @@ import {DateSelectComponent} from '@eg/share/date-select/date-select.component';
     StringComponent,
     OpChangeComponent,
     FmRecordEditorComponent,
-    DateSelectComponent
+    DateSelectComponent,
+    RecordBucketDialogComponent,
+    MarcHtmlComponent
   ],
   imports: [
     EgCommonModule
@@ -49,7 +53,9 @@ import {DateSelectComponent} from '@eg/share/date-select/date-select.component';
     StringComponent,
     OpChangeComponent,
     FmRecordEditorComponent,
-    DateSelectComponent
+    DateSelectComponent,
+    RecordBucketDialogComponent,
+    MarcHtmlComponent
   ]
 })